Skip to main content

Effective working with email messages using IMAP protocol.

Project description

Effective working with email messages using IMAP protocol.

Python version

3.3+

License

MIT

PyPI

https://pypi.python.org/pypi/imap_tools/

Features

  • transparent work with letter attributes

  • work with letters in directories (copy, delete, flag, move, seen)

  • work with directories (list, set, get, create, exists, rename, delete, status)

  • dependencies: typing

Installation

$ pip install imap_tools

Quick guide

Init:

from imap_tools import MailBox
mailbox = MailBox('imap.mail.com')
mailbox.login('test@mail.com', 'password')

Message attributes:

# NOTE: All message properties are cached by functools.lru_cache

for message in mailbox.fetch():
    message.id
    message.uid
    message.subject
    message.from_
    message.to
    message.date
    message.text
    message.html
    message.flags
    message.from_values
    message.to_values
    for filename, payload in message.attachments:
        filename, payload

Actions with messages in folder:

# NOTE: You can use 2 approaches to perform these operations
# "by one" - Perform operation for each message separately per N commands
# "in bulk" - Perform operation for message set per 1 command

# COPY all messages from current dir to folder1, *by one
for msg in mailbox.fetch():
    res = mailbox.copy(msg.uid, 'INBOX/folder1')

# DELETE all messages from current dir to folder1, *in bulk
mailbox.delete([msg.uid for msg in mailbox.fetch()])

# FLAG unseen messages in current folder as Answered and Flagged, *in bulk
mailbox.flag(mailbox.fetch('(UNSEEN)'), ['Answered', 'Flagged'], True)

# MOVE all messages from current dir to folder2, *in bulk
mailbox.move(mailbox.fetch(), 'INBOX/folder2')

# mark SEEN all messages sent at 05.03.2007 in current folder as unseen, *in bulk
mailbox.seen(mailbox.fetch("SENTON 05-Mar-2007"), False)

Actions with folders:

# LIST
for folder in mailbox.folder.list('INBOX'):
    print(folder['flags'], folder['delim'], folder['name'])
# SET
mailbox.folder.set('INBOX')
# GET
current_folder = mailbox.folder.get()
# CREATE
mailbox.folder.create('folder1')
# EXISTS
is_exists = mailbox.folder.exists('folder1')
# RENAME
mailbox.folder.rename('folder1', 'folder2')
# DELETE
mailbox.folder.delete('folder2')
# STATUS
for status_key, status_val in mailbox.folder.status('some_folder').items():
    print(status_key, status_val)

Reasons

There are many different libraries for working with e-mail via the imap protocol. Including imaplib library. However, these libraries contain various shortcomings, such as:

  • excessive low level

  • returned results are not ready to work with them

  • no convenient tools for working with: directories, letters in directories

Thanks to

shilkazx somepad

Project details


Release history Release notifications | RSS feed

This version

0.5

Download files

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

Source Distribution

imap_tools-0.5.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

imap_tools-0.5-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file imap_tools-0.5.tar.gz.

File metadata

  • Download URL: imap_tools-0.5.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5

File hashes

Hashes for imap_tools-0.5.tar.gz
Algorithm Hash digest
SHA256 0977b56ebf438afffec276d7d7c01fe974df44ae85f402a28be3df9b2cc6af62
MD5 ee5e3c3b0f6ed83546a24d3518d08efd
BLAKE2b-256 68516a66d51513681075a3271fc078bb776b3ec5ae1db13c72ae040f149f595b

See more details on using hashes here.

File details

Details for the file imap_tools-0.5-py3-none-any.whl.

File metadata

  • Download URL: imap_tools-0.5-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5

File hashes

Hashes for imap_tools-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 95b26c303f9b5e13774e51d743d37b3655dcaf2eb1e0ab72728859c78cb919ab
MD5 90676870729b7ac53491a57277775fd1
BLAKE2b-256 3c3f053720ddb791186a19c1b584037f0bf034ea1104b3adb55c744e3585d0fe

See more details on using hashes here.

Supported by

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