1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
21
from bzrlib import urlutils
24
class MailClient(object):
26
def compose(self, to, subject, attachment):
27
raise NotImplementedError
30
class Editor(MailClient):
35
class Thunderbird(MailClient):
37
def compose(self, to, subject, attachment):
38
fd, pathname = tempfile.mkstemp('.patch', 'bzr-mail-')
40
os.write(fd, attachment)
43
cmdline = ['thunderbird']
44
cmdline.extend(self._get_compose_commandline(to, subject, pathname))
45
subprocess.call(cmdline)
47
def _get_compose_commandline(self, to, subject, attach_path):
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(
56
options_list = ["%s='%s'" % (k, v) for k, v in
57
sorted(message_options.iteritems())]
58
return ['-compose', ','.join(options_list)]