Example #1
0
 def test_vacation_reply(self):
     mail = get_email_as_bytes("vacation-reply.eml")
     body = serialize_mail(mail)
     body_map = {k: v for k, v in body}
     manifest = json.loads(body_map["manifest"][1].read().decode("utf-8"))
     self.assertTrue(manifest["headers"]["auto_reply_type"],
                     "vacation-reply")
Example #2
0
 def test_html_only(self):
     mail = get_email_as_bytes("html_only.eml")
     body = serialize_mail(mail)
     body_map = {k: v for k, v in body}
     manifest = json.loads(body_map["manifest"][1].read().decode("utf-8"))
     self.assertTrue(manifest["text"]["content"])
     self.assertTrue(manifest["text"]["html_content"])
Example #3
0
def process_msg(client, msg_id, config, session, sentry_client=None):
    print("Fetch message ID {}".format(msg_id))
    start = time.time()
    raw_mail = client.fetch(msg_id)
    end = time.time()
    print("Message downloaded in {} seconds".format(end - start))

    try:
        start = time.time()
        body = serialize_mail(raw_mail, config['compress_eml'])
        end = time.time()
        print("Message serialized in {} seconds".format(end - start))
        response = session.post(config['webhook'], json=body).json()
        print("Delivered message id {} :".format(msg_id), response)
        if config['imap']['on_success'] == 'delete':
            client.mark_delete(msg_id)
        elif config['imap']['on_success'] == 'move':
            client.move(msg_id, config['imap']['success'])
        else:
            print("Nothing to do for message id {}".format(msg_id))
    except Exception as e:
        if sentry_client:
            sentry_client.captureException()
        client.move(msg_id, config['imap']['error'])
        print("Unable to parse or delivery msg", e)
Example #4
0
def process_msg(client, msg_id, config, session, sentry_client=None):
    print("Fetch message ID {}".format(msg_id))
    start = time.time()
    raw_mail = client.fetch(msg_id)
    end = time.time()
    print("Message downloaded in {} seconds".format(end - start))

    try:
        start = time.time()
        body = serialize_mail(raw_mail, config["compress_eml"])
        end = time.time()
        print("Message serialized in {} seconds".format(end - start))
        res = session.post(config['webhook'], files=body)
        print("Received response:", res.text)
        res.raise_for_status()
        response = res.json()
        print("Delivered message id {} :".format(msg_id), response)
        if config["imap"]["on_success"] == "delete":
            client.mark_delete(msg_id)
        elif config["imap"]["on_success"] == "move":
            client.move(msg_id, config["imap"]["success"])
        else:
            print("Nothing to do for message id {}".format(msg_id))
    except Exception as e:
        sentry_sdk.capture_exception(e)
        client.move(msg_id, config["imap"]["error"])
        print("Unable to parse or delivery msg", e)
Example #5
0
 def test_html_only(self):
     mail = get_email_as_bytes('html_only.eml')
     body = serialize_mail(mail)
     self.assertTrue(body['text']['content'])
Example #6
0
 def test_vacation_reply(self):
     mail = get_email_as_bytes('vacation-reply.eml')
     body = serialize_mail(mail)
     self.assertTrue(body['headers']['auto_reply_type'], 'vacation-reply')
Example #7
0
 def test_disposition_notification(self):
     mail = get_email_as_bytes('disposition-notification.eml')
     body = serialize_mail(mail)
     self.assertTrue(body['headers']['auto_reply_type'],
                     'disposition-notification')