Skip to content

Commit

Permalink
Support new Exim Message-ID format (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
shawniverson authored Dec 27, 2023
1 parent 785ef5c commit 8aa5101
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
5 changes: 5 additions & 0 deletions common/etc/MailScanner/MailScanner.conf
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ Sendmail = /usr/lib/sendmail
#Sendmail2 = /usr/sbin/sendmail -C /etc/exim/exim_send.conf
Sendmail2 = /usr/lib/sendmail

# Path to Exim binary, used to check version for proper Message-ID
# handling. Will try to look for exim automatically if not set. Set this to
# the the exim command full path if necessary.
Exim Command =

#
# Incoming Work Dir Settings
# --------------------------
Expand Down
31 changes: 31 additions & 0 deletions common/usr/sbin/MailScanner
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,37 @@ my($MTAmod, $MTADSmod);
$_=MailScanner::Config::QuickPeek($ConfFile, 'mta');
$_='sendmail' if $WantLintOnly || $WantLintLiteOnly || $WantRuleCheck;
if (/exim/i) {
# Check for version >= 4.97
my $eximcommand = MailScanner::Config::QuickPeek($ConfFile, 'eximcommand');
if ($eximcommand eq "") {
# try to find exim
eval {
$eximcommand = `which exim`;
}
if ($@ || $eximcommand eq "") {
print STDERR "Exim binary not found. Please supply the full path to Exim Command in MailScanner.conf";
exit 1;
}
}
# Get exim version
my @out;
my @line;
my $ver;
eval {
@out = `$eximcommand -bV`;
@line = split(/ /, $out[0]);
$ver = $line[2];
$ver =~ /\d+\.\d+/;
}
if ($@) {
print STDERR "Unable to obtain version of Exim. Please check the path to Exim Command in MailScanner.conf";
exit 1;
}
if ($ver >= 4.97) {
MailScanner::Config::SetValue('eximlongids',1);
} else {
MailSCanner::Config::SetValue('eximlongids',0);
}
$MTAmod = 'Exim.pm';
$MTADSmod = 'EximDiskStore.pm';
} elsif(/zmailer/i) {
Expand Down
3 changes: 2 additions & 1 deletion common/usr/share/MailScanner/perl/MailScanner/ConfigDefs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
msmaildeliverymethod = MSMailDeliveryMethod
msmailsockettype = MSMailSocketType
msmailsocketdir = MSMailSocketDir
eximcommand = EximCommand
#
# Simple variables which can only have a single value, no rules allowed.
Expand Down Expand Up @@ -319,7 +320,6 @@
stilldeliverunscannable 0 no 0 yes 1
retrybatchscanner 1 no 0 yes 1
# These should be checked for dir existence
[Simple,Dir]
incomingworkdir /var/spool/MailScanner/incoming
Expand Down Expand Up @@ -457,6 +457,7 @@
KseSocket /var/run/kse/kse.sock
FsecureSocket /tmp/.fsav-0
SAVIDSocket /var/lib/savdid/savdid.sock
EximCommand
#
# These variables match on any rule matching From:, else anything for To:
Expand Down
40 changes: 32 additions & 8 deletions common/usr/share/MailScanner/perl/MailScanner/EximDiskStore.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# MailScanner - SMTP Email Processor
# Copyright (C) 2002 Julian Field
# Copyright (C) 2023 MailScanner Project
#
# $Id: EximDiskStore.pm 4446 2008-05-08 19:15:02Z sysjkf $
#
Expand Down Expand Up @@ -208,9 +208,16 @@ sub DoPendingDeletes {
# whether the spool is split or not.
sub OutQDir {
my $name = shift;
my $offset;

if (MailScanner::Config::Value('eximlongids') =~ /1/) {
$offset = -20;
} else {
$offset = -13;
}

if (MailScanner::Config::Value('spliteximspool')) {
return '/' . substr($name,-13,1) . '/';
return '/' . substr($name,$offset,1) . '/';
} else {
return '/';
}
Expand Down Expand Up @@ -433,9 +440,18 @@ sub WriteEntireMessage {
# We have to strip the message-ID off the beginning of the file
# using sysread since that is what File::Copy uses and it doesn't
# play nicely with stdio operations such as $body->getline. The
# magic number 19 is from the length of NNNNNN-NNNNNN-NN-D\n.
# magic number 19 or 26 is from the length of message-ID in file\n.
my $discard;
sysread($body, $discard, 19);

my $offset;

if (MailScanner::Config::Value('eximlongids') =~ /1/) {
$offset = 26;
} else {
$offset = 19;
}

sysread($body, $discard, $offset);

copy($body, $handle);

Expand Down Expand Up @@ -509,17 +525,25 @@ sub ReadMessageHandle {
# We have to strip the message-ID off the beginning of the file
# using sysread since that is what File::Copy uses and it doesn't
# play nicely with stdio operations such as $body->getline. The
# magic number 19 is from the length of NNNNNN-NNNNNN-NN-D\n.
# magic number 19 or 26 is from the length of message-ID in file\n.
my $from_h = \do { local *FH1 };
open($from_h, "< $dhandle");
binmode $from_h or die "($!,$^E)";

sysseek($from_h, 19, 0);
my $offset;

if (MailScanner::Config::Value('eximlongids') =~ /1/) {
$offset = 26;
} else {
$offset = 19;
}

sysseek($from_h, $offset, 0);

my $size;
my $buf = "";
my $lasteol = ' ';
my $dlength = -s $dhandle; # Catch case where -D file is 0 (ie 19) bytes
my $dlength = -s $dhandle; # Catch case where -D file is 0 (ie 19 or 26) bytes
$size = $dlength;
$size = 1024 if ($size < 512);
$size = 1024*1024*2 if $size > 1024*1024*2;
Expand All @@ -538,7 +562,7 @@ sub ReadMessageHandle {

# Need to ensure the end of the file is and new-line character,
# unless it's a 0 length file.
if ($lasteol !~ /[\n\r]/s && $dlength>19) {
if ($lasteol !~ /[\n\r]/s && $dlength>$offset) {
$lasteol = "\n";
syswrite($to_h, $lasteol);
}
Expand Down

0 comments on commit 8aa5101

Please sign in to comment.