/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: Alexander Belchenko
  • Date: 2008-03-12 05:59:01 UTC
  • mfrom: (3266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3267.
  • Revision ID: bialix@ukr.net-20080312055901-44umxb8uc3zs10fe
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        self.config = config
38
38
 
39
39
    def compose(self, prompt, to, subject, attachment, mime_subtype,
40
 
                extension):
 
40
                extension, basename=None):
41
41
        """Compose (and possibly send) an email message
42
42
 
43
43
        Must be implemented by subclasses.
52
52
            "plain", "x-patch", etc.
53
53
        :param extension: The file extension associated with the attachment
54
54
            type, e.g. ".patch"
 
55
        :param basename: The name to use for the attachment, e.g.
 
56
            "send-nick-3252"
55
57
        """
56
58
        raise NotImplementedError
57
59
 
58
 
    def compose_merge_request(self, to, subject, directive):
 
60
    def compose_merge_request(self, to, subject, directive, basename=None):
59
61
        """Compose (and possibly send) a merge request
60
62
 
61
63
        :param to: The address to send the request to
62
64
        :param subject: The subject line to use for the request
63
65
        :param directive: A merge directive representing the merge request, as
64
66
            a bytestring.
 
67
        :param basename: The name to use for the attachment, e.g.
 
68
            "send-nick-3252"
65
69
        """
66
70
        prompt = self._get_merge_prompt("Please describe these changes:", to,
67
71
                                        subject, directive)
68
72
        self.compose(prompt, to, subject, directive,
69
 
            'x-patch', '.patch')
 
73
            'x-patch', '.patch', basename)
70
74
 
71
75
    def _get_merge_prompt(self, prompt, to, subject, attachment):
72
76
        """Generate a prompt string.  Overridden by Editor.
91
95
                         attachment.decode('utf-8', 'replace')))
92
96
 
93
97
    def compose(self, prompt, to, subject, attachment, mime_subtype,
94
 
                extension):
 
98
                extension, basename=None):
95
99
        """See MailClient.compose"""
96
100
        if not to:
97
101
            raise errors.NoMailAddressSpecified()
119
123
            return self._client_commands
120
124
 
121
125
    def compose(self, prompt, to, subject, attachment, mime_subtype,
122
 
                extension):
 
126
                extension, basename=None):
123
127
        """See MailClient.compose.
124
128
 
125
129
        Writes the attachment to a temporary file, invokes _compose.
126
130
        """
127
 
        fd, pathname = tempfile.mkstemp(extension, 'bzr-mail-')
 
131
        if basename is None:
 
132
            basename = 'attachment'
 
133
        pathname = tempfile.mkdtemp(prefix='bzr-mail-')
 
134
        attach_path = osutils.pathjoin(pathname, basename + extension)
 
135
        outfile = open(attach_path, 'wb')
128
136
        try:
129
 
            os.write(fd, attachment)
 
137
            outfile.write(attachment)
130
138
        finally:
131
 
            os.close(fd)
132
 
        self._compose(prompt, to, subject, pathname, mime_subtype, extension)
 
139
            outfile.close()
 
140
        self._compose(prompt, to, subject, attach_path, mime_subtype,
 
141
                      extension)
133
142
 
134
143
    def _compose(self, prompt, to, subject, attach_path, mime_subtype,
135
144
                extension):
327
336
            return XDGEmail(self.config)
328
337
 
329
338
    def compose(self, prompt, to, subject, attachment, mime_subtype,
330
 
                extension):
 
339
                extension, basename=None):
331
340
        """See MailClient.compose"""
332
341
        try:
333
342
            return self._mail_client().compose(prompt, to, subject,
334
343
                                               attachment, mimie_subtype,
335
 
                                               extension)
 
344
                                               extension, basename)
336
345
        except errors.MailClientNotFound:
337
346
            return Editor(self.config).compose(prompt, to, subject,
338
347
                          attachment, mimie_subtype, extension)