Commit 1baea3d3 authored by Kevin Deldycke's avatar Kevin Deldycke

Add an exemple of iso/quoted-printable encoded header field.

uuencode is not a standard encoding for mail.
Comment out code that support attachments because not well tested yet.
Fix bugs to handle well encoding of incoming mails.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6406 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 09c0b37d
...@@ -40,7 +40,8 @@ import smtplib ...@@ -40,7 +40,8 @@ import smtplib
from zLOG import LOG from zLOG import LOG
# TODO: support "from"/"to" field header QP decoding # TODO: support "from"/"to" field header QP decoding exemple:
# =?iso-8859-15?q?K=E9vin=20De?= <kevin.de@machin.com>
# Support mail decoding in both python v2.3 and v2.4. # Support mail decoding in both python v2.3 and v2.4.
# See http://www.freesoft.org/CIE/RFC/1521/5.htm for 'content-transfer-encoding' explaination. # See http://www.freesoft.org/CIE/RFC/1521/5.htm for 'content-transfer-encoding' explaination.
...@@ -54,7 +55,6 @@ try: ...@@ -54,7 +55,6 @@ try:
, 'base32' : base64.b32decode , 'base32' : base64.b32decode
, 'base16' : base64.b16decode , 'base16' : base64.b16decode
# , 'quoted-printable': None # , 'quoted-printable': None
# , 'uuencode' : None
# "8bit", "7bit", and "binary" values all mean that NO encoding has been performed # "8bit", "7bit", and "binary" values all mean that NO encoding has been performed
, '8bit' : None , '8bit' : None
, '7bit' : None , '7bit' : None
...@@ -66,7 +66,6 @@ except AttributeError: ...@@ -66,7 +66,6 @@ except AttributeError:
supported_decoding = { supported_decoding = {
'base64' : base64.decodestring 'base64' : base64.decodestring
, 'quoted-printable': binascii.a2b_qp , 'quoted-printable': binascii.a2b_qp
# , 'uuencode' : None
# "8bit", "7bit", and "binary" values all mean that NO encoding has been performed # "8bit", "7bit", and "binary" values all mean that NO encoding has been performed
, '8bit' : None , '8bit' : None
, '7bit' : None , '7bit' : None
...@@ -98,34 +97,25 @@ class MailMessage(XMLObject, Event, CMFMailInMessage): ...@@ -98,34 +97,25 @@ class MailMessage(XMLObject, Event, CMFMailInMessage):
, PropertySheet.MailMessage , PropertySheet.MailMessage
) )
def __init__(self, *args, **kw): ####### TODO: support attachments !!!!
XMLObject.__init__(self, *args, **kw) # def __init__(self, *args, **kw):
# Save attachments in a special variable # XMLObject.__init__(self, *args, **kw)
attachments = kw.get('attachments', {}) # # Save attachments in a special variable
if kw.has_key('attachments'): # attachments = kw.get('attachments', {})
del kw['attachments'] # if kw.has_key('attachments'):
self.attachments = attachments # del kw['attachments']
# Clean up the the message data that came from the portal_mailin tool. # self.attachments = attachments
self.cleanMessage(**kw)
def _edit(self, *args, **kw): def _edit(self, *args, **kw):
XMLObject._edit(self, *args, **kw) XMLObject._edit(self, *args, **kw)
# Input body is already clean because it came from ERP5 GUI self.cleanMessage()
self.cleanMessage(clean_body=True, **kw)
def cleanMessage(self, clean_body=False, **kw): def cleanMessage(self):
""" """
Clean up the the message data to have UTF-8 encoded body and a clean header. Clean up the the message data to have UTF-8 encoded body and a clean header.
""" """
# Get a decoded body in UTF-8
if clean_body == True:
# Assume that the inputted charset is always UTF-8 and decoded
new_body = kw['body']
else:
# Autodetect the charset encoding via header and get a clean body
new_body = self.getBody()
# Update the body to the clean one # Update the body to the clean one
self.body = new_body self.body = self.getBody()
# Update the charset and the encoding since the body is known has 'cleaned' # Update the charset and the encoding since the body is known has 'cleaned'
header = self.getHeader() header = self.getHeader()
if header != None: if header != None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment