Skip to main content

Simple imap wrapper.

Project description

About this module

Simple imap wrapper.

Example to use

connect function create IMAP4_SSL instance by default:

>>> import easyimap
>>> host = "imap.gmail.com"
>>> user = "me@example.com"
>>> password = "hogehogehogehoge"
>>> mailbox = "secret"
>>> imapper = easyimap.connect(host, user, password, mailbox)

connect function also create IMAP4 instance by passing ssl argument:

>>> import easyimap
>>> host = "imap.gmail.com"
>>> user = "me@example.com"
>>> password = "hogehogehogehoge"
>>> mailbox = "secret"
>>> imapper = easyimap.connect(host, user, password, mailbox, ssl=False, port=143)
This imapper can list up latest n mail by listup method.
By default, This invoke fetch from IMAP4_SSL instance with ‘(UID RFC822)’.::
>>> imapper.listup(2)
[(80, <easyimap.easyimap.MailObj object at 0x...>), (79, <easyimap.easyimap.MailObj object at 0x...)]
>>> [(id1, mail1), (id2, mail2)] = imapper.listup(2)
>>> id1
80
>>> mail1
<easyimap.easyimap.MailObj object at 0x...>
>>> type(mail1.body)
<type 'unicode'>
>>> type(mail1.title)
<type 'unicode'>
>>> type(mail1.date)
<type 'unicode'>
>>> type(mail1.sender)
<type 'unicode'>

You can check latest unseen mail by unseen method:

>>> imapper.unseen(2)
[(82, <easyimap.easyimap.MailObj object at 0x...>), (81, <easyimap.easyimap.MailObj object at 0x...)]

You can directly fetch email object with specific id:

>>> imapper.mail(80)
<easyimap.easyimap.MailObj object at 0x...>

You can download attachments:

>>> imapper.mail(80)
>>> (id, mail) = imapper.mail(80)
>>> for attachment in mail.attachment:
>>>     print attachment[0], attachment[1]

Finally, call quit method:

>>> imapper.quit()

Basic API

  • easyimap.connect(host, user, password, mailbox=’INBOX’, timeout=15, ssl=True, port=993, **kwargs)
    Create IMAP4(_SSL) wrapper.
    If you want to keep read/unread status, Please pass optional read_only=True argument.
    kwargs are read from Imapper’s constructor. Plz read source code.

Imapper

  • listids(limit=10, criterion=None)
    Returns list of available email ids.
  • listup(limit=10, criterion=None, include_raw=False)
    Returns list of tuples(email_id, mail_object).
  • unseen(limit=10)
    Returns list of typles(email_id, mail_object).
  • mail(id, include_raw=False)
    Returns MailObj.
  • change_mailbox(mailbox)
    Change mailbox.
  • quit()
    Close and Logout.

MailObject

  • uid

    Returns UID(type: int).

  • raw

    if you fetched email with include_raw option, this returns raw Data:

    >>> [(id1, mail1), (id2, mail2)] = imapper.listup(2, include_raw)
    >>> data = mail1.raw
    
  • title

    Returns string of ‘Subject’ header.

  • sender

    Returns string of ‘Sender’ header.

  • from_addr

    Returns string of ‘From’ header.

  • to

    Returns string of ‘To’ header.

  • date

    Returns string of ‘Date’ header.

  • body

    Returns string of Body.

  • contenttype

    Returns string of ‘Content-Type’ header.

  • contenttransferencoding

    Returns string of ‘Content-Transfer-Encoding’ header.

  • references

    Returns string of ‘References’ header.

  • inreplyto

    Returns string of ‘In-Reply-To’ header.

  • replyto

    Returns string of ‘Reply-To’ header.

  • returnpath

    Returns string of ‘Return-Path’ header.

  • mimeversion

    Returns string of ‘MIME-Version’ header.

  • messageid

    Returns string of ‘Message-ID’ header.

  • attachments

    Returns list of tuples(‘attached file name’, MailObj).

Project details


Release history Release notifications

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

This version
History Node

0.5.0

History Node

0.4.1

History Node

0.4.0

History Node

0.3.9

History Node

0.3.8

History Node

0.3.7

History Node

0.3.6

History Node

0.3.5

History Node

0.3.4

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.0

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
easyimap-0.5.0.tar.gz (5.7 kB) Copy SHA256 hash SHA256 Source None Jan 9, 2014
easyimap-0.5.0.zip (9.9 kB) Copy SHA256 hash SHA256 Source None Jan 9, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page