Skip to main content

Simple imap wrapper.

Project description

About this module

Simple imap wrapper.

Latest Version Supported Python versions License Status

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)’.:

>>> mail1, mail2 = imapper.listup(2)
>>> mail1.uid
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

  • copy(uid=id, to=”AnotherMailBox”)

    Copies a mail to another mailbox uid = MailObject.uid To = To which mailbox (String)

  • listids(limit=10, criterion=None)

    Returns list of available email ids.

  • listup(limit=10, criterion=None, include_raw=False)

    Returns list of mail_object.

  • unseen(limit=10)

    Returns list of mail_object.

  • mail(uid, 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.

  • content_type

    Returns string of ‘Content-Type’ header.

  • content_transfer_encoding

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

  • references

    Returns string of ‘References’ header.

  • in_reply_to

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

  • reply_to

    Returns string of ‘Reply-To’ header.

  • return_path

    Returns string of ‘Return-Path’ header.

  • mime_version

    Returns string of ‘MIME-Version’ header.

  • message_id

    Returns string of ‘Message-ID’ header.

  • attachments

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

Recent Change

  • 0.7.1
    • Hotfix changed copy mail function

  • 0.7.0
    • Added new feature to copy mails to another mailbox

  • 0.6.3
    • Add support for python-3.5.

    • Fixed a bug in decoding an attached plain text.

  • 0.6.2
    • Fixed a bug in header/body encoding

  • 0.6.1
    • Fixed a bug in _decode_header function

  • 0.6.0
    • Add support for Python-3.4.

    • Backward incompatible changes
      • Modify listup to return list of mailobj.

      • Rename many properties to underbar separated format.

Project details


Download files

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

Source Distribution

easyimap-python-0.7.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easyimap_python-0.7.1-py2.py3-none-any.whl (5.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file easyimap-python-0.7.1.tar.gz.

File metadata

File hashes

Hashes for easyimap-python-0.7.1.tar.gz
Algorithm Hash digest
SHA256 f3bc58fc583152b12fc94c15edf6af5fae24074d12b140c3a87d80ec58f1d5ab
MD5 c014f3241a31edfde3e9f78e1990b84d
BLAKE2b-256 7b714b800fd9adbb04a07ebca30fa9e0cf93f779bd8be4c4a2d84c5ca5b72a54

See more details on using hashes here.

File details

Details for the file easyimap_python-0.7.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for easyimap_python-0.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 43ee4fd4d957c3195adef9549e8beaa0f4548db9c2007321f0a7811d3e86c448
MD5 aa7299643dedf14b25b911c221cbcf4a
BLAKE2b-256 a284c7f6e90a5f097560dcd29de11f8c6437bc4e42cc657ba93707216ac97da5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page