Skip to content

mailgun/flanker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flanker - email address and MIME parsing for Python

image

image

Flanker is an open source parsing library written in Python by the Mailgun Team. Flanker currently consists of an address parsing library (flanker.addresslib) as well as a MIME parsing library (flanker.mime).

Detailed documentation is provided in the User Manual as well as the API Reference. A Quickstart Guide is provided below.

Python Versions

Flanker is heavily used by Mailgun in production with Python 2.7. The current production version is v0.8.5.

Support for Python 3 was added in v0.9.0 by popular demand from the community. We are not using Flanker with Python 3 in the house. All we know is that tests pass with Python 3.6, so use at your own risk. Feel free to report Python 3 specific issues if you see any.

Installing

You can install flanker via pip or clone the repo from GitHub.

You'll need Python headers files before you start working with flanker, so install them first:

If you are using pip, simply type:

If you are cloning from GitHub, you can type:

Address Parsing

To parse a single mailbox (display name as well as email address):

An invalid address is returned as `None`:

To parse a single email address (no display name):

To parse an address list:

To parse an address list as well as return a tuple containing the parsed addresses and the unparsable portions

To parse an address list in strict mode:

To validate an email address (parse as well as DNS, MX existence, and ESP grammar checks):

To validate an address list:

MIME Parsing

For the following examples, message_string will be set to the following MIME message:

MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c1d71697c7f004e6856996
From: Bob <bob@example.com>
To: Alice <alice@example.com>
Subject: hello, world
Date: Mon, 16 Sep 2013 12:43:03 -0700

--001a11c1d71697c7f004e6856996
Content-Type: text/plain; charset=us-ascii

Hello, *Alice*

--001a11c1d71697c7f004e6856996
Content-Type: text/html; charset=us-ascii

<p>Hello, <b>Alice</b></p>

--001a11c1d71697c7f004e6856996--

To parse a MIME message:

MIME message headers (unicode multi-value dictionary with headers):

Useful content_type member with predicates:

Decoded body of a message: