Skip to main content

Tool for work with e-mail messages and not with the imap protocol.

Project description

Tool for work with e-mail messages and not with the imap protocol.

Python version

3.3+

License

MIT

PyPI

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

About

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

  • excessive low level

  • returned results are not ready to work with them

  • lack of convenient tools for working with directories

  • lack of convenient tools for working with letters in directories

imap_tools library takes into account the shortcomings of other libraries. Main 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)

  • absence of external dependencies

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:

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

Mailbox:

# 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([msg.uid for msg in mailbox.fetch('(UNSEEN)')], ['Answered', 'Flagged'], True)

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

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

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)

Project details


Release history Release notifications | RSS feed

This version

0.1.7

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.1.7.zip (10.2 kB view details)

Uploaded Source

File details

Details for the file imap_tools-0.1.7.zip.

File metadata

  • Download URL: imap_tools-0.1.7.zip
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for imap_tools-0.1.7.zip
Algorithm Hash digest
SHA256 95fb88cbd68a34b783c30d8c676f6f47de6afba51a11624cd405934647310866
MD5 281c94c6d76c89117bd8b75f8350ab39
BLAKE2b-256 763d8a29a36326a9cd7fff6c3d1d99614e8e2daa199820da6f24fa1f7305f45b

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