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
24
class TestMutt(tests.TestCase):
26
def test_commandline(self):
27
mutt = mail_client.Mutt(None)
28
commandline = mutt._get_compose_commandline(None, None, 'file%')
29
self.assertEqual(['-a', 'file%'], commandline)
30
commandline = mutt._get_compose_commandline('jrandom@example.org',
32
self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
35
def test_commandline_is_8bit(self):
36
mutt = mail_client.Mutt(None)
37
cmdline = mutt._get_compose_commandline(u'jrandom@example.org',
38
u'Hi there!', u'file%')
40
['-s', 'Hi there!', '-a', 'file%', 'jrandom@example.org'],
43
self.assertFalse(isinstance(item, unicode),
44
'Command-line item %r is unicode!' % item)
47
class TestThunderbird(tests.TestCase):
49
def test_commandline(self):
50
tbird = mail_client.Thunderbird(None)
51
commandline = tbird._get_compose_commandline(None, None,
53
self.assertEqual(['-compose', "attachment='%s'" %
54
urlutils.local_path_to_url('file%')], commandline)
55
commandline = tbird._get_compose_commandline('jrandom@example.org',
57
self.assertEqual(['-compose', "subject='Hi there!',"
58
"to='jrandom@example.org'"], commandline)
60
def test_commandline_is_8bit(self):
61
# test for bug #139318
62
tbird = mail_client.Thunderbird(None)
63
cmdline = tbird._get_compose_commandline(u'jrandom@example.org',
64
u'Hi there!', u'file%')
65
self.assertEqual(['-compose',
66
("attachment='%s'," % urlutils.local_path_to_url('file%')) +
67
"subject='Hi there!',to='jrandom@example.org'",
70
self.assertFalse(isinstance(item, unicode),
71
'Command-line item %r is unicode!' % item)
74
class TestXDGEmail(tests.TestCase):
76
def test_commandline(self):
77
xdg_email = mail_client.XDGEmail(None)
78
self.assertRaises(errors.NoMailAddressSpecified,
79
xdg_email._get_compose_commandline,
81
commandline = xdg_email._get_compose_commandline(
82
'jrandom@example.org', None, 'file%')
83
self.assertEqual(['jrandom@example.org', '--attach', 'file%'],
85
commandline = xdg_email._get_compose_commandline(
86
'jrandom@example.org', 'Hi there!', None)
87
self.assertEqual(['jrandom@example.org', '--subject', 'Hi there!'],
90
def test_commandline_is_8bit(self):
91
xdg_email = mail_client.XDGEmail(None)
92
cmdline = xdg_email._get_compose_commandline(u'jrandom@example.org',
93
u'Hi there!', u'file%')
95
['jrandom@example.org', '--subject', 'Hi there!',
99
self.assertFalse(isinstance(item, unicode),
100
'Command-line item %r is unicode!' % item)
103
class TestEvolution(tests.TestCase):
105
def test_commandline(self):
106
evo = mail_client.Evolution(None)
107
commandline = evo._get_compose_commandline(None, None, 'file%')
108
self.assertEqual(['mailto:?attach=file%25'], commandline)
109
commandline = evo._get_compose_commandline('jrandom@example.org',
111
self.assertEqual(['mailto:jrandom@example.org?subject=Hi%20there%21'],
114
def test_commandline_is_8bit(self):
115
evo = mail_client.Evolution(None)
116
cmdline = evo._get_compose_commandline(u'jrandom@example.org',
117
u'Hi there!', u'file%')
119
['mailto:jrandom@example.org?attach=file%25&subject=Hi%20there%21'
123
self.assertFalse(isinstance(item, unicode),
124
'Command-line item %r is unicode!' % item)
127
class TestKMail(tests.TestCase):
129
def test_commandline(self):
130
kmail = mail_client.KMail(None)
131
commandline = kmail._get_compose_commandline(None, None, 'file%')
132
self.assertEqual(['--attach', 'file%'], commandline)
133
commandline = kmail._get_compose_commandline('jrandom@example.org',
135
self.assertEqual(['-s', 'Hi there!', 'jrandom@example.org'],
138
def test_commandline_is_8bit(self):
139
kmail = mail_client.KMail(None)
140
cmdline = kmail._get_compose_commandline(u'jrandom@example.org',
141
u'Hi there!', u'file%')
143
['-s', 'Hi there!', '--attach', 'file%', 'jrandom@example.org'],
146
self.assertFalse(isinstance(item, unicode),
147
'Command-line item %r is unicode!' % item)
150
class TestEditor(tests.TestCase):
152
def test_get_merge_prompt_unicode(self):
153
"""Prompt, to and subject are unicode, the attachement is binary"""
154
editor = mail_client.Editor(None)
155
prompt = editor._get_merge_prompt(u'foo\u1234',
158
u'qux\u1234'.encode('utf-8'))
159
self.assertContainsRe(prompt, u'foo\u1234(.|\n)*bar\u1234'
160
u'(.|\n)*baz\u1234(.|\n)*qux\u1234')
161
editor._get_merge_prompt(u'foo', u'bar', u'baz', 'qux\xff')