summaryrefslogtreecommitdiff
path: root/tests/mail_to_db.pl
diff options
context:
space:
mode:
authorunknown <jani@hynda.mysql.fi>2001-12-27 15:37:45 +0200
committerunknown <jani@hynda.mysql.fi>2001-12-27 15:37:45 +0200
commite0473960774175402fdc5430f7a48a2ad88aa052 (patch)
treeaab971c1ca58f358bec03c814fbf0d20a6de7bf3 /tests/mail_to_db.pl
parentc865e96362b75d1d59ac31c9a2fd34ee1ccdf058 (diff)
downloadmariadb-git-e0473960774175402fdc5430f7a48a2ad88aa052.tar.gz
Made new version of mail_to_db.pl
tests/mail_to_db.pl: Fixed a bug in mail_to_db.pl when it couldn't handle Mac - type inboxes. Made also output more clear.
Diffstat (limited to 'tests/mail_to_db.pl')
-rwxr-xr-xtests/mail_to_db.pl65
1 files changed, 44 insertions, 21 deletions
diff --git a/tests/mail_to_db.pl b/tests/mail_to_db.pl
index aa0d3c51368..6433b4248b8 100755
--- a/tests/mail_to_db.pl
+++ b/tests/mail_to_db.pl
@@ -17,7 +17,7 @@ use DBI;
use Getopt::Long;
$| = 1;
-$VER = "2.4";
+$VER = "2.5";
$opt_help = 0;
$opt_version = 0;
@@ -152,19 +152,41 @@ sub main
$dbh->disconnect if (!$opt_test);
$ignored = ($mail_no_from_f + $mail_no_subject_f + $mail_no_txt_f +
- $mail_too_big + $mail_duplicates);
- print "Mails inserted:\t\t\t$mail_inserted\n";
- print "Mails ignored:\t\t\t$ignored\n";
- print "Mails without \"From:\" -field:\t$mail_no_from_f\n";
- print "Mails without message:\t\t$mail_no_txt_f\n";
- print "Mails without subject:\t\t$mail_no_subject_f\n";
- print "Too big mails (> $opt_max_mail_size):\t$mail_too_big\n";
- print "Duplicate mails:\t\t$mail_duplicates\n";
- print "Forwarded mails:\t\t$mail_forwarded\n";
- print "Total number of mails:\t\t";
+ $mail_too_big + $mail_duplicates + $mail_fixed);
+ print "Mails inserted:\t\t\t\t\t$mail_inserted\n\n";
+ if ($ignored)
+ {
+ print "Ignored mails\n";
+ print "-------------\n";
+ $mail_no_from_f ?
+ print "Reason: mail without \"From:\" -field:\t\t$mail_no_from_f\n" :
+ print "";
+ $mail_no_txt_f ?
+ print "Reason: mail without message:\t\t\t$mail_no_txt_f\n" :
+ print "";
+ $mail_no_subject_f ?
+ print "Reason: mail without subject:\t\t\t$mail_no_subject_f\n" :
+ print "";
+ $mail_too_big ?
+ print "Reason: mail too big (over $opt_max_mail_size bytes):\t$mail_too_big\n" :
+ print "";
+ $mail_duplicates ?
+ print "Reason: duplicate mail, or in db already:\t$mail_duplicates\n" :
+ print "";
+ $mail_fixed ?
+ print "Reason: mail was an unsubscribe - mail:\t\t$mail_fixed\n" :
+ print "";
+ print " ";
+ print "=" . "=" x length("$ignored") . "=\n";
+ print "Total number of ignored mails:\t\t\t$ignored\n\n";
+ }
+ print "Total number of mails:\t\t\t\t";
print $mail_inserted + $ignored;
- print "\n";
- print "Mails with unsubscribe removed:\t$mail_fixed\n";
+ print " (OK: ";
+ print sprintf("%.1f", (($mail_inserted / ($mail_inserted+$ignored)) * 100));
+ print "% Ignored: ";
+ print sprintf("%.1f", (($ignored / ($mail_inserted + $ignored)) * 100));
+ print "%)\n";
exit(0);
}
@@ -269,7 +291,8 @@ sub process_mail_file
$values{$type} .= "\n" . $_;
$check--;
}
- elsif (/^From .* \d\d:\d\d:\d\d\s\d\d\d\d$/)
+ elsif (/^From .* \d\d:\d\d:\d\d\s\d\d\d\d$/ ||
+ /^From .* \d\d\d\d\s\d\d:\d\d:\d\d/)
{
$values{'hash'} = checksum("$values{'message'}");
update_table($dbh, $file_name, \%values);
@@ -338,26 +361,26 @@ sub date_parser
sub update_table
{
my($dbh, $file_name, $values) = @_;
- my($q,$tail,$message);
+ my($q, $tail, $message);
if (!defined($values->{'subject'}) || !defined($values->{'to'}))
{
$mail_no_subject_f++;
return; # Ignore these
}
- $message=$values->{'message'};
- $message =~ s/^\s*//; #removes whitespaces from the beginning
+ $message = $values->{'message'};
+ $message =~ s/^\s*//; # removes whitespaces from the beginning
restart:
- $message =~ s/[\s\n>]*$//; #removes whitespaces and '>' from the end
- $values->{'message'}=$message;
+ $message =~ s/[\s\n>]*$//; # removes whitespaces and '>' from the end
+ $values->{'message'} = $message;
foreach $tail (@remove_tail)
{
$message =~ s/$tail//;
}
if ($message ne $values->{'message'})
{
- $message =~ s/\s*$//; #removes whitespaces from the end
+ $message =~ s/\s*$//; # removes whitespaces from the end
$mail_fixed++;
goto restart; # Some mails may have duplicated messages
}
@@ -445,7 +468,7 @@ sub update_table
sub checksum
{
my ($txt)= @_;
- my ($crc,$i,$count);
+ my ($crc, $i, $count);
$count = length($txt);
for ($crc = $i = 0; $i < $count ; $i++)
{