~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/email_message.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-20 14:42:48 UTC
  • mto: This revision was merged to the branch mainline in revision 2641.
  • Revision ID: john@arbash-meinel.com-20070720144248-6qltqb2tkm9x49lw
Some cleanups for the EmailMessage class.
Remove self._msgobj as it can lead to reporting incorrect cached data.
Update tests for changes in python2.5, adding similar strings
into a dictionary, with one being unicode and the other string
causes a UnicodeWarning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        self._headers = {}
58
58
        self._body = body
59
59
        self._parts = []
60
 
        self._msgobj = None
61
60
 
62
61
        if isinstance(to_address, basestring):
63
62
            to_address = [ to_address ]
93
92
            self._body = None
94
93
 
95
94
        self._parts.append((body, filename, mime_subtype))
96
 
        self._msgobj = None
97
95
 
98
96
    def as_string(self, boundary=None):
99
97
        """Return the entire formatted message as a string.
101
99
        :param boundary: The boundary to use between MIME parts, if applicable.
102
100
            Used for tests.
103
101
        """
104
 
        if self._msgobj is not None:
105
 
            return self._msgobj.as_string()
106
 
 
107
102
        if not self._parts:
108
 
            self._msgobj = Message.Message()
 
103
            msgobj = Message.Message()
109
104
            if self._body is not None:
110
105
                body, encoding = self.string_with_encoding(self._body)
111
 
                self._msgobj.set_payload(body, encoding)
 
106
                msgobj.set_payload(body, encoding)
112
107
        else:
113
 
            self._msgobj = MIMEMultipart.MIMEMultipart()
 
108
            msgobj = MIMEMultipart.MIMEMultipart()
114
109
 
115
110
            if boundary is not None:
116
 
                self._msgobj.set_boundary(boundary)
 
111
                msgobj.set_boundary(boundary)
117
112
 
118
113
            for body, filename, mime_subtype in self._parts:
119
114
                body, encoding = self.string_with_encoding(body)
125
120
                    payload.replace_header('Content-Type', content_type)
126
121
 
127
122
                payload['Content-Disposition'] = 'inline'
128
 
                self._msgobj.attach(payload)
 
123
                msgobj.attach(payload)
129
124
 
130
125
        # sort headers here to ease testing
131
126
        for header, value in sorted(self._headers.items()):
132
 
            self._msgobj[header] = value
 
127
            msgobj[header] = value
133
128
 
134
 
        return self._msgobj.as_string()
 
129
        return msgobj.as_string()
135
130
 
136
131
    __str__ = as_string
137
132