Apache-App-Mercury
view release on metacpan or search on metacpan
Mercury/SMTP_Message.pm view on Meta::CPAN
return $self->set_smtp_status('sent');
} elsif ($autoforw{$self->{'security'}} eq 'notify') {
my $msg = $self->mime_notify($self->{'address'});
$self->warn("->send_by_e_mail: sending notify message to <".$self->{'address'}.">:");
eval {
$msg->send_by_smtp(SMTP_SERVER, Hello => SMTP_HELLO,
Timeout => SMTP_TIMEOUT, Debug => SMTP_DEBUG);
};
if ($@) {
$self->log_error("->send_by_e_mail: $@");
return 0;
}
return $self->set_smtp_status('sent');
}
$self->set_smtp_status;
return 0;
}
sub datestamp {
my ($self) = @_;
# read message's timestamp and convert to MIME Date: header format
my ($y, $m, $d, $hr, $min, $sec) =
( $self->{'time'} =~ m/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ );
my ($u_wdy, $u_mon, $u_mdy, $u_time, $u_y4) =
split(/\s+/, gmtime(mktime($sec, $min, $hr, $d, $m-1, $y-1900)));
return "$u_wdy, $u_mdy $u_mon $u_y4 $u_time UT";
}
sub mime_notify {
my ($self, @to) = @_;
return MIME::Lite->new
(From => 'postmaster@'.SMTP_HELLO,
To => join(', ', @to),
Subject => MIME_NOTIFY_HDR,
Date => $self->datestamp,
Data => MIME_NOTIFY_MSG . MIME_FOOTER,
Type => "text/plain",
);
}
sub to_mime {
my ($self, @to) = @_;
my $msg = MIME::Lite->new
(From => $self->{'sender'}.'@'.SMTP_HELLO,
To => join(', ', @to),
Subject => $self->{'subject'},
Date => $self->datestamp,
Data => $self->{'body'} . MIME_FOOTER,
Type => "text/plain",
);
if (ref $self->{'Attachments'} eq "ARRAY") {
foreach my $a (@{$self->{'Attachments'}}) {
$msg->attach
(Path => (Apache::App::Mercury::Config::ATTACHMENT_FILESYS_BASE() .
$a->{'Filename'}),
Filename => $a->{'Name'},
Type => $self->autotype_by_ext($a->{'Filename'}),
);
}
}
return $msg;
}
sub autotype_by_ext {
my ($self, $filesys) = @_;
if ($filesys =~ m/\.gif$/i) {
return "image/gif";
} elsif ($filesys =~ m/\.(?:jpg|jpeg)$/i) {
return "image/jpeg";
} elsif ($filesys =~ m/\.(?:html|htm)$/i) {
return "text/html";
} elsif ($filesys =~ m/\.xml$/i) {
return "text/xml";
} else {
return "text/plain";
}
}
1;
( run in 1.101 second using v1.01-cache-2.11-cpan-e1769b4cff6 )