Mega Search
23.2 Million


Sign Up

Make a donation  
Indy Imap4 attachment problem  
News Group: embarcadero.public.cppbuilder.internet.socket

Hello,

my application must extract certain attachments from emails. This works 
fine with Indy's TIdIMAP4 component.

Since a couple of days I receive emails with an attachment that is not 
in the MessageParts-list of the TIdMessage which is initialized this way:

String fn("mail.dat");
Imap4->RetrieveNoDecodeToFile(msg_nr, fn);
Msg->LoadFromFile(fn, false);

The missing attachment looks like this:

------_=_NextPart_001_01D01459.1C17EB7E
Content-Type: text/plain;
	name="BC34662006E.txt"
Content-Transfer-Encoding: base64
Content-ID: <17491B8934BAB6A96280E59CCE8@exchange.test-services.org>
Content-Description: BC34662006E.txt
Content-Location: BC34662006E.txt

VU5BOissPyAnVU5CK1VOT0M6Mys5ODcwMDE2MDAwMDAwOjUwMis5ODAwMDAx
ODAwMDA4OjUwMisxNDEyMTA6MTAwNitCQzM0NjYyMDA2RSsrVEwnVU5IKzEr
TVNDT05TOkQ6MDRCOlVOOjIuMmMnQkdNKzcrQkMzNDY2MjAwNkUtMSs5J0RU
TSsxMzc6MjAxNDEyMTAxMDA2OjIwMydSRkYrWjEzOjEzMDAxJ05BRCtNUys5
ODcwMDE2MDAwMDAwOjozMzInTkFEK01SKzk4MDAwMDE4MDAwMDg6OjMzMidV
....
LjIyOlNSVydRVFkrMjIwOjEsMDA1NydEVE0rMTYzOjIwMTQxMjAxMDYwMD8r
MDE6MzAzJ0RUTSsxNjQ6MjAxNTAxMDEwNjAwPyswMTozMDMnVU5UKzk2KzIn
VU5aKzIrQkMzNDY2MjAwNkUn

------_=_NextPart_001_01D01459.1C17EB7E--

I have compared this with attachments without problems and found out 
that those have a declaration like this:

Content-Disposition: attachment;
	filename="BC34662006E.txt"


Is there a chance to get the missing attachment using Indy?
Outlook and Thunderbird have no problems to show the attachment.


Markus

-- 
Bjarne Stroustrup about lambda expressions in C++:
Some consider this "really neat!"; others see it as a way to write 
dangerously obscure code. IMO, both are right.

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 12-Dec-2014, at 4:52 AM EST
From: Markus Donath
 
Re: Indy Imap4 attachment problem  
News Group: embarcadero.public.cppbuilder.internet.socket
On 12.12.2014 20:52, Remy Lebeau (TeamB) wrote:
> Markus wrote:
>
>> I have compared this with attachments without problems and found
>> out that those have a declaration like this:
>>
>> Content-Disposition: attachment; filename="BC34662006E.txt"
>
> That header tells TIdMessage to store the MIME part as a TIdAttachment object.
>   If that header is not present, TIdMessage looks at the "Content-Type" header
> and will store the data in a TIdText object if it is a "text/..." or "multipart/..."
> media type, otherwise it is stored as a TIdAttachment object.  This means
> that MIME text parts are treated as attachments only if they are explicitly
> marked as "attachment" in the "Content-Disposition" header.
>
>> Is there a chance to get the missing attachment using Indy?
>
> You would have to look for the resulting TIdText object in the MessageParts
> collection.  It will have a FileName assigned to it.
>
>> Outlook and Thunderbird have no problems to show the attachment.
>
> I can't speak for Thunderbird, but Outlook/Exchange treats a MIME part as
> an attachment if it has a filename, even if it has a "Content-Disposition:
> inline" header.  This is documented on MSDN:
>
> XIMS: Exchange Displays Message That Uses "Inline" MIME Content-Disposition
> Header as Attachment
> http://support.microsoft.com/kb/323482
>
> Indy used to do that as well, until we discovered cases of inlined text that
> had filenames, and attachments that did not have filenames.  Per RFCs 1806
> and 2183, any MIME part can have a "filename" attribute in the "Content-Disposition"
> header.  The presence of a "filename" attribute does not by itself force
> the MIME part to be an attachment.  The explicit "attachment" value of the
> header does that.  The "filename" is merely a suggested value *if* the MIME
> part is saved to a file.  So Indy was updated to account for that, by using
> TIdText for any text part that does not have an explicit "attachment" disposition,
> and using TIdAttachment for everything else.
>
> --
> Remy Lebeau (TeamB)
>

Thanks a lot.

Markus Donath

-- 
Bjarne Stroustrup about lambda expressions in C++:
Some consider this "really neat!"; others see it as a way to write 
dangerously obscure code. IMO, both are right.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 15-Dec-2014, at 1:29 AM EST
From: Markus Donath
 
Re: Indy Imap4 attachment problem  
News Group: embarcadero.public.cppbuilder.internet.socket
Markus wrote:

> I have compared this with attachments without problems and found
> out that those have a declaration like this:
> 
> Content-Disposition: attachment; filename="BC34662006E.txt"

That header tells TIdMessage to store the MIME part as a TIdAttachment object. 
 If that header is not present, TIdMessage looks at the "Content-Type" header 
and will store the data in a TIdText object if it is a "text/..." or "multipart/..." 
media type, otherwise it is stored as a TIdAttachment object.  This means 
that MIME text parts are treated as attachments only if they are explicitly 
marked as "attachment" in the "Content-Disposition" header.

> Is there a chance to get the missing attachment using Indy?

You would have to look for the resulting TIdText object in the MessageParts 
collection.  It will have a FileName assigned to it.

> Outlook and Thunderbird have no problems to show the attachment.

I can't speak for Thunderbird, but Outlook/Exchange treats a MIME part as 
an attachment if it has a filename, even if it has a "Content-Disposition: 
inline" header.  This is documented on MSDN:

XIMS: Exchange Displays Message That Uses "Inline" MIME Content-Disposition 
Header as Attachment 
http://support.microsoft.com/kb/323482

Indy used to do that as well, until we discovered cases of inlined text that 
had filenames, and attachments that did not have filenames.  Per RFCs 1806 
and 2183, any MIME part can have a "filename" attribute in the "Content-Disposition" 
header.  The presence of a "filename" attribute does not by itself force 
the MIME part to be an attachment.  The explicit "attachment" value of the 
header does that.  The "filename" is merely a suggested value *if* the MIME 
part is saved to a file.  So Indy was updated to account for that, by using 
TIdText for any text part that does not have an explicit "attachment" disposition, 
and using TIdAttachment for everything else.

--
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 12-Dec-2014, at 11:52 AM EST
From: Remy Lebeau (TeamB)