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"
|
description="Generate SMTP messages to send a mail"
|
||||||
)
|
)
|
||||||
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now(tz=datetime.UTC).astimezone()
|
||||||
now_email = email.utils.formatdate(now.timestamp(), True)
|
now_email = email.utils.formatdate(now.timestamp(), localtime=True)
|
||||||
|
|
||||||
parser.add_argument("-o", "--origin", env_var="ORIGIN", default="localhost")
|
parser.add_argument("-o", "--origin", env_var="ORIGIN", default="localhost")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -89,7 +89,7 @@ if __name__ == "__main__":
|
||||||
args.reply_to = getattr(args, "from")
|
args.reply_to = getattr(args, "from")
|
||||||
if args.password:
|
if args.password:
|
||||||
password = args.password
|
password = args.password
|
||||||
args.password = "********"
|
args.password = "********" # noqa: S105
|
||||||
mid = email.utils.make_msgid(domain=args.helo)
|
mid = email.utils.make_msgid(domain=args.helo)
|
||||||
|
|
||||||
# Transmission content
|
# Transmission content
|
||||||
|
@ -109,7 +109,7 @@ XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"""
|
||||||
body = f"\n\n{args.body}"
|
body = f"\n\n{args.body}"
|
||||||
|
|
||||||
text = f"""Date: {now_email}
|
text = f"""Date: {now_email}
|
||||||
From: {args.me} <{getattr(args, 'from')}>
|
From: {args.me} <{getattr(args, "from")}>
|
||||||
Subject: {args.subject}
|
Subject: {args.subject}
|
||||||
To: {args.to}
|
To: {args.to}
|
||||||
Reply-To: {args.reply_to}
|
Reply-To: {args.reply_to}
|
||||||
|
@ -127,7 +127,7 @@ Input arguments:
|
||||||
|
|
||||||
--
|
--
|
||||||
{args.me}
|
{args.me}
|
||||||
."""
|
.""" # noqa: W291
|
||||||
|
|
||||||
# Transmission setup
|
# Transmission setup
|
||||||
cmd = []
|
cmd = []
|
||||||
|
@ -160,24 +160,27 @@ Input arguments:
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SMTP_ERROR_CODES_START = 400
|
||||||
|
|
||||||
def recv() -> None:
|
def recv() -> None:
|
||||||
if args.dryrun:
|
if args.dryrun:
|
||||||
return
|
return
|
||||||
|
|
||||||
assert isinstance(p.stdout, io.BufferedReader)
|
assert isinstance(p.stdout, io.BufferedReader)
|
||||||
next = True
|
more = True
|
||||||
while next:
|
while more:
|
||||||
line = p.stdout.readline()
|
line = p.stdout.readline()
|
||||||
try:
|
try:
|
||||||
code = int(line[:3])
|
code = int(line[:3])
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
raise ValueError(f"Could not parse line: '{line.decode()}'")
|
msg = f"Could not parse line: '{line.decode()}'"
|
||||||
success = code < 400
|
raise ValueError(msg) from err
|
||||||
|
success = code < SMTP_ERROR_CODES_START
|
||||||
color = colorama.Fore.GREEN if success else colorama.Fore.RED
|
color = colorama.Fore.GREEN if success else colorama.Fore.RED
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print(color + f"< {line[:-1].decode()}" + colorama.Fore.RESET)
|
print(color + f"< {line[:-1].decode()}" + colorama.Fore.RESET)
|
||||||
next = line[3] == b"-"[0]
|
more = line[3] == b"-"[0]
|
||||||
if not next and not success:
|
if not more and not success:
|
||||||
send("QUIT") # TODO Can loop if QUIT fails
|
send("QUIT") # TODO Can loop if QUIT fails
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue