本文整理汇总了Python中froide.helper.email_utils.EmailParser类的典型用法代码示例。如果您正苦于以下问题:Python EmailParser类的具体用法?Python EmailParser怎么用?Python EmailParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EmailParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_mail
def _process_mail(mail_string, mail_type=None, manual=False):
parser = EmailParser()
if mail_type is None:
email = parser.parse(BytesIO(mail_string))
elif mail_type == 'postmark':
email = parser.parse_postmark(json.loads(mail_string.decode('utf-8')))
return _deliver_mail(email, mail_string=mail_string, manual=manual)
示例2: test_attachment_name_parsing
def test_attachment_name_parsing(self):
with open(p("test_mail_07.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(len(mail['attachments']), 1)
self.assertEqual(mail['attachments'][0].name, u'Bescheid Fäker.pdf')
示例3: test_attachment_name_broken_encoding
def test_attachment_name_broken_encoding(self):
with open(p("test_mail_06.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(len(mail['attachments']), 1)
self.assertEqual(mail['attachments'][0].name, u'Eingangsbestätigung und Hinweis auf Unzustellbarkeit - Username.pdf')
示例4: test_attachment_name_parsing_header
def test_attachment_name_parsing_header(self):
with open(p("test_mail_10.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(len(mail.attachments), 1)
self.assertEqual(mail.attachments[0].name, 'Eingangsbestätigung Akteneinsicht.doc')
示例5: _process_mail
def _process_mail(mail_string):
parser = EmailParser()
email = parser.parse(mail_string)
received_list = email['to'] + email['cc'] \
+ email['resent_to'] + email['resent_cc']
# TODO: BCC?
from foirequest.models import FoiRequest
mail_filter = lambda x: x[1].endswith("@%s" % settings.FOI_EMAIL_DOMAIN)
received_list = filter(mail_filter, received_list)
# make original mail storeable as unicode
try:
mail_string = mail_string.decode("utf-8")
except UnicodeDecodeError:
mail_string = base64.b64encode(mail_string).decode("utf-8")
for received in received_list:
secret_mail = received[1]
try:
foi_request = FoiRequest.objects.get_by_secret_mail(secret_mail)
except FoiRequest.DoesNotExist:
if secret_mail.endswith('@%s' % settings.FOI_EMAIL_DOMAIN):
mail_managers(_('Unknown FoI-Mail Recipient'),
unknown_foimail_message % {'address': secret_mail})
continue
foi_request.add_message_from_email(email, mail_string)
示例6: test_borked_subject
def test_borked_subject(self):
''' Subject completly borked '''
with open(p("test_mail_09.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertIn('Unterlagen nach', mail.subject)
self.assertIn('E-Mail Empfangsbest', mail.subject)
示例7: test_attachment_name_parsing_2
def test_attachment_name_parsing_2(self):
with open(p("test_mail_11.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(mail.subject, 'Bescheid zu Ihrer ergänzten IFG-Anfrage Bestellung Infomaterial, Broschüren... [#32154]')
self.assertEqual(len(mail.attachments), 1)
self.assertEqual(mail.attachments[0].name, '20180904_Bescheid Broschüren.pdf')
示例8: test_attachment_name_broken_encoding
def test_attachment_name_broken_encoding(self):
with open(p("test_mail_06.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(len(mail.attachments), 2)
self.assertEqual(mail.attachments[0].name, 'usernameEingangsbestätigung und Hinweis auf Unzustellbarkeit - Username.pdf')
self.assertEqual(mail.attachments[1].name, '15-725_002 II_0367.pdf')
示例9: test_recipient_parsing
def test_recipient_parsing(self):
with open(p("test_mail_05.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(len(mail.cc), 2)
self.assertEqual(len(mail.to), 3) # contains X-Original-To as well
self.assertTrue(mail.is_auto_reply)
示例10: deferred_fill_sender
def deferred_fill_sender(apps, schema_editor):
parser = EmailParser()
DeferredMessage = apps.get_model('foirequest', 'DeferredMessage')
for deferred in DeferredMessage.objects.all():
print(deferred.pk)
email = parser.parse(BytesIO(base64.b64decode(deferred.mail)))
deferred.sender = email.from_[1]
deferred.save()
示例11: test_eml_attachments
def test_eml_attachments(self):
with open(p("test_mail_08.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
subject = u'WG: Disziplinarverfahren u.a. gegen B\xfcrgermeister/Hauptverwaltungsbeamte/Amtsdirektoren/ehrenamtliche B\xfcrgermeister/Ortsvorsteher/Landr\xe4te im Land Brandenburg in den letzten Jahren [#5617]'
self.assertEqual(mail['attachments'][0].name,
'%s.eml' % subject[:45])
示例12: _process_mail
def _process_mail(mail_bytes, mail_type=None, manual=False):
parser = EmailParser()
if mail_type is None:
with closing(BytesIO(mail_bytes)) as stream:
email = parser.parse(stream)
elif mail_type == 'postmark':
email = parser.parse_postmark(json.loads(mail_bytes.decode('utf-8')))
return _deliver_mail(email, mail_bytes=mail_bytes, manual=manual)
示例13: test_attachment_name_parsing
def test_attachment_name_parsing(self):
with open(p("test_mail_07.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertEqual(mail.subject, 'Anfrage nach dem Informationsfreiheitsgesetz; Gespräch damaliger BM Steinmeier Matthias Müller VW AG; Vg. 069-2018')
self.assertEqual(len(mail.attachments), 2)
self.assertEqual(mail.attachments[0].name, 'Bescheid Fäker.pdf')
self.assertEqual(mail.attachments[1].name, '180328 Schreiben an Antragstellerin; Vg. 069-2018.pdf')
示例14: test_html_only_mail
def test_html_only_mail(self):
with open(p("test_mail_13.txt"), 'rb') as f:
parser = EmailParser()
content = f.read()
mail = parser.parse(BytesIO(content))
self.assertTrue(len(mail.body) > 10)
# Markdown like links are rendered
self.assertIn('](https://', mail.body)
self.assertIn('*[email protected]*', mail.body)
示例15: test_bounce_parsing_2
def test_bounce_parsing_2(self):
parser = EmailParser()
with open(p("bounce_002.txt"), 'rb') as f:
email = parser.parse(f)
bounce_address = make_bounce_address(self.email)
email.to = [('', bounce_address)]
bounce_info = email.bounce_info
self.assertTrue(bounce_info.is_bounce)
self.assertEqual(bounce_info.bounce_type, 'hard')
self.assertEqual(bounce_info.status, (5, 1, 1))