[EXIM] The Body Vanishes (or: a nasty gotcha with use_crlf a…

Top Pagina
Delete this message
Reply to this message
Auteur: Malcolm Beattie
Datum:  
Aan: exim-users
Onderwerp: [EXIM] The Body Vanishes (or: a nasty gotcha with use_crlf and prefix)
Here's a nasty gotcha I ran into this week, along with its solution
in case any of you come across the same problem. I'm setting up an
IMAP cluster using Exim 2.02 with users' mailboxes in mbx format,
using the UW imapd and tmail to deliver into those inboxes. The
local delivery transport section I originally had was:

    local_delivery_mbx:
    driver = pipe
    command = "/usr/local/bin/tmail ${local_part}"
    log_fail_output = true
    log_defer_output = true
    user = exim
    current_directory = /


tmail finds the user's home INBOX and delivers to it in mbx format.
Now that worked but tmail moaned in the logs because it prefers \r\n
terminated lines. I'd been using an old printed copy of the Exim
manual and finally printed out a newer version (a truly excellent
manual, by the way). In it, I noticed the "use_crlf" transport option
to terminate lines with \r\n and, to please tmail, added the option
to the local_delivery_mbx transport. After that (although I only
realised that was the cause in hindsight), any messages delivered
accessed via the IMAP server with pine or my own Web/IMAP client
displayed no body. The headers were fine: the body simply vanished.
Debugging showed it wasn't a client problem: the actual raw IMAP
protocol command to fetch the body of a message just returned a
zero length string. The body had definitely been delivered and,
indeed, the IMAP command to fetch the whole raw message displayed it
fine, body and all. Using the mbxcvt utililty to convert the mbx
mailbox into a standard Berkeley one produced a perfect mailbox,
complete with bodies that appeared without trouble.

Those were the symptoms, now for the solution. After mailing Mark
Crispin (UW cclient/imapd/RFC1730 author) he found extra \r
characters in the problematic messages. Some deductions and RTFMing
later, I figured it out: tmail uses the line terminator on the first
line it sees to determine whether lines are \r\n or \n. If the
latter, it moans to stderr and changed subsequent \n terminators to
\r\n. I finally discovered the "prefix = " option of Exim which has a
default of "From ...\n". Note the hard-coded "\n" terminator,
unaffected by the use_crlf option. So tmail was seeing the "From "
line first, seeing the \n-only terminator and deciding to prepend
\r to the \n terminator on all subsequent lines. But exim's use_crlf
made all other lines \r\n terminated leading to doubled \r\r\n lines
and corrupt mbx mailboxes. Converting to Berkeley format silently
fixed it because all lines are converted to \n-only. The solution,
therefore, is "prefix =" to have no "From " line at all (tmail
doesn't need one). The resulting transport is

    local_delivery_mbx:
    driver = pipe
    command = "/usr/local/bin/tmail ${local_part}"
    log_fail_output = true
    log_defer_output = true
    user = exim
    current_directory = /
        use_crlf
        prefix =


and that works (though in my real exim.conf I've got 9 lines of
comments to remind me of how important it is).

If anyone sees vanishing bodies with exim and mbx/tmail (and it's
not something simple like the original message not having a blank
line separating headers and body), you have been warned. This was
a public service brought to you by someone who now has rather less
hair than he had on Monday.

--Malcolm

--
Malcolm Beattie <mbeattie@???>
Unix Systems Programmer
Oxford University Computing Services

--
*** Exim information can be found at http://www.exim.org/ ***