Expand description
The email lexical layer (RFC 5322, RFC 2045, RFC 2047, RFC 2231): header lines and folding, encoded words, MIME parameters with continuations, addresses, and message identifiers. The grammar smtp-net needs to write mail and gate-net needs to validate login addresses (D-008); not a mail parser. Charsets decoded: UTF-8, US-ASCII, ISO-8859-1.
§Examples
use parse_net::{mail, SliceSink, Limits};
let mut buf = [0u8; 256];
let mut out = SliceSink::new(&mut buf);
mail::encode_words("Caf\u{e9} au lait", 64, &mut out).expect("room");
assert_eq!(out.written(), b"=?UTF-8?Q?Caf=C3=A9_au_lait?=");
let a = mail::parse_addr_spec(b"\"john doe\"@example.com")?;
assert!(a.is_ascii());
assert!(mail::parse_addr_spec(b"john..doe@example.com").is_err());
let (p, _) = mail::parse_mime_params(b"; filename*0*=UTF-8''caf%C3%A9; filename*1=\".txt\"", &Limits::DEFAULT)?;
let mut name = [0u8; 32];
assert_eq!(p.decode_into("filename", &mut name)?, Some("caf\u{e9}.txt"));Re-exports§
pub use crate::MailDate;
Structs§
- Addr
Spec - An address:
local-part "@" domain. - Continuation
- The sections of an RFC 2231 continued value, validated at parse.
- Mailbox
- A mailbox: an optional display name and an address.
- Mime
Param Iter - The parameters of a validated
MimeParams. - Mime
Params - Validated MIME parameters.
- MsgId
- A message identifier:
"<" id-left "@" id-right ">". - Unfold
Iter - The pieces of an
Unfoldedvalue. - Unfolded
- A validated folded field body.
Enums§
Functions§
- check_
header_ value - Checks a header field value for writing: no CR, LF, or NUL, and at most
998 bytes (the physical line limit of RFC 5322 section 2.1.1, which the
caller’s
Name:also counts toward). - decode_
words - Decodes the RFC 2047 encoded words in unstructured header text into
outand returns the text. Text outside encoded words is copied; whitespace between two adjacent encoded words is dropped (section 6.2);_is a space in Q; an encoded word must stand alone between whitespace, and words inside a quoted string are not decoded (section 5). Charsets: UTF-8, US-ASCII, ISO-8859-1 (transcoded), with an optional RFC 2231*language.Bwords need theencode-libfeature, which is not yet available (D-002). - encode_
words - Writes
textfor an unstructured header field: as it is when it is printable ASCII without=?, otherwise as RFC 2047=?UTF-8?Q?...?=words of at most 75 bytes, split only between characters, separated by CRLF SP. The first word fits inroom_first_line(the columns left afterName:); when not even one character fits there, the words start on a new line. - fold
- Writes
Name: valuewith CRLF folds before whitespace so lines stay within 78 columns where the words allow, never creating a line of only whitespace and never one over 998 bytes. A space is added after the colon whenvaluedoes not start with whitespace. No CRLF is written at the end. - is_
field_ name - Whether
nameis an email header field name: one or moreftext(%d33-57 / %d59-126, RFC 5322 section 3.6.8). - parse_
addr_ spec - Parses an
addr-spec(RFC 5322 section 3.4.1) without obsolete forms, comments, or folding: adot-atomor quoted local part,@, and adot-atomdomain or[domain-literal]. The local part is at most 64 octets and the address at most 254; non-ASCII is accepted only as valid UTF-8 (RFC 6532). Surrounding SP and HTAB are stripped. - parse_
mailbox - Parses a
mailbox(RFC 5322 section 3.4):[display-name] "<" addr-spec ">"or a bareaddr-spec. The display name is checked as a phrase (atoms, dots, quoted strings, comments, UTF-8) and returned raw. - parse_
mime_ params - Parses
*( ";" attribute "=" value )(RFC 2045 section 5.1) with the MIME token class, CFWS between the parts, and case-insensitive names, and validates every RFC 2231 extended value and continuation. Returns the parameters and the bytes used (parsing stops at the first byte that does not start another parameter). - parse_
msg_ id - Parses a
msg-id(RFC 5322 section 3.6.4):dot-atom-texton both sides of@, or ano-fold-literal([...]) on the right. - unfold
- Validates a folded header field body and returns its pieces: the text
between
CRLF WSPfolds, each CRLF removed and the WSP kept (RFC 5322 section 2.2.3). Concatenated, the pieces are the unfolded value. - write_
mime_ param - Writes
; name=value: as a token, as a quoted string, or, for non-ASCII or long values, as; name*=UTF-8''..., split intoname*0*,name*1*sections on folded lines when one line would pass 78 columns. The output parses back withparse_mime_paramsto the same value. - write_
msg_ id - Writes
<left@right>.leftmust be ASCIIdot-atom-text;rightthe same or a domain literal in brackets.