~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smtp_connection.py

  • Committer: Adeodato Simó
  • Date: 2007-07-18 15:51:52 UTC
  • mto: (2639.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2640.
  • Revision ID: dato@net.com.org.es-20070718155152-pv6rwq41eckqyxem
New EmailMessage class, façade around email.Message and MIMEMultipart.

* bzrlib/email_message.py,
  bzrlib/tests/test_email_message.py:
  New files.

* bzrlib/tests/__init__.py:
  (test_suite): add bzrlib.tests.test_email_message.

* bzrlib/merge_directive.py:
  (MergeDirective.to_email): Use EmailMessage instead of email.Message.

* bzrlib/tests/test_merge_directive.py,
  bzrlib/tests/blackbox/test_merge_directive.py:
  (__main__): adjust EMAIL1 and EMAIL2 strings to how EmailMessage
  formats itself.

* bzrlib/smtp_connection.py:
  (SMTPConnection.get_message_addresses): do not use methods present in
  email.Message but not in EmailMessage (get_all). Use get() instead of
  __getitem__ to make explicit that None is returned if the header does
  not exist.

* bzrlib/tests/test_smtp_connection.py:
  (TestSMTPConnection.test_get_message_addresses, 
   TestSMTPConnection.test_destination_address_required): test the
   functions against EmailMessage in addition to email.Message.

* NEWS:
  Mention EmailMessage in INTERNALS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    def get_message_addresses(message):
80
80
        """Get the origin and destination addresses of a message.
81
81
 
82
 
        :param message: An email.Message or email.MIMEMultipart object.
 
82
        :param message: A message object supporting get() to access its
 
83
            headers, like email.Message or bzrlib.email_message.EmailMessage.
83
84
        :return: A pair (from_email, to_emails), where from_email is the email
84
85
            address in the From header, and to_emails a list of all the
85
86
            addresses in the To, Cc, and Bcc headers.
86
87
        """
87
 
        from_email = Utils.parseaddr(message['From'])[1]
 
88
        from_email = Utils.parseaddr(message.get('From', None))[1]
88
89
        to_full_addresses = []
89
90
        for header in ['To', 'Cc', 'Bcc']:
90
 
            to_full_addresses += message.get_all(header, [])
 
91
            value = message.get(header, None)
 
92
            if value:
 
93
                to_full_addresses.append(value)
91
94
        to_emails = [ pair[1] for pair in
92
95
                Utils.getaddresses(to_full_addresses) ]
93
96