I'm trying to pull multipart emails in MIME format from an IMAP server using Indy 10.5.5 in Delphi 2010. These are the lines of code that I'm having trouble with are below, where I instatiate the curMessage object, retrieve a message into it, and then call CountParts:
var
curMessage: TIdMessage;
IMAP4: TIdIMAP4;
msgIndex: Integer;
begin
...
curMessage := TIdMessage.Create(nil);
IMAP4.Retrieve(msgIndex, curMessage);
curMessage.MessageParts.CountParts;
//code that checks counts
//and
end;
I then have some code that checks the various count properties of curMessage.MessageParts (i.e. TextPartCount). However, the CountPart procedure isn't returning anything, because the Count
property referenced in the procedure block is 0, even though I've verified that the message is retrieved and placed into the curMessage.
One thing I've noticed, and haven't gotten to the bottom of yet, is that IsMsgSinglePartMime is coming back as true, even though all the messages on the server have Content-Type: multipart/mixed;
.
Any help would be really appreciated.
What am I missing here? I can provide more code if needed,
Without seeing the actual email data, it is difficult to say for sure exactly why the data is not where you expect it to be. But if the TIdMessage.IsMsgSinglePartMime
is getting set to True then that means that either:
TIdMessage.Encoding
is meMIME
but TIdMessage.MIMEBoundary.Count
is 0, meaning there was no MIME boundary
value detected in the top-level Content-Type
header. If the Content-Type
is a 'multipart/...'
type, a boundary
is required. If it is present, it is likely malformed in a way that prevented Indy from parsing it.
TIdMessage.Encoding
is mePlainText
but TIdMessage.ContentTransferEncoding
is either 'base64'
or 'quoted-printable'
.
In either case, if there is body content present then it would end up in the TIdMessage.Body
property if it is textual data, otherwise it would end up in the TIdMessage.MessageParts
as an attachment instead. Since TIdMessage.MessageParts.Count
is 0 in your case, the data is either in TIdMessage.Body
, or is got discarded.
You may want to consider upgrading to a newer Indy version. The version shipped with D2010 is pretty old, and there have been fixes/changes made to TIdIMAP4
and TIdMessage
(and its internal parsers) in recent years.