Mail::...terator(3pm)
π Mail::SpamAssassin::ArchiveIterator π
okay bestie, welcome to the Perl manual page for Mail::SpamAssassin::ArchiveIterator β it's part of the User Contributed Perl Documentation situation, and it's genuinely iconic once you get it. sit down, grab a strawberry π, and let's go.
β¨ NAME β¨
Mail::SpamAssassin::ArchiveIterator β literally just here to find and process messages one at a time π¦
π SYNOPSIS π
my $iter = Mail::SpamAssassin::ArchiveIterator->new(
{
'opt_max_size' => 500 * 1024, # 0 implies no limit
'opt_cache' => 1,
}
);
$iter->set_functions( \&wanted, sub { } );
eval { $iter->run(@ARGV); };
sub wanted {
my($class, $filename, $recv_date, $msg_array) = @_;
...
}
like, that's the whole vibe right there. β¨
πΈ DESCRIPTION πΈ
okay so the Mail::SpamAssassin::ArchiveIterator module is gonna go through a whole set of mbox files, mbx files, and directories (with a single message per file, no cap) and generate a list of messages for you. then it calls the wanted_sub and result_sub functions appropriately per message. main character energy fr fr π
π METHODS π
$item = Mail::SpamAssassin::ArchiveIterator->new( [ { opt => val, ... } ] )
Constructs a brand new Mail::SpamAssassin::ArchiveIterator object, periodt. you may pass the following attribute-value pairs to the constructor. the pairs are optional unless otherwise noted β so don't stress. π«Ά
opt_max_sizeβ this one sets a limit (number of bytes) beyond which a message is considered large and gets skipped by ArchiveIterator. a value of0implies no size limit at all, all messages are examined. an undefined value implies a default limit of 500 KiB.opt_allβ setting this option to true implicitly setsopt_max_sizeto0, i.e. no limit of a message size, all messages are processed by ArchiveIterator. this exists for compatibility with SpamAssassin versions older than 3.4.0 which lacked optionopt_max_size.opt_scanprobβ randomly select messages to scan, with a probability of N, where N ranges from 0.0 (no messages scanned) to 1.0 (all messages scanned). default is 1.0. this setting can be specified separately for each target. π²opt_beforeβ only use messages which are received after the given time_t value. negative values are an offset from the current time, e.g.-86400= last 24 hours; or as parsed by Time::ParseDate (e.g.'-6 months'). this setting can be specified separately for each target.opt_afterβ same asopt_before, except the messages are only used if after the given time_t value. this setting can be specified separately for each target.opt_want_dateβ set to 1 (default) if you want the received date to be filled in in thewanted_subcallback below. set this to 0 to avoid this; it's a good idea to set this to 0 if you can, as it imposes a performance hit. πopt_skip_empty_messagesβ set to 1 if you want to skip corrupt, 0-byte messages. the default is 0.opt_cacheβ set to 0 (default) if you don't want to use cached information to help speed up ArchiveIterator. set to 1 to enable. this setting requiresopt_cachediralso be set.opt_cachedirβ set to the path of a directory where you wish to store cached information foropt_cache, if you don't want to mix them with the input files (as is the default). the directory must be both readable and writable. π₯wanted_subβ reference to a subroutine which will process message data. usually set viaset_functions(). the routine will be passed 5 values: class (scalar), filename (scalar), received date (scalar), message content (array reference, one message line per element), and the message format key ('f'for file,'m'for mbox,'b'for mbx). note that ifopt_want_dateis set to 0, the received date scalar will be undefined.result_subβ reference to a subroutine which will process the results of the wanted_sub for each message processed. usually set viaset_functions(). the routine will be passed 3 values: class (scalar), result (scalar, returned from wanted_sub), and received date (scalar). note that ifopt_want_dateis set to 0, the received date scalar will be undefined.scan_progress_subβ reference to a subroutine which will be called intermittently during the 'scan' phase of the mass-check. no guarantees are made as to how frequently this may happen, mind you. πopt_from_regexβ this setting allows for flexibility in specifying the mbox format From separator. it defaults to the regular expression:
/^From \S+ ?(\S\S\S \S\S\S .?\d .?\d:\d\d:\d\d
\d{4}|.?\d-\d\d-\d{4}_\d\d:\d\d:\d\d_)/
some SpamAssassin programs such as sa-learn will use the configuration option 'mbox_format_from_regex' to override the default regular expression.
set_functions( \&wanted_sub, \&result_sub )
sets the subroutines used for message processing (wanted_sub), and result reporting. for more information, see new() above. simple as. β¨
run ( @target_paths )
generates the list of messages to process, then runs each message through the configured wanted subroutine. the way this function just does things? obsessed. π§
compressed files are detected and uncompressed automatically regardless of file extension. supported formats are "gzip", "bzip2", "xz", "lz4", "lzip", "lzo". Gzip is uncompressed via IO::Zlib module, others use their specific command line tool (bzip2/xz/lz4/lzip/lzop). compressed mailbox/mbox files are not supported. π
the target_paths array is expected to be either one element per path in the following format: "class:format:raw_location", or a hash reference containing key-value option pairs and a 'target' key with a value in that format.
the key-value option pairs that can be used are: opt_scanprob, opt_after, opt_before. see the constructor method's documentation for more information on their effects.
run() returns 0 if there was an error (can't open a file, etc,) and 1 if there were no errors. π
class
either 'h' for ham or 's' for spam. if the class is longer than 1 character, it will be truncated. if blank, 'h' is default.
format
specifies the format of the raw_location. "dir" is a directory whose files are individual messages, "file" a file with a single message, "mbox" an mbox formatted file, or "mbx" for an mbx formatted directory.
"detect" can also be used. this assumes "mbox" for any file whose path contains the pattern /\.mbox/i, "file" anything that is not a directory, or "directory" otherwise.
raw_location
path to file or directory. file globbing is allowed using the standard csh-style globbing (see perldoc -f glob). "~" at the front of the value will be replaced by the HOME environment variable. escaped whitespace is protected as well.
NOTE: "~user" is not allowed.
NOTE 2: "-" is not allowed as a raw location. to have ArchiveIterator deal with STDIN, generate a temp file. π«
π SEE ALSO π
Mail::SpamAssassin(3) spamassassin(1) mass-check(1)
and that's the whole page, bestie. π this one's perl v5.40.1, dated 2026-07-23, straight from the User Contributed Perl Documentation girlies. go forth and iterate, you ate. π
β¨π
π¦ where this page comes from
- ubuntu stonking: spamassassin 4.0.2+svn1935691-1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms