qpsmtpd/plugins/content_log
2014-12-02 16:51:51 -06:00

38 lines
996 B
Perl

#!perl -w
# A simple example of a plugin that logs all incoming mail to a file.
# Useful for debugging other plugins or keeping an archive of things.
use POSIX qw:strftime:;
sub register {
my ( $self, $qp ) = @_;
my $enabled = $qp->config('enable_content_log');
$enabled = 'true' if ! defined $enabled;
return if lc($enabled) ne 'true';
$self->register_hook('data_post', 'data_post_handler');
}
sub data_post_handler {
my ($self, $transaction) = @_;
open my $out, '>>', $self->content_log_file;
or return DECLINED, "Could not open log file.. continuing anyway";
$transaction->header->print($out);
$transaction->body_resetpos;
while (my $line = $transaction->body_getline) {
print $out $line;
}
close $out;
return DECLINED, "successfully saved message.. continuing";
}
sub content_log_file {
# as a decent default, log on a per-day-basis
my $date = strftime("%Y%m%d", localtime(time));
return "mail/$date";
}