~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Alexander Belchenko
  • Date: 2008-03-02 16:54:19 UTC
  • mto: This revision was merged to the branch mainline in revision 3267.
  • Revision ID: bialix@ukr.net-20080302165419-2u0r0ogn1h7s4gib
because every mail client has different rules to compose command line we should encode arguments to 8 bit string only when needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import errno
18
18
import os
19
19
import subprocess
20
20
import sys
21
21
import tempfile
22
 
import urllib
23
22
 
24
23
import bzrlib
25
24
from bzrlib import (
28
27
    msgeditor,
29
28
    osutils,
30
29
    urlutils,
31
 
    registry
32
30
    )
33
31
 
34
 
mail_client_registry = registry.Registry()
35
 
 
36
32
 
37
33
class MailClient(object):
38
34
    """A mail client that can send messages with attachements."""
41
37
        self.config = config
42
38
 
43
39
    def compose(self, prompt, to, subject, attachment, mime_subtype,
44
 
                extension, basename=None, body=None):
 
40
                extension):
45
41
        """Compose (and possibly send) an email message
46
42
 
47
43
        Must be implemented by subclasses.
56
52
            "plain", "x-patch", etc.
57
53
        :param extension: The file extension associated with the attachment
58
54
            type, e.g. ".patch"
59
 
        :param basename: The name to use for the attachment, e.g.
60
 
            "send-nick-3252"
61
55
        """
62
56
        raise NotImplementedError
63
57
 
64
 
    def compose_merge_request(self, to, subject, directive, basename=None,
65
 
                              body=None):
 
58
    def compose_merge_request(self, to, subject, directive):
66
59
        """Compose (and possibly send) a merge request
67
60
 
68
61
        :param to: The address to send the request to
69
62
        :param subject: The subject line to use for the request
70
63
        :param directive: A merge directive representing the merge request, as
71
64
            a bytestring.
72
 
        :param basename: The name to use for the attachment, e.g.
73
 
            "send-nick-3252"
74
65
        """
75
66
        prompt = self._get_merge_prompt("Please describe these changes:", to,
76
67
                                        subject, directive)
77
68
        self.compose(prompt, to, subject, directive,
78
 
            'x-patch', '.patch', basename, body)
 
69
            'x-patch', '.patch')
79
70
 
80
71
    def _get_merge_prompt(self, prompt, to, subject, attachment):
81
72
        """Generate a prompt string.  Overridden by Editor.
89
80
 
90
81
 
91
82
class Editor(MailClient):
92
 
    __doc__ = """DIY mail client that uses commit message editor"""
93
 
 
94
 
    supports_body = True
 
83
    """DIY mail client that uses commit message editor"""
95
84
 
96
85
    def _get_merge_prompt(self, prompt, to, subject, attachment):
97
86
        """See MailClient._get_merge_prompt"""
102
91
                         attachment.decode('utf-8', 'replace')))
103
92
 
104
93
    def compose(self, prompt, to, subject, attachment, mime_subtype,
105
 
                extension, basename=None, body=None):
 
94
                extension):
106
95
        """See MailClient.compose"""
107
96
        if not to:
108
97
            raise errors.NoMailAddressSpecified()
109
 
        body = msgeditor.edit_commit_message(prompt, start_message=body)
 
98
        body = msgeditor.edit_commit_message(prompt)
110
99
        if body == '':
111
100
            raise errors.NoMessageSupplied()
112
101
        email_message.EmailMessage.send(self.config,
116
105
                                        body,
117
106
                                        attachment,
118
107
                                        attachment_mime_subtype=mime_subtype)
119
 
mail_client_registry.register('editor', Editor,
120
 
                              help=Editor.__doc__)
121
 
 
122
 
 
123
 
class BodyExternalMailClient(MailClient):
124
 
 
125
 
    supports_body = True
 
108
 
 
109
 
 
110
class ExternalMailClient(MailClient):
 
111
    """An external mail client."""
126
112
 
127
113
    def _get_client_commands(self):
128
114
        """Provide a list of commands that may invoke the mail client"""
133
119
            return self._client_commands
134
120
 
135
121
    def compose(self, prompt, to, subject, attachment, mime_subtype,
136
 
                extension, basename=None, body=None):
 
122
                extension):
137
123
        """See MailClient.compose.
138
124
 
139
125
        Writes the attachment to a temporary file, invokes _compose.
140
126
        """
141
 
        if basename is None:
142
 
            basename = 'attachment'
143
 
        pathname = osutils.mkdtemp(prefix='bzr-mail-')
144
 
        attach_path = osutils.pathjoin(pathname, basename + extension)
145
 
        outfile = open(attach_path, 'wb')
 
127
        fd, pathname = tempfile.mkstemp(extension, 'bzr-mail-')
146
128
        try:
147
 
            outfile.write(attachment)
 
129
            os.write(fd, attachment)
148
130
        finally:
149
 
            outfile.close()
150
 
        if body is not None:
151
 
            kwargs = {'body': body}
152
 
        else:
153
 
            kwargs = {}
154
 
        self._compose(prompt, to, subject, attach_path, mime_subtype,
155
 
                      extension, **kwargs)
 
131
            os.close(fd)
 
132
        self._compose(prompt, to, subject, pathname, mime_subtype, extension)
156
133
 
157
134
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
158
 
                 extension, body=None, from_=None):
 
135
                extension):
159
136
        """Invoke a mail client as a commandline process.
160
137
 
161
138
        Overridden by MAPIClient.
166
143
            "text", but the precise subtype can be specified here
167
144
        :param extension: A file extension (including period) associated with
168
145
            the attachment type.
169
 
        :param body: Optional body text.
170
 
        :param from_: Optional From: header.
171
146
        """
172
147
        for name in self._get_client_commands():
173
148
            cmdline = [self._encode_path(name, 'executable')]
174
 
            if body is not None:
175
 
                kwargs = {'body': body}
176
 
            else:
177
 
                kwargs = {}
178
 
            if from_ is not None:
179
 
                kwargs['from_'] = from_
180
149
            cmdline.extend(self._get_compose_commandline(to, subject,
181
 
                                                         attach_path,
182
 
                                                         **kwargs))
 
150
                                                         attach_path))
183
151
            try:
184
152
                subprocess.call(cmdline)
185
153
            except OSError, e:
190
158
        else:
191
159
            raise errors.MailClientNotFound(self._client_commands)
192
160
 
193
 
    def _get_compose_commandline(self, to, subject, attach_path, body):
 
161
    def _get_compose_commandline(self, to, subject, attach_path):
194
162
        """Determine the commandline to use for composing a message
195
163
 
196
164
        Implemented by various subclasses
209
177
        :return:    encoded string if u is unicode, u itself otherwise.
210
178
        """
211
179
        if isinstance(u, unicode):
212
 
            return u.encode(osutils.get_user_encoding(), 'replace')
 
180
            return u.encode(bzrlib.user_encoding, 'replace')
213
181
        return u
214
182
 
215
183
    def _encode_path(self, path, kind):
223
191
        """
224
192
        if isinstance(path, unicode):
225
193
            try:
226
 
                return path.encode(osutils.get_user_encoding())
 
194
                return path.encode(bzrlib.user_encoding)
227
195
            except UnicodeEncodeError:
228
196
                raise errors.UnableEncodePath(path, kind)
229
197
        return path
230
198
 
231
199
 
232
 
class ExternalMailClient(BodyExternalMailClient):
233
 
    __doc__ = """An external mail client."""
234
 
 
235
 
    supports_body = False
236
 
 
237
 
 
238
 
class Evolution(BodyExternalMailClient):
239
 
    __doc__ = """Evolution mail client."""
 
200
class Evolution(ExternalMailClient):
 
201
    """Evolution mail client."""
240
202
 
241
203
    _client_commands = ['evolution']
242
204
 
243
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
 
205
    def _get_compose_commandline(self, to, subject, attach_path):
244
206
        """See ExternalMailClient._get_compose_commandline"""
245
207
        message_options = {}
246
208
        if subject is not None:
247
209
            message_options['subject'] = subject
248
210
        if attach_path is not None:
249
211
            message_options['attach'] = attach_path
250
 
        if body is not None:
251
 
            message_options['body'] = body
252
212
        options_list = ['%s=%s' % (k, urlutils.escape(v)) for (k, v) in
253
213
                        sorted(message_options.iteritems())]
254
214
        return ['mailto:%s?%s' % (self._encode_safe(to or ''),
255
215
            '&'.join(options_list))]
256
 
mail_client_registry.register('evolution', Evolution,
257
 
                              help=Evolution.__doc__)
258
 
 
259
 
 
260
 
class Mutt(BodyExternalMailClient):
261
 
    __doc__ = """Mutt mail client."""
 
216
 
 
217
 
 
218
class Mutt(ExternalMailClient):
 
219
    """Mutt mail client."""
262
220
 
263
221
    _client_commands = ['mutt']
264
222
 
265
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
 
223
    def _get_compose_commandline(self, to, subject, attach_path):
266
224
        """See ExternalMailClient._get_compose_commandline"""
267
225
        message_options = []
268
226
        if subject is not None:
270
228
        if attach_path is not None:
271
229
            message_options.extend(['-a',
272
230
                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])
281
231
        if to is not None:
282
 
            message_options.extend(['--', self._encode_safe(to)])
 
232
            message_options.append(self._encode_safe(to))
283
233
        return message_options
284
 
mail_client_registry.register('mutt', Mutt,
285
 
                              help=Mutt.__doc__)
286
 
 
287
 
 
288
 
class Thunderbird(BodyExternalMailClient):
289
 
    __doc__ = """Mozilla Thunderbird (or Icedove)
 
234
 
 
235
 
 
236
class Thunderbird(ExternalMailClient):
 
237
    """Mozilla Thunderbird (or Icedove)
290
238
 
291
239
    Note that Thunderbird 1.5 is buggy and does not support setting
292
240
    "to" simultaneously with including a attachment.
296
244
    """
297
245
 
298
246
    _client_commands = ['thunderbird', 'mozilla-thunderbird', 'icedove',
299
 
        '/Applications/Mozilla/Thunderbird.app/Contents/MacOS/thunderbird-bin',
300
 
        '/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin']
 
247
        '/Applications/Mozilla/Thunderbird.app/Contents/MacOS/thunderbird-bin']
301
248
 
302
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
 
249
    def _get_compose_commandline(self, to, subject, attach_path):
303
250
        """See ExternalMailClient._get_compose_commandline"""
304
251
        message_options = {}
305
252
        if to is not None:
309
256
        if attach_path is not None:
310
257
            message_options['attachment'] = urlutils.local_path_to_url(
311
258
                attach_path)
312
 
        if body is not None:
313
 
            options_list = ['body=%s' % urllib.quote(self._encode_safe(body))]
314
 
        else:
315
 
            options_list = []
316
 
        options_list.extend(["%s='%s'" % (k, v) for k, v in
317
 
                        sorted(message_options.iteritems())])
 
259
        options_list = ["%s='%s'" % (k, v) for k, v in
 
260
                        sorted(message_options.iteritems())]
318
261
        return ['-compose', ','.join(options_list)]
319
 
mail_client_registry.register('thunderbird', Thunderbird,
320
 
                              help=Thunderbird.__doc__)
321
262
 
322
263
 
323
264
class KMail(ExternalMailClient):
324
 
    __doc__ = """KDE mail client."""
 
265
    """KDE mail client."""
325
266
 
326
267
    _client_commands = ['kmail']
327
268
 
336
277
        if to is not None:
337
278
            message_options.extend([self._encode_safe(to)])
338
279
        return message_options
339
 
mail_client_registry.register('kmail', KMail,
340
 
                              help=KMail.__doc__)
341
 
 
342
 
 
343
 
class Claws(ExternalMailClient):
344
 
    __doc__ = """Claws mail client."""
345
 
 
346
 
    supports_body = True
347
 
 
348
 
    _client_commands = ['claws-mail']
349
 
 
350
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None,
351
 
                                 from_=None):
352
 
        """See ExternalMailClient._get_compose_commandline"""
353
 
        compose_url = []
354
 
        if from_ is not None:
355
 
            compose_url.append('from=' + urllib.quote(from_))
356
 
        if subject is not None:
357
 
            # Don't use urllib.quote_plus because Claws doesn't seem
358
 
            # to recognise spaces encoded as "+".
359
 
            compose_url.append(
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))
369
 
        # Collect command-line options.
370
 
        message_options = ['--compose', compose_url]
371
 
        if attach_path is not None:
372
 
            message_options.extend(
373
 
                ['--attach', self._encode_path(attach_path, 'attachment')])
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
 
 
385
 
mail_client_registry.register('claws', Claws,
386
 
                              help=Claws.__doc__)
387
 
 
388
 
 
389
 
class XDGEmail(BodyExternalMailClient):
390
 
    __doc__ = """xdg-email attempts to invoke the user's preferred mail client"""
 
280
 
 
281
 
 
282
class XDGEmail(ExternalMailClient):
 
283
    """xdg-email attempts to invoke the user's preferred mail client"""
391
284
 
392
285
    _client_commands = ['xdg-email']
393
286
 
394
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
 
287
    def _get_compose_commandline(self, to, subject, attach_path):
395
288
        """See ExternalMailClient._get_compose_commandline"""
396
289
        if not to:
397
290
            raise errors.NoMailAddressSpecified()
401
294
        if attach_path is not None:
402
295
            commandline.extend(['--attach',
403
296
                self._encode_path(attach_path, 'attachment')])
404
 
        if body is not None:
405
 
            commandline.extend(['--body', self._encode_safe(body)])
406
 
        return commandline
407
 
mail_client_registry.register('xdg-email', XDGEmail,
408
 
                              help=XDGEmail.__doc__)
409
 
 
410
 
 
411
 
class EmacsMail(ExternalMailClient):
412
 
    __doc__ = """Call emacsclient to have a mail buffer.
413
 
 
414
 
    This only work for emacs >= 22.1 due to recent -e/--eval support.
415
 
 
416
 
    The good news is that this implementation will work with all mail
417
 
    agents registered against ``mail-user-agent``. So there is no need
418
 
    to instantiate ExternalMailClient for each and every GNU Emacs
419
 
    MUA.
420
 
 
421
 
    Users just have to ensure that ``mail-user-agent`` is set according
422
 
    to their tastes.
423
 
    """
424
 
 
425
 
    _client_commands = ['emacsclient']
426
 
 
427
 
    def __init__(self, config):
428
 
        super(EmacsMail, self).__init__(config)
429
 
        self.elisp_tmp_file = None
430
 
 
431
 
    def _prepare_send_function(self):
432
 
        """Write our wrapper function into a temporary file.
433
 
 
434
 
        This temporary file will be loaded at runtime in
435
 
        _get_compose_commandline function.
436
 
 
437
 
        This function does not remove the file.  That's a wanted
438
 
        behaviour since _get_compose_commandline won't run the send
439
 
        mail function directly but return the eligible command line.
440
 
        Removing our temporary file here would prevent our sendmail
441
 
        function to work.  (The file is deleted by some elisp code
442
 
        after being read by Emacs.)
443
 
        """
444
 
 
445
 
        _defun = r"""(defun bzr-add-mime-att (file)
446
 
  "Attach FILE to a mail buffer as a MIME attachment."
447
 
  (let ((agent mail-user-agent))
448
 
    (if (and file (file-exists-p file))
449
 
        (cond
450
 
         ((eq agent 'sendmail-user-agent)
451
 
          (progn
452
 
            (mail-text)
453
 
            (newline)
454
 
            (if (functionp 'etach-attach)
455
 
              (etach-attach file)
456
 
              (mail-attach-file file))))
457
 
         ((or (eq agent 'message-user-agent)
458
 
              (eq agent 'gnus-user-agent)
459
 
              (eq agent 'mh-e-user-agent))
460
 
          (progn
461
 
            (mml-attach-file file "text/x-patch" "BZR merge" "inline")))
462
 
         ((eq agent 'mew-user-agent)
463
 
          (progn
464
 
            (mew-draft-prepare-attachments)
465
 
            (mew-attach-link file (file-name-nondirectory file))
466
 
            (let* ((nums (mew-syntax-nums))
467
 
                   (syntax (mew-syntax-get-entry mew-encode-syntax nums)))
468
 
              (mew-syntax-set-cd syntax "BZR merge")
469
 
              (mew-encode-syntax-print mew-encode-syntax))
470
 
            (mew-header-goto-body)))
471
 
         (t
472
 
          (message "Unhandled MUA, report it on bazaar@lists.canonical.com")))
473
 
      (error "File %s does not exist." file))))
474
 
"""
475
 
 
476
 
        fd, temp_file = tempfile.mkstemp(prefix="emacs-bzr-send-",
477
 
                                         suffix=".el")
478
 
        try:
479
 
            os.write(fd, _defun)
480
 
        finally:
481
 
            os.close(fd) # Just close the handle but do not remove the file.
482
 
        return temp_file
483
 
 
484
 
    def _get_compose_commandline(self, to, subject, attach_path):
485
 
        commandline = ["--eval"]
486
 
 
487
 
        _to = "nil"
488
 
        _subject = "nil"
489
 
 
490
 
        if to is not None:
491
 
            _to = ("\"%s\"" % self._encode_safe(to).replace('"', '\\"'))
492
 
        if subject is not None:
493
 
            _subject = ("\"%s\"" %
494
 
                        self._encode_safe(subject).replace('"', '\\"'))
495
 
 
496
 
        # Funcall the default mail composition function
497
 
        # This will work with any mail mode including default mail-mode
498
 
        # User must tweak mail-user-agent variable to tell what function
499
 
        # will be called inside compose-mail.
500
 
        mail_cmd = "(compose-mail %s %s)" % (_to, _subject)
501
 
        commandline.append(mail_cmd)
502
 
 
503
 
        # Try to attach a MIME attachment using our wrapper function
504
 
        if attach_path is not None:
505
 
            # Do not create a file if there is no attachment
506
 
            elisp = self._prepare_send_function()
507
 
            self.elisp_tmp_file = elisp
508
 
            lmmform = '(load "%s")' % elisp
509
 
            mmform  = '(bzr-add-mime-att "%s")' % \
510
 
                self._encode_path(attach_path, 'attachment')
511
 
            rmform = '(delete-file "%s")' % elisp
512
 
            commandline.append(lmmform)
513
 
            commandline.append(mmform)
514
 
            commandline.append(rmform)
515
 
 
516
 
        return commandline
517
 
mail_client_registry.register('emacsclient', EmacsMail,
518
 
                              help=EmacsMail.__doc__)
519
 
 
520
 
 
521
 
class MAPIClient(BodyExternalMailClient):
522
 
    __doc__ = """Default Windows mail client launched using MAPI."""
 
297
        return commandline
 
298
 
 
299
 
 
300
class MAPIClient(ExternalMailClient):
 
301
    """Default Windows mail client launched using MAPI."""
523
302
 
524
303
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
525
 
                 extension, body=None):
 
304
                 extension):
526
305
        """See ExternalMailClient._compose.
527
306
 
528
307
        This implementation uses MAPI via the simplemapi ctypes wrapper
529
308
        """
530
309
        from bzrlib.util import simplemapi
531
310
        try:
532
 
            simplemapi.SendMail(to or '', subject or '', body or '',
533
 
                                attach_path)
 
311
            simplemapi.SendMail(to or '', subject or '', '', attach_path)
534
312
        except simplemapi.MAPIError, e:
535
313
            if e.code != simplemapi.MAPI_USER_ABORT:
536
314
                raise errors.MailClientNotFound(['MAPI supported mail client'
537
315
                                                 ' (error %d)' % (e.code,)])
538
 
mail_client_registry.register('mapi', MAPIClient,
539
 
                              help=MAPIClient.__doc__)
540
 
 
541
 
 
542
 
class MailApp(BodyExternalMailClient):
543
 
    __doc__ = """Use MacOS X's Mail.app for sending email messages.
544
 
 
545
 
    Although it would be nice to use appscript, it's not installed
546
 
    with the shipped Python installations.  We instead build an
547
 
    AppleScript and invoke the script using osascript(1).  We don't
548
 
    use the _encode_safe() routines as it's not clear what encoding
549
 
    osascript expects the script to be in.
550
 
    """
551
 
 
552
 
    _client_commands = ['osascript']
553
 
 
554
 
    def _get_compose_commandline(self, to, subject, attach_path, body=None,
555
 
                                from_=None):
556
 
       """See ExternalMailClient._get_compose_commandline"""
557
 
 
558
 
       fd, self.temp_file = tempfile.mkstemp(prefix="bzr-send-",
559
 
                                         suffix=".scpt")
560
 
       try:
561
 
           os.write(fd, 'tell application "Mail"\n')
562
 
           os.write(fd, 'set newMessage to make new outgoing message\n')
563
 
           os.write(fd, 'tell newMessage\n')
564
 
           if to is not None:
565
 
               os.write(fd, 'make new to recipient with properties'
566
 
                   ' {address:"%s"}\n' % to)
567
 
           if from_ is not None:
568
 
               # though from_ doesn't actually seem to be used
569
 
               os.write(fd, 'set sender to "%s"\n'
570
 
                   % sender.replace('"', '\\"'))
571
 
           if subject is not None:
572
 
               os.write(fd, 'set subject to "%s"\n'
573
 
                   % subject.replace('"', '\\"'))
574
 
           if body is not None:
575
 
               # FIXME: would be nice to prepend the body to the
576
 
               # existing content (e.g., preserve signature), but
577
 
               # can't seem to figure out the right applescript
578
 
               # incantation.
579
 
               os.write(fd, 'set content to "%s\\n\n"\n' %
580
 
                   body.replace('"', '\\"').replace('\n', '\\n'))
581
 
 
582
 
           if attach_path is not None:
583
 
               # FIXME: would be nice to first append a newline to
584
 
               # ensure the attachment is on a new paragraph, but
585
 
               # can't seem to figure out the right applescript
586
 
               # incantation.
587
 
               os.write(fd, 'tell content to make new attachment'
588
 
                   ' with properties {file name:"%s"}'
589
 
                   ' at after the last paragraph\n'
590
 
                   % self._encode_path(attach_path, 'attachment'))
591
 
           os.write(fd, 'set visible to true\n')
592
 
           os.write(fd, 'end tell\n')
593
 
           os.write(fd, 'end tell\n')
594
 
       finally:
595
 
           os.close(fd) # Just close the handle but do not remove the file.
596
 
       return [self.temp_file]
597
 
mail_client_registry.register('mail.app', MailApp,
598
 
                              help=MailApp.__doc__)
599
316
 
600
317
 
601
318
class DefaultMail(MailClient):
602
 
    __doc__ = """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
 
319
    """Default mail handling.  Tries XDGEmail (or MAPIClient on Windows),
603
320
    falls back to Editor"""
604
321
 
605
 
    supports_body = True
606
 
 
607
322
    def _mail_client(self):
608
323
        """Determine the preferred mail client for this platform"""
609
324
        if osutils.supports_mapi():
612
327
            return XDGEmail(self.config)
613
328
 
614
329
    def compose(self, prompt, to, subject, attachment, mime_subtype,
615
 
                extension, basename=None, body=None):
 
330
                extension):
616
331
        """See MailClient.compose"""
617
332
        try:
618
333
            return self._mail_client().compose(prompt, to, subject,
619
334
                                               attachment, mimie_subtype,
620
 
                                               extension, basename, body)
 
335
                                               extension)
621
336
        except errors.MailClientNotFound:
622
337
            return Editor(self.config).compose(prompt, to, subject,
623
 
                          attachment, mimie_subtype, extension, body)
 
338
                          attachment, mimie_subtype, extension)
624
339
 
625
 
    def compose_merge_request(self, to, subject, directive, basename=None,
626
 
                              body=None):
 
340
    def compose_merge_request(self, to, subject, directive):
627
341
        """See MailClient.compose_merge_request"""
628
342
        try:
629
343
            return self._mail_client().compose_merge_request(to, subject,
630
 
                    directive, basename=basename, body=body)
 
344
                                                             directive)
631
345
        except errors.MailClientNotFound:
632
346
            return Editor(self.config).compose_merge_request(to, subject,
633
 
                          directive, basename=basename, body=body)
634
 
mail_client_registry.register('default', DefaultMail,
635
 
                              help=DefaultMail.__doc__)
636
 
mail_client_registry.default_key = 'default'
637
 
 
638
 
 
 
347
                          directive)