cURL / Mailing Lists / curl-library / Single Mail


SMTP, data corruption and dot stuffing

From: <>
Date: Wed, 19 Oct 2011 01:54:16 +0200


I'm using libcurl for sending mail via SMTP. And until now I have
encountered very little problems. But during testing I've discovered
a strange and very difficult to reproduce bug. Some attachments get
corrupted when sent via libcurl and yet it's very hard to find a
repeatable pattern.
Sometimes the same test mail with 3 pdfs sent 10 times will be
received in Thunderbird uncorrupted 10 times and for no apparent
reason the 11th, one the 3 pdf will get corrupted.

To encode attachments I use base64 (Content-Transfer-Encoding:
base64 and Content-Disposition: attachment
) and <CR><LF> for line ending.

Inspecting the sent data via the debug mode (CURLOPT_DEBUGFUNCTION)
I've been able to find where the problem is occurring.

When libcurl is sending data, if at the end of CURL_MAX_WRITE_SIZE
(16834 bytes) the message (in this context base64 encoded lines) is
near a line ending libcurl will add a dot :

3fbf: JbGF8Cu30jhZIFvAhYSTsznYy5a7eKp8YV1BkeLVtUgsx42AyHEzYXZDTA7GsmVe
=> Send data, 0000016384 bytes (0x00004000)
0000: .vZXBVWg4zQkIGKLEYRLyCYUBt81HGYApWcaFggbFiSurioNMrQzkmYlM5hlxY7Y
0040: E
0043: YGGnK4vCbqBvyQQf1dRioIHMXgwsoWCNVUsAgxtYqQePhRC6kTJULWHLRczsBhqb

Another one.

3fbf: O5NC5D2zxtOkEAGCpM5ZqQK9bmGDIQkxTLEYDEms3dSiEC0/zIZCEkvmyoZCEu62
3fff: .
=> Send data, 0000016384 bytes (0x00004000)
0000: .d6WTQoQrUv/UoJCk7W42FIKWEiWpGgqRnDLaioEhWAOvkgyGCGr4xAZDrNIxxMw
0040: a

This explains why the bug is so evanescent. Replacing the dot
corruption with the original content in the received email will fix
the attachment (pdfs).

I guess the dot is added in the vicinity of a line ending. But I
can't be more precise, the problem could be in this function
Curl_smtp_escape_eob (smtp.c)

I'd appreciate any take on this especially if you think this is not
a libcurl bug.


List admin:
Received on 2011-10-19