Various smtpdummy fixes

This commit is contained in:
Geoffrey Frogeye 2023-07-23 13:23:28 +02:00
parent eba894d9f4
commit 6a2afb3280
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8

View file

@ -9,7 +9,6 @@ import io
import pprint import pprint
import subprocess import subprocess
import sys import sys
import uuid
if __name__ == "__main__": if __name__ == "__main__":
@ -34,6 +33,7 @@ if __name__ == "__main__":
) )
parser.add_argument("-l", "--helo", env_var="HELO") parser.add_argument("-l", "--helo", env_var="HELO")
parser.add_argument("-L", "--helo-verb", env_var="HELO_VERB", default="EHLO")
parser.add_argument( parser.add_argument(
"-s", "--sender", env_var="SENDER", default="geoffrey@frogeye.fr" "-s", "--sender", env_var="SENDER", default="geoffrey@frogeye.fr"
) )
@ -79,11 +79,11 @@ if __name__ == "__main__":
if args.to is None: if args.to is None:
args.to = args.receiver[0] args.to = args.receiver[0]
if args.reply_to is None: if args.reply_to is None:
args.reply_to = args.to args.reply_to = getattr(args, 'from')
if args.password: if args.password:
password = args.password password = args.password
args.password = "********" args.password = "********"
mid = f"{uuid.uuid1()}@{args.helo}" mid = email.utils.make_msgid(domain=args.helo)
# Transmission content # Transmission content
@ -190,7 +190,7 @@ Input arguments:
if args.security != "starttls": if args.security != "starttls":
recv() recv()
send(f"EHLO {args.helo}") send(f"{args.helo_verb} {args.helo}")
if args.user: if args.user:
encoded = base64.b64encode( encoded = base64.b64encode(
args.user.encode() args.user.encode()
@ -200,9 +200,9 @@ Input arguments:
+ password.encode() + password.encode()
).decode() ).decode()
send(f"AUTH PLAIN {encoded}") send(f"AUTH PLAIN {encoded}")
send(f"MAIL FROM: <{args.sender}>" + (" SMTPUTF8" if args.smtputf8 else "")) send(f"MAIL FROM:<{args.sender}>" + (" SMTPUTF8" if args.smtputf8 else ""))
for receiver in args.receiver: for receiver in args.receiver:
send(f"RCPT TO: <{receiver}>") send(f"RCPT TO:<{receiver}>")
if not args.callout: if not args.callout:
send("DATA") send("DATA")
send(text) send(text)