module grabber.mailboximap

Inheritance diagram of pymmails.grabber.mailboximap

Short summary

module pymmails.grabber.mailboximap

Defines a mailbox using IMAP

source on GitHub

Classes

class

truncated documentation

MailBoxImap

Defines a mail box with :epkg:`IMAP` interface.

Methods

method

truncated documentation

__init__

enumerate_mails_in_folder

Enumerates all mails in folder folder.

enumerate_search_person

Enumerates all mails in folder folder from a user or sent to a user.

enumerate_search_subject

Enumerates all mails in folder folder with a subject verifying a regular expression.

folders

Returns the list of folder of the mail box.

login

login

logout

logout

Documentation

Defines a mailbox using IMAP

source on GitHub

class pymmails.grabber.mailboximap.MailBoxImap(user, pwd, server, ssl=False, fLOG=<function noLOG>)[source]

Bases: object

Defines a mail box with :epkg:`IMAP` interface.

Fetch mails from a gmail account

user = "address no domain"
pwd = "password"
server = "imap.gmail.com"

box = MailBoxImap(user, pwd, server, ssl=True)
box.login()

# ... fetch emails

box.logout()

source on GitHub

Parameters
  • user – user

  • pwd – password

  • server – server something like imap.domain.ext

  • ssl – select IMPA_SSL or IMAP

  • fLOG – logging function

For gmail, it is imap.gmail.com and ssl must be true.

source on GitHub

__init__(user, pwd, server, ssl=False, fLOG=<function noLOG>)[source]
Parameters
  • user – user

  • pwd – password

  • server – server something like imap.domain.ext

  • ssl – select IMPA_SSL or IMAP

  • fLOG – logging function

For gmail, it is imap.gmail.com and ssl must be true.

source on GitHub

enumerate_mails_in_folder(folder, skip_function=None, date=None, pattern='ALL', body=True)[source]

Enumerates all mails in folder folder.

Parameters
  • folder – folder name

  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)

  • pattern – search pattern (see below)

  • date – add a date to the pattern

  • body – add body

Returns

iterator on (message)

The search pattern can be used to look for a subset of email. It follows these specifications. If a folder is a subfolder, the syntax should be folder/subfolder.

Search pattern

pattern='FROM "xavier" SINCE 1-Feb-2013'
pattern='FROM "xavier" SINCE 1-Feb-2013 BEFORE 5-May-2013'
pattern='FROM "xavier" SINCE 1-Feb-2013 BEFORE 5-May-2013 (UNANSWERED)'
pattern='CC "jacques" FROM "xavier" (DELETED)'
pattern='TEXT "github"'
pattern='LARGER 10000 SMALLER 1000000'
pattern='SUBJECT "programmation"'
pattern='TO "student" (FLAGGED)'
pattern='(UNSEEN)'

If the function generates an error such as:

imaplib.error: command: SEARCH => got more than 10000 bytes

The keyword RECENT will be added to the search pattern in order to retreive the newest mails.

source on GitHub

enumerate_search_person(person, folder, skip_function=None, date=None, max_dest=5, body=True)[source]

Enumerates all mails in folder folder from a user or sent to a user.

Parameters
  • person – person to look for or persons to look for

  • folder – folder name

  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)

  • pattern – search pattern (see below)

  • max_dest – maximum number of receivers

  • body – get the body

Returns

iterator on (message)

If person is a list, the function iterates on the list of persons to look for. It returns only unique mails.

source on GitHub

enumerate_search_subject(subject, folder, skip_function=None, date=None, max_dest=5)[source]

Enumerates all mails in folder folder with a subject verifying a regular expression.

Parameters
  • subject – subject to look for

  • folder – folder name

  • skip_function – if not None, use this function on the header/body to avoid loading the entire message (and skip it)

  • pattern – search pattern (see below)

  • max_dest – maximum number of receivers

Returns

iterator on (message)

source on GitHub

folders()[source]

Returns the list of folder of the mail box.

source on GitHub

login()[source]

source on GitHub

logout()[source]

source on GitHub