Initial rough

This commit is contained in:
2020-03-05 13:56:57 +08:00
commit aeffbeac64

27
smart.py Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/python3
import base64
import sys
import fileinput
import os
import email
archiveDir = '/var/www/html/reports/'
rawEmail = sys.stdin.read().decode('utf-8')
emailObject = email.message_from_string(rawEmail)
for part in emailObject.walk():
if part.get_content_maintype() =='multipart':
continue
if part.get('Content-Disposition') is None:
continue
fileName = part.get_filename()
if bool(fileName):
filePath = os.path.join(archiveDir, fileName)
if not os.path.isfile(filePath):
fp = open(filePath, 'wb')
fp.write(part.get_payload(decode=True))
fp.close()