From b6a93b5679430a00182b533fe6531e51a448d937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Fri, 27 Jun 2025 21:12:45 +0200 Subject: [PATCH] smtpdummy: Fix warnings --- hm/scripts/smtpdummy | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hm/scripts/smtpdummy b/hm/scripts/smtpdummy index c16e8af..1922cef 100755 --- a/hm/scripts/smtpdummy +++ b/hm/scripts/smtpdummy @@ -19,8 +19,8 @@ if __name__ == "__main__": description="Generate SMTP messages to send a mail" ) - now = datetime.datetime.now() - now_email = email.utils.formatdate(now.timestamp(), True) + now = datetime.datetime.now(tz=datetime.UTC).astimezone() + now_email = email.utils.formatdate(now.timestamp(), localtime=True) parser.add_argument("-o", "--origin", env_var="ORIGIN", default="localhost") parser.add_argument( @@ -89,7 +89,7 @@ if __name__ == "__main__": args.reply_to = getattr(args, "from") if args.password: password = args.password - args.password = "********" + args.password = "********" # noqa: S105 mid = email.utils.make_msgid(domain=args.helo) # Transmission content @@ -109,7 +109,7 @@ XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X""" body = f"\n\n{args.body}" text = f"""Date: {now_email} -From: {args.me} <{getattr(args, 'from')}> +From: {args.me} <{getattr(args, "from")}> Subject: {args.subject} To: {args.to} Reply-To: {args.reply_to} @@ -127,7 +127,7 @@ Input arguments: -- {args.me} -.""" +.""" # noqa: W291 # Transmission setup cmd = [] @@ -160,24 +160,27 @@ Input arguments: stderr=subprocess.DEVNULL, ) + SMTP_ERROR_CODES_START = 400 + def recv() -> None: if args.dryrun: return assert isinstance(p.stdout, io.BufferedReader) - next = True - while next: + more = True + while more: line = p.stdout.readline() try: code = int(line[:3]) - except ValueError: - raise ValueError(f"Could not parse line: '{line.decode()}'") - success = code < 400 + except ValueError as err: + msg = f"Could not parse line: '{line.decode()}'" + raise ValueError(msg) from err + success = code < SMTP_ERROR_CODES_START color = colorama.Fore.GREEN if success else colorama.Fore.RED if not args.quiet: print(color + f"< {line[:-1].decode()}" + colorama.Fore.RESET) - next = line[3] == b"-"[0] - if not next and not success: + more = line[3] == b"-"[0] + if not more and not success: send("QUIT") # TODO Can loop if QUIT fails sys.exit(1)