Initial class construction

This commit is contained in:
João Narciso
2019-05-06 16:34:28 +02:00
parent 67f2d57e03
commit 431ff5f7d4
5813 changed files with 1622108 additions and 0 deletions

View File

@ -0,0 +1,25 @@
# Copyrights 1995-2018 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of the bundle MailTools. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md for Copyright.
# Licensed under the same terms as Perl itself.
package Mail::Mailer::qmail;
use vars '$VERSION';
$VERSION = '2.20';
use base 'Mail::Mailer::rfc822';
use strict;
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;

View File

@ -0,0 +1,34 @@
# Copyrights 1995-2018 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of the bundle MailTools. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md for Copyright.
# Licensed under the same terms as Perl itself.
package Mail::Mailer::rfc822;
use vars '$VERSION';
$VERSION = '2.20';
use base 'Mail::Mailer';
use strict;
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 "\n"; # terminate headers
}
1;

View File

@ -0,0 +1,30 @@
# Copyrights 1995-2018 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of the bundle MailTools. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md for Copyright.
# Licensed under the same terms as Perl itself.
package Mail::Mailer::sendmail;
use vars '$VERSION';
$VERSION = '2.20';
use base 'Mail::Mailer::rfc822';
use strict;
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 command line.
exec( $exe, '-t', @$args );
}
1;

View File

@ -0,0 +1,107 @@
# Copyrights 1995-2018 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of the bundle MailTools. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md for Copyright.
# Licensed under the same terms as Perl itself.
package Mail::Mailer::smtp;
use vars '$VERSION';
$VERSION = '2.20';
use base 'Mail::Mailer::rfc822';
use strict;
use Net::SMTP;
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;
my $smtp = Net::SMTP->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::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 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::smtp::pipe;
use vars '$VERSION';
$VERSION = '2.20';
sub TIEHANDLE
{ my ($class, $self) = @_;
my $sock = ${*$self}{sock};
bless \$sock, $class;
}
sub PRINT
{ my $self = shift;
my $sock = $$self;
$sock->datasend( @_ );
}
1;

View File

@ -0,0 +1,112 @@
# Copyrights 1995-2018 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of the bundle MailTools. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md for Copyright.
# Licensed under the same terms as Perl itself.
# Based on smtp.pm, adapted by Maciej Żenczykowski
package Mail::Mailer::smtps;
use vars '$VERSION';
$VERSION = '2.20';
use base 'Mail::Mailer::rfc822';
use strict;
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.20';
sub TIEHANDLE
{ my ($class, $self) = @_;
my $sock = ${*$self}{sock};
bless \$sock, $class;
}
sub PRINT
{ my $self = shift;
my $sock = $$self;
$sock->datasend( @_ );
}
1;

View File

@ -0,0 +1,58 @@
# Copyrights 1995-2018 by [Mark Overmeer].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of the bundle MailTools. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md for Copyright.
# Licensed under the same terms as Perl itself.
package Mail::Mailer::testfile;
use vars '$VERSION';
$VERSION = '2.20';
use base 'Mail::Mailer::rfc822';
use strict;
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.20';
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;