core.utils.fetchers.SafePOPMixin module

Module with the SafePOPMixin mixin.

type core.utils.fetchers.SafePOPMixin.POP3Response = bytes | tuple[bytes, list[bytes], int]
class core.utils.fetchers.SafePOPMixin.POP3FetcherClass(*args, **kwargs)[source]

Bases: Protocol

Protocol defining the required attributes of a class implementing this mixin.

_mail_client: poplib.POP3
logger: logging.Logger
__init__(*args, **kwargs)
_is_protocol = True
class core.utils.fetchers.SafePOPMixin.SafePOPMixin[source]

Bases: object

Mixin with safe POP operations.

The implementing class must have an _mail_client that is an poplib.POP3 or poplib.POP3_SSL and an instance logger.

Only errors leading up to and during the fetching process should raise outside of the class. Otherwise issues with logout etc would destroy the work done with fetching, which makes no sense.

check_response(response, command_name, exception_class, expected_status=b'+OK')[source]

Checks the status response of a POP action.

If it doesn’t match the expectation raises an exception.

Todo

Safely! extract error message from response for logging and exception.

Parameters:
Raises:

exception_class – If the response status doesn’t match the expectation.

Return type:

None

static safe(exception_class, expected_status=b'+OK')[source]
Overloads:
  • exception_class (type[FetcherError]), expected_status (bytes) → Callable[[Callable[…, POP3ActionResponse]], Callable[…, POP3ActionResponse]]

  • exception_class (None), expected_status (bytes) → Callable[[Callable[…, POP3ActionResponse]], Callable[…, POP3ActionResponse | None]]

Parameters:
Return type:

Callable[[Callable[[…], POP3ActionResponse]], Callable[[…], POP3ActionResponse | None]]

Wrapper for POP actions.

Catches expected errors and checks for correct responses and raises an FetcherError.

Todo

Find a better way to disable the exception and getting rid of the typing mess.

Parameters:
Returns:

The return value of the wrapped action. None if an error occurs and exception is None.

Raises:

exception_class – If an error occurs or the status doesn’t match the expectation.

Return type:

Callable[[Callable[[…], POP3ActionResponse]], Callable[[…], POP3ActionResponse | None]]

safe_user(*args, **kwargs)[source]
Return type:

TypeVar(POP3ActionResponse, bound= bytes | tuple[bytes, list[bytes], int]) | None

Parameters:
safe_pass_(*args, **kwargs)[source]
Return type:

TypeVar(POP3ActionResponse, bound= bytes | tuple[bytes, list[bytes], int]) | None

Parameters:
safe_noop(*args, **kwargs)[source]
Return type:

TypeVar(POP3ActionResponse, bound= bytes | tuple[bytes, list[bytes], int]) | None

Parameters:
safe_list(*args, **kwargs)[source]
Return type:

TypeVar(POP3ActionResponse, bound= bytes | tuple[bytes, list[bytes], int]) | None

Parameters:
safe_retr(*args, **kwargs)[source]
Return type:

TypeVar(POP3ActionResponse, bound= bytes | tuple[bytes, list[bytes], int]) | None

Parameters:
safe_quit(*args, **kwargs)[source]
Return type:

TypeVar(POP3ActionResponse, bound= bytes | tuple[bytes, list[bytes], int]) | None

Parameters: