Home

Py4Gmail

Very simple class for interacting with Gmail through the IMAP protocol

Installation:

pip install hg+https://lzantal@bitbucket.org/lzantal/py4gmail#egg=py4gmail

Basic Usage:

from py4gmail import Py4Gmail

m = Py4Gmail()
m.login("email@gmail.com","password")
# see all the mailboxes
for mailbox in m.mailboxes():
    print mailbox
# select a mailbox, it returns the number of emails in the mailbox
m.select_mailbox() # default Inbox
email_ids = m.filter_emails() # default ALL
email = m.email_by_id(1)
print email["From"]
print email["Subject"]
print m.email_body(email)
# save attachment(s)
m.email_attachment(email, True, "/some/directory")
# get attachment(s) so we can work on it
# attachment_dict is a dictionary with the keys are the filenames
resp, attahment_dict = m.email_attachment(email)
m.logout()

IMAP Filter/Search Keys

  • ALL All messages in the mailbox; the default initial key for ANDing.
  • ANSWERED Messages with the \Answered flag set.
  • BCC Messages that contain the specified string in the envelope structure's BCC field.
  • BEFORE Messages whose internal date (disregarding time and timezone) is earlier than the specified date.
  • BODY Messages that contain the specified string in the body of the message.
  • CC Messages that contain the specified string in the envelope structure's CC field.
  • DELETED Messages with the \Deleted flag set.
  • DRAFT Messages with the \Draft flag set.
  • FLAGGED Messages with the \Flagged flag set.
  • FROM Messages that contain the specified string in the envelope structure's FROM field.
  • HEADER Messages that have a header with the specified field-name (as defined in [RFC-2822]) and that contains the specified string in the text of the header (what comes after the colon). If the string to search is zero-length, this matches all messages that have a header line with the specified field-name regardless of the contents.
  • KEYWORD Messages with the specified keyword flag set.
  • LARGER Messages with an [RFC-2822] size larger than the specified number of octets.
  • NEW Messages that have the \Recent flag set but not the \Seen flag. This is functionally equivalent to "(RECENT UNSEEN)".
  • NOT Messages that do not match the specified search key.
  • OLD Messages that do not have the \Recent flag set. This is functionally equivalent to "NOT RECENT" (as opposed to "NOT NEW").
  • ON Messages whose internal date (disregarding time and timezone) is within the specified date.
  • OR Messages that match either search key.
  • RECENT Messages that have the \Recent flag set.
  • SEEN Messages that have the \Seen flag set.
  • SENTBEFORE Messages whose [RFC-2822] Date: header (disregarding time and timezone) is earlier than the specified date.
  • SENTON Messages whose [RFC-2822] Date: header (disregarding time and timezone) is within the specified date.
  • SENTSINCE Messages whose [RFC-2822] Date: header (disregarding time and timezone) is within or later than the specified date.
  • SINCE Messages whose internal date (disregarding time and timezone) is within or later than the specified date.
  • SMALLER Messages with an [RFC-2822] size smaller than the specified number of octets.
  • SUBJECT Messages that contain the specified string in the envelope structure's SUBJECT field.
  • TEXT Messages that contain the specified string in the header or body of the message.
  • TO Messages that contain the specified string in the envelope structure's TO field.
  • UID Messages with unique identifiers corresponding to the specified unique identifier set. Sequence set ranges are permitted.
  • UNANSWERED Messages that do not have the \Answered flag set.
  • UNDELETED Messages that do not have the \Deleted flag set.
  • UNDRAFT Messages that do not have the \Draft flag set.
  • UNFLAGGED Messages that do not have the \Flagged flag set.
  • UNKEYWORD Messages that do not have the specified keyword flag set.
  • UNSEEN Messages that do not have the \Seen flag set.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.