Board index » delphi » TIdMessage problem

TIdMessage problem


2005-05-29 08:10:59 AM
delphi188
TIdMessage can't read an email file (.eml) with a simple format, for
example:
---------------------------------------------
To: XXXX@XXXXX.COM
From: XXXX@XXXXX.COM
Subject: A simple email
Some lines in mail content.
---------------------------------------------
When TIdMessage read this, the content type is "text/plain", but the body is
empty. How to solve this problem?
Thanks
Patrick
 
 

Re:TIdMessage problem

TIdMessage can't read an email file (.eml) with a simple format, for
example:
---------------------------------------------
To: XXXX@XXXXX.COM
From: XXXX@XXXXX.COM
Subject: A simple email
Some lines in mail content.
---------------------------------------------
When TIdMessage read this, the content type is "text/plain", but the body is
empty. How to solve this problem?
Thanks
Patrick
 

Re:TIdMessage problem

You should post the raw email, but I'd guess that the content is in
TIdMessage.MessageParts[0], which is normal in many cases.
Ciaran
"Patrick" <XXXX@XXXXX.COM>writes
Quote
TIdMessage can't read an email file (.eml) with a simple format, for
example:

---------------------------------------------
To: XXXX@XXXXX.COM
From: XXXX@XXXXX.COM
Subject: A simple email


Some lines in mail content.

---------------------------------------------

When TIdMessage read this, the content type is "text/plain", but the body
is
empty. How to solve this problem?

Thanks

Patrick


 

Re:TIdMessage problem

Thanks Ciaran.
Yes, it is raw email just for test. Save the lines of the email I posted to
a .eml file or other text file, and read it with TIdMessage, you can find
the problem.
Both TIdMessage.MessageParts.TextPartCount and TIdMessage.MessageParts.Count
are 0, so I can't read the content with
TIdText(TIdMessage.MessageParts[0]).Body, it gives me "List index out of
bounds(0)" error.
How to solve it?
Thanks
"Ciaran Costelloe" <XXXX@XXXXX.COM>写入消息
Quote
You should post the raw email, but I'd guess that the content is in
TIdMessage.MessageParts[0], which is normal in many cases.

Ciaran

"Patrick" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>TIdMessage can't read an email file (.eml) with a simple format, for
>example:
>
>---------------------------------------------
>To: XXXX@XXXXX.COM
>From: XXXX@XXXXX.COM
>Subject: A simple email
>
>
>Some lines in mail content.
>
>---------------------------------------------
>
>When TIdMessage read this, the content type is "text/plain", but the
body
>is
>empty. How to solve this problem?
>
>Thanks
>
>Patrick
>
>


 

Re:TIdMessage problem

"Patrick" <XXXX@XXXXX.COM>writes
Quote
TIdMessage can't read an email file (.eml) with a simple format
Yes, it can.
Quote
When TIdMessage read this, the content type is "text/plain"
As it should be.
Quote
but the body is empty.
I highly doubt that. Which version of Indy are you actually using?
Gambit
 

Re:TIdMessage problem

"Patrick" <XXXX@XXXXX.COM>writes
Quote
Both TIdMessage.MessageParts.TextPartCount and
TIdMessage.MessageParts.Count are 0
TextPartCount is supposed to be 0 in this situation, as it is updated only
when MessageParts.CountParts() is called, which does NOT happen when
decoding a message, only when encoding it prior to transmission/saving. As
for MessageParts.Count being 0, that is also as it should be in this
situation since your message is not MIME or UUE encoded to begin with, thus
there is nothing to fill the MessageParts with. There is, however, no way
the TIdMessage.Body can be empty in this situation.
Gambit
 

Re:TIdMessage problem

Thank you very much for your reply!
I am using Indy 10, the latest version. The TIdMessage version is Rev 1.53
(in the IdMessage.pas file).
Can you tell me how can I get the simple email body with TIdMessage.
Thanks
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>Wrote
Quote

"Patrick" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...

>TIdMessage can't read an email file (.eml) with a simple format

Yes, it can.

>When TIdMessage read this, the content type is "text/plain"

As it should be.

>but the body is empty.

I highly doubt that. Which version of Indy are you actually using?


Gambit


 

Re:TIdMessage problem

Thank you very much for your reply!
Yes, I had called MessageParts.CountParts before got the part count. My code
in this part is:
var
MailMsg: TIdMessage;
partcount: Integer;
BodyStrs: TStringList;
begin
...
MailMsg.LoadFromStream(SourceStream); //The SourceStream loaded the
simple email file(.eml) before this line
MailMsg.MessageParts.CountParts;
partcount := MailMsg.MessageParts.TextPartCount; //I got partcount=0 in
this line
...
BodyStrs.AddStrings(MailMsg.Body); //The BodyStrs is empty after this
line, it added nothing in this line.
...
end;
Please tell me what's wrong in these codes. Thanks
"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>wrote
Quote

"Patrick" <XXXX@XXXXX.COM>writes
news:429a70ba$XXXX@XXXXX.COM...

>Both TIdMessage.MessageParts.TextPartCount and
>TIdMessage.MessageParts.Count are 0

TextPartCount is supposed to be 0 in this situation, as it is updated only
when MessageParts.CountParts() is called, which does NOT happen when
decoding a message, only when encoding it prior to transmission/saving.
As
for MessageParts.Count being 0, that is also as it should be in this
situation since your message is not MIME or UUE encoded to begin with,
thus
there is nothing to fill the MessageParts with. There is, however, no way
the TIdMessage.Body can be empty in this situation.


Gambit


 

Re:TIdMessage problem

Hi Remy,
Can you help me? I am using Indy10.
Thanks
"Patrick" <XXXX@XXXXX.COM>写入消息
Quote
Thank you very much for your reply!

I am using Indy 10, the latest version. The TIdMessage version is Rev 1.53
(in the IdMessage.pas file).

Can you tell me how can I get the simple email body with TIdMessage.

Thanks

"Remy Lebeau (TeamB)" <XXXX@XXXXX.COM>Wrote
news:429c1f56$XXXX@XXXXX.COM...
>
>"Patrick" <XXXX@XXXXX.COM>writes
>news:XXXX@XXXXX.COM...
>
>>TIdMessage can't read an email file (.eml) with a simple format
>
>Yes, it can.
>
>>When TIdMessage read this, the content type is "text/plain"
>
>As it should be.
>
>>but the body is empty.
>
>I highly doubt that. Which version of Indy are you actually using?
>
>
>Gambit
>
>


 

Re:TIdMessage problem

Quote
Can you help me? I am using Indy10.
>Can you tell me how can I get the simple email body with TIdMessage.
Check in the docs:
TIdMessage.Body Property
Represents the body of the message.
Description
Body is a TStrings property that contains the textual values that make up the body of the message. Body normally contains values when the ContentType for the message is a member of the "text/*" MIME family.
When ContentType contains a value in the "multipart/*" MIME family, use MessageParts to access one or more TIdText instances that represent the message content.
When IsEncoded is True, Body contains values that are encoded using the encoding scheme identified in ContentTransferEncoding.
When IsEncoded is False, Body contains ASCII text that represents the entire contents of the message.
hth...
 

Re:TIdMessage problem

"Patrick" <XXXX@XXXXX.COM>writes
Quote
I am using Indy 10, the latest version. The TIdMessage version
is Rev 1.53 (in the IdMessage.pas file).

Can you tell me how can I get the simple email body with TIdMessage.
In today's complex email formats, there is very little "simple" things left.
At the very least, most email nowadays is MIME-encoded, which complicates
its processing a bit. Fortunately, Indy handles much of the complexity for
you, but you still need a basic understanding of how MIME works in general
in order to understand why Indy works the way it does.
To expand on what Don already told you, when entries are present in the
MessageParts collection, then you need to loop through the MessageParts
backwards from last item to first, looking for TIdText object instances,
examining the ContentType of each one until you find a type that you can
handle, where 'text/plain' endsup being the last resort. 'text/html' is
very popular, and 'text/rtf' shows up sometimes (usually wrapped inside a
TNEF-encoded attachment).
Gambit