adding required argument message_from_binary_file (#43)
* adding required argument message_from_binary_file message_from_binary_file now has a required argument `policy` https://docs.python.org/3/library/email.parser.html#email.message_from_binary_file In a future version a default will be added, but as of now, calling message_from_binary_file without policy will throw an error and not work https://docs.python.org/3/library/email.parser.html#email.parser.BytesFeedParser Also added some code to show how to iterate through attachments and how to get attachment filename, type, extension, attachment data and attachment object * Update template.py
This commit is contained in:
+13
-1
@@ -16,6 +16,9 @@ except:
|
||||
from io import BytesIO
|
||||
import time
|
||||
import email
|
||||
from email import message_from_binary_file
|
||||
from email import policy
|
||||
import mimetypes
|
||||
import os
|
||||
import sys
|
||||
from socket import AF_INET, AF_INET6
|
||||
@@ -114,7 +117,16 @@ class myMilter(Milter.Base):
|
||||
|
||||
def eom(self):
|
||||
self.fp.seek(0)
|
||||
msg = email.message_from_binary_file(self.fp)
|
||||
msg = email.message_from_binary_file(self.fp, policy=policy.default)
|
||||
|
||||
#example on how to iterate through attachments
|
||||
for attachment in msg.iter_attachments():
|
||||
#attachment holds the attachment object so that it can be used with a new MIMEMultipart() message
|
||||
self.log("Attachment filename is %s" % (attachment.get_filename(),))
|
||||
self.log("Attachment content/type is %s" % (attachment.get_content_type(),))
|
||||
data = attachment.get_content()
|
||||
self.log("Attachment content is %s" % (data,))
|
||||
|
||||
# many milter functions can only be called from eom()
|
||||
# example of adding a Bcc:
|
||||
self.addrcpt('<%s>' % 'spy@example.com')
|
||||
|
||||
Reference in New Issue
Block a user