18
19
_addMessageSource, getMessageSources,
19
20
MessageSourceFragment, SENDER_RELATION,
20
21
MessageDisplayPreferenceCollection,
22
MessageBodyFragment, Correspondent,
23
25
from xquotient.quotientapp import QuotientPreferenceCollection
24
from xquotient import mimeutil
26
from xquotient import mimeutil, smtpout, inbox, compose
25
27
from xquotient.actions import SenderPersonFragment
26
28
from xquotient.test.util import (MIMEReceiverMixin, PartMaker,
27
29
DummyMessageImplWithABunchOfAddresses)
28
from xquotient.exmess import Correspondent
30
from xquotient.test.test_inbox import testMessageFactory
31
from xquotient.mimepart import Header, MIMEPart
34
class ComposeActionsTestCase(TestCase):
36
Tests for the compose-related actions of L{xquotient.exmess.MessageDetail}
37
(reply, forward, etc) and related functionality
43
LoginMethod(store=self.store, internal=False, protocol=u'email',
44
localpart=u'recipient', domain=u'host', verified=True,
47
fromAddr = smtpout.FromAddress(
48
address=u'recipient@host', store=self.store)
49
installOn(inbox.Inbox(store=self.store), self.store)
50
installOn(compose.Composer(store=self.store), self.store)
52
self.msg = testMessageFactory(
55
impl=DummyMessageImplWithABunchOfAddresses(store=self.store))
56
installOn(self.msg, self.store)
57
self.msgDetail = MessageDetail(self.msg)
59
def _recipientsToStrings(self, recipients):
61
Convert a mapping of "strings to lists of
62
L{xquotient.mimeutil.EmailAddress} instances" into a mapping of
63
"strings to lists of string email addresses"
66
for (k, v) in recipients.iteritems():
67
result[k] = list(e.email for e in v)
70
def test_replyToAll(self):
72
Test L{xquotient.exmess.MessageDetail.replyAll}
75
self._recipientsToStrings(
76
self.msgDetail.replyAll().recipients),
77
{'bcc': ['blind-copy@host'],
79
'to': ['sender@host', 'recipient2@host']})
82
def test_replyToAllFromAddress(self):
84
Test that L{xquotient.exmess.MessageDetail.replyAll} doesn't include
85
addresses of L{xquotient.smtpout.FromAddress} items that exist in the
86
same store as the message that is being replied to
88
addrs = set(u'blind-copy@host copy@host sender@host recipient2@host'.split())
90
fromAddr = smtpout.FromAddress(address=addr, store=self.msg.store)
92
for l in self.msgDetail.replyAll().recipients.itervalues():
93
gotAddrs.update(e.email for e in l)
97
fromAddr.deleteFromStore()
101
class MoreComposeActionsTestCase(TestCase):
103
Test compose-action related stuff that requires an on-disk store.
107
self.store = Store(dbdir=self.mktemp())
109
installOn(inbox.Inbox(store=self.store), self.store)
110
self.composer = compose.Composer(store=self.store)
111
installOn(self.composer, self.store)
113
LoginMethod(store=self.store, internal=False, protocol=u'email',
114
localpart=u'recipient', domain=u'host', verified=True,
117
self.msg = testMessageFactory(
120
impl=DummyMessageImplWithABunchOfAddresses(store=self.store))
121
self.msgDetail = MessageDetail(self.msg)
125
def test_setStatus(self):
127
Test that statuses requested for parent messages get set after
128
the created message is sent.
130
self.composer.__dict__['sendMessage'] = lambda fromA, toA, msg: None
134
def addStatus(self, status):
135
if self.statuses is None:
136
self.statuses = [status]
138
self.statuses.append(status)
141
parent.impl.headers = [Header("message-id", "<msg99@example.com>"),
142
Header("references", "<msg98@example.com>"),
143
Header("references", "<msg97@example.com>")]
145
toAddresses = [mimeutil.EmailAddress(
146
'testuser@example.com',
148
cf = self.msgDetail._composeSomething(
150
u'Sup dood', u'A body', [], parent, REPLIED_STATUS)
151
cf._sendOrSave(self.store.findFirst(smtpout.FromAddress),
152
toAddresses, u'Sup dood', u'A body',
154
self.assertEqual(parent.statuses, [REPLIED_STATUS])
30
158
class UtilityTestCase(TestCase):