Subject: problem with fetching/decoding

From: Chip Holloway <[email-masked]>
Date: Wed, 07 May 1997 13:18:55 -0400

<HTML><BODY>
I am having a problem with the following code:
<BR>
<BR>Envelope = mail_fetchheader_full (DefImapHandle, DefMsgHandle,NIL,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&amp;HeaderLength, 0);
<BR>xBody = mail_fetchtext_full (DefImapHandle, DefMsgHandle, NIL,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&amp;BodyLength, 0);
<BR>decodedBody = (char *) rfc822_base64 (xBody, BodyLength, &amp;decodedBodyLength);
<BR>
<BR>The output generated is:
<BR>
<BR>A00005 FETCH 4 BODY.PEEK[HEADER]
<BR>* 4 FETCH (BODY[HEADER] {522}
<BR>)
<BR>A00005 OK FETCH completed
<BR>A00006 FETCH 4 BODY[TEXT]
<BR>* 4 FETCH (BODY[TEXT] {1267}
<BR>&nbsp;FLAGS (\Seen))
<BR>A00006 OK FETCH completed
<BR>?Out of free storage
<BR>
<BR>... ouch!
<BR>
<BR>The relavent portion of a trace of the core dump is:
<BR>
<BR>[9] _kill(0x1d28, 0x6)&nbsp; [0xbffb7303]
<BR>[8] abort(presumed: 0x80477c0, 0x809ae38, 0x81096dc)&nbsp;&nbsp;&nbsp;
[0xbffe5cf3]
<BR>[7] fatal(string="Out of free storage") [os_sv4.c@45]
<BR>[6] fs_get(size=101533387)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [os_sv4.c@44]
<BR>[5] rfc822_base64(Warning: Formatted print string too long, truncated
<BR>src="--===========================_ _= 4699096(18018)\r\nContent-Type:
text/plai
<BR>n\r\n\r\nThis Message was relay", srcl=135377844, len=0x80477fc)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
[rfc822.
<BR>c@1589]
<BR>
<BR>All my declarations seem to be correct and the code is taken from the LstMsgs
function in lstmsg.c .
<BR>What am I doing wrong?

</BODY>
</HTML>

---

From: Mike Byrns <[email-masked]>
Date: 07 May 97 20:50:54 -0500

Hi, Chip.  You sent your message body in HTML so I'll assume your client can
understand it.  My comments are in red.  The list doesn't like HTML posts too much
so I am cc:'ing them plain.  What client did you use to send it?  There was no
<HEAD>...</HEAD>.  Part in it and I can't tell if it was that, that it was not
in a proper MIME part, or that your content-type was text/plain when it should
have been text/html.  I just want to rule out any bugs in my client.

You have not included your variable declarations so I can't see if that's a
problem - make sure BodyLength matches the mail_fetchtext_full prototype exactly!
If it's too small or signed when it should be unsigned you are going to have
problems since you are passing only its address.
<snip>
xBody = mail_fetchtext_full (DefImapHandle, DefMsgHandle, NIL, &BodyLength, 0);
Set a breakpoint here and examine the value of BodyLegth.  If it's much larger
than expected there's your problem. 
decodedBody = (char *) rfc822_base64 (xBody, BodyLength, &decodedBodyLength);
How large is your decodedBody buffer?  Make it as large as your BodyLength to
be safe.   
<snip>
A00006 OK FETCH completed
The error is occurring in the decode... Was the message body properly formed?
Did c-client sent it?
?Out of free storage 
[6] fs_get(size=101533387)      [os_sv4.c@44] 
[5] rfc822_base64(Warning: Formatted print string too long, truncated 
src="--===========================_ _= 4699096(18018)\r\nContent-Type:
text/plai 
n\r\n\r\nThis Message was relay", srcl=135377844, len=0x80477fc)       
[rfc822. 
c@1589] 
The enclosed file wasn't really len=0x80477fc (128 meg) I hope :-).

This really looks like a signed/unsigned problem due to the conspicuous size. 
But why would mail_fetchtext_full be handing back a negative value?  I'll have
to look at rfc822_base64 a little closer to tell you anymore.

------------------------------------------------------------
Mike Byrns - MSB Consulting Services - [email-masked]
"The Most Significant Bit of your computing solutions."