commit aeffbeac643e2e0b014e5c7fb3f4ae80c2e8d871 Author: Adrian Woodley Date: Thu Mar 5 13:56:57 2020 +0800 Initial rough diff --git a/smart.py b/smart.py new file mode 100644 index 0000000..b5db4ee --- /dev/null +++ b/smart.py @@ -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() \ No newline at end of file