Skip to main content

mailbox over IMAP

Project description

Please note that imap_mailbox is still under active development and will be subject to significant changes.

import imap_mailbox

# connect to the IMAP server
with imap_mailbox.IMAPMailbox('imap.example.com', 'username', 'password') as mailbox:
    
    # search messages from vip@example.com
    uids = mailbox.search('FROM', 'vip@example.com')
    
    # move the messages to the 'VIP' folder
    mailbox.move(uids, 'VIP')

This module provides a subclass of mailbox.Mailbox that allows you to interact with an IMAP server. It is designed to be a drop-in replacement for the standard library mailbox module.

Installation

Install the latest stable version from PyPI:

pip install imap-mailbox

Install the latest version from GitHub:

pip install https://github.com/medecau/imap_mailbox/archive/refs/heads/main.zip

Examples

Iterate over messages in a folder

import imap_mailbox

# connect to the IMAP server
with imap_mailbox.IMAPMailbox('imap.example.com', 'username', 'password') as mailbox:
    
    # select the INBOX folder
    mailbox.select('INBOX')
    
    # iterate over messages in the folder
    for message in mailbox:
        print(f"From: {message['From']}")
        print(f"Subject: {message['Subject']}")

Connect to a Proton Mail account

import imap_mailbox

# connect to the local IMAP bridge
with imap_mailbox.IMAPMailbox(
    '127.0.0.1', 'username', 'password'
    port=1143, security='STARTTLS'
    ) as mailbox:
    
    # search messages from your friend
    uids = mailbox.search('FROM', 'handler@proton.me')

    # erase the evidence
    mailbox.delete(uids)
    

this is a joke; don't use proton for crimes – stay safe

Delete messages from a noisy sender

import imap_mailbox

with imap_mailbox.IMAPMailbox('imap.example.com', 'username', 'password') as mailbox:
    
    # search messages from
    uids = mailbox.search('FROM', 'spammer@example.com')

    # delete the messages
    mailbox.delete(uids)

Delete GitHub messages older than two years

import imap_mailbox

with imap_mailbox.IMAPMailbox('imap.example.com', 'username', 'password') as mailbox:
    
    # search messages older than two years from github.com
    uids = mailbox.search('NOT PAST2YEARS FROM github.com')
    
    # delete the messages
    mailbox.delete(uids)

Contribution

Help improve imap_mailbox by reporting any issues or suggestions on our issue tracker at github.com/medecau/imap_mailbox/issues.

Get involved with the development, check out the source code at github.com/medecau/imap_mailbox.

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

imap_mailbox-0.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

imap_mailbox-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file imap_mailbox-0.2.0.tar.gz.

File metadata

  • Download URL: imap_mailbox-0.2.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.0 Darwin/22.2.0

File hashes

Hashes for imap_mailbox-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fdba27f4384861f4c6cdef5bafd75666a1138003c1f00b1228a9f55dfa3eae80
MD5 deb588010bce1e78ff56515247cf77db
BLAKE2b-256 237ca63e124e41d5b4d73dd0b59013a381f649b90c35a8e14c87f4d2a84fa295

See more details on using hashes here.

File details

Details for the file imap_mailbox-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: imap_mailbox-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.0 Darwin/22.2.0

File hashes

Hashes for imap_mailbox-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61b7838d039968c943e9a0c61a4f90969de0e344b5ae5743f7ff203dfd55e7c8
MD5 805a800a55f118bd8b7f3e2b243484b6
BLAKE2b-256 2466818183252898555b5600dc040c1532e0a06cfee397a9054d406ae65eb273

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