Blame examples/mailZip.pl
|
Packit |
0bf95d |
#!/usr/bin/perl -w
|
|
Packit |
0bf95d |
# Requires the following to be installed:
|
|
Packit |
0bf95d |
# File::Path
|
|
Packit |
0bf95d |
# File::Spec
|
|
Packit |
0bf95d |
# IO::Scalar, ... from the IO-stringy distribution
|
|
Packit |
0bf95d |
# MIME::Base64
|
|
Packit |
0bf95d |
# MIME::QuotedPrint
|
|
Packit |
0bf95d |
# Net::SMTP
|
|
Packit |
0bf95d |
# Mail::Internet, ... from the MailTools distribution.
|
|
Packit |
0bf95d |
# MIME::Tools
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
use strict;
|
|
Packit |
0bf95d |
use Archive::Zip qw(:CONSTANTS :ERROR_CODES);
|
|
Packit |
0bf95d |
use IO::Scalar;
|
|
Packit |
0bf95d |
use MIME::Entity; # part of MIME::Tools package
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
my $zipContents = '';
|
|
Packit |
0bf95d |
my $SH = IO::Scalar->new(\$zipContents);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
my $zip = Archive::Zip->new();
|
|
Packit |
0bf95d |
my $member;
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# add a string as a member:
|
|
Packit |
0bf95d |
my $stringMember = '<html><head></head><body>Testing</body></html>';
|
|
Packit |
0bf95d |
$member = $zip->addString($stringMember, 'whatever.html');
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# $member->desiredCompressionMethod(COMPRESSION_STORED);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# write it to the scalar
|
|
Packit |
0bf95d |
my $status = $zip->writeToFileHandle($SH);
|
|
Packit |
0bf95d |
$SH->close;
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
print STDERR "zip is " . length($zipContents) . " bytes long\n";
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
### Create an entity:
|
|
Packit |
0bf95d |
my $top = MIME::Entity->build(
|
|
Packit |
0bf95d |
Type => 'multipart/mixed',
|
|
Packit |
0bf95d |
From => 'ned@bike-nomad.com',
|
|
Packit |
0bf95d |
To => 'billnevin@tricom.net',
|
|
Packit |
0bf95d |
Subject => "Your zip",
|
|
Packit |
0bf95d |
);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# attach the message
|
|
Packit |
0bf95d |
$top->attach(
|
|
Packit |
0bf95d |
Encoding => '7bit',
|
|
Packit |
0bf95d |
Data => "here is the zip you ordered\n"
|
|
Packit |
0bf95d |
);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# attach the zip
|
|
Packit |
0bf95d |
$top->attach(
|
|
Packit |
0bf95d |
Data => \$zipContents,
|
|
Packit |
0bf95d |
Type => "application/x-zip",
|
|
Packit |
0bf95d |
Encoding => "base64",
|
|
Packit |
0bf95d |
Disposition => 'attachment',
|
|
Packit |
0bf95d |
Filename => 'your.zip'
|
|
Packit |
0bf95d |
);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# attach this code
|
|
Packit |
0bf95d |
$top->attach(
|
|
Packit |
0bf95d |
Encoding => '8bit',
|
|
Packit |
0bf95d |
Type => 'text/plain',
|
|
Packit |
0bf95d |
Path => $0,
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# Data => 'whatever',
|
|
Packit |
0bf95d |
Disposition => 'inline'
|
|
Packit |
0bf95d |
);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# and print it out to stdout
|
|
Packit |
0bf95d |
$top->print(\*STDOUT);
|