1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/// Parse and represent full "top-level" emails (RFC 822, RFC 2045, RFC 2046)
/// Parse and represent emails "parts" as defined by MIME (RFC 2046)
/// Parse and represent IMF (Internet Message Format) headers (RFC 822, RFC 5322)
/// Parse and represent MIME headers (RFC 2045, RFC 2047)
/// MIME and IMF represent headers the same way: module contains their common logic
/// Low-level email-specific text-based representation for data
/// Printing with email-specific line folding
/// Helpers related to UTF-8 support in headers (RFC 6532)
/// Support for storing references to raw input slices in AST nodes.
/// Custom equality trait used for fuzz-checking
// Re-export bounded_static because we implement its traits
pub use bounded_static;
/// Parse a whole email including its (MIME) body
///
/// # Arguments
///
/// * `input` - A buffer of bytes containing your full email
///
/// # Returns
///
/// * `msg` - The parsed message
///
/// # Examples
///
/// ```
/// let input = br#"Date: 7 Mar 2023 08:00:00 +0200
/// From: deuxfleurs@example.com
/// To: someone_else@example.com
/// Subject: An RFC 822 formatted message
/// MIME-Version: 1.0
/// Content-Type: text/plain; charset=us-ascii
///
/// This is the plain text body of the message. Note the blank line
/// between the header information and the body of the message."#;
///
/// let email = eml_codec::parse_message(input);
/// println!(
/// "{} message structure is:\n{:#?}",
/// email.imf.from_or_sender().unwrap().to_string(),
/// email,
/// );
/// ```
/// Print a whole email.
///
/// The `seed` parameter controls the RNG used to generate multipart boundaries.
/// Passing `None` will use randomness from the operating system.
/// Only extract the headers of the email that are part of the Internet Message Format spec
///
/// Emails headers contain MIME and IMF (Internet Message Format) headers.
/// Sometimes you only need to know the recipient or the sender of an email,
/// and are not interested in its content. In this case, you only need to parse the IMF
/// fields and can ignore the MIME headers + the body. This is what this function does.
///
/// # Arguments
///
/// * `input` - A buffer of bytes containing either only the headers of your email or your full
/// email (in both cases, the body will be ignored)
///
/// # Returns
///
/// * `rest` - The rest of the buffer, ie. the body of your email as raw bytes
/// * `imf` - The parsed IMF headers of your email
///
/// # Examples
///
/// ```
/// let input = br#"Date: 7 Mar 2023 08:00:00 +0200
/// From: deuxfleurs@example.com
/// To: someone_else@example.com
/// Subject: An RFC 822 formatted message
/// MIME-Version: 1.0
/// Content-Type: text/plain; charset=us-ascii
///
/// This is the plain text body of the message. Note the blank line
/// between the header information and the body of the message."#;
///
/// let (_, imf) = eml_codec::parse_imf(input);
/// println!(
/// "{} just sent you an email with subject \"{}\"",
/// imf.from_or_sender().unwrap().to_string(),
/// imf.subject.unwrap().to_string(),
/// );
/// ```
/// Get the raw subslice of the input that corresponds to the header section.
///
/// It can be later parsed using `parse_imf` or `parse_message` (resulting in an
/// empty body). This is equivalent to directly parsing the full input, but
/// allows the header section to e.g. be stored separately without storing the
/// body.