pymap.backend.maildir
¶
- class pymap.backend.maildir.MaildirBackend(login, config)[source]¶
Defines an on-disk backend that uses
Maildir
for mailbox storage and MailboxFormat/Maildir for metadata storage.- Parameters:
login (Login)
config (Config)
- property login: Login¶
Login interface that handles authentication credentials.
- property status: HealthStatus¶
The health status for the backend.
- classmethod add_subparser(name, subparsers)[source]¶
Add a command-line argument sub-parser that will be used to choose this backend. For example:
parser = subparsers.add_parser('foo', help='foo backend') parser.add_argument(...)
- Parameters:
name (str) – The name to use for the subparser.
subparsers (Any) – The special action object as returned by
add_subparsers()
.
- Returns:
The new sub-parser object.
- Return type:
- async classmethod init(args, **overrides)[source]¶
Initialize the backend and return an instance.
- Parameters:
- Return type:
- async start(stack)[source]¶
Start the backend.
- Parameters:
stack (AsyncExitStack) – An exit stack that should be used for cleanup.
- Return type:
None
- class pymap.backend.maildir.Config(args, *, base_dir, layout, colon, **extra)[source]¶
The config implementation for the maildir backend.
- Parameters:
- property backend_capability: BackendCapability¶
Allows backends to declare support for IMAP extensions and other capabilities.
- property colon: str | None¶
The info delimiter in mail filename.
See also
Note on
colon
inmailbox.Maildir
.
pymap.backend.maildir.flags
¶
- class pymap.backend.maildir.flags.MaildirFlags(path)[source]¶
Maintains a set of IMAP keywords (non-standard flags) that are available for use on messages. This uses a custom file format to define keywords, which might look like this:
0 $Junk 1 $NonJunk
The lower-case letter codes that correspond to each keyword start with
'a'
for 0,'b'
for 1, etc. and up to 26 are supported.- Parameters:
keywords – The list of keywords available for use on messages.
path (str)
See also
- property permanent_flags: frozenset[Flag]¶
Return the set of all permanent flags, system and keyword.
pymap.backend.maildir.layout
¶
- class pymap.backend.maildir.layout.MaildirLayout(*args, **kwargs)[source]¶
Manages the folder layout of a
Maildir
inbox.See also
- classmethod get(path, layout, maildir_type)[source]¶
- Parameters:
- Raises:
ValueError – The layout name was not recognized.
- Return type:
MaildirLayout[_MaildirT]
- abstract list_folders(delimiter, top='INBOX')[source]¶
Return all folders, starting with
top
and traversing through the sub-folder heirarchy.- Parameters:
- Raises:
FileNotFoundError – The folder did not exist.
- Return type:
- abstract get_folder(name, delimiter)[source]¶
Return the existing sub-folder.
- Parameters:
- Raises:
FileNotFoundError – The folder did not exist.
- Return type:
_MaildirT
- abstract add_folder(name, delimiter)[source]¶
Add a new sub-folder.
- Parameters:
- Raises:
FileExistsError – The folder already exists.
FileNotFoundError – A parent folder did not exist.
- Return type:
None
- abstract remove_folder(name, delimiter)[source]¶
Remove the existing sub-folder.
- Parameters:
- Raises:
FileNotFoundError – The folder did not exist.
OSError – With
ENOTEMPTY
, the folder has sub-folders.
- Return type:
None
- abstract rename_folder(source_name, dest_name, delimiter)[source]¶
Rename the existing sub-folder to the destination.
- Parameters:
- Raises:
FileNotFoundError – The source folder did not exist.
FileExistsError – The destination folder already exists.
- Return type:
None
- class pymap.backend.maildir.layout.DefaultLayout(path, maildir_type)[source]¶
The default Maildir++ layout, which uses sub-folder names starting with and using
.
as a delimiter for nesting , e.g.:.Trash/ .Important.To-Do/ .Important.Misc/
pymap.backend.maildir.subscriptions
¶
- class pymap.backend.maildir.subscriptions.Subscriptions(path)[source]¶
Maintains the set of folders currently subscribed to.
- Parameters:
path (str) – The directory of the file.
- add(folder)[source]¶
Add a new folder to the subscriptions.
- Parameters:
folder (str)
- Return type:
None
pymap.backend.maildir.uidlist
¶
- class pymap.backend.maildir.uidlist.Record(uid, fields, filename)[source]¶
Defines a single record read from the UID list file.
- Parameters:
- class pymap.backend.maildir.uidlist.UidList(path, uid_validity, next_uid, global_uid=None)[source]¶
Maintains the file with UID mapping to maildir files.
- Parameters:
- FILE_NAME: ClassVar[str] = 'dovecot-uidlist'¶
The UID list file name, stored in the mailbox directory.
- LOCK_FILE: ClassVar[str] = 'dovecot-uidlist.lock'¶
The UID list lock file, stored adjacent to the UID list file.
pymap.backend.maildir.mailbox
¶
- class pymap.backend.maildir.mailbox.Maildir(dirname, factory=None, create=True)[source]¶
- claim_new()[source]¶
Checks for messages in the
new
subdirectory, moving them tocur
and returning their keys.
- get_message_metadata(key)[source]¶
Like
get_message()
but the message contents are not read from disk.- Parameters:
key (str)
- Return type:
- update_metadata(key, msg)[source]¶
Uses
os.rename()
to atomically update the message filename based onget_info()
.- Parameters:
key (str)
msg (MaildirMessage)
- Return type:
None
- class pymap.backend.maildir.mailbox.Message(uid, internal_date, permanent_flags, *, expunged=False, email_id=None, thread_id=None, recent=False, maildir=None, key=None)[source]¶
- Parameters:
- async load_content(requirement)[source]¶
Loads the content of the message.
- Parameters:
requirement (FetchRequirement) – The data required from the message content.
- Return type:
LoadedMessage
- class pymap.backend.maildir.mailbox.MailboxData(mailbox_id, maildir, path)[source]¶
-
- property selected_set: SelectedSet¶
The set of selected mailbox sessions currently active.
- async update_selected(selected, *, wait_on=None)[source]¶
Populates and returns the selected mailbox object with the state needed to discover updates.
- Parameters:
selected (SelectedMailbox) – the selected mailbox object.
wait_on (Event | None) – If given, block until this event signals or mailbox activity occurs.
- Return type:
- async append(append_msg, *, recent=False)[source]¶
Adds a new message to the end of the mailbox, returning a copy of message with its assigned UID.
- Parameters:
append_msg (AppendMessage) – The new message data.
recent (bool) – True if the message should be marked recent.
- Return type:
- async copy(uid, destination, *, recent=False)[source]¶
Copies a message, if it exists, from this mailbox to the destination mailbox.
- Parameters:
uid (int) – The UID of the message to copy.
destination (MailboxData) – The destination mailbox.
recent (bool) – True if the message should be marked recent.
- Return type:
int | None
- async move(uid, destination, *, recent=False)[source]¶
Moves a message, if it exists, from this mailbox to the destination mailbox.
- Parameters:
uid (int) – The UID of the message to move.
destination (MailboxData) – The destination mailbox.
recent (bool) – True if the message should be marked recent.
- Return type:
int | None
- async get(uid, cached_msg)[source]¶
Return the message with the given UID.
- Parameters:
uid (int) – The message UID.
cached_msg (CachedMessage) – The last known cached message.
- Return type:
- async claim_recent(selected)[source]¶
Messages that are newly added to the mailbox are assigned the
\Recent
flag in the current selected mailbox session.- Parameters:
selected (SelectedMailbox) – The selected mailbox session.
- Return type:
None
- async cleanup()[source]¶
Perform any necessary “housekeeping” steps. This may be a slow operation, and may run things like garbage collection on the backend.
See also
- Return type:
None
- class pymap.backend.maildir.mailbox.MailboxSet(maildir, layout)[source]¶
- Parameters:
maildir (Maildir)
layout (MaildirLayout[Any])
- async set_subscribed(name, subscribed)[source]¶
Add or remove the subscribed status of a mailbox.
See also
- async get_mailbox(name)[source]¶
Return an existing mailbox by name.
- async add_mailbox(name)[source]¶
Create a new mailbox, returning its object ID.
See also
- Parameters:
name (str) – The name of the mailbox.
- Raises:
ValueError – The mailbox already exists.
- Return type:
- async rename_mailbox(before, after)[source]¶
Rename an existing mailbox.
See also
- Parameters:
- Raises:
KeyError – The before mailbox does not exist.
ValueError – The after mailbox already exists.
- Return type:
None
pymap.backend.maildir.users
¶
- class pymap.backend.maildir.users.UserRecord(name, password='', uid='', gid='', comment='', home_dir='', shell='')[source]¶
Encapsulates a single user line in the passwd file.
See also
- class pymap.backend.maildir.users.PasswordRecord(name, password, last_change_date='', min_password_age='', max_password_age='', password_warning_period='', password_inactivity_period='', account_expiration_date='', reserved='')[source]¶
Encapsulates a single user line in the shadow file.
See also
- class pymap.backend.maildir.users.GroupRecord(name, password='', gid='', users_list='')[source]¶
Encapsulates a single group line in the group file.
See also
- class pymap.backend.maildir.users.UsersFile(path)[source]¶
Reads and writes a file using the passwd file format. The home directory field in the user record will be the path (absolute or relative to the base directory) to the user’s maildir.
- Parameters:
path (str)
- class pymap.backend.maildir.users.PasswordsFile(path)[source]¶
Reads and writes a file using the passwd file format. Similar to the
/etc/shadow
file on a Linux system, this file contains the password representation and may have stricter file permissions.- Parameters:
path (str)
- class pymap.backend.maildir.users.GroupsFile(path)[source]¶
Reads and writes a file using the group file format. The name field in each record is the role name, and the users list are the users that have been assigned that role.
- Parameters:
path (str)
- class pymap.backend.maildir.users.TokensFile(path)[source]¶
Reads and writes a file using the group file format. The name field in each record is the token identifier, the password field is the private key, and the users list contains the user or users it is valid for.
- Parameters:
path (str)