core.utils.fetchers.JMAPFetcher module

Module with the JMAPFetcher class.

class core.utils.fetchers.JMAPFetcher.JMAPFetcher(account)[source]

Bases: BaseFetcher

Maintains a connection to the JMAP server and fetches data using jmapc.

Opens a connection to the JMAP server on construction and is preferably used in a ‘with’ environment. Allows fetching of mails and mailboxes from an account on an JMAP host.

Parameters:

account (Account)

PROTOCOL = 'JMAP'

Name of the used protocol, refers to MailFetchingProtocols.JMAP.

AVAILABLE_FETCHING_CRITERIA: tuple[str, ...] = (EmailFetchingCriterionChoices.ALL, EmailFetchingCriterionChoices.SEEN, EmailFetchingCriterionChoices.UNSEEN, EmailFetchingCriterionChoices.DRAFT, EmailFetchingCriterionChoices.UNDRAFT, EmailFetchingCriterionChoices.ANSWERED, EmailFetchingCriterionChoices.UNANSWERED, EmailFetchingCriterionChoices.DAILY, EmailFetchingCriterionChoices.WEEKLY, EmailFetchingCriterionChoices.MONTHLY, EmailFetchingCriterionChoices.ANNUALLY, EmailFetchingCriterionChoices.BODY, EmailFetchingCriterionChoices.FROM, EmailFetchingCriterionChoices.SENTSINCE, EmailFetchingCriterionChoices.LARGER, EmailFetchingCriterionChoices.SMALLER)

Tuple of all criteria available for fetching. Refers to MailFetchingCriteria. Must be immutable!

__init__(account)[source]

Constructor basis, sets up the instance logger.

Parameters:

account (Account) – The model of the account to fetch from.

Return type:

None

connect_to_host()[source]

Opens the connection to the mailserver.

Return type:

None

test(mailbox=None)[source]

Tests the connection to the mailaccount and, if given, the mailbox.

Parameters:

mailbox (Mailbox | None) – The mailbox to be tested. Default is None.

Raises:

ValueError – If the mailbox argument does not belong to self.account.

Return type:

None

fetch_emails(mailbox, criterion=<core.utils.FetchingCriterion.FetchingCriterion object>)[source]

Fetches emails based on a criterion from the server.

Parameters:
Yields:

Mails in the mailbox matching the criterion as bytes.

Raises:

ValueError – If the fetching_criterion is not available for this fetcher.

Return type:

Generator[bytes]

fetch_mailboxes()[source]

Fetches all mailbox names from the server.

Return type:

list[tuple[str, str]]

Returns:

List of data of all mailboxes in the account. Empty if none are found.

restore(email)[source]

Restores an email to a mailbox.

Parameters:

email (Email) – The email to restore.

Raises:
Return type:

None

close()[source]

No cleanup of jmapc.Client required.

Return type:

None