/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: Aaron Bentley
  • Date: 2008-03-07 18:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 3255.
  • Revision ID: aaron@aaronbentley.com-20080307181713-gq97309x7jnbvs67
Use nick/revno-based names for merge directives

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        self.config = config
37
37
 
38
38
    def compose(self, prompt, to, subject, attachment, mime_subtype,
39
 
                extension):
 
39
                extension, basename=None):
40
40
        """Compose (and possibly send) an email message
41
41
 
42
42
        Must be implemented by subclasses.
51
51
            "plain", "x-patch", etc.
52
52
        :param extension: The file extension associated with the attachment
53
53
            type, e.g. ".patch"
 
54
        :param basename: The name to use for the attachment, e.g.
 
55
            "send-nick-3252"
54
56
        """
55
57
        raise NotImplementedError
56
58
 
57
 
    def compose_merge_request(self, to, subject, directive):
 
59
    def compose_merge_request(self, to, subject, directive, basename=None):
58
60
        """Compose (and possibly send) a merge request
59
61
 
60
62
        :param to: The address to send the request to
61
63
        :param subject: The subject line to use for the request
62
64
        :param directive: A merge directive representing the merge request, as
63
65
            a bytestring.
 
66
        :param basename: The name to use for the attachment, e.g.
 
67
            "send-nick-3252"
64
68
        """
65
69
        prompt = self._get_merge_prompt("Please describe these changes:", to,
66
70
                                        subject, directive)
67
71
        self.compose(prompt, to, subject, directive,
68
 
            'x-patch', '.patch')
 
72
            'x-patch', '.patch', basename)
69
73
 
70
74
    def _get_merge_prompt(self, prompt, to, subject, attachment):
71
75
        """Generate a prompt string.  Overridden by Editor.
90
94
                         attachment.decode('utf-8', 'replace')))
91
95
 
92
96
    def compose(self, prompt, to, subject, attachment, mime_subtype,
93
 
                extension):
 
97
                extension, basename=None):
94
98
        """See MailClient.compose"""
95
99
        if not to:
96
100
            raise errors.NoMailAddressSpecified()
118
122
            return self._client_commands
119
123
 
120
124
    def compose(self, prompt, to, subject, attachment, mime_subtype,
121
 
                extension):
 
125
                extension, basename=None):
122
126
        """See MailClient.compose.
123
127
 
124
128
        Writes the attachment to a temporary file, invokes _compose.
125
129
        """
126
 
        fd, pathname = tempfile.mkstemp(extension, 'bzr-mail-')
 
130
        if basename is None:
 
131
            basename = 'attachment'
 
132
        pathname = tempfile.mkdtemp(prefix='bzr-mail-')
 
133
        attach_path = osutils.pathjoin(pathname, basename + extension)
 
134
        outfile = open(attach_path, 'wb')
127
135
        try:
128
 
            os.write(fd, attachment)
 
136
            outfile.write(attachment)
129
137
        finally:
130
 
            os.close(fd)
131
 
        self._compose(prompt, to, subject, pathname, mime_subtype, extension)
 
138
            outfile.close()
 
139
        self._compose(prompt, to, subject, attach_path, mime_subtype,
 
140
                      extension)
132
141
 
133
142
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
134
143
                extension):
295
304
            return XDGEmail(self.config)
296
305
 
297
306
    def compose(self, prompt, to, subject, attachment, mime_subtype,
298
 
                extension):
 
307
                extension, basename=None):
299
308
        """See MailClient.compose"""
300
309
        try:
301
310
            return self._mail_client().compose(prompt, to, subject,
302
311
                                               attachment, mimie_subtype,
303
 
                                               extension)
 
312
                                               extension, basename)
304
313
        except errors.MailClientNotFound:
305
314
            return Editor(self.config).compose(prompt, to, subject,
306
315
                          attachment, mimie_subtype, extension)