Log headers in a separate table

tags/0.1.4
Daniel Berteaud 12 years ago
parent 260359acbb
commit 825e337c60
  1. 1
      root/etc/cron.daily/qpsmtpd-db-cleanup
  2. 2
      root/etc/e-smith/templates/var/service/qpsmtpd/config/peers/0/03log2sql
  3. 2
      root/etc/e-smith/templates/var/service/qpsmtpd/config/peers/local/03log2sql
  4. 17
      root/usr/share/qpsmtpd/plugins/logging/log2sql
  5. 8
      smtp_log.sql

@ -11,5 +11,6 @@ DB=$(/sbin/e-smith/db configuration getprop qpsmtpd DbName || echo smtp_log)
echo "delete from rcpts where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from message_body where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from message_headers where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY);" | mysql $DB

@ -7,7 +7,7 @@ if (($qpsmtpd{'Log2Sql'} || 'enabled') eq 'enabled'){
$OUT .=<<"EOF";
# Log to MySQL
logging/log2sql d $dbname h $dbhost u $dbuser p $dbpass D Yes
logging/log2sql d $dbname h $dbhost u $dbuser p $dbpass D Yes H Yes
EOF
}
else{

@ -7,7 +7,7 @@ if (($qpsmtpd{'Log2Sql'} || 'enabled') eq 'enabled'){
$OUT .=<<"EOF";
# Log to MySQL
logging/log2sql d $dbname h $dbhost u $dbuser p $dbpass D Yes
logging/log2sql d $dbname h $dbhost u $dbuser p $dbpass D Yes H Yes
EOF
}
else{

@ -16,7 +16,7 @@ use strict;
#plugin level variables are here since version 0.02
my ($dsn,$mail_table,$rcpt_table,$user,$passwd,$mail_id);
my ($log_header);
my ($log_all_body,$log_deny_body,$body_table);
my ($log_all_body,$log_deny_body,$body_table,$headers_table);
my ($dbh,$sth);
sub register {
@ -52,6 +52,7 @@ sub register {
$log_all_body = $args{B} || undef;
$log_deny_body = $args{DB} || undef;
$body_table = $args{b} || 'message_body';
$headers_table = $args{I} || 'message_headers';
}
sub connect_handler {
@ -170,9 +171,9 @@ sub data_post_handler{
#if $args{H} then log the message header in the main 'messages' table
if ($log_header){
$statement = "UPDATE ".$mail_table." SET ".
"header=".$dbh->quote($header->as_string()).
"WHERE mail_id=".$mail_id;
$statement = "INSERT INTO ".$headers_table." (mail_id,header)".
" VALUES(".$mail_id.",".$dbh->quote($header->as_string()).
")";
$self->log(LOGDEBUG,"data_post_handler log header statement:".$statement);
$dbh->do($statement)
@ -287,6 +288,7 @@ The plugin accepts the following parameters:
u - database user (default root)
p - database password (default '')
H - log the header of the message in the main table for mail messages (e.g. 'messages'). For example "H Yes".
I - sql table for the message headers. H parameter is requiered
=head1 CONFIGURATION OF THE ADDITIONAL FEATURES
@ -316,7 +318,6 @@ Here are the CREATE statements for the tables. Assuming the 'messages' table is
`header_size` int(11) default NULL,
`body_size` int(11) default NULL,
`spam_status` float default NULL,
`header` text,
`deny` set('YES','NO') default NULL,
`deny_plugin` varchar(100) default '',
`deny_code` int(11) default '0',
@ -338,6 +339,12 @@ Here are the CREATE statements for the tables. Assuming the 'messages' table is
PRIMARY KEY (`bdy_id`)
) TYPE=MyISAM;
CREATE TABLE `message_headers` (
`header_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`header` text,
PRIMARY KEY (`header_id`)
) TYPE=MyISAM;
=head1 AUTHOR

@ -11,7 +11,6 @@ CREATE TABLE `messages` (
`header_size` int(11) default NULL,
`body_size` int(11) default NULL,
`spam_status` float default NULL,
`header` text,
`deny` set('YES','NO') default NULL,
`deny_plugin` varchar(100) default '',
`deny_code` int(11) default '0',
@ -32,3 +31,10 @@ CREATE TABLE `message_body` (
`body` text,
PRIMARY KEY (`bdy_id`)
) TYPE=MyISAM;
CREATE TABLE `message_headers` (
`header_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`header` text,
PRIMARY KEY (`header_id`)
) TYPE=MyISAM;

Loading…
Cancel
Save