26 lines
597 B
Python
26 lines
597 B
Python
#!/usr/bin/python3
|
|
import sys
|
|
import os
|
|
import email
|
|
|
|
archiveDir = '/var/www/html/'
|
|
|
|
rawEmail = sys.stdin.read()
|
|
|
|
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()
|