~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Robert J. Tanner
  • Date: 2009-06-10 03:56:49 UTC
  • mfrom: (4423 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4425.
  • Revision ID: tanner@real-time.com-20090610035649-7rfx4cls4550zc3c
Merge 1.15.1 back to trunk

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))
253
257
                              help=Evolution.__doc__)
254
258
 
255
259
 
256
 
class Mutt(ExternalMailClient):
 
260
class Mutt(BodyExternalMailClient):
257
261
    """Mutt mail client."""
258
262
 
259
263
    _client_commands = ['mutt']
260
264
 
261
 
    def _get_compose_commandline(self, to, subject, attach_path):
 
265
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
262
266
        """See ExternalMailClient._get_compose_commandline"""
263
267
        message_options = []
264
268
        if subject is not None:
266
270
        if attach_path is not None:
267
271
            message_options.extend(['-a',
268
272
                self._encode_path(attach_path, 'attachment')])
 
273
        if body is not None:
 
274
            # Store the temp file object in self, so that it does not get
 
275
            # garbage collected and delete the file before mutt can read it.
 
276
            self._temp_file = tempfile.NamedTemporaryFile(
 
277
                prefix="mutt-body-", suffix=".txt")
 
278
            self._temp_file.write(body)
 
279
            self._temp_file.flush()
 
280
            message_options.extend(['-i', self._temp_file.name])
269
281
        if to is not None:
270
282
            message_options.extend(['--', self._encode_safe(to)])
271
283
        return message_options
331
343
class Claws(ExternalMailClient):
332
344
    """Claws mail client."""
333
345
 
 
346
    supports_body = True
 
347
 
334
348
    _client_commands = ['claws-mail']
335
349
 
336
 
    def _get_compose_commandline(self, to, subject, attach_path):
 
350
    def _get_compose_commandline(self, to, subject, attach_path, body=None,
 
351
                                 from_=None):
337
352
        """See ExternalMailClient._get_compose_commandline"""
338
 
        compose_url = ['mailto:']
339
 
        if to is not None:
340
 
            compose_url.append(self._encode_safe(to))
341
 
        compose_url.append('?')
 
353
        compose_url = []
 
354
        if from_ is not None:
 
355
            compose_url.append('from=' + urllib.quote(from_))
342
356
        if subject is not None:
343
357
            # Don't use urllib.quote_plus because Claws doesn't seem
344
358
            # to recognise spaces encoded as "+".
345
359
            compose_url.append(
346
 
                'subject=%s' % urllib.quote(self._encode_safe(subject)))
 
360
                'subject=' + urllib.quote(self._encode_safe(subject)))
 
361
        if body is not None:
 
362
            compose_url.append(
 
363
                'body=' + urllib.quote(self._encode_safe(body)))
 
364
        # to must be supplied for the claws-mail --compose syntax to work.
 
365
        if to is None:
 
366
            raise errors.NoMailAddressSpecified()
 
367
        compose_url = 'mailto:%s?%s' % (
 
368
            self._encode_safe(to), '&'.join(compose_url))
347
369
        # Collect command-line options.
348
 
        message_options = ['--compose', ''.join(compose_url)]
 
370
        message_options = ['--compose', compose_url]
349
371
        if attach_path is not None:
350
372
            message_options.extend(
351
373
                ['--attach', self._encode_path(attach_path, 'attachment')])
352
374
        return message_options
 
375
 
 
376
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
 
377
                 extension, body=None, from_=None):
 
378
        """See ExternalMailClient._compose"""
 
379
        if from_ is None:
 
380
            from_ = self.config.get_user_option('email')
 
381
        super(Claws, self)._compose(prompt, to, subject, attach_path,
 
382
                                    mime_subtype, extension, body, from_)
 
383
 
 
384
 
353
385
mail_client_registry.register('claws', Claws,
354
386
                              help=Claws.__doc__)
355
387
 
506
538
    """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
507
539
    falls back to Editor"""
508
540
 
 
541
    supports_body = True
 
542
 
509
543
    def _mail_client(self):
510
544
        """Determine the preferred mail client for this platform"""
511
545
        if osutils.supports_mapi():