Importing Archive::Zip 1.16
[archive-zip.git] / examples / mailZip.pl
blobc0f0b06460eb121e371703d4683a1f2611335e16
1 #!/usr/bin/perl -w
2 # Requires the following to be installed:
3 # File::Path
4 # File::Spec
5 # IO::Scalar, ... from the IO-stringy distribution
6 # MIME::Base64
7 # MIME::QuotedPrint
8 # Net::SMTP
9 # Mail::Internet, ... from the MailTools distribution.
10 # MIME::Tools
12 use strict;
13 use Archive::Zip qw(:CONSTANTS :ERROR_CODES);
14 use IO::Scalar;
15 use MIME::Entity; # part of MIME::Tools package
17 my $zipContents = '';
18 my $SH = IO::Scalar->new( \$zipContents );
20 my $zip = Archive::Zip->new();
21 my $member;
23 # add a string as a member:
24 my $stringMember = '<html><head></head><body><h1>Testing</h1></body></html>';
25 $member = $zip->addString($stringMember, 'whatever.html');
26 # $member->desiredCompressionMethod(COMPRESSION_STORED);
28 # write it to the scalar
29 my $status = $zip->writeToFileHandle($SH);
30 $SH->close;
32 print STDERR "zip is ". length($zipContents). " bytes long\n";
34 ### Create an entity:
35 my $top = MIME::Entity->build(
36 Type => 'multipart/mixed',
37 From => 'ned@bike-nomad.com',
38 To => 'billnevin@tricom.net',
39 Subject => "Your zip",
42 # attach the message
43 $top->attach(
44 Encoding => '7bit',
45 Data => "here is the zip you ordered\n"
48 # attach the zip
49 $top->attach(
50 Data => \$zipContents,
51 Type => "application/x-zip",
52 Encoding => "base64",
53 Disposition => 'attachment',
54 Filename => 'your.zip'
57 # attach this code
58 $top->attach(
59 Encoding => '8bit',
60 Type => 'text/plain',
61 Path => $0,
62 # Data => 'whatever',
63 Disposition => 'inline'
66 # and print it out to stdout
67 $top->print( \*STDOUT );