/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 breezy/mail_client.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-16 01:55:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6740.
  • Revision ID: jelmer@jelmer.uk-20170716015539-esj2f7vjje9366u0
Fix more imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
39
61
class MailClient(object):
40
62
    """A mail client that can send messages with attachements."""
41
63
 
107
129
                extension, basename=None, body=None):
108
130
        """See MailClient.compose"""
109
131
        if not to:
110
 
            raise errors.NoMailAddressSpecified()
 
132
            raise NoMailAddressSpecified()
111
133
        body = msgeditor.edit_commit_message(prompt, start_message=body)
112
134
        if body == '':
113
 
            raise errors.NoMessageSupplied()
 
135
            raise NoMessageSupplied()
114
136
        email_message.EmailMessage.send(self.config,
115
137
                                        self.config.get('email'),
116
138
                                        to,
190
212
            else:
191
213
                break
192
214
        else:
193
 
            raise errors.MailClientNotFound(self._client_commands)
 
215
            raise MailClientNotFound(self._client_commands)
194
216
 
195
217
    def _get_compose_commandline(self, to, subject, attach_path, body):
196
218
        """Determine the commandline to use for composing a message
365
387
                'body=' + urlutils.quote(self._encode_safe(body)))
366
388
        # to must be supplied for the claws-mail --compose syntax to work.
367
389
        if to is None:
368
 
            raise errors.NoMailAddressSpecified()
 
390
            raise NoMailAddressSpecified()
369
391
        compose_url = 'mailto:%s?%s' % (
370
392
            self._encode_safe(to), '&'.join(compose_url))
371
393
        # Collect command-line options.
396
418
    def _get_compose_commandline(self, to, subject, attach_path, body=None):
397
419
        """See ExternalMailClient._get_compose_commandline"""
398
420
        if not to:
399
 
            raise errors.NoMailAddressSpecified()
 
421
            raise NoMailAddressSpecified()
400
422
        commandline = [self._encode_safe(to)]
401
423
        if subject is not None:
402
424
            commandline.extend(['--subject', self._encode_safe(subject)])
535
557
                                attach_path)
536
558
        except simplemapi.MAPIError as e:
537
559
            if e.code != simplemapi.MAPI_USER_ABORT:
538
 
                raise errors.MailClientNotFound(['MAPI supported mail client'
 
560
                raise MailClientNotFound(['MAPI supported mail client'
539
561
                                                 ' (error %d)' % (e.code,)])
540
562
mail_client_registry.register('mapi', MAPIClient,
541
563
                              help=MAPIClient.__doc__)
620
642
            return self._mail_client().compose(prompt, to, subject,
621
643
                                               attachment, mime_subtype,
622
644
                                               extension, basename, body)
623
 
        except errors.MailClientNotFound:
 
645
        except MailClientNotFound:
624
646
            return Editor(self.config).compose(prompt, to, subject,
625
647
                          attachment, mime_subtype, extension, body)
626
648
 
630
652
        try:
631
653
            return self._mail_client().compose_merge_request(to, subject,
632
654
                    directive, basename=basename, body=body)
633
 
        except errors.MailClientNotFound:
 
655
        except MailClientNotFound:
634
656
            return Editor(self.config).compose_merge_request(to, subject,
635
657
                          directive, basename=basename, body=body)
636
658
mail_client_registry.register('default', DefaultMail,