better debug and updated attachment handling

This commit is contained in:
Chris 2023-11-19 17:12:26 +01:00
parent 02b41673fd
commit 4fc5478078

View file

@ -42,18 +42,22 @@ class CustomHandler:
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()
# Save attachments
for part in message.iter_attachments():
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))
print(attachments)
edata = {
'subject': message['subject'],
'body': plaintext,
@ -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:
@ -141,7 +145,7 @@ if __name__ == '__main__':
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:
Config = configparser.ConfigParser(allow_no_value=True)
@ -154,9 +158,8 @@ if __name__ == '__main__':
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")
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))