/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import sys
23
23
import tempfile
24
24
 
25
 
import breezy
26
 
from . import (
 
25
import bzrlib
 
26
from bzrlib import (
27
27
    config as _mod_config,
28
28
    email_message,
29
29
    errors,
36
36
mail_client_registry = registry.Registry()
37
37
 
38
38
 
39
 
class MailClientNotFound(errors.BzrError):
40
 
 
41
 
    _fmt = "Unable to find mail client with the following names:"\
42
 
        " %(mail_command_list_string)s"
43
 
 
44
 
    def __init__(self, mail_command_list):
45
 
        mail_command_list_string = ', '.join(mail_command_list)
46
 
        errors.BzrError.__init__(
47
 
            self, mail_command_list=mail_command_list,
48
 
            mail_command_list_string=mail_command_list_string)
49
 
 
50
 
 
51
 
class NoMessageSupplied(errors.BzrError):
52
 
 
53
 
    _fmt = "No message supplied."
54
 
 
55
 
 
56
 
class NoMailAddressSpecified(errors.BzrError):
57
 
 
58
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
59
 
 
60
 
 
61
39
class MailClient(object):
62
40
    """A mail client that can send messages with attachements."""
63
41
 
129
107
                extension, basename=None, body=None):
130
108
        """See MailClient.compose"""
131
109
        if not to:
132
 
            raise NoMailAddressSpecified()
 
110
            raise errors.NoMailAddressSpecified()
133
111
        body = msgeditor.edit_commit_message(prompt, start_message=body)
134
112
        if body == '':
135
 
            raise NoMessageSupplied()
 
113
            raise errors.NoMessageSupplied()
136
114
        email_message.EmailMessage.send(self.config,
137
115
                                        self.config.get('email'),
138
116
                                        to,
206
184
                                                         **kwargs))
207
185
            try:
208
186
                subprocess.call(cmdline)
209
 
            except OSError as e:
 
187
            except OSError, e:
210
188
                if e.errno != errno.ENOENT:
211
189
                    raise
212
190
            else:
213
191
                break
214
192
        else:
215
 
            raise MailClientNotFound(self._client_commands)
 
193
            raise errors.MailClientNotFound(self._client_commands)
216
194
 
217
195
    def _get_compose_commandline(self, to, subject, attach_path, body):
218
196
        """Determine the commandline to use for composing a message
274
252
        if body is not None:
275
253
            message_options['body'] = body
276
254
        options_list = ['%s=%s' % (k, urlutils.escape(v)) for (k, v) in
277
 
                        sorted(message_options.items())]
 
255
                        sorted(message_options.iteritems())]
278
256
        return ['mailto:%s?%s' % (self._encode_safe(to or ''),
279
257
            '&'.join(options_list))]
280
258
mail_client_registry.register('evolution', Evolution,
338
316
        else:
339
317
            options_list = []
340
318
        options_list.extend(["%s='%s'" % (k, v) for k, v in
341
 
                        sorted(message_options.items())])
 
319
                        sorted(message_options.iteritems())])
342
320
        return ['-compose', ','.join(options_list)]
343
321
mail_client_registry.register('thunderbird', Thunderbird,
344
322
                              help=Thunderbird.__doc__)
387
365
                'body=' + urlutils.quote(self._encode_safe(body)))
388
366
        # to must be supplied for the claws-mail --compose syntax to work.
389
367
        if to is None:
390
 
            raise NoMailAddressSpecified()
 
368
            raise errors.NoMailAddressSpecified()
391
369
        compose_url = 'mailto:%s?%s' % (
392
370
            self._encode_safe(to), '&'.join(compose_url))
393
371
        # Collect command-line options.
418
396
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
419
397
        """See ExternalMailClient._get_compose_commandline"""
420
398
        if not to:
421
 
            raise NoMailAddressSpecified()
 
399
            raise errors.NoMailAddressSpecified()
422
400
        commandline = [self._encode_safe(to)]
423
401
        if subject is not None:
424
402
            commandline.extend(['--subject', self._encode_safe(subject)])
551
529
 
552
530
        This implementation uses MAPI via the simplemapi ctypes wrapper
553
531
        """
554
 
        from .util import simplemapi
 
532
        from bzrlib.util import simplemapi
555
533
        try:
556
534
            simplemapi.SendMail(to or '', subject or '', body or '',
557
535
                                attach_path)
558
 
        except simplemapi.MAPIError as e:
 
536
        except simplemapi.MAPIError, e:
559
537
            if e.code != simplemapi.MAPI_USER_ABORT:
560
 
                raise MailClientNotFound(['MAPI supported mail client'
 
538
                raise errors.MailClientNotFound(['MAPI supported mail client'
561
539
                                                 ' (error %d)' % (e.code,)])
562
540
mail_client_registry.register('mapi', MAPIClient,
563
541
                              help=MAPIClient.__doc__)
642
620
            return self._mail_client().compose(prompt, to, subject,
643
621
                                               attachment, mime_subtype,
644
622
                                               extension, basename, body)
645
 
        except MailClientNotFound:
 
623
        except errors.MailClientNotFound:
646
624
            return Editor(self.config).compose(prompt, to, subject,
647
625
                          attachment, mime_subtype, extension, body)
648
626
 
652
630
        try:
653
631
            return self._mail_client().compose_merge_request(to, subject,
654
632
                    directive, basename=basename, body=body)
655
 
        except MailClientNotFound:
 
633
        except errors.MailClientNotFound:
656
634
            return Editor(self.config).compose_merge_request(to, subject,
657
635
                          directive, basename=basename, body=body)
658
636
mail_client_registry.register('default', DefaultMail,