added more mail scripts
This commit is contained in:
parent
c95fd6c427
commit
e81fd3702d
7 changed files with 833 additions and 0 deletions
132
mail/search maillogs/findrecpt.pl
Executable file
132
mail/search maillogs/findrecpt.pl
Executable file
|
@ -0,0 +1,132 @@
|
|||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Name: checkrecpt.pl
|
||||
# Purpose: Checks a specified postfix maillog for a specified sender
|
||||
# email address and returns a list of recipients email addresses
|
||||
# to which email was sent.
|
||||
# Author: David Miller -- <dmiller@newportnet.com>
|
||||
# Version: 0.04
|
||||
# Created: 23 Jul 2002
|
||||
# Modified: 24 Jul 2002 -- Optimization of message id array to eliminate
|
||||
# processing of duplicates. Accepts commandline parameters.
|
||||
# Modified: 24 Jul 2002 -- Cleanup and optimization of message search loop.
|
||||
# Modified: 25 Jul 2002 -- Added code to handle 'expired' reporting.
|
||||
#
|
||||
#
|
||||
use strict;
|
||||
|
||||
#--------------
|
||||
# variables
|
||||
#--------------
|
||||
my $maillog;
|
||||
my $sender;
|
||||
my @msgids;
|
||||
|
||||
#---------------------------
|
||||
# Main Thread of Execution
|
||||
#---------------------------
|
||||
# process command line arguments
|
||||
usage() unless ($#ARGV > 0 && $#ARGV < 2);
|
||||
$sender = $ARGV[0];
|
||||
$maillog = $ARGV[1];
|
||||
|
||||
# check sender name for basically valid form
|
||||
if (! ($sender =~ /.*@.*/)) {
|
||||
print "Sender address $sender does not appear valid\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# test for existance of maillog
|
||||
if(! -r $maillog) {
|
||||
print "Can not find mail log $maillog\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# get all message ids associated with the sender in temporary array
|
||||
my @temp;
|
||||
open(LOG, "<$maillog") || die "Open of $maillog failed\n";
|
||||
while(<LOG>) {
|
||||
if(/from=<$sender>/) {
|
||||
my @fields = split " ";
|
||||
$fields[5] =~ s/://;
|
||||
$temp[$#temp + 1] = $fields[5];
|
||||
}
|
||||
}
|
||||
close(LOG);
|
||||
|
||||
# optimize list by sorting and removing duplicates
|
||||
@temp = sort @temp;
|
||||
foreach my $msg (@temp) {
|
||||
if($#msgids < 0) {
|
||||
$msgids[0] = $msg;
|
||||
} elsif ($msgids[$#msgids] ne $msg) {
|
||||
$msgids[$#msgids + 1] = $msg;
|
||||
}
|
||||
}
|
||||
|
||||
# display count of messages and display header if there are messages
|
||||
# if no messages we are done
|
||||
print "Found " . ($#msgids + 1) . " messages from $sender in $maillog\n";
|
||||
printMessageHeader() if ($#msgids >= 0) || exit 0;
|
||||
|
||||
# Lookup recipients for each message id
|
||||
open(LOG, "<$maillog") || die "Open of $maillog failed\n";
|
||||
foreach my $msg (@msgids) {
|
||||
while(<LOG>) {
|
||||
chomp();
|
||||
if(/$msg/ && /smtp/ && /to=</) {
|
||||
my $status;
|
||||
my @fields = split " ", $_, 11;
|
||||
# recipient address
|
||||
$fields[6] =~ s/^to=<//;
|
||||
$fields[6] =~ s/>,$//;
|
||||
# status
|
||||
if($fields[9] =~ /^status=/) {
|
||||
$status = $fields[9];
|
||||
}
|
||||
$status =~ s/^status=//;
|
||||
# display the message info
|
||||
print "$msg $status \t$fields[6]";
|
||||
if(($status eq "bounced") || ($status eq "deferred")) {
|
||||
print " $fields[10]";
|
||||
}
|
||||
print "\n";
|
||||
# loop optimization
|
||||
last if ($status eq "bounced");
|
||||
} elsif (/$msg/ && /status=expired/) { # handle exired messages
|
||||
my $status;
|
||||
my @fields = split " ", $_, 9;
|
||||
# sender address for return
|
||||
$fields[6] =~ s/^from=<//;
|
||||
$fields[6] =~ s/>,$//;
|
||||
# status field
|
||||
if($fields[7] =~ /^status=/) {
|
||||
$status = $fields[7];
|
||||
}
|
||||
$status =~ s/^status=//;
|
||||
$status =~ s/,$//;
|
||||
# display the message info
|
||||
print "$msg $status \t<$fields[8]>\t\t$fields[6]\n";
|
||||
last;
|
||||
}
|
||||
}
|
||||
seek LOG, 0, 0;
|
||||
}
|
||||
close(LOG);
|
||||
exit 0;
|
||||
|
||||
#----------------
|
||||
# Sub Routines
|
||||
#----------------
|
||||
sub usage
|
||||
{
|
||||
print "usage: $0 sender maillog\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
sub printMessageHeader
|
||||
{
|
||||
print "Checking for message recipients\n\n";
|
||||
print "Message ID Status \tRecipient\n";
|
||||
print "----------------------------------------------------------------\n";
|
||||
}
|
157
mail/search maillogs/findsender.pl
Executable file
157
mail/search maillogs/findsender.pl
Executable file
|
@ -0,0 +1,157 @@
|
|||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Name: findsender.pl
|
||||
# Purpose: Checks a specified postfix maillog for a specified recipient
|
||||
# email address and returns a list of sender's email addresses
|
||||
# to which email was sent.
|
||||
# Author: David Miller -- <>
|
||||
# Version: 0.01
|
||||
# Created: 25 Jul 2002
|
||||
# Modified: for additional syslog formats,
|
||||
#
|
||||
use strict;
|
||||
|
||||
#--------------
|
||||
# variables
|
||||
#--------------
|
||||
my $debug = 0;
|
||||
my $maillog;
|
||||
my $recipient;
|
||||
my @msgids;
|
||||
my $msg;
|
||||
my @fields;
|
||||
|
||||
my $qid; # field numbers within $maillog
|
||||
my $nrcpts;
|
||||
my $sender;
|
||||
my $size;
|
||||
|
||||
#---------------------------
|
||||
# Main Thread of Execution
|
||||
#---------------------------
|
||||
# process command line arguments
|
||||
usage() unless (@ARGV == 2);
|
||||
$recipient = $ARGV[0];
|
||||
$maillog = $ARGV[1];
|
||||
|
||||
# check sender name for basically valid form
|
||||
if (! ($recipient =~ /.+@.+/)) {
|
||||
print "Recipient address $recipient does not appear valid\n";
|
||||
exit 1;
|
||||
}
|
||||
# test for existence of maillog
|
||||
if(! -r $maillog) {
|
||||
print "Can not find mail log $maillog\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# get all message ids associated with the recipient in temporary array
|
||||
my @temp;
|
||||
open(LOG, "<$maillog") || die "Initial open of $maillog failed\n";
|
||||
while(<LOG>) {
|
||||
# on the fly, determine log line format (where various fields are)
|
||||
unless (defined $nrcpts) {
|
||||
if(/from=</ && !/postfix\/pickup/ && !/: warning: .*;/) {
|
||||
my @fields = split;
|
||||
find_fromline_fields(@fields);
|
||||
}
|
||||
}
|
||||
if(/to=/) { # feature: matches Postfix orig_to= also
|
||||
if(/to=<?$recipient[\W_]/) { # same feature
|
||||
my @fields = split;
|
||||
$fields[$qid] =~ s/://;
|
||||
push @temp, $fields[$qid];
|
||||
}
|
||||
}
|
||||
}
|
||||
close(LOG);
|
||||
|
||||
# optimize list by sorting and removing duplicates
|
||||
@temp = sort @temp;
|
||||
foreach my $msg (@temp) {
|
||||
if ((@msgids == 0) || ($msgids[$#msgids] ne $msg)) { # not yet recorded
|
||||
push @msgids, $msg;
|
||||
}
|
||||
}
|
||||
|
||||
# display count of messages, and display header if there are messages
|
||||
# if no messages we are done
|
||||
print "Found ", scalar @msgids, " messages for $recipient in $maillog\n";
|
||||
(@msgids) ? printMessageHeader() : exit 0;
|
||||
|
||||
# look up sender, size, etc. for each message id
|
||||
open(LOG, "<$maillog") || die "2nd open of $maillog failed\n";
|
||||
foreach $msg (@msgids) {
|
||||
while(<LOG>) {
|
||||
chomp();
|
||||
if(/$msg/ && /from=</ && !/postfix\/pickup/ && !/: warning: .*;/) {
|
||||
@fields = split " ", $_, 14;
|
||||
# munge data fields for output
|
||||
if ($fields[$sender] =~ /^from=<>,$/) {
|
||||
$fields[$sender] = "<>";
|
||||
} else {
|
||||
$fields[$sender] =~ s/^from=<(.+)>,$/$1/; # keep just the addr
|
||||
}
|
||||
$fields[$size] =~ s/^size=(\d+),$/$1/; # keep just the number
|
||||
$fields[$nrcpts] =~ s/^nrcpts?=(\d+),?$/$1/; # keep just the number
|
||||
# display the message info
|
||||
write;
|
||||
last;
|
||||
}
|
||||
}
|
||||
unless ($msg eq $msgids[-1]) { # in which case we're done
|
||||
seek LOG, 0, 0 && die "Seek/rewind failed: $!";
|
||||
}
|
||||
}
|
||||
close(LOG);
|
||||
exit 0;
|
||||
|
||||
format =
|
||||
@<<<<<<<<<<<<<< @>>>>>> @> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
$msg, $fields[$size], $fields[$nrcpts], $fields[$sender]
|
||||
.
|
||||
|
||||
#----------------
|
||||
# Sub Routines
|
||||
#----------------
|
||||
sub usage
|
||||
{
|
||||
print "usage: $0 recipient maillog\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
sub printMessageHeader
|
||||
{
|
||||
print "Checking for message senders\n\n";
|
||||
print "Message ID Size Rcpts Sender\n";
|
||||
print "-"x70, "\n";
|
||||
}
|
||||
|
||||
sub find_fromline_fields
|
||||
{
|
||||
my @fields = @_;
|
||||
|
||||
for my $i (0 .. $#fields) {
|
||||
unless (defined $qid) {
|
||||
if ($fields[$i] =~ /^[A-Za-z\d]+:$/) { # alphanum+colon
|
||||
$qid = $i;
|
||||
print if ($debug > 1);
|
||||
print "DEBUG: \$qid\t= $qid\n" if ($debug);
|
||||
}
|
||||
}
|
||||
if ($fields[$i] =~ /from=/) {
|
||||
$sender = $i;
|
||||
print if ($debug > 1);
|
||||
print "DEBUG: \$sender\t= $sender\n" if ($debug);
|
||||
} elsif ($fields[$i] =~ /size=/) {
|
||||
$size = $i;
|
||||
print if ($debug > 1);
|
||||
print "DEBUG: \$size\t= $size\n" if ($debug);
|
||||
} elsif ($fields[$i] =~ /nrcpts?=/) {
|
||||
$nrcpts = $i;
|
||||
print if ($debug > 1);
|
||||
print "DEBUG: \$nrcpts\t= $nrcpts\n" if ($debug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
mail/search maillogs/prepflog-0.4.tgz
Executable file
BIN
mail/search maillogs/prepflog-0.4.tgz
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue