SMTP - Simple Mail Transfer Protocol¶
pcapkit.protocols.application.smtp.protocol contains
SMTP, which implements an
extractor for the Simple Mail Transfer Protocol (SMTP) [RFC 5321] at TCP
port 25, and for Message Submission [RFC 6409], the same protocol at TCP port
587. Its lines are read through pcapkit.utilities.lines, which FTP shares.
Added in version 1.10.0.
- class pcapkit.protocols.application.smtp.protocol.SMTP(file, length=None, /, *, layer=None, protocol=None, context=None)[source]¶
Bases:
Application[SMTP,SMTP]This class implements Simple Mail Transfer Protocol.
What a client sends after a
354reply is mail data, but one segment carries no session state to tell it from commands. So a segment reads as the first of these that it is, whole:a command, one line of a verb and its argument clause (RFC 5321 Section 4.1.1);
a reply, lines sharing one code, each before the last followed by a hyphen (RFC 5321 Section 4.2); if the last is too, the reply goes on in a later segment;
mail data, lines whose last, and only the last, holds a single period: the end of mail data indication (RFC 5321 Section 4.1.1.4), the one mark in the octets that they follow a
354.
Mail data in the segments before the one that ends it is therefore refused, as are octets that are not whole lines, and a line of it alone in a segment reads as a command if it can. Pipelined commands (RFC 2920) and several replies in one segment are refused too, so on a TCP port each such segment is kept as
Raw.Text is decoded with the charset chardet detects, which can misread a short run of non-ASCII octets; the octets still rebuild exactly, as FTP’s do.
Properties
- property length: NoReturn¶
Header length of current protocol.
- Raises:
UnsupportedCall – This protocol doesn’t support
length.
Methods
- read(length=None, **kwargs)[source]¶
Read Simple Mail Transfer Protocol (SMTP).
- Parameters:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the packet is no command, reply or mail data.
- make(*, cmmd=None, args=None, raw_cmmd=None, code=None, text=None, more=False, lines=None, charset=None, **kwargs)[source]¶
Make (construct) packet data.
A command takes
cmmd,argsandraw_cmmd, a replycode,textandmore, bothcharset, and mail datalinesalone. Each line is terminated with CRLF, and each is checked to read back as made.- Parameters:
cmmd (
Command|str|None) – Command verb, astr(aCommandmember is one).args (
str|bytes|bytearray|None) – Argument clause, written after a single SP;Nonewrites neither.raw_cmmd (
bytes|None) – Verb as received, written in place ofcmmdwhen the two differ only in case (RFC 5321 Section 2.4).code (
ReplyCode|int|None) – Reply code, anint(aReplyCodemember is one).text (
str|bytes|bytearray|Iterable[str|bytes|bytearray|None] |None) – Text of a one-line reply, or of each line in order. ANonelast line is the code alone, with no SP.more (
bool) – Whether the last line carries a hyphen, so the reply goes on in a later segment.lines (
Iterable[bytes|bytearray] |None) – Lines of mail data as sent, dot-stuffed (seestuff()); the line ending the mail data is written after them.charset (
str|None) – Encoding forstrarguments and text, UTF-8 if not given;bytesare written verbatim.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If not exactly one of
cmmd,codeandlinesis 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:
- Returns:
Numeral registry index of the protocol in IANA service names and port numbers: TCP port 25, the port of
TCP.smtpas anint, whichTCP.__proto__dispatches here, as it does port 587 (The Registry Index).
Utilities
Auxiliary Data¶
- class pcapkit.protocols.application.smtp.protocol.Type(*values)[source]¶
Bases:
EnumLookup,StrEnumSMTP packet type.
Built on
EnumLookup, the lookup contract shared by every non-registry enumeration (#877).- COMMAND = 'command'¶
Command packet.
- REPLY = 'reply'¶
Reply packet.
- MAIL_DATA = 'mail_data'¶
Mail data packet.
Header Schemas¶
Data Models¶
- class pcapkit.protocols.application.smtp.data.SMTP(*args, **kwargs)[source]¶
Bases:
ProtocolData model for SMTP protocol.
- class pcapkit.protocols.application.smtp.data.Command(type, cmmd, args, charset, raw_cmmd)[source]¶
Bases:
SMTPData model for an SMTP command (RFC 5321 Section 4.1.1).
- class pcapkit.protocols.application.smtp.data.Reply(type, code, text, more, charset)[source]¶
Bases:
SMTPData model for an SMTP reply (RFC 5321 Section 4.2).
- class pcapkit.protocols.application.smtp.data.MailData(type, lines, text)[source]¶
Bases:
SMTPData model for the mail data a
DATAcommand sends, up to and including the end of mail data indication (RFC 5321 Section 4.1.1.4).- lines: tuple[bytes, ...]¶
Lines as sent, dot-stuffed, without their CRLF or the line ending the mail data.
- text: tuple[bytes, ...]¶
The same lines with the dot-stuffing undone (RFC 5321 Section 4.5.2).
Constants¶
- pcapkit.protocols.application.smtp.const.SMTP_COMMAND¶
An SMTP command line, CRLF excluded. A verb of letters, then SP and the argument clause where one follows (RFC 5321 Section 4.1.1); only the one SP is syntax, so trailing white space stays in the argument clause.
- pcapkit.protocols.application.smtp.const.SMTP_REPLY¶
An SMTP reply line, CRLF excluded. A
Reply-code(RFC 5321 Section 4.2), then a hyphen or SP and the text, or nothing where the line closes the reply.