POP3 - Post Office Protocol - Version 3

pcapkit.protocols.application.pop3.protocol contains POP3, which implements an extractor for the Post Office Protocol - Version 3 (POP3) [RFC 1939] at TCP port 110, with its extension mechanism [RFC 2449]. Its lines are read through pcapkit.utilities.lines, which FTP and SMTP share.

Added in version 1.10.0.

class pcapkit.protocols.application.pop3.protocol.POP3(file, length=None, /, *, layer=None, protocol=None, context=None)[source]

Bases: Application[POP3, POP3]

This class implements Post Office Protocol - Version 3.

One segment carries no session state, so it reads as the first of these that it is, whole:

  • a response: a status line of a status indicator and its text (RFC 1939 Section 3), alone, or followed by lines whose last, and only the last, holds a single period, which ends a multi-line response;

  • a server challenge of the AUTH command (RFC 5034 Section 4);

  • a command, one line of a keyword and its parameters (RFC 2449 Section 3);

  • the rest of a multi-line response, lines whose last, and only the last, holds a single period.

A multi-line response is read whole from one segment, or its end alone from the segment ending it, so the segments between, and one holding a status line and more lines but not that end, are refused: such a segment may as well hold several pipelined responses (RFC 2449 Section 6.6). Octets that are not whole lines, a status line of more than 512 octets and a command line of more than 255 (RFC 2449 Section 4) are refused too, so on a TCP port each such segment is kept as Raw. A line of a response, or a client’s Base64 answer to a challenge, alone in a segment reads as a command if it can, since only the session marks either.

Text is ASCII (RFC 1939 Section 3) or, after the UTF8 and LANG commands, UTF-8 (RFC 6856 Section 2), so it is decoded as UTF-8 and octets that are not are refused. A parameter is ASCII, but for those of USER, PASS and APOP, which may be UTF-8 too (RFC 6856 Section 2.2). A response code a response’s text opens with is read into Response.code (RFC 2449 Section 8), and any other text is free text, as RFC 1939 has it: the text grammar of RFC 2449 Section 3 admits no SP, so it would refuse that RFC’s own examples. The greeting’s timestamp (RFC 1939 Section 7) stays in its text, since only the session marks a greeting.

Properties

property name: Literal['Post Office Protocol - Version 3']

Name of current protocol.

property length: NoReturn

Header length of current protocol.

Raises:

UnsupportedCall – This protocol doesn’t support length.

Methods

read(length=None, **kwargs)[source]

Read Post Office Protocol - Version 3 (POP3).

Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

POP3

Returns:

Parsed packet data.

Raises:

ProtocolError – If the packet is no response, server challenge, command or end of a multi-line response.

make(*, status=None, text=None, lines=None, challenge=None, cmmd=None, args=None, raw_cmmd=None, **kwargs)[source]

Make (construct) packet data.

A response takes status, text and lines, a server challenge challenge alone, a command cmmd, args and raw_cmmd, and the end of a multi-line response lines alone. Each line is terminated with CRLF, and the octets are checked to read back as made.

Parameters:
  • status (Status | str | None) – Status indicator, a str (a Status member is one).

  • text (str | bytes | bytearray | None) – Text of the status line, written after a single SP, a response code it opens with included; None writes neither. A str is encoded as UTF-8; bytes are written verbatim.

  • lines (Iterable[bytes | bytearray] | None) – Lines of a multi-line response after its first, as sent, byte-stuffed (see stuff()); the line ending the response is written after them. With status, None makes a single-line response.

  • challenge (str | bytes | bytearray | None) – Challenge in Base64, written after + and a single SP; empty for an empty challenge.

  • cmmd (Command | str | None) – Command keyword, a str (a Command member is one).

  • args (str | bytes | bytearray | Iterable[str | bytes | bytearray] | None) – Parameters, each written after a single SP, or one parameter; a str is encoded as UTF-8, bytes are written verbatim.

  • raw_cmmd (bytes | None) – Keyword as received, written in place of cmmd when the two differ only in case (RFC 1939 Section 3).

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

POP3

Returns:

Constructed packet data.

Raises:

ProtocolError – If not exactly one of status, challenge, cmmd and lines alone is given, or with another’s keywords, or if the octets made would not read back as made.

Data Models

classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

int

Returns:

Numeral registry index of the protocol in IANA service names and port numbers: TCP port 110, the port of TCP.pop3 as an int, which TCP.__proto__ dispatches here (The Registry Index).

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (POP3) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

Auxiliary Data

class pcapkit.protocols.application.pop3.protocol.Type(*values)[source]

Bases: EnumLookup, StrEnum

POP3 packet type.

Built on EnumLookup, the lookup contract shared by every non-registry enumeration (#877).

COMMAND = 'command'

Command packet.

RESPONSE = 'response'

Response packet.

CHALLENGE = 'challenge'

Server challenge packet.

TAIL = 'tail'

Packet ending a multi-line response.

class pcapkit.protocols.application.pop3.protocol.Status(*values)[source]

Bases: EnumLookup, StrEnum

POP3 status indicator (RFC 1939 Section 3), sent in upper case.

Built on EnumLookup, the lookup contract shared by every non-registry enumeration (#877).

OK = '+OK'

Positive status indicator.

ERR = '-ERR'

Negative status indicator.

Header Schemas

class pcapkit.protocols.application.pop3.schema.POP3(data=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for POP3 packet.

data: bytes = <BytesField data>

Packet data.

Data Models

class pcapkit.protocols.application.pop3.data.POP3(*args, **kwargs)[source]

Bases: Protocol

Data model for POP3 protocol.

type: Type

Type.

class pcapkit.protocols.application.pop3.data.Command(type, cmmd, args, raw_cmmd)[source]

Bases: POP3

Data model for a POP3 command (RFC 1939 Section 3).

type: Literal[Type.COMMAND]

Type.

cmmd: Command

Command keyword.

args: tuple[str, ...]

Parameters, in order.

raw_cmmd: bytes

Keyword as received, in its original case; cmmd is the case-insensitive lookup of it.

class pcapkit.protocols.application.pop3.data.Response(type, status, text, code, lines, body)[source]

Bases: POP3

Data model for a POP3 response, single-line or multi-line (RFC 1939 Section 3).

type: Literal[Type.RESPONSE]

Type.

status: Status

Status indicator.

text: str | None

Text after the status indicator and SP, None where the line ends with the status indicator.

code: ResponseCode | None

Response code text opens with (RFC 2449 Section 8), if any.

lines: tuple[bytes, ...] | None

Lines after the first, as sent, byte-stuffed, without their CRLF or the line ending the response; None for a single-line response.

body: tuple[bytes, ...] | None

The same lines with the byte-stuffing undone.

class pcapkit.protocols.application.pop3.data.Challenge(type, challenge)[source]

Bases: POP3

Data model for a server challenge of the AUTH command (RFC 5034 Section 4).

type: Literal[Type.CHALLENGE]

Type.

challenge: str

Challenge in Base64, as sent; empty for an empty challenge.

class pcapkit.protocols.application.pop3.data.Tail(type, lines, body)[source]

Bases: POP3

Data model for the rest of a multi-line response whose first line an earlier segment carried, up to and including the line ending it (RFC 1939 Section 3).

type: Literal[Type.TAIL]

Type.

lines: tuple[bytes, ...]

Lines as sent, byte-stuffed, without their CRLF or the line ending the response.

body: tuple[bytes, ...]

The same lines with the byte-stuffing undone.

Constants

pcapkit.protocols.application.pop3.const.POP3_COMMAND

A POP3 command line, CRLF excluded. A keyword of three or four printable ASCII characters, then each parameter after a single SP (RFC 2449 Section 3). A parameter is printable ASCII, or UTF-8 as well for the keywords of POP3_UTF8_COMMANDS, which the reader checks.

pcapkit.protocols.application.pop3.const.POP3_COMMAND_MAX = 255

The most octets a command line holds, CRLF included (RFC 2449 Section 4).

pcapkit.protocols.application.pop3.const.POP3_UTF8_COMMANDS

The commands whose parameters may hold UTF-8 beyond ASCII (RFC 6856 Section 2.2).

pcapkit.protocols.application.pop3.const.POP3_STATUS

The first line of a POP3 response, CRLF excluded. A status indicator, then SP and the text where any follows (RFC 1939 Section 3).

pcapkit.protocols.application.pop3.const.POP3_STATUS_MAX = 512

The most octets the first line of a response holds, CRLF included (RFC 2449 Section 4).

pcapkit.protocols.application.pop3.const.POP3_RESP_CODE

The response code a response’s text opens with (RFC 2449 Section 8), its levels separated by /, as the resp-code grammar of RFC 2449 Section 3 has them.

pcapkit.protocols.application.pop3.const.POP3_CHALLENGE

A server challenge, CRLF excluded. +, SP and the challenge in Base64, which is empty for an empty challenge (RFC 5034 Section 4), as the continue-req grammar of RFC 5034 Section 5 has it.