qpsmtpd/plugins/content_log

79 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

#!perl -w
POD corrections, additional tests, plugin consistency on files in plugins dir: fixed a number of POD errors formatted some # comments into POD removed bare 1; (these are plugins, not perl modules) most instances of this were copy/pasted from a previous plugin that had it removed instances of # vim ts=N ... they weren't consistent, many didn't match .perltidyrc on modules that failed perl -c tests, added 'use Qpsmtpd::Constants;' Conflicts: plugins/async/check_earlytalker plugins/async/dns_whitelist_soft plugins/async/dnsbl plugins/async/queue/smtp-forward plugins/async/require_resolvable_fromhost plugins/async/rhsbl plugins/async/uribl plugins/auth/auth_checkpassword plugins/auth/auth_cvm_unix_local plugins/auth/auth_flat_file plugins/auth/auth_ldap_bind plugins/auth/auth_vpopmail plugins/auth/auth_vpopmail_sql plugins/auth/authdeny plugins/check_badmailfromto plugins/check_badrcptto_patterns plugins/check_bogus_bounce plugins/check_earlytalker plugins/check_norelay plugins/check_spamhelo plugins/connection_time plugins/dns_whitelist_soft plugins/dnsbl plugins/domainkeys plugins/greylisting plugins/hosts_allow plugins/http_config plugins/logging/adaptive plugins/logging/apache plugins/logging/connection_id plugins/logging/transaction_id plugins/logging/warn plugins/milter plugins/queue/exim-bsmtp plugins/queue/maildir plugins/queue/postfix-queue plugins/queue/smtp-forward plugins/quit_fortune plugins/random_error plugins/rcpt_map plugins/rcpt_regexp plugins/relay_only plugins/require_resolvable_fromhost plugins/rhsbl plugins/sender_permitted_from plugins/spamassassin plugins/tls plugins/tls_cert plugins/uribl plugins/virus/aveclient plugins/virus/bitdefender plugins/virus/clamav plugins/virus/clamdscan plugins/virus/hbedv plugins/virus/kavscanner plugins/virus/klez_filter plugins/virus/sophie plugins/virus/uvscan
2012-04-08 02:11:16 +02:00
2014-12-03 17:01:31 +01:00
=head1 NAME
content_log - record incoming mail to a file
=head1 DESCRIPTION
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.
=head1 CONFIG
=head2 content_log_enabled <true|false>
Used to enable and disable content logging
Default: true
2014-12-03 22:50:45 +01:00
=head2 content_log_file <pattern>
Path to the content log file.
This option is passed through strftime(); see
http://man7.org/linux/man-pages/man3/strftime.3.html
or the appropriate documentation for your operating system)
Default: mail/%Y%m%d
2014-12-03 17:01:31 +01:00
=cut
use POSIX qw:strftime:;
sub register {
2014-12-03 00:08:07 +01:00
my ( $self ) = @_;
return if ! $self->content_log_enabled;
$self->register_hook('data_post', 'data_post_handler');
}
sub data_post_handler {
my ($self, $transaction) = @_;
return DECLINED, 'excluded from content logging'
if $self->exclude();
2014-12-02 23:54:03 +01:00
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";
}
2014-12-02 23:28:51 +01:00
sub content_log_file {
2014-12-03 22:50:45 +01:00
my ( $self ) = @_;
2014-12-02 23:28:51 +01:00
# as a decent default, log on a per-day-basis
2014-12-03 22:50:45 +01:00
my $path = $self->qp->config('content_log_file');
$path ||= 'mail/%Y%m%d';
return strftime($path, localtime(time));
2014-12-02 23:28:51 +01:00
}
2014-12-03 00:08:07 +01:00
sub content_log_enabled {
my ( $self ) = @_;
my $enabled = $self->qp->config('content_log_enabled');
2014-12-03 00:08:07 +01:00
$enabled = 'true' if ! defined $enabled;
return 1 if $enabled =~ /^(?:true|1|yes)\s*$/i;
2014-12-03 00:08:07 +01:00
return 0;
}
sub exclude {
# override this method to exclude some messages from content logging
return 0;
}