def bounced_addresses_filter(searcher, contacts): query = QueryParser('bounced', searcher.schema).parse('*') bounced_addresses = searcher.search( query, limit=None, groupedby=sorting.FieldFacet('bounced', allow_overlap=True)).groups() return set(contacts) - set(flatten([bounced_addresses]))
def bounced_addresses_filter(searcher, contacts): query = QueryParser('bounced', searcher.schema).parse('*') bounced_addresses = searcher.search(query, limit=None, groupedby=sorting.FieldFacet('bounced', allow_overlap=True)).groups() return set(contacts) - set(flatten([bounced_addresses]))
def sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) self.smtp_client.sendmail( self.account_email_address, recipients, mail.to_smtp_format() )
def sendmail(self, mail): recipients = flatten([mail.get_to(), mail.get_cc(), mail.get_bcc()]) self.smtp_client.sendmail( self.account_email_address, recipients, mail.to_smtp_format() )
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))
def test_iterates_over_recipients_and_send_whitout_bcc_field(self): input_mail = InputMail.from_dict(mail_dict()) bccs = input_mail.bcc 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(MailToSmtpFormatCapture(recipient, bccs), TwistedSmtpUserCapture(recipient))
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 sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) resultDeferred = Deferred() senderFactory = SMTPSenderFactory(fromEmail=self.account_email_address, toEmail=recipients, file=StringIO(mail.to_smtp_format()), deferred=resultDeferred) return reactor.connectTCP('localhost', 4650, senderFactory)
def sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) results = yield self._send_mail_to_all_recipients(mail, recipients) all_succeeded = reduce(lambda a, b: a and b, [r[0] for r in results]) if not all_succeeded: error_map = self._build_error_map(recipients, results) raise MailSenderException('Failed to send mail to all recipients', error_map) defer.returnValue(all_succeeded)
def sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) resultDeferred = Deferred() senderFactory = SMTPSenderFactory( fromEmail=self.account_email_address, toEmail=recipients, file=StringIO(mail.to_smtp_format()), deferred=resultDeferred) return reactor.connectTCP('localhost', 4650, senderFactory)
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)
def sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) results = yield self._send_mail_to_all_recipients(mail, recipients) all_succeeded = reduce(lambda a, b: a and b, [r[0] for r in results]) if not all_succeeded: error_map = self._build_error_map(recipients, results) raise MailSenderException('Failed to send mail to all recipients', error_map) defer.returnValue(all_succeeded)
def search_addresses(searcher, query): restrict_q = Term("tag", "drafts") | Term("tag", "trash") results = [] for field in ['to', 'cc', 'bcc', 'sender']: query_parser = QueryParser(field, searcher.schema) results.append(searcher.search(query_parser.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet(field, allow_overlap=True)).groups()) return flatten(results)
def search_addresses(searcher, query): restrict_q = Term("tag", "drafts") | Term("tag", "trash") results = [] for field in ['to', 'cc', 'bcc', 'sender']: query_parser = QueryParser(field, searcher.schema) results.append( searcher.search(query_parser.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet( field, allow_overlap=True)).groups()) return flatten(results)
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_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))
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_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_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)
def sendmail(self, mail): if self.ensure_smtp_is_running_cb(): recipients = flatten([mail.to, mail.cc, mail.bcc]) result_deferred = Deferred() sender_factory = SMTPSenderFactory( fromEmail=self.account_email_address, toEmail=set([parseaddr(recipient)[1] for recipient in recipients]), file=StringIO(mail.to_smtp_format()), deferred=result_deferred) reactor.connectTCP('localhost', 4650, sender_factory) return result_deferred return fail(SMTPDownException())
def sendmail(self, mail): # message is changed in sending, but should be saved unaltered mail = deepcopy(mail) recipients = flatten([mail.to, mail.cc, mail.bcc]) results = yield self._send_mail_to_all_recipients(mail, recipients) all_succeeded = reduce(lambda a, b: a and b, [r[0] for r in results]) if not all_succeeded: error_map = self._build_error_map(recipients, results) raise MailSenderException('Failed to send mail to all recipients', error_map) defer.returnValue(all_succeeded)
def sendmail(self, mail): # message is changed in sending, but should be saved unaltered mail = deepcopy(mail) recipients = flatten([mail.to, mail.cc, mail.bcc]) results = yield self._send_mail_to_all_recipients(mail, recipients) all_succeeded = reduce(lambda a, b: a and b, [r[0] for r in results]) if not all_succeeded: error_map = self._build_error_map(recipients, results) raise MailSenderException('Failed to send mail to all recipients', error_map) defer.returnValue(all_succeeded)
def contacts(self, query): if query: to = QueryParser('to', self._index.schema) cc = QueryParser('cc', self._index.schema) bcc = QueryParser('bcc', self._index.schema) with self._index.searcher() as searcher: to = searcher.search(to.parse("*%s*" % query), limit=None, groupedby=sorting.FieldFacet('to', allow_overlap=True)).groups() cc = searcher.search(cc.parse("*%s*" % query), limit=None, groupedby=sorting.FieldFacet('cc', allow_overlap=True)).groups() bcc = searcher.search(bcc.parse("*%s*" % query), limit=None, groupedby=sorting.FieldFacet('bcc', allow_overlap=True)).groups() return flatten([to, cc, bcc]) return []
def test_keymanager_encrypt_problem_raises_exception(self): input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org') when(OutgoingMail)._maybe_attach_key(any(), any(), any()).thenReturn( defer.succeed(None)) when(OutgoingMail)._fix_headers(any(), any(), any()).thenReturn( defer.succeed((None, mock()))) when(self._keymanager_mock).encrypt(any(), any(), sign=any(), fetch_remote=any()).thenReturn(defer.fail(Exception('pretend key expired'))) with patch('leap.bitmask.mail.outgoing.service.emit_async'): 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)
def contacts(self, query): restrict_q = Term("tag", "drafts") | Term("tag", "trash") if query: to = QueryParser('to', self._index.schema) cc = QueryParser('cc', self._index.schema) bcc = QueryParser('bcc', self._index.schema) sender = QueryParser('sender', self._index.schema) with self._index.searcher() as searcher: to = searcher.search(to.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('to', allow_overlap=True)).groups() cc = searcher.search(cc.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('cc', allow_overlap=True)).groups() bcc = searcher.search(bcc.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('bcc', allow_overlap=True)).groups() sender = searcher.search(sender.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('sender', allow_overlap=True)).groups() return flatten([to, cc, bcc, sender]) return []
def contacts(self, query): if query: to = QueryParser('to', self._index.schema) cc = QueryParser('cc', self._index.schema) bcc = QueryParser('bcc', self._index.schema) with self._index.searcher() as searcher: to = searcher.search(to.parse("*%s*" % query), limit=None, groupedby=sorting.FieldFacet( 'to', allow_overlap=True)).groups() cc = searcher.search(cc.parse("*%s*" % query), limit=None, groupedby=sorting.FieldFacet( 'cc', allow_overlap=True)).groups() bcc = searcher.search(bcc.parse("*%s*" % query), limit=None, groupedby=sorting.FieldFacet( 'bcc', allow_overlap=True)).groups() return flatten([to, cc, bcc]) return []