Skip to content

Commit

Permalink
better debug and updated attachment handling
Browse files Browse the repository at this point in the history
  • Loading branch information
geek-at committed Nov 19, 2023
1 parent 02b4167 commit 4fc5478
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions python/mailserver3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ async def handle_DATA(self, server, session, envelope):
html = ''
attachments = {}
for part in message.walk():
if part.get_content_maintype() == 'multipart':
continue
print ("aktueller part ist vom typ",part.get_content_type())
if part.get_content_type() == 'text/plain':
plaintext += part.get_payload()
elif part.get_content_type() == 'text/html':
html += part.get_payload()
else:
print("!!!attachment found!!!")
filename = part.get_filename()
if filename is None:
filename = 'untitled'
attachments['file%d' % len(attachments)] = (filename,part.get_payload(decode=True))

# Save attachments
for part in message.iter_attachments():
filename = part.get_filename()
if filename is None:
filename = 'untitled'
attachments['file%d' % len(attachments)] = (filename,part.get_payload(decode=True))
print(attachments)

edata = {
'subject': message['subject'],
Expand Down Expand Up @@ -123,8 +127,8 @@ def cleanup():
async def run(port):
controller = Controller(CustomHandler(), hostname='0.0.0.0', port=port)
controller.start()
print("[i] Ready to receive Emails")
print("")
logger.info("[i] Ready to receive Emails")
logger.info("")

try:
while True:
Expand All @@ -141,22 +145,21 @@ async def run(port):
logger.addHandler(ch)

if not os.path.isfile("../config.ini"):
print("[ERR] Config.ini not found. Rename example.config.ini to config.ini. Defaulting to port 25")
logger.info("[ERR] Config.ini not found. Rename example.config.ini to config.ini. Defaulting to port 25")
port = 25
else :
else:
Config = configparser.ConfigParser(allow_no_value=True)
Config.read("../config.ini")
port = int(Config.get("MAILSERVER","MAILPORT"))
port = int(Config.get("MAILSERVER", "MAILPORT"))
if("discard_unknown" in Config.options("MAILSERVER")):
DISCARD_UNKNOWN = (Config.get("MAILSERVER","DISCARD_UNKNOWN").lower() == "true")
DOMAINS = Config.get("GENERAL","DOMAINS").lower().split(",")
DISCARD_UNKNOWN = (Config.get("MAILSERVER", "DISCARD_UNKNOWN").lower() == "true")
DOMAINS = Config.get("GENERAL", "DOMAINS").lower().split(",")

if("CLEANUP" in Config.sections() and "delete_older_than_days" in Config.options("CLEANUP")):
DELETE_OLDER_THAN_DAYS = (Config.get("CLEANUP","DELETE_OLDER_THAN_DAYS").lower() == "true")
DELETE_OLDER_THAN_DAYS = (Config.get("CLEANUP", "DELETE_OLDER_THAN_DAYS").lower() == "true")

print("[i] Starting Mailserver on port",port)
print("[i] Discard unknown domains:",DISCARD_UNKNOWN)
print("[i] Listening for domains:",DOMAINS)

logger.info("[i] Starting Mailserver on port " + str(port))
logger.info("[i] Discard unknown domains: " + str(DISCARD_UNKNOWN))
logger.info("[i] Listening for domains: " + str(DOMAINS))

asyncio.run(run(port))

0 comments on commit 4fc5478

Please sign in to comment.