~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Barry Warsaw
  • Date: 2009-06-04 19:25:38 UTC
  • mto: This revision was merged to the branch mainline in revision 4409.
  • Revision ID: barry@python.org-20090604192538-tac3fs21cihfvjqp
Much simpler approach to support From: in Claws, after discussion with
abentley.  This does not try to add the support to every mail client.

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
                      extension, **kwargs)
156
156
 
157
157
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
158
 
                extension, body=None):
 
158
                 extension, body=None, from_=None):
159
159
        """Invoke a mail client as a commandline process.
160
160
 
161
161
        Overridden by MAPIClient.
166
166
            "text", but the precise subtype can be specified here
167
167
        :param extension: A file extension (including period) associated with
168
168
            the attachment type.
 
169
        :param body: Optional body text.
 
170
        :param from_: Optional From: header.
169
171
        """
170
172
        for name in self._get_client_commands():
171
173
            cmdline = [self._encode_path(name, 'executable')]
173
175
                kwargs = {'body': body}
174
176
            else:
175
177
                kwargs = {}
 
178
            if from_ is not None:
 
179
                kwargs['from_'] = from_
176
180
            cmdline.extend(self._get_compose_commandline(to, subject,
177
181
                                                         attach_path,
178
182
                                                         **kwargs))
335
339
 
336
340
    _client_commands = ['claws-mail']
337
341
 
338
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
 
342
    def _get_compose_commandline(self, to, subject, attach_path, body=None,
 
343
                                 from_=None):
339
344
        """See ExternalMailClient._get_compose_commandline"""
340
345
        compose_url = []
341
 
        email = self.config.get_user_option('email')
342
 
        if email is not None:
343
 
            compose_url.append('from=' + urllib.quote(email))
 
346
        if from_ is not None:
 
347
            compose_url.append('from=' + urllib.quote(from_))
344
348
        if subject is not None:
345
349
            # Don't use urllib.quote_plus because Claws doesn't seem
346
350
            # to recognise spaces encoded as "+".
360
364
            message_options.extend(
361
365
                ['--attach', self._encode_path(attach_path, 'attachment')])
362
366
        return message_options
 
367
 
 
368
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
 
369
                 extension, body=None, from_=None):
 
370
        """See ExternalMailClient._compose"""
 
371
        if from_ is None:
 
372
            from_ = self.config.get_user_option('email')
 
373
        super(Claws, self)._compose(prompt, to, subject, attach_path,
 
374
                                    mime_subtype, extension, body, from_)
 
375
 
 
376
 
363
377
mail_client_registry.register('claws', Claws,
364
378
                              help=Claws.__doc__)
365
379