Skip to content
Permalink
Browse files

Add files via upload

  • Loading branch information...
fenugeek committed Aug 8, 2019
1 parent 841f690 commit a2fe4956cee9e8f36e7c5a30cb78b1b1aa29418b
Showing with 42 additions and 20 deletions.
  1. +4 −0 dmarcts-report-parser.conf.sample
  2. +38 −20 dmarcts-report-parser.pl
@@ -30,6 +30,10 @@ $imapreadfolder = 'Inbox';
# the --delete option!)
$imapmovefolder = 'Inbox.processed';

# If $imapmovefoldererr is set, IMAP messages that fail will be moved. If unset, failed messages
# will move to $imapmovefolder (if it is set). Overruled by the --delete option!
$imapmovefoldererr = 'Inbox.notProcessed';

# maximum size of XML files to store in database, long files can cause transaction aborts
$maxsize_xml = 50000;
# store XML as base64 encopded gzip in database (save space, harder usable)
@@ -117,7 +117,8 @@ sub show_usage {
# Define all possible configuration options.
our ($debug, $delete_reports, $delete_failed, $reports_replace, $maxsize_xml, $compress_xml,
$dbname, $dbuser, $dbpass, $dbhost, $dbport,
$imapserver, $imapuser, $imappass, $imapignoreerror, $imapssl, $imaptls, $imapmovefolder, $imapreadfolder, $imapopt, $tlsverify);
$imapserver, $imapuser, $imappass, $imapignoreerror, $imapssl, $imaptls, $imapmovefolder,
$imapmovefoldererr, $imapreadfolder, $imapopt, $tlsverify);

# defaults
$maxsize_xml = 50000;
@@ -281,26 +282,16 @@ sub show_usage {
$imap->delete_message($msg)
or print "Could not delete IMAP message. [$@]\n";
} elsif ($imapmovefolder) {
print "Moving (copy and delete) processed IMAP message file to IMAP folder: $imapmovefolder\n" if $debug;

# Try to create $imapmovefolder, if it does not exist.
if (!$imap->exists($imapmovefolder)) {
$imap->create($imapmovefolder)
or print "Could not create IMAP folder: $imapmovefolder.\n";
}

# Try to move the message to $imapmovefolder.
my $newid = $imap->copy($imapmovefolder, [ $msg ]);
if (!$newid) {
print "Error on moving (copy and delete) processed IMAP message: Could not COPY message to IMAP folder: <$imapmovefolder>!\n";
print "Messsage will not be moved/deleted. [$@]\n";
} else {
$imap->delete_message($msg)
or do {
print "Error on moving (copy and delete) processed IMAP message: Could not DELETE message\n";
print "after copying it to <$imapmovefolder>. [$@]\n";
}
if ($processResult & 1 || !$imapmovefoldererr) {
# processXML processed the XML OK, or it failed and there is no error imap folder
moveToImapFolder($imap, $msg, $imapmovefolder);
} elsif ($imapmovefoldererr) {
# processXML failed and error folder set
moveToImapFolder($imap, $msg, $imapmovefoldererr);
}
} elsif ($imapmovefoldererr && !($processResult & 1)) {
# processXML failed, error imap folder set, but imapmovefolder unset. An unlikely setup, but still...
moveToImapFolder($imap, $msg, $imapmovefoldererr);
}
}

@@ -390,6 +381,33 @@ sub show_usage {
### subroutines ################################################################
################################################################################

sub moveToImapFolder {
my $imap = $_[0];
my $msg = $_[1];
my $imapfolder = $_[2];

print "Moving (copy and delete) IMAP message file to IMAP folder: $imapfolder\n" if $debug;

# Try to create $imapfolder, if it does not exist.
if (!$imap->exists($imapfolder)) {
$imap->create($imapfolder)
or print "Could not create IMAP folder: $imapfolder.\n";
}

# Try to move the message to $imapfolder.
my $newid = $imap->copy($imapfolder, [ $msg ]);
if (!$newid) {
print "Error on moving (copy and delete) processed IMAP message: Could not COPY message to IMAP folder: <$imapfolder>!\n";
print "Messsage will not be moved/deleted. [$@]\n";
} else {
$imap->delete_message($msg)
or do {
print "Error on moving (copy and delete) processed IMAP message: Could not DELETE message\n";
print "after copying it to <$imapfolder>. [$@]\n";
}
}
}

sub processXML {
my $type = $_[0];
my $filecontent = $_[1];

0 comments on commit a2fe495

Please sign in to comment.
You can’t perform that action at this time.