Commit 6511eab7 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

mixin/mail_message: more robust algorythm to choose the first preferred text format part.

parent c916c06f
...@@ -84,29 +84,28 @@ class MailMessageMixin: ...@@ -84,29 +84,28 @@ class MailMessageMixin:
Based on rfc: http://tools.ietf.org/html/rfc2046#section-5.1.4) Based on rfc: http://tools.ietf.org/html/rfc2046#section-5.1.4)
""" """
# Default value if no text is found
found_part = None
part_list = [self._getMessage()] part_list = [self._getMessage()]
found_part_list = []
preferred_content_type = self.getPortalObject().portal_preferences.getPreferredTextFormat('text/html')
while part_list: while part_list:
part = part_list.pop(0) part = part_list.pop(0)
if part.is_multipart(): if part.is_multipart():
if part.get_content_subtype() == 'alternative': if part.get_content_subtype() in ('alternative', 'mixed', 'related'):
# Try to get the favourite text format defined on preference # Try to get the favourite text format defined on preference
preferred_content_type = self.getPortalObject().portal_preferences.\ favourite_part = None
getPreferredTextFormat('text/html')
for subpart in part.get_payload(): for subpart in part.get_payload():
if subpart.get_content_type() == preferred_content_type: if subpart.get_content_maintype() == 'text' and not subpart.get_filename():
part_list.insert(0, subpart) if subpart.get_content_type() == preferred_content_type:
found_part_list.insert(0, subpart)
break
elif not found_part_list:
found_part_list.append(subpart)
else: else:
part_list.append(subpart) part_list.extend(part.get_payload())
else:
part_list.extend(part.get_payload())
elif part.get_content_maintype() == 'text': elif part.get_content_maintype() == 'text':
found_part = part found_part_list.append(part)
break if found_part_list:
return found_part_list[0]
return found_part
security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation') security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation')
def getContentInformation(self): def getContentInformation(self):
......
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