imap_storage.connection package¶
Submodules¶
imap_storage.connection.config module¶
Account config class
-
class
imap_storage.connection.config.
Config
[source]¶ Bases:
object
Account Configuration class
-
TAG
= 'IMAP-Storage'¶
-
imap_storage.connection.imap module¶
Imap connection class This class represents the connection layer Many of them are reimplementation of IMAPClient methods
-
class
imap_storage.connection.imap.
Imap
(config, unsafe=False)[source]¶ Bases:
imapclient.imapclient.IMAPClient
Imap connection class :param config: Config Object with correct data :param unsafe: Workaround for invalid ssl certificates (unproductive only)
-
append
(folder, msg, flags=(), msg_time=None)[source]¶ Append a message to folder.
msg should be a string contains the full message including headers.
flags should be a sequence of message flags to set. If not specified no flags will be set.
msg_time is an optional datetime instance specifying the date and time to set on the message. The server will set a time if it isn’t specified. If msg_time contains timezone information (tzinfo), this will be honoured. Otherwise the local machine’s time zone sent to the server.
Returns the APPEND response as returned by the server.
-
clean_folder_path
(folder)[source]¶ clean a folder path
Parameters: folder (str) – Folder path to clean Returns: folder path that starts with config.directory separated by ‘.’ Return type: str
-
create_folder
(folder, connect=True)[source]¶ Create folder on the server returning the server response string.
-
delete_folder
(folder, allow_base=False)[source]¶ delete folder and all sub folders recursive :returns: list of deleted folders and subfolders
-
delete_messages
(messages, silent=False)[source]¶ delete message on the server :param messages: message uid(s) to delete :returns: bool if uids are not in self.uids anymore
-
expunge
(messages=None)[source]¶ When, no messages are specified, remove all messages from the currently selected folder that have the
\Deleted
flag set.The return value is the server response message followed by a list of expunge responses. For example:
('Expunge completed.', [(2, 'EXPUNGE'), (1, 'EXPUNGE'), (0, 'RECENT')])
In this case, the responses indicate that the message with sequence numbers 2 and 1 where deleted, leaving no recent messages in the folder.
See RFC 3501#section-6.4.3 section 6.4.3 and RFC 3501#section-7.4.1 section 7.4.1 for more details.
When messages are specified, remove the specified messages from the selected folder, provided those messages also have the
\Deleted
flag set. The return value isNone
in this case.Expunging messages by id(s) requires that use_uid is
True
for the client.See RFC 4315#section-2.1 section 2.1 for more details.
-
fetch
(messages, data, modifiers=None)[source]¶ Retrieve selected data associated with one or more messages in the currently selected folder.
data should be specified as a sequnce of strings, one item per data selector, for example
['INTERNALDATE', 'RFC822']
.modifiers are required for some extensions to the IMAP protocol (eg. RFC 4551). These should be a sequnce of strings if specified, for example
['CHANGEDSINCE 123']
.A dictionary is returned, indexed by message number. Each item in this dictionary is also a dictionary, with an entry corresponding to each item in data. Returned values will be appropriately typed. For example, integer values will be returned as Python integers, timestamps will be returned as datetime instances and ENVELOPE responses will be returned as
Envelope
instances.String data will generally be returned as bytes (Python 3) or str (Python 2).
In addition to an element for each data item, the dict returned for each message also contains a SEQ key containing the sequence number for the message. This allows for mapping between the UID and sequence number (when the use_uid property is
True
).Example:
>> c.fetch([3293, 3230], ['INTERNALDATE', 'FLAGS']) {3230: {b'FLAGS': (b'\Seen',), b'INTERNALDATE': datetime.datetime(2011, 1, 30, 13, 32, 9), b'SEQ': 84}, 3293: {b'FLAGS': (), b'INTERNALDATE': datetime.datetime(2011, 2, 24, 19, 30, 36), b'SEQ': 110}}
-
list_folders
(connect=True)[source]¶ Get a listing of folders on the server as a list of
(flags, delimiter, name)
tuples.Specifying directory will limit returned folders to the given base directory. The directory and any child directories will returned.
Specifying pattern will limit returned folders to those with matching names. The wildcards are supported in pattern.
*
matches zero or more of any character and%
matches 0 or more characters except the folder delimiter.Calling list_folders with no arguments will recursively list all folders available for the logged in user.
Folder names are always returned as unicode strings, and decoded from modified UTF-7, except if folder_decode is not set.
-