~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/mail/sendmail.py

  • Committer: Jelmer Vernooij
  • Date: 2011-10-12 01:00:11 UTC
  • mfrom: (14133 devel)
  • mto: This revision was merged to the branch mainline in revision 14141.
  • Revision ID: jelmer@canonical.com-20111012010011-1hqgg5b30ciywbsa
MergeĀ lp:launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
216
216
        self.attachments = []
217
217
 
218
218
    def addAttachment(self, content, content_type='application/octet-stream',
219
 
                      inline=False, filename=None):
 
219
                      inline=False, filename=None, charset=None):
220
220
        attachment = Message()
221
 
        attachment.set_payload(content)
222
 
        attachment['Content-type'] = content_type
 
221
        if charset and isinstance(content, unicode):
 
222
            content = content.encode(charset)
 
223
        attachment.add_header('Content-Type', content_type)
223
224
        if inline:
224
225
            disposition = 'inline'
225
226
        else:
229
230
            disposition_kwargs['filename'] = filename
230
231
        attachment.add_header(
231
232
            'Content-Disposition', disposition, **disposition_kwargs)
 
233
        attachment.set_payload(content, charset)
232
234
        self.encodeOptimally(attachment)
233
235
        self.attachments.append(attachment)
234
236
 
248
250
        :param exact: If True, the encoding will ensure newlines are not
249
251
            mangled.  If False, 7-bit attachments will not be encoded.
250
252
        """
 
253
        # If encoding has already been done by virtue of a charset being
 
254
        # previously specified, then do nothing.
 
255
        if 'Content-Transfer-Encoding' in part:
 
256
            return
251
257
        orig_payload = part.get_payload()
252
258
        if not exact and is_ascii_only(orig_payload):
253
259
            return