Subject: | A couple minor bugs, and some feature enchancements |
I just found your module in CPAN the other day. I've been doing this
by hand every time, and was about to write this myself. Thanks much!
Well, I found a couple things. Net::SMTP changed the syntax of their
to() function a while back, and made it so that Net::SMTP::to() can no
longer accept an array, but it will take a list. Unfortunately, you
can't pass a list as a hash value. So I added some processing to
Header() to allow it to accept an arrayref for the 'To' value. While
I was at it, I added support for Cc and Bcc fields. Also, I noticed
that the module seemed to be cutting out the first line of all the
non-file attachments. Checking the code, it looks like you left out
one of the newlines. I added it.
I also added the ability to specify a display name for the attached
files. So that instead of displaying the full filename and path of
the source file, you can specify a desired file name to use instead of
the actual name.
Finally, I added two new files to your package, first I added a
Meta.yml file, that MakeMaker seemed to want, also I added a module
test, so that platform testers can verify it works on their platform.
If you've got any questions about what I did, please let me know.
Orien
diff -Nru Net-SMTP-Multipart-1.5.originals/MANIFEST Net-SMTP-Multipart-1.5/MANIFEST
--- Net-SMTP-Multipart-1.5.originals/MANIFEST 2002-04-05 06:38:33.000000000 -0500
+++ Net-SMTP-Multipart-1.5/MANIFEST 2004-09-19 11:23:51.197842738 -0400
@@ -2,4 +2,5 @@
Makefile.PL
MANIFEST
Multipart.pm
-
+t/use.t
+META.yml Module meta-data (added by MakeMaker)
diff -Nru Net-SMTP-Multipart-1.5.originals/META.yml Net-SMTP-Multipart-1.5/META.yml
--- Net-SMTP-Multipart-1.5.originals/META.yml 1969-12-31 19:00:00.000000000 -0500
+++ Net-SMTP-Multipart-1.5/META.yml 2004-09-19 11:27:03.728521423 -0400
@@ -0,0 +1,13 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: Net-SMTP-Multipart
+version: 1.5
+version_from: Multipart.pm
+installdirs: site
+requires:
+ MIME::Base64: 0
+ Net::SMTP: 0
+ Test: 0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
diff -Nru Net-SMTP-Multipart-1.5.originals/Makefile.PL Net-SMTP-Multipart-1.5/Makefile.PL
--- Net-SMTP-Multipart-1.5.originals/Makefile.PL 2002-04-05 06:39:10.000000000 -0500
+++ Net-SMTP-Multipart-1.5/Makefile.PL 2004-09-19 11:26:23.275935249 -0400
@@ -32,6 +32,7 @@
'PREREQ_PM' => {
MIME::Base64 => 0,
Net::SMTP => 0,
+ Test => 0,
}, # e.g., Module::Name => 1.1
'dist' => {
ZIP => 'wzzip.exe',
diff -Nru Net-SMTP-Multipart-1.5.originals/Multipart.pm Net-SMTP-Multipart-1.5/Multipart.pm
--- Net-SMTP-Multipart-1.5.originals/Multipart.pm 2002-11-11 07:13:29.000000000 -0500
+++ Net-SMTP-Multipart-1.5/Multipart.pm 2004-09-19 11:21:39.962867180 -0400
@@ -53,10 +53,45 @@
carp 'Net::SMTP::Multipart:Header: must be called with a To value' unless $arg{To};
carp 'Net::SMTP::Multipart:Header: must be called with a Subj value' unless $arg{Subj};
carp 'Net::SMTP::Multipart:Header: must be called with a From value' unless $arg{From};
- $self->mail($arg{From}); # Sender Mail Address
- $self->to($arg{To}); # Recpient Mail Address
+
+ my (@to, $toString, $ccString);
+
+ if (ref($arg{To}) eq 'ARRAY') {
+ push @to, @{$arg{To}};
+ $toString = join ", ", @to;
+ } else {
+ push @to, $arg{To};
+ $toString = $arg{To};
+ }
+
+ if (ref($arg{Cc}) eq 'ARRAY') {
+ if (@{$arg{Cc}}) {
+ push @to, @{$arg{Cc}};
+ $ccString = join ", ", @{$arg{Cc}};
+ }
+ } else {
+ if ($arg{Cc}) {
+ push @to, $arg{Cc};
+ $ccString = $arg{Cc};
+ }
+ }
+
+ if (ref($arg{Bcc}) eq 'ARRAY') {
+ if (@{$arg{Bcc}}) {
+ push @to, @{$arg{Bcc}};
+ # No string for Bcc, because it's hidden
+ }
+ } else {
+ if ($arg{Bcc}) {
+ push @to, $arg{Bcc};
+ }
+ }
+
+ $self->mail($arg{From}); # Sender Mail Address
+ $self->to(@to); # Recipient Mail Addresses
$self->data();
- $self->datasend("To: $arg{To}\n");
+ $self->datasend("To: $toString\n");
+ $self->datasend("Cc: $ccString\n") if ($ccString);
$self->datasend("Subject: $arg{Subj}\n");
$self->datasend("MIME-Version: 1.0\n");
$self->datasend(sprintf "Content-Type: multipart/mixed; BOUNDARY=\"%s\"\n",$b);
@@ -65,7 +100,7 @@
sub Text {
my $self = shift;
$self->datasend(sprintf"\n--%s\n",$b);
- $self->datasend("Content-Type: text/plain\n");
+ $self->datasend("Content-Type: text/plain\n\n");
foreach my $text (@_) {
$self->datasend($text);
}
@@ -75,6 +110,13 @@
sub FileAttach {
my $self = shift;
foreach my $file (@_) {
+ my $displayname;
+ if (ref($file) eq 'ARRAY') {
+ $displayname = $file->[0];
+ $file = $file->[1];
+ } else {
+ $displayname = $file;
+ }
unless (-f $file) {
carp 'Net::SMTP::Multipart:FileAttach: unable to find file $file';
next;
@@ -101,9 +143,9 @@
if ($data){
$self->datasend("--$b\n");
- $self->datasend("Content-Type: ; name=\"$file\"\n");
+ $self->datasend("Content-Type: ; name=\"$displayname\"\n");
$self->datasend("Content-Transfer-Encoding: base64\n");
- $self->datasend("Content-Disposition: attachment; =filename=\"$file\"\n\n");
+ $self->datasend("Content-Disposition: attachment; =filename=\"$displayname\"\n\n");
$self->datasend(encode_base64($data));
$self->datasend("--$b\n");
}
@@ -114,7 +156,7 @@
sub End {
my $self = shift;
- $self->datasend(sprintf"\n--%s--\n",$b); # send boundary end message
+ $self->datasend(sprintf"\n--%s--\n\n",$b); # send boundary end message
foreach my $epl (@_) {
$self->datasend("$epl"); # send epilogue text
}
@@ -190,7 +232,6 @@
The B<new> method invokes a new instance of the Net::SMTP::Multipart class, using the same
arguments as the parent method.
-
=item B<Header>
The B<Header> method creates the header of the multipart message. It should be called with
@@ -212,6 +253,20 @@
=back
+Additionally, you can specify the following additional arguments, if desired
+
+=over 4
+
+=item B<Cc>
+
+an array of mail addresses which should receive carbon copies of the mail
+
+=item B<Bcc>
+
+an array of mail addresses which should receive blind carbon copies of the mail
+
+=back
+
=item B<Text>
This method generates a text part to the message. The argument provided is treated as text and
@@ -219,8 +274,10 @@
=item B<FileAttach>
-This method includes a file (identified in the argument when this is called) within an encoded
-part of the message.
+This method includes a file (identified in the argument when this is called)
+within an encoded part of the message. Alternatively, this function can also be
+called with a reference to a two item array with a display filename as it's
+first element, and the actual filename as it's second.
=item B<End>
@@ -246,6 +303,16 @@
=head1 EXAMPLES
+ $smtp = Net::SMTP::Multipart->new("mailrelay.someco.com");
+ $smtp->Header(To => "someone\@someco.com",
+ Cc => [ "someoneelse\@example.com", "ceo\@example.com" ],
+ Bcc => "coworker\@someco.com",
+ Subj => "Multipart Mail Demo",
+ From => "me\@someco.com");
+ $smtp->Text("This is the first text part of the message");
+ $smtp->FileAttach( [ 'ReadThis.doc', 'c:/tmp/ImportantInternalDocument.doc' ]);
+ $smtp->End();
+
=head1 TO DO
=head1 AUTHOR
diff -Nru Net-SMTP-Multipart-1.5.originals/t/use.t Net-SMTP-Multipart-1.5/t/use.t
--- Net-SMTP-Multipart-1.5.originals/t/use.t 1969-12-31 19:00:00.000000000 -0500
+++ Net-SMTP-Multipart-1.5/t/use.t 2004-09-19 11:07:43.246852941 -0400
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl -w
+use strict;
+use Test;
+
+BEGIN { plan tests => 1};
+
+use Net::SMTP::Multipart;
+ok(1);
+exit;
+__END__