summaryrefslogtreecommitdiff
path: root/cpan/lib/Mail/Mailer
diff options
context:
space:
mode:
authorfukachan <fukachan>2018-01-01 03:52:14 +0000
committerfukachan <fukachan>2018-01-01 03:52:14 +0000
commitecc21ac78150d32a0125703ca03b085c9805c7c6 (patch)
tree079acf91ecaaf4ab2f84846f210bb33b9b31f36c /cpan/lib/Mail/Mailer
parent7bc5f8929e4ebb0cc24bf9a4ae7a67228aa70152 (diff)
downloadfml8-MailTools-2-19.tar.gz
fml8-MailTools-2-19.tar.bz2
fml8-MailTools-2-19.zip
import MailTools-2.19MailTools-2-19
Diffstat (limited to 'cpan/lib/Mail/Mailer')
-rw-r--r--cpan/lib/Mail/Mailer/qmail.pm25
-rw-r--r--cpan/lib/Mail/Mailer/rfc822.pm35
-rw-r--r--cpan/lib/Mail/Mailer/sendmail.pm21
-rw-r--r--cpan/lib/Mail/Mailer/smtp.pm115
-rw-r--r--cpan/lib/Mail/Mailer/smtps.pm108
-rw-r--r--cpan/lib/Mail/Mailer/testfile.pm54
6 files changed, 285 insertions, 73 deletions
diff --git a/cpan/lib/Mail/Mailer/qmail.pm b/cpan/lib/Mail/Mailer/qmail.pm
index ea312606..19660675 100644
--- a/cpan/lib/Mail/Mailer/qmail.pm
+++ b/cpan/lib/Mail/Mailer/qmail.pm
@@ -1,9 +1,22 @@
+# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# For other contributors see ChangeLog.
+# See the manual pages for details on the licensing terms.
+# Pod stripped from pm file by OODoc 2.02.
+
+use strict;
+
package Mail::Mailer::qmail;
-use vars qw(@ISA);
-require Mail::Mailer::rfc822;
-@ISA = qw(Mail::Mailer::rfc822);
+use vars '$VERSION';
+$VERSION = '2.19';
+
+use base 'Mail::Mailer::rfc822';
-sub exec {
- my($self, $exe, $args, $to) = @_;
- exec(( $exe ));
+sub exec($$$$)
+{ my($self, $exe, $args, $to, $sender) = @_;
+ my $address = defined $sender && $sender =~ m/\<(.*?)\>/ ? $1 : $sender;
+
+ exec($exe, (defined $address ? "-f$address" : ()));
+ die "ERROR: cannot run $exe: $!";
}
+
+1;
diff --git a/cpan/lib/Mail/Mailer/rfc822.pm b/cpan/lib/Mail/Mailer/rfc822.pm
index fa59d0fe..c87e76f5 100644
--- a/cpan/lib/Mail/Mailer/rfc822.pm
+++ b/cpan/lib/Mail/Mailer/rfc822.pm
@@ -1,20 +1,29 @@
+# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# For other contributors see ChangeLog.
+# See the manual pages for details on the licensing terms.
+# Pod stripped from pm file by OODoc 2.02.
+use strict;
+
package Mail::Mailer::rfc822;
-use vars qw(@ISA);
-@ISA = qw(Mail::Mailer);
-
-sub set_headers {
- my $self = shift;
- my $hdrs = shift;
- local($\)="";
- foreach(keys %$hdrs) {
- next unless m/^[A-Z]/;
-
- my ($h);
- foreach $h ($self->to_array($hdrs->{$_}))
+use vars '$VERSION';
+$VERSION = '2.19';
+
+use base 'Mail::Mailer';
+
+sub set_headers
+{ my ($self, $hdrs) = @_;
+
+ local $\ = "";
+
+ foreach (keys %$hdrs)
+ { next unless m/^[A-Z]/;
+
+ foreach my $h ($self->to_array($hdrs->{$_}))
{ $h =~ s/\n+\Z//;
- print $self "$_: ", $h, "\n";
+ print $self "$_: $h\n";
}
}
+
print $self "\n"; # terminate headers
}
diff --git a/cpan/lib/Mail/Mailer/sendmail.pm b/cpan/lib/Mail/Mailer/sendmail.pm
index ea67d7e0..343b6cc1 100644
--- a/cpan/lib/Mail/Mailer/sendmail.pm
+++ b/cpan/lib/Mail/Mailer/sendmail.pm
@@ -1,17 +1,26 @@
+# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# For other contributors see ChangeLog.
+# See the manual pages for details on the licensing terms.
+# Pod stripped from pm file by OODoc 2.02.
+use strict;
+
package Mail::Mailer::sendmail;
-use vars qw(@ISA);
-require Mail::Mailer::rfc822;
-@ISA = qw(Mail::Mailer::rfc822);
+use vars '$VERSION';
+$VERSION = '2.19';
+use base 'Mail::Mailer::rfc822';
-sub exec {
- my($self, $exe, $args, $to) = @_;
+sub exec($$$$)
+{ my($self, $exe, $args, $to, $sender) = @_;
# Fork and exec the mailer (no shell involved to avoid risks)
# We should always use a -t on sendmail so that Cc: and Bcc: work
# Rumor: some sendmails may ignore or break with -t (AIX?)
# Chopped out the @$to arguments, because -t means
# they are sent in the body, and postfix complains if they
- # are also given on comand line.
+ # are also given on command line.
+
exec( $exe, '-t', @$args );
}
+
+1;
diff --git a/cpan/lib/Mail/Mailer/smtp.pm b/cpan/lib/Mail/Mailer/smtp.pm
index 42eac5e4..aa5e4a87 100644
--- a/cpan/lib/Mail/Mailer/smtp.pm
+++ b/cpan/lib/Mail/Mailer/smtp.pm
@@ -1,84 +1,103 @@
+# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# For other contributors see ChangeLog.
+# See the manual pages for details on the licensing terms.
+# Pod stripped from pm file by OODoc 2.02.
+use strict;
+
package Mail::Mailer::smtp;
-use vars qw(@ISA);
+use vars '$VERSION';
+$VERSION = '2.19';
+
+use base 'Mail::Mailer::rfc822';
+
use Net::SMTP;
use Mail::Util qw(mailaddress);
use Carp;
-require Mail::Mailer::rfc822;
-@ISA = qw(Mail::Mailer::rfc822);
-
sub can_cc { 0 }
sub exec {
- my($self, $exe, $args, $to) = @_;
+ my ($self, $exe, $args, $to) = @_;
my %opt = @$args;
my $host = $opt{Server} || undef;
$opt{Debug} ||= 0;
- # for Net::SMTP we do not really exec
my $smtp = Net::SMTP->new($host, %opt)
or return undef;
- ${*$self}{'sock'} = $smtp;
-
- $smtp->mail(mailaddress());
- my $u;
- foreach $u (@$to) {
- $smtp->to($u);
+ if($opt{Auth})
+ { $smtp->auth(@{$opt{Auth}})
+ or return undef;
}
+
+ ${*$self}{sock} = $smtp;
+
+ $smtp->mail($opt{From} || mailaddress());
+ $smtp->to($_) for @$to;
$smtp->data;
- untie(*$self) if tied *$self;
- tie *$self, 'Mail::Mailer::smtp::pipe',$self;
+
+ untie *$self if tied *$self;
+ tie *$self, 'Mail::Mailer::smtp::pipe', $self;
$self;
}
-sub set_headers {
- my($self,$hdrs) = @_;
- $self->SUPER::set_headers({
- From => "<" . mailaddress() . ">",
- %$hdrs,
- 'X-Mailer' => "Mail::Mailer[v$Mail::Mailer::VERSION] Net::SMTP[v$Net::SMTP::VERSION]"
- })
+sub set_headers($)
+{ my ($self, $hdrs) = @_;
+ $self->SUPER::set_headers
+ ( { From => "<" . mailaddress() . ">"
+ , %$hdrs
+ , 'X-Mailer' => "Mail::Mailer[v$Mail::Mailer::VERSION] Net::SMTP[v$Net::SMTP::VERSION]"
+ }
+ );
}
-sub epilogue {
- my $self = shift;
- my $sock = ${*$self}{'sock'};
- $sock->dataend;
+sub epilogue()
+{ my $self = shift;
+ my $sock = ${*$self}{sock};
+
+ my $ok = $sock->dataend;
$sock->quit;
- delete ${*$self}{'sock'};
- untie(*$self);
+
+ delete ${*$self}{sock};
+ untie *$self;
+ $ok;
}
-sub close {
- my($self, @to) = @_;
- my $sock = ${*$self}{'sock'};
- if ($sock && fileno($sock)) {
- $self->epilogue;
- # Epilogue should destroy the SMTP filehandle,
- # but just to be on the safe side.
- if ($sock && fileno($sock)) {
- close $sock
- or croak 'Cannot destroy socket filehandle';
- }
- }
- 1;
+sub close(@)
+{ my ($self, @to) = @_;
+ my $sock = ${*$self}{sock};
+
+ $sock && fileno $sock
+ or return 1;
+
+ my $ok = $self->epilogue;
+
+ # Epilogue should destroy the SMTP filehandle,
+ # but just to be on the safe side.
+ $sock && fileno $sock
+ or return $ok;
+
+ close $sock
+ or croak 'Cannot destroy socket filehandle';
+
+ $ok;
}
package Mail::Mailer::smtp::pipe;
+use vars '$VERSION';
+$VERSION = '2.19';
-sub TIEHANDLE {
- my $pkg = shift;
- my $self = shift;
- my $sock = ${*$self}{'sock'};
- return bless \$sock;
+
+sub TIEHANDLE
+{ my ($class, $self) = @_;
+ my $sock = ${*$self}{sock};
+ bless \$sock, $class;
}
-sub PRINT {
- my $self = shift;
+sub PRINT
+{ my $self = shift;
my $sock = $$self;
$sock->datasend( @_ );
}
-
1;
diff --git a/cpan/lib/Mail/Mailer/smtps.pm b/cpan/lib/Mail/Mailer/smtps.pm
new file mode 100644
index 00000000..90d10efc
--- /dev/null
+++ b/cpan/lib/Mail/Mailer/smtps.pm
@@ -0,0 +1,108 @@
+# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# For other contributors see ChangeLog.
+# See the manual pages for details on the licensing terms.
+# Pod stripped from pm file by OODoc 2.02.
+# Based on smtp.pm, adapted by Maciej Żenczykowski
+
+use strict;
+
+package Mail::Mailer::smtps;
+use vars '$VERSION';
+$VERSION = '2.19';
+
+use base 'Mail::Mailer::rfc822';
+
+use Net::SMTP::SSL;
+use Mail::Util qw(mailaddress);
+use Carp;
+
+sub can_cc { 0 }
+
+sub exec {
+ my ($self, $exe, $args, $to) = @_;
+ my %opt = @$args;
+ my $host = $opt{Server} || undef;
+ $opt{Debug} ||= 0;
+ $opt{Port} ||= 465;
+
+ my $smtp = Net::SMTP::SSL->new($host, %opt)
+ or return undef;
+
+ if($opt{Auth})
+ { $smtp->auth(@{$opt{Auth}})
+ or return undef;
+ }
+
+ ${*$self}{sock} = $smtp;
+
+ $smtp->mail($opt{From} || mailaddress);
+ $smtp->to($_) for @$to;
+ $smtp->data;
+
+ untie *$self if tied *$self;
+ tie *$self, 'Mail::Mailer::smtps::pipe', $self;
+ $self;
+}
+
+sub set_headers($)
+{ my ($self, $hdrs) = @_;
+ $self->SUPER::set_headers
+ ( { From => "<" . mailaddress() . ">"
+ , %$hdrs
+ , 'X-Mailer' => "Mail::Mailer[v$Mail::Mailer::VERSION] "
+ . " Net::SMTP[v$Net::SMTP::VERSION]"
+ . " Net::SMTP::SSL[v$Net::SMTP::SSL::VERSION]"
+ }
+ );
+}
+
+sub epilogue()
+{ my $self = shift;
+ my $sock = ${*$self}{sock};
+
+ my $ok = $sock->dataend;
+ $sock->quit;
+
+ delete ${*$self}{sock};
+ untie *$self;
+ $ok;
+}
+
+sub close(@)
+{ my ($self, @to) = @_;
+ my $sock = ${*$self}{sock};
+
+ $sock && fileno $sock
+ or return 1;
+
+ my $ok = $self->epilogue;
+
+ # Epilogue should destroy the SMTP filehandle,
+ # but just to be on the safe side.
+ $sock && fileno $sock
+ or return $ok;
+
+ close $sock
+ or croak 'Cannot destroy socket filehandle';
+
+ $ok;
+}
+
+package Mail::Mailer::smtps::pipe;
+use vars '$VERSION';
+$VERSION = '2.19';
+
+
+sub TIEHANDLE
+{ my ($class, $self) = @_;
+ my $sock = ${*$self}{sock};
+ bless \$sock, $class;
+}
+
+sub PRINT
+{ my $self = shift;
+ my $sock = $$self;
+ $sock->datasend( @_ );
+}
+
+1;
diff --git a/cpan/lib/Mail/Mailer/testfile.pm b/cpan/lib/Mail/Mailer/testfile.pm
new file mode 100644
index 00000000..94dcad40
--- /dev/null
+++ b/cpan/lib/Mail/Mailer/testfile.pm
@@ -0,0 +1,54 @@
+# Copyrights 1995-2017 by [Mark Overmeer <perl@overmeer.net>].
+# For other contributors see ChangeLog.
+# See the manual pages for details on the licensing terms.
+# Pod stripped from pm file by OODoc 2.02.
+use strict;
+
+package Mail::Mailer::testfile;
+use vars '$VERSION';
+$VERSION = '2.19';
+
+use base 'Mail::Mailer::rfc822';
+
+use Mail::Util qw/mailaddress/;
+
+my $num = 0;
+sub can_cc() { 0 }
+
+sub exec($$$)
+{ my ($self, $exe, $args, $to) = @_;
+
+ my $outfn = $Mail::Mailer::testfile::config{outfile} || 'mailer.testfile';
+ open F, '>>', $outfn
+ or die "Cannot append message to testfile $outfn: $!";
+
+ print F "\n===\ntest ", ++$num, " ", (scalar localtime),
+ "\nfrom: " . mailaddress(),
+ "\nto: " . join(' ',@{$to}), "\n\n";
+ close F;
+
+ untie *$self if tied *$self;
+ tie *$self, 'Mail::Mailer::testfile::pipe', $self;
+ $self;
+}
+
+sub close { 1 }
+
+package Mail::Mailer::testfile::pipe;
+use vars '$VERSION';
+$VERSION = '2.19';
+
+
+sub TIEHANDLE
+{ my ($class, $self) = @_;
+ bless \$self, $class;
+}
+
+sub PRINT
+{ my $self = shift;
+ open F, '>>', $Mail::Mailer::testfile::config{outfile} || 'mailer.testfile';
+ print F @_;
+ close F;
+}
+
+1;