cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: SMTP returns "read function returned funny values" for large attachments.

From: Steve Holme <steve_holme_at_hotmail.com>
Date: Mon, 22 Apr 2013 11:15:37 +0100

Hi Mark,

On Mon, 22 Apr 2013, mwt Bigpond wrote:

> I'm using libcurl C library, to build a fairly simple SMTP client to
> send emails with any number of attachments. I expect the attachments
> to be a reasonable size (less that 2 Mb) and I hold the MIME record
> sequence in memory during the mailing process. I could change this if
> necessary, and use a temporary file.
>
> I have a read callback function, with CURLOPT_READFUNCTION and
> READDATA options set in the email function.

This mechanism is good and there shouldn't be any need to use a temporary
file. I've been using libcurl to do this for nearly 2 years now to send
emails with file attachments of varying sizes.

> Attaching any number of small files works fine. If I attach a larger
> file (I think 16 Kb might be the limit) the program crashes with a Curl
> message "read function returned funny values", immediately after
> the base64 string containing the attached file has been returned to
> Curl through the read callback.
>
> INFILESIZE has been set to the total length of the MIME records. The
> read callback returns the correct number of characters for each call,
> including the last one that causes the crash.

I don't know of any issues in libcurl and just double checking the code in
transfer.c, to refresh my memory , I would say you are returning a size from
your read function larger than the size * nmemb.

This is typically 1 * BUFSIZE and as such you should only at maximum this
amount of data in each call from libcurl to your callback. Without seeing
your code it feels like you are returning the whole of your MIME buffer at
this point and not chunking it into smaller amounts?

BUFSIZE is defined as CURL_MAX_WRITE_SIZE which in turn is defined as 16384
so that will confirm the 16k theory ;-)

> Is there something simple that I've overlooked? I'd appreciate your
> help.

Are you able to post your callback function for us to take a look at?

Additionally, what version of libcurl on what platform are you working with?

Kind Regards

Steve

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-04-22