Ejemplo n.º 1
0
    def test_crackHeaders_default_community_in_CC(self):
        from karl.testing import DummyUsers
        context = self._makeRoot()
        context.users = DummyUsers()
        profile = self._makeContext()
        profile.__name__ = 'extant'
        by_email = {'*****@*****.**': profile}
        pf = context['profiles'] = self._makeContext()
        pf.getProfileByEmail = lambda email: by_email.get(email)
        cf = context['communities'] = self._makeContext()
        community = cf['testing'] = self._makeContext()
        community['default'] = self._makeContext()
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**',)
        message.cc = ('*****@*****.**',)
        message.from_ = ('*****@*****.**',)
        message.subject = 'subject'

        info = mailin.crackHeaders(message)
        self.failIf(info.get('error'))
        self.assertEqual(info['author'], 'extant')
        self.assertEqual(info['subject'], 'subject')
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['community'], 'testing')
        self.assertEqual(info['tool'], 'default')
        self.assertEqual(info['in_reply_to'], None)
Ejemplo n.º 2
0
 def test_crackHeaders_with_date_from_date_header(self):
     import datetime
     from email.utils import formatdate
     from karl.testing import DummyUsers
     import time
     context = self._makeRoot()
     context.users = DummyUsers()
     profile = self._makeContext()
     profile.__name__ = 'extant'
     by_email = {'*****@*****.**': profile}
     pf = context['profiles'] = self._makeContext()
     pf.getProfileByEmail = lambda email: by_email.get(email)
     cf = context['communities'] = self._makeContext()
     community = cf['testing'] = self._makeContext()
     community['default'] = self._makeContext()
     mailin = self._makeOne(context)
     mailin.default_tool = 'default'
     message = DummyMessage()
     message.to = ('*****@*****.**',)
     message.from_ = ('*****@*****.**',)
     message.subject = 'subject'
     date = time.mktime((2010, 5, 12, 2, 42, 0, 0, 0, -1))
     message.date = formatdate(date)
     info = mailin.crackHeaders(message)
     self.assertEqual(info['date'], datetime.datetime(2010, 5, 12, 2, 42))
Ejemplo n.º 3
0
    def test_crackHeaders_no_From(self):
        context = self._makeRoot()
        cf = context['communities'] = self._makeContext()
        cf['testing'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.crackHeaders(message)
        self.assertEqual(info['error'], 'missing From:')
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['community'], 'testing')
        self.assertEqual(info['tool'], 'tool')
        self.assertEqual(info['in_reply_to'], '12345')
Ejemplo n.º 4
0
    def test_crackHeaders_permission_denied(self):
        from karl.testing import registerDummySecurityPolicy
        registerDummySecurityPolicy('someuser', permissive=False)
        from karl.testing import DummyUsers
        context = self._makeRoot()
        context.users = DummyUsers()
        profile = self._makeContext()
        profile.__name__ = 'extant'
        by_email = {'*****@*****.**': profile}
        pf = context['profiles'] = self._makeContext()
        pf.getProfileByEmail = lambda email: by_email.get(email)
        cf = context['communities'] = self._makeContext()
        community = cf['testing'] = self._makeContext()
        community['default'] = self._makeContext()
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**',)
        message.from_ = ('*****@*****.**',)
        message.subject = 'subject'

        info = mailin.crackHeaders(message)
        self.assertEqual(info['targets'][0]['error'], 'Permission Denied')
Ejemplo n.º 5
0
 def test_crackHeaders_no_To(self):
     mailin = self._makeOne()
     message = DummyMessage()
     info = mailin.crackHeaders(message)
     self.assertEqual(info['error'],
                      'no community or distribution list specified')
Ejemplo n.º 6
0
 def test_crackHeaders_no_To(self):
     mailin = self._makeOne()
     message = DummyMessage()
     info = mailin.crackHeaders(message)
     self.assertEqual(info['error'],
                      'no community or distribution list specified')