1Mail::SpamAssassin::MesUssaegre(C3o)ntributed Perl DocumMeanitla:t:iSopnamAssassin::Message(3)
2
3
4
6 Mail::SpamAssassin::Message - decode, render, and hold an RFC-2822
7 message
8
10 This module encapsulates an email message and allows access to the
11 various MIME message parts and message metadata.
12
13 The message structure, after initiating a parse() cycle, looks like
14 this:
15
16 Message object, also top-level node in Message::Node tree
17 |
18 +---> Message::Node for other parts in MIME structure
19 | |---> [ more Message::Node parts ... ]
20 | [ others ... ]
21 |
22 +---> Message::Metadata object to hold metadata
23
25 new()
26 Creates a Mail::SpamAssassin::Message object. Takes a hash
27 reference as a parameter. The used hash key/value pairs are as
28 follows:
29
30 "message" is either undef (which will use STDIN), a scalar - a
31 string containing an entire message, a reference to such string, an
32 array reference of the message with one line per array element, or
33 either a file glob or an IO::File object which holds the entire
34 contents of the message.
35
36 Note: The message is expected to generally be in RFC 2822 format,
37 optionally including an mbox message separator line (the "From "
38 line) as the first line.
39
40 "parse_now" specifies whether or not to create the MIME tree at
41 object-creation time or later as necessary.
42
43 The parse_now option, by default, is set to false (0). This allows
44 SpamAssassin to not have to generate the tree of
45 Mail::SpamAssassin::Message::Node objects and their related data if
46 the tree is not going to be used. This is handy, for instance,
47 when running "spamassassin -d", which only needs the pristine
48 header and body which is always handled when the object is created.
49
50 "subparse" specifies how many MIME recursion levels should be
51 parsed. Defaults to 20.
52
53 find_parts()
54 Used to search the tree for specific MIME parts. See
55 Mail::SpamAssassin::Message::Node for more details.
56
57 get_pristine_header()
58 Returns pristine headers of the message. If no specific header
59 name is given as a parameter (case-insensitive), then all headers
60 will be returned as a scalar, including the blank line at the end
61 of the headers.
62
63 If called in an array context, an array will be returned with each
64 specific header in a different element. In a scalar context, the
65 last specific header is returned.
66
67 ie: If 'Subject' is specified as the header, and there are 2
68 Subject headers in a message, the last/bottom one in the message is
69 returned in scalar context or both are returned in array context.
70
71 Btw, returning the last header field (not the first) happens to be
72 consistent with DKIM signatures, which search for and cover
73 multiple header fields bottom-up according to the 'h' tag. Let's
74 keep it this way.
75
76 Note: the returned header will include the ending newline and any
77 embedded whitespace folding.
78
79 get_mbox_separator()
80 Returns the mbox separator found in the message, or undef if there
81 wasn't one.
82
83 get_body()
84 Returns an array of the pristine message body, one line per array
85 element.
86
87 get_pristine()
88 Returns a scalar of the entire pristine message.
89
90 get_pristine_body()
91 Returns a scalar of the pristine message body.
92
93 get_pristine_body_digest()
94 Returns SHA1 hex digest of the pristine message body. CRLF line
95 endings are normalized to LF before hashing.
96
97 get_msgid()
98 Returns Message-ID header for the message, with <> and surrounding
99 whitespace removed. Returns undef, if nothing found between <>.
100
101 generate_msgid()
102 Generate a calculated "Message-ID" in sha1hex@sa_generated format,
103 using To, Date headers and pristine body as source for hashing.
104
105 extract_message_metadata($permsgstatus)
106 $str = get_metadata($hdr)
107 put_metadata($hdr, $text)
108 delete_metadata($hdr)
109 $str = get_all_metadata()
110 finish_metadata()
111 Destroys the metadata for this message. Once a message has been
112 scanned fully, the metadata is no longer required. Destroying
113 this will free up some memory.
114
115 finish()
116 Clean up an object so that it can be destroyed.
117
118 receive_date()
119 Return a time_t value with the received date of the current
120 message, or current time if received time couldn't be determined.
121
123 These methods take a RFC2822-esque formatted message and create a tree
124 with all of the MIME body parts included. Those parts will be decoded
125 as necessary, and text/html parts will be rendered into a standard text
126 format, suitable for use in SpamAssassin.
127
128 parse_body()
129 parse_body() passes the body part that was passed in onto the
130 correct part parser, either _parse_multipart() for multipart/*
131 parts, or _parse_normal() for everything else. Multipart sections
132 become the root of sub-trees, while everything else becomes a leaf
133 in the tree.
134
135 For multipart messages, the first call to parse_body() doesn't
136 create a new sub-tree and just uses the parent node to contain
137 children. All other calls to parse_body() will cause a new sub-
138 tree root to be created and children will exist underneath that
139 root. (this is just so the tree doesn't have a root node which
140 points at the actual root node ...)
141
142 _parse_multipart()
143 Generate a root node, and for each child part call parse_body() to
144 generate the tree.
145
146 _parse_normal()
147 Generate a leaf node and add it to the parent.
148
149
150
151perl v5.36.0 2023-01-21 Mail::SpamAssassin::Message(3)