Mailscanner and Exim - Spool File Return Code problems.

Julian Field MailScanner at
Thu May 8 20:12:56 IST 2008

Chris Russell wrote:
> Hi All,
>  Probably one for Julian, as right now its a "from the top of your 
> head" question.
>  When using Exim, and have store and queue files=yes. Does Mailscanner 
> copy the original spool file, or read it in, then recreate the 
> outbound queue file ?
>  I have an odd issue. This only seems to affect HTML email, mostly 
> from mailing lists/groups and with long from addresses (ie: 
> xdkdddddddddd_ddsfsdfsdfsdfsfdsdfsdf at 
> <mailto:xdkdddddddddd_ddsfsdfsdfsdfsfdsdfsdf at>) 
> etc.
>  Basically, these will be passed by MailScanner, however will not be 
> sent.  The reason for this is exim doesn't sanity check for \r\n at 
> the end of the -D spool file when sending, it basically throws this 
> out via remote smtp. If there is no \r\n at the end of the file, the 
> period on a line by itself never happens.
>  When I look at the spool file (-D),  the end line is the end of the 
> HTML and no \r\n is present.
>  Just wondering if this is a potential bug ? Mailscanner version is a 
> little behind 4.66.5 however I can't see anything for exim in the 
> recent change logs. Other HTML email goes through fine, the only 
> commonality I can find is long sender addresses, but no idea why this 
> would affect the creation of the spool file.
>  Julian, any potential thoughts ?

Please gunzip the attached file,
rename it to
and put it in /usr/lib/MailScanner/MailScanner over the top of your 
existing one (best make a backup of your existing one first in case it 
goes bang in your face!)

So please try the attached replacement. It should check that when it's 
writing to the output file, the last byte it wrote was a cr or lf, and 
writes a newline character if it wasn't.

I can see this occurring if, for example, you add a signature on the end 
of a plain-text message (with "Sign Clean Messages = yes"). Edit the 
inline text signature file with Notepad in Windows, and you can get a 
text file that doesn't end with a newline character (I believe). Then 
MailScanner will write the signature on the end of the plain-text 
message, resulting in a message that now does not end with a newline 

Exim doesn't appear to check that the SMTP message body it sends ends in 
a newline (which it doesn't need to normally as any message read from 
another SMTP server must end in a newline). So rather than try to find 
every possible point at which I read any data that is added onto the end 
of the message (and I'm bound to miss one by Sod's law), I am now 
checking what I have just written to ensure it ends in a newline 
character. I don't want to just arbitrarily add a newline to the end of 
every message, as that will just make the output files bigger by 1 byte 
which is a really trashy thing to do to your carefully crafted messages.

Please let me know if
a) it works at all (i.e. causes no damage, doesn't crash, etc)
b) it solves the problem.



Julian Field MEng CITP CEng
Buy the MailScanner book at

MailScanner customisation, or any advanced system administration help?
Contact me at Jules at Jules.FM

PGP footprint: EE81 D763 3DB0 0BFD E1DC 7222 11F6 5947 1415 B654
PGP public key:

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: EximDiskStore_pm.gz
Type: application/x-gzip
Size: 5960 bytes
Desc: not available
Url :

More information about the MailScanner mailing list