smtpdummy: Fix warnings
This commit is contained in:
parent
98165841b1
commit
b6a93b5679
1 changed files with 15 additions and 12 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue