Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: MessageParts.Count always 0 (zero)
| Subject: | Re: MessageParts.Count always 0 (zero) |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Tue, 1 Aug 2006 14:31:38 |
"Cornie" <cornievs@gmail.com> wrote in message
news:44cfb473$1@newsgroups.borland.com...
> I have two apps. One send a MIME encoded mail, with one or more
> files attached. The other app then downloads the mail and the
attachments.
> I use GMail and everything work fine until 5 days ago. Now the
"receiving"
> app does not see the attachments to the message.
What does the raw message data actually look like? What does your code look
like that is sending and downloading the message?
> The MessageParts.Count is always zero!
For that to happen, either you are downloading the message data with
automatic parsing disabled, or the parsing is unable to recognize the format
of the message. Again, please show the actual code and the actual raw
message data.
When I view the message in Gmail or
> Thunderbird it is 100% and I can save the attached files, so I believe
> the problem lies with the receiving app. I have tried almost everything,
> changing the Encoding type, used no Decode, no Encode, etc but
> MessageParts.Count stays 0. The code is:
> If (POP.Retrieve(intIndex, Msg)) then begin
What are the properties of the TIdMessage actually set to?
> for Index2 := 0 to Pred(Msg.MessageParts.Count) do begin
> TIdAttachmentMemory(Msg.MessageParts.Items[Index2]).
> SaveToFile(ExtractFilePath(Application.exename)+'\'+
> TIdAttachmentFile(Msg.MessageParts.Items[Index2]).Filename);
You are assuming that every item in the MessageParts collection is a
TIdAttachmentMemory. That may not actually be the case. For one thing,
Indy uses TIdAttachmentFile instead of TIdAttachmentMemory by default. Do
you have an event handler assigned to the TIdMessage.OnCreateAttachment
event to override that? You should always verify the real class type before
blindly type casting. In any case, I would suggest casting to the
TIdAttachment base class instead of to a specific descendant class. You are
also mangling the target filename because ExtractFilePath() includes the
trailing backslash, to which you are then adding an unnecessary extra
backslash. You are also not taking into account that attachments are not
required to have filenames, so you should be checking for that as well. Try
this code instead:
var
LPart: TIdMessagePart;
LAttachment: TIdAttachment;
LFileName: String;
for Index2 := 0 to Pred(Msg.MessageParts.Count) do
begin
LPart := Msg.MessageParts.Items[Index2];
if LPart is TIdAttachment then
begin
LAttachment := TIdAttachment(LPart);
LFileName := ExtractFileName(LAttachment.FileName);
if LFileName = '' then LFileName := GetUniqueFileName('',
'MyTempFile', '.tmp');
LAttachment.SaveToFile(ExtractFilePath(Application.ExeName) +
LFileName);
end;
end;
Gambit