# HG changeset patch # User Paul Boddie # Date 1509401685 -3600 # Node ID 0d6768d83dd79c23f40e270608abf924bbdaa2b4 # Parent 683059dc2e7bdd2d32cf98ff4048ba9d35c4617e Changed the structure of wrapped messages to employ multipart/alternative and to collect calendar system information into a text part rather than the MIME preamble. diff -r 683059dc2e7b -r 0d6768d83dd7 imiptools/mail.py --- a/imiptools/mail.py Fri Oct 27 22:26:10 2017 +0200 +++ b/imiptools/mail.py Mon Oct 30 23:14:45 2017 +0100 @@ -144,7 +144,7 @@ """ Return a simple summary using details from 'msg' and the given 'parts'. Information messages provided amongst the parts by the handlers will be - merged into the preamble so that mail programs will show them + merged into a single text part so that mail programs will show them immediately. """ @@ -157,12 +157,16 @@ """ Wrap 'msg' and provide the given 'parts' as the primary content. Information messages provided amongst the parts by the handlers will be - merged into the preamble so that mail programs will show them + merged into a single text part so that mail programs will show them immediately. """ message = self._make_container_for_parts(parts, True) payload = message.get_payload() + + # The original message is placed in a mailbox part for reference, + # attached to the rest of the primary content parts. + payload.append(MIMEMessage(msg)) self._copy_headers(message, msg) return message @@ -193,14 +197,30 @@ else: info = [] - # Insert a preamble message before any calendar information messages. + # Provide a preamble message before any other data. + + preamble = self.preamble_text or \ + self.gettext and self.gettext(PREAMBLE_TEXT) or PREAMBLE_TEXT + + # Provide a mixture of aggregated message parts. + + message = parts and MIMEMultipart("mixed", _subparts=parts) or None + + # Provide an informational message using the aggregated information. - info.insert(0, self.preamble_text or - self.gettext and self.gettext(PREAMBLE_TEXT) or PREAMBLE_TEXT) + info_message = info and MIMEText("\n\n".join(info)) or None + + # Wrap the information and message parts. - message = MIMEMultipart("mixed", _subparts=parts) - message.preamble = "\n\n".join(info) - return message + subparts = [] + if info_message: + subparts.append(info_message) + if message: + subparts.append(message) + + top = MIMEMultipart("alternative", _subparts=subparts) + top.preamble = preamble + return top def _merge_calendar_info_parts(self, parts):