Beispiel #1
0
    def test_sendmail(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**',
                                 self.ensure_smtp_is_running_cb)

        return self._succeed(mail_sender.sendmail(input_mail))
 def setUp(self):
     self._cert_path = u'/some/cert/path'
     self._keymanager_mock = mock()
     self._remote_smtp_host = 'some.host.test'
     self._remote_smtp_port = 1234
     self._smtp_config = LeapSMTPConfig('*****@*****.**',
                                        self._cert_path,
                                        self._remote_smtp_host,
                                        self._remote_smtp_port)
     self.sender = MailSender(self._smtp_config, self._keymanager_mock)
    def test_iterates_over_recipients(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(any(), any()).thenAnswer(lambda: defer.succeed(None))

        yield sender.sendmail(input_mail)

        for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient))
    def test_senmail_returns_deffered(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**', self.smtp)

        deferred = mail_sender.sendmail(input_mail)

        self.assertIsNotNone(deferred)
        self.assertTrue(isinstance(deferred, Deferred))

        return self._succeed(deferred)
    def test_senmail_returns_deffered(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**', self.smtp)

        deferred = mail_sender.sendmail(input_mail)

        self.assertIsNotNone(deferred)
        self.assertTrue(isinstance(deferred, Deferred))

        return self._succeed(deferred)
    def test_doesnt_send_mail_if_smtp_is_not_running(self):
        mail_sender = MailSender('*****@*****.**', self.ensure_smtp_is_not_running_cb)

        deferred = mail_sender.sendmail({})

        def _assert(_):
            self.assertTrue(isinstance(deferred.result.value, SMTPDownException))

        deferred.addErrback(_assert)

        return deferred
    def test_problem_with_email_raises_exception(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(any(), any()).thenAnswer(lambda: defer.fail(Exception('pretend something went wrong')))

        try:
            yield sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
    def test_sendmail_uses_twisted(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)

        input_mail = InputMail.from_dict(mail_dict())

        mail_sender = MailSender('*****@*****.**', self.smtp)

        sent_deferred = mail_sender.sendmail(input_mail)

        verify(reactor).connectTCP('localhost', 4650, any())

        return self._succeed(sent_deferred)
    def test_sendmail_uses_twisted(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)

        input_mail = InputMail.from_dict(mail_dict())

        mail_sender = MailSender('*****@*****.**', self.smtp)

        sent_deferred = mail_sender.sendmail(input_mail)

        verify(reactor).connectTCP('localhost', 4650, any())

        return self._succeed(sent_deferred)
Beispiel #10
0
    def test_doesnt_send_mail_if_smtp_is_not_running(self):
        mail_sender = MailSender('*****@*****.**',
                                 self.ensure_smtp_is_not_running_cb)

        deferred = mail_sender.sendmail({})

        def _assert(_):
            self.assertTrue(
                isinstance(deferred.result.value, SMTPDownException))

        deferred.addErrback(_assert)

        return deferred
Beispiel #11
0
    def test_iterates_over_recipients(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(
            any(), any()).thenAnswer(lambda: defer.succeed(None))

        yield sender.sendmail(input_mail)

        for recipient in flatten(
            [input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(
                any(), TwistedSmtpUserCapture(recipient))
class MailSenderTest(unittest.TestCase):

    def setUp(self):
        self._cert_path = u'/some/cert/path'
        self._keymanager_mock = mock()
        self._remote_smtp_host = 'some.host.test'
        self._remote_smtp_port = 1234
        self._smtp_config = LeapSMTPConfig('*****@*****.**', self._cert_path, self._remote_smtp_host, self._remote_smtp_port)
        self.sender = MailSender(self._smtp_config, self._keymanager_mock)

    def tearDown(self):
        unstub()

    @defer.inlineCallbacks
    def test_iterates_over_recipients(self):
        input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient))

    @defer.inlineCallbacks
    def test_send_leaves_mail_in_tact(self):
        input_mail_dict = mail_dict()
        input_mail = InputMail.from_dict(input_mail_dict, from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        self.assertEqual(input_mail.to, input_mail_dict["header"]["to"])
        self.assertEqual(input_mail.cc, input_mail_dict["header"]["cc"])
        self.assertEqual(input_mail.bcc, input_mail_dict["header"]["bcc"])
        self.assertEqual(input_mail.subject, input_mail_dict["header"]["subject"])

    @defer.inlineCallbacks
    def test_problem_with_email_raises_exception(self):
        input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.fail(Exception('pretend something went wrong')))

        try:
            yield self.sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
Beispiel #13
0
    def test_problem_with_email_raises_exception(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(any(), any()).thenAnswer(
            lambda: defer.fail(Exception('pretend something went wrong')))

        try:
            yield sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten(
                [input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
 def setUp(self):
     self._cert_path = u'/some/cert/path'
     self._keymanager_mock = mock()
     self._remote_smtp_host = 'some.host.test'
     self._remote_smtp_port = 1234
     self._smtp_config = LeapSMTPConfig('*****@*****.**', self._cert_path, self._remote_smtp_host, self._remote_smtp_port)
     self.sender = MailSender(self._smtp_config, self._keymanager_mock)
def init_app(app, leap_home, leap_session):
    leap_session.start_background_jobs()
    keymanager = leap_session.nicknym.keymanager

    soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad)

    search_engine = SearchEngine(soledad_querier, agent_home=leap_home)
    pixelated_mail_sender = MailSender(
        leap_session.account_email(),
        lambda: leap_session.smtp.ensure_running())

    pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier,
                                    search_engine)
    draft_service = DraftService(pixelated_mailboxes)
    mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender,
                               soledad_querier, search_engine)

    MailboxIndexerListener.SEARCH_ENGINE = search_engine
    InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email()

    app.resource.initialize(soledad_querier, keymanager, search_engine,
                            mail_service, draft_service)

    register(signal=proto.SOLEDAD_DONE_DATA_SYNC,
             callback=init_index_and_remove_dupes(querier=soledad_querier,
                                                  search_engine=search_engine,
                                                  mail_service=mail_service))

    register(signal=proto.SOLEDAD_DONE_DATA_SYNC,
             uid=CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK,
             callback=look_for_user_key_and_create_if_cant_find(leap_session))

    reactor.threadpool.adjustPoolsize(20, 40)
    reactor.stop = stop_incoming_mail_fetcher(reactor.stop, leap_session)
class MailSenderTest(unittest.TestCase):
    def setUp(self):
        self._cert_path = u'/some/cert/path'
        self._keymanager_mock = mock()
        self._remote_smtp_host = 'some.host.test'
        self._remote_smtp_port = 1234
        self._smtp_config = LeapSMTPConfig('*****@*****.**',
                                           self._cert_path,
                                           self._remote_smtp_host,
                                           self._remote_smtp_port)
        self.sender = MailSender(self._smtp_config, self._keymanager_mock)

    def tearDown(self):
        unstub()

    @defer.inlineCallbacks
    def test_iterates_over_recipients(self):
        input_mail = InputMail.from_dict(mail_dict(),
                                         from_address='pixelated@org')

        when(OutgoingMail).send_message(any(),
                                        any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        for recipient in flatten(
            [input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(
                any(), TwistedSmtpUserCapture(recipient))

    @defer.inlineCallbacks
    def test_problem_with_email_raises_exception(self):
        input_mail = InputMail.from_dict(mail_dict(),
                                         from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(
            defer.fail(Exception('pretend something went wrong')))

        try:
            yield self.sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten(
                [input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
class PixelatedDuplicateEmailTest(unittest.TestCase):
    def setUp(self):
        self.mail_sender = MailSender(self, "*****@*****.**")

    def test_remove_duplicate_mail_recepients(self):
        mail_list = ['*****@*****.**', '*****@*****.**', '*****@*****.**']
        normalized_recepients = self.mail_sender.recepients_normalizer(mail_list)
        self.assertEquals(normalized_recepients, set(['*****@*****.**', '*****@*****.**']))

    def test_get_email_addresses(self):
        mail_list = ['simbarashe<*****@*****.**>', '*****@*****.**', 'Fabio<*****@*****.**>', '*****@*****.**']
        selected_recepients = self.mail_sender.get_email_addresses(mail_list)
        self.assertEquals(selected_recepients, set(['*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**']))

    def test_remove_duplicate_emails_with_routing_format(self):
        mail_list = ['simbarashe<*****@*****.**>', 'simba<*****@*****.**>', 'Fabio<*****@*****.**>', 'Fabinho<*****@*****.**>']
        selected_recepients = self.mail_sender.get_email_addresses(mail_list)
        self.assertEquals(selected_recepients, set(['*****@*****.**', '*****@*****.**']))
Beispiel #18
0
    def _setup_mail_service(self, search_engine):
        pixelated_mail_sender = MailSender(
            self._leap_session.smtp_config,
            self._leap_session.keymanager.keymanager)

        return MailService(pixelated_mail_sender,
                           self._leap_session.mail_store, search_engine,
                           self._leap_session.account_email(),
                           LeapAttachmentStore(self._leap_session.soledad))
 def setup_mail_service(self, leap_session, search_engine):
     # if False:   FIXME
     #    yield pixelated_mailboxes.add_welcome_mail_for_fresh_user()
     pixelated_mail_sender = MailSender(
         leap_session.account_email(),
         leap_session.smtp)
     return MailService(
         pixelated_mail_sender,
         leap_session.mail_store,
         search_engine)
Beispiel #20
0
 def setup_mail_service(self, leap_session, soledad_querier, search_engine, pixelated_mailboxes):
     if False:   # FIXME
         yield pixelated_mailboxes.add_welcome_mail_for_fresh_user()
     pixelated_mail_sender = MailSender(
         leap_session.account_email(),
         leap_session.smtp)
     defer.returnValue(MailService(
         pixelated_mailboxes,
         pixelated_mail_sender,
         leap_session.mail_store,
         soledad_querier,
         search_engine))
Beispiel #21
0
    def setup_mail_service(self, leap_session, search_engine):
        pixelated_mail_sender = MailSender(leap_session.smtp_config,
                                           leap_session.nicknym.keymanager)

        return MailService(pixelated_mail_sender, leap_session.mail_store,
                           search_engine, leap_session.account_email())
 def setUp(self):
     self.mail_sender = MailSender(self, "*****@*****.**")
    def test_sendmail(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**', self.ensure_smtp_is_running_cb)

        return self._succeed(mail_sender.sendmail(input_mail))