pisak.email package

pisak.email.description module

pisak.email.address_book

Email address book management.

class pisak.email.address_book.AddressBook[source]

Bases: pisak.text_tools.Predictor

Book of mail contacts. Serves also as a predictor for new message address inserts. Internally, the entire address book content is stored inside a database. Database session instance that is used by some of the methods, each time is provided to them by the ‘_db_session_handler’ decorator. After executing one of these methods all changes made to the session are commited and the session is closed.

add_contact(contact)[source]

Add new contact to the address book. Contact must contain ‘address’ key and can contain the following keys: ‘name’ and ‘photo’.

Parameters:contact – dictionary with new contact.
Returns:True on successfull update of the book with the given

contact or False otherwise, for example when address same as the one of the given contact has already been in the book.

do_prediction(text, position)[source]

Implementation of the text_tools.Predictor method.

Parameters:
  • text – text to feed the predictor with.
  • position – how many signs from the given text should ba taken.
edit_contact_address(contact_id, address)[source]

Edit email address of a contact.

Parameters:
  • contact_id – id of the contact
  • name – new email address
edit_contact_name(contact_id, name)[source]

Edit name of a contact.

Parameters:
  • contact_id – id of the contact
  • name – new name
edit_contact_photo(contact_id, photo)[source]

Edit photo path for a contact.

Parameters:
  • contact_id – id of the contact
  • photo – path to the new photo
get_all_contacts()[source]

Retrieve all records from the address book.

Returns:list of all contacts.
get_contact(contact_id)[source]

Get single contact from the address book.

Parameters:contact_id – identification number of a contact that should

be returned.

Returns:single instance of a _Contact with the given id or None if

there was no match.

get_contact_by_address(address)[source]

As each address in the address book is unique one can query for a given contact by its address.

Parameters:address – address of the contact.
Returns:_Contact object with a given address

or None if nothing found.

get_count()[source]

Get number of contacts in the address book.

Returns:integer with number of contacts in the address book
remove_contact(contact_id)[source]

Remove contact from the book. If the book does not contain the given contact then nothing happens.

Parameters:contact – id of the contact to be removed
search_contacts(feed)[source]

Look for all the contacts that contain the given feed in their name or address, sort them properly and return as a list.

Parameters:feed – string that the search will be based on.
Returns:list of all the matching contacts, sorted properly.
exception pisak.email.address_book.AddressBookError(*args, **kwargs)[source]

Bases: pisak.exceptions.PisakException

Address book unexpected condition, maybe problems when accessing the database.

pisak.email.config

Email settings.

class pisak.email.config.Config[source]

Bases: object

Configuration object containing all the email related setup.

DEFAULT_SENT_BOX = {'unknown': 'Sent', 'gmail.com': '[Gmail]/Wa&AXw-ne'}
PATH = '/home/alex/.pisak/configs/main_config.ini'
static decrypt_password(encrypted)[source]

Decrypt the given encrypted password.

Parameters:encrypted – encrypted password.
Returns:decrypted password.
static encrypt_password(password)[source]

Not very safe solution. Only for people who really are unable to remember their password. Anyone who gets here will be able to decrypt the password so we do not need to be very inventive.

Parameters:password – not encrypted password.
Returns:encrypted password, string.
get_account_setup()[source]

Get previously saved email account settings. If the configuration object’s content is not valid raise EmailConfigError.

Returns:config object with email settings.
exception pisak.email.config.EmailConfigError(*args, **kwargs)[source]

Bases: pisak.exceptions.PisakException

Unexpected condition met by the configurator.

pisak.email.imap_client

Module providing access to the email account through the imap client.

class pisak.email.imap_client.IMAPClient(custom_config=None)[source]

Bases: object

Class representing an email account connection. Used access protocol - IMAP.

delete_message_from_inbox(id)[source]

Permanently delete the given message from the inbox.

Parameters:id – unique id of the message.
delete_message_from_sent_box(id)[source]

Permanently delete the given message from the sent box.

Parameters:id – unique id of the message.
get_inbox_ids()[source]

Get a list of ids of all the messages in the inbox.

Returns:list of ids; or False on query failure.
get_inbox_status()[source]

Get number of all messages in the inbox and number of the unseen messages.

Returns:tuple with two integers: number of all messages

and number of unseen messages; or False on query failure.

get_many_previews_from_inbox(ids)[source]

Get many previews with the given ids from the inbox.

Parameters:ids – list of ids of the messages.
Returns:list of dictionaries with the previews; or False on query failure.
get_many_previews_from_sent_box(ids)[source]

Get previews with the given ids from the box of sent messages.

Parameters:ids – list of ids of the previewss.
Returns:list of dictionaries with the previews; or False on query failure.
get_message_from_inbox(id)[source]

Get message with the given id from the inbox.

Parameters:id – id of the message.
Returns:dictionary with the message; or False on query failure.
get_message_from_sent_box(id)[source]

Get message with the given id from the box of sent messages.

Parameters:id – id of the message.
Returns:dictionary with the message; or False on query failure.
get_sent_box_count()[source]

Get number of all messages in the sent box.

Returns:integers with number of all messages;

or False on query failure.

get_sent_box_ids()[source]

Get a list of ids of all the messages in the sent box.

Returns:list of ids; or False on query failure.
login()[source]

Login to the IMAP account.

logout()[source]

Logout from the account.

exception pisak.email.imap_client.IMAPClientError(*args, **kwargs)[source]

Bases: pisak.exceptions.PisakException

IMAP protocol-related unexpected condition met by the client.

exception pisak.email.imap_client.InvalidCredentialsError(*args, **kwargs)[source]

Bases: pisak.email.imap_client.IMAPClientError

Error raised when an authentication attempt fails because of invalid credentials.

exception pisak.email.imap_client.MailboxNotFoundError(*args, **kwargs)[source]

Bases: pisak.email.imap_client.IMAPClientError

Error raised when some mailbox can not be found.

pisak.email.handlers module

pisak.email.widgets module

pisak.email.message module

Module implements one class that can send e-mail messages through the SMTP protocol.

exception pisak.email.message.EmailSendingError(*args, **kwargs)[source]

Bases: pisak.exceptions.PisakException

SMTP protocol-related error.

class pisak.email.message.SimpleMessage[source]

Bases: object

Simple message consisting of just a subject, body and recipients.

body

Body of the message. Body should be a single string containing only plain text without any markup.

clear()[source]

Clear the whole message, all headers etc and start creating a new one from the very beginning.

get_pretty()[source]

Compose a prettyfied version of the message that can be saved in a human-readable shape, for example as a draft message.

Returns:dictionary containing all the separate message fields.
recipients

Recipients of the message. Recipients are stored as a set of unique email addresses. New recipients can be added by setting this property with either a single address in a string format or with a list of many addresses. Each new address will be added to the existing set of recipients. Before adding to the set each address is examined and if any of them is not correct then ValueError is raised. Remove recipients using the remove_recipient method.

remove_recipient(recipient)[source]

Remove recipient from the collection of all recipients. All removings should be performed by using this method.

Parameters:recipient – recipient to be removed.
send()[source]

Send the message through the SMTP.

subject

Subject of the message. Subject should be a single string.

pisak.email.parsers module

Email parsers.

pisak.email.parsers.parse_mailbox_list(ids, msg_data, headers)[source]

Parse list of message previews.

Parameters:
  • ids – list of the given messages ids.
  • msg_data – raw messages data.
  • headers – list of headers to be parsed.
Returns:

list of dictionaries containing parsed message previews.

pisak.email.parsers.parse_message(raw_message)[source]

Parse the given raw message.

Parameters:raw_message – single string with the whole raw message.
Returns:dictionary containing all fields of parsed message.

Module contents

pisak.email.test(config)[source]

Test provided email settings or server connection.