better debug and updated attachment handling
This commit is contained in:
parent
02b41673fd
commit
4fc5478078
|
@ -42,17 +42,21 @@ class CustomHandler:
|
||||||
html = ''
|
html = ''
|
||||||
attachments = {}
|
attachments = {}
|
||||||
for part in message.walk():
|
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':
|
if part.get_content_type() == 'text/plain':
|
||||||
plaintext += part.get_payload()
|
plaintext += part.get_payload()
|
||||||
elif part.get_content_type() == 'text/html':
|
elif part.get_content_type() == 'text/html':
|
||||||
html += part.get_payload()
|
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
|
print(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))
|
|
||||||
|
|
||||||
edata = {
|
edata = {
|
||||||
'subject': message['subject'],
|
'subject': message['subject'],
|
||||||
|
@ -123,8 +127,8 @@ def cleanup():
|
||||||
async def run(port):
|
async def run(port):
|
||||||
controller = Controller(CustomHandler(), hostname='0.0.0.0', port=port)
|
controller = Controller(CustomHandler(), hostname='0.0.0.0', port=port)
|
||||||
controller.start()
|
controller.start()
|
||||||
print("[i] Ready to receive Emails")
|
logger.info("[i] Ready to receive Emails")
|
||||||
print("")
|
logger.info("")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -141,22 +145,21 @@ if __name__ == '__main__':
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
|
|
||||||
if not os.path.isfile("../config.ini"):
|
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
|
port = 25
|
||||||
else :
|
else:
|
||||||
Config = configparser.ConfigParser(allow_no_value=True)
|
Config = configparser.ConfigParser(allow_no_value=True)
|
||||||
Config.read("../config.ini")
|
Config.read("../config.ini")
|
||||||
port = int(Config.get("MAILSERVER","MAILPORT"))
|
port = int(Config.get("MAILSERVER", "MAILPORT"))
|
||||||
if("discard_unknown" in Config.options("MAILSERVER")):
|
if("discard_unknown" in Config.options("MAILSERVER")):
|
||||||
DISCARD_UNKNOWN = (Config.get("MAILSERVER","DISCARD_UNKNOWN").lower() == "true")
|
DISCARD_UNKNOWN = (Config.get("MAILSERVER", "DISCARD_UNKNOWN").lower() == "true")
|
||||||
DOMAINS = Config.get("GENERAL","DOMAINS").lower().split(",")
|
DOMAINS = Config.get("GENERAL", "DOMAINS").lower().split(",")
|
||||||
|
|
||||||
if("CLEANUP" in Config.sections() and "delete_older_than_days" in Config.options("CLEANUP")):
|
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)
|
logger.info("[i] Starting Mailserver on port " + str(port))
|
||||||
print("[i] Discard unknown domains:",DISCARD_UNKNOWN)
|
logger.info("[i] Discard unknown domains: " + str(DISCARD_UNKNOWN))
|
||||||
print("[i] Listening for domains:",DOMAINS)
|
logger.info("[i] Listening for domains: " + str(DOMAINS))
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(run(port))
|
asyncio.run(run(port))
|
||||||
|
|
Loading…
Reference in a new issue