NAME

Mail::SpamAssassin::Util::Zip - read zip archives within a size limit

SYNOPSIS

use Mail::SpamAssassin::Util::Zip;

my $zip = Mail::SpamAssassin::Util::Zip::open_zip(\$data) or return;
foreach my $member ($zip->members()) {
  my ($content, $produced) =
    Mail::SpamAssassin::Util::Zip::member_contents($member, $limit);
}

DESCRIPTION

Reads zip archives held in memory with Archive::Zip, uncompressing members in small steps so that the output never goes far past the caller's limit. The sizes declared in an archive are not trusted.

Several zip archives joined end to end, a known way of hiding files from zip readers that show only the first or only the last, are all read.

open_zip(\$data)

Returns an object for the zip archives in $data, or undef if Archive::Zip is not installed or no zip archive can be read from the data. Of joined archives, up to 4 are read from the start of the data, and the last one is always read. $data must not change while the object is in use.

The object's members, memberNamed and membersMatching methods work as those of Archive::Zip do, over all the archives read, in order.

member_contents($member, $limit)

Uncompresses the Archive::Zip::Member $member. Returns the data, or undef if the member is encrypted, cannot be read, or uncompresses to more than $limit bytes; and as a second value the number of bytes uncompressed, which callers should count against their limits whether or not the data is returned.