~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/mail_client.py

  • Committer: Aaron Bentley
  • Date: 2007-08-09 19:30:31 UTC
  • mto: (2681.5.3 bzr-mail)
  • mto: This revision was merged to the branch mainline in revision 2736.
  • Revision ID: abentley@panoramicfeedback.com-20070809193031-efscxiwt74sxk5o1
Add Thunderbird support to bzr send

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import os
 
18
import subprocess
 
19
import tempfile
 
20
 
 
21
from bzrlib import urlutils
 
22
 
 
23
 
 
24
class MailClient(object):
 
25
 
 
26
    def compose(self, to, subject, attachment):
 
27
        raise NotImplementedError
 
28
 
 
29
 
 
30
class Editor(MailClient):
 
31
 
 
32
    pass
 
33
 
 
34
 
 
35
class Thunderbird(MailClient):
 
36
 
 
37
    def compose(self, to, subject, attachment):
 
38
        fd, pathname = tempfile.mkstemp('.patch', 'bzr-mail-')
 
39
        try:
 
40
            os.write(fd, attachment)
 
41
        finally:
 
42
            os.close(fd)
 
43
        cmdline = ['thunderbird']
 
44
        cmdline.extend(self._get_compose_commandline(to, subject, pathname))
 
45
        subprocess.call(cmdline)
 
46
 
 
47
    def _get_compose_commandline(self, to, subject, attach_path):
 
48
        message_options = {}
 
49
        if to is not None:
 
50
            message_options['to'] = to
 
51
        if subject is not None:
 
52
            message_options['subject'] = subject
 
53
        if attach_path is not None:
 
54
            message_options['attachment'] = urlutils.local_path_to_url(
 
55
                attach_path)
 
56
        options_list = ["%s='%s'" % (k, v) for k, v in
 
57
                        sorted(message_options.iteritems())]
 
58
        return ['-compose', ','.join(options_list)]