Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: MessageParts.Count always 0 (zero)
| Subject: | Re: MessageParts.Count always 0 (zero) |
| Posted by: | "Cornie" (cornie..@gmail.com) |
| Date: | Tue, 1 Aug 2006 23:59:19 |
Thanks for the speedy reply.
> What does the raw message data actually look like? What does your code look
> like that is sending and downloading the message?
object Msg: TIdMessage
AttachmentEncoding = 'MIME'
BccList = <>
CCList = <>
Encoding = meMIME
FromList = <
item
end>
Recipients = <>
ReplyTo = <>
ConvertPreamble = True
Left = 152
Top = 388
end
Procedure TICXF.StartConnectionForMail(Mail:Boolean=True);
var c:Integer;
begin
ToSend:=TStringList.Create;
try
if
FindFirst(ExtractFilePath(Application.ExeName)+'\Data\InFoX\OutBox\*.InfoX',faAnyFile,FName)
= 0 then begin
ToSend.Add(ExtractFilePath(Application.ExeName)+'\Data\InFoX\OutBox\'+FName.Name);
MailSize:=Fname.Size;
while FindNext(FNAme)= 0 do begin
ToSend.Add(ExtractFilePath(Application.ExeName)+'\Data\InFoX\OutBox\'+FName.Name);
MailSize:=MailSize+Fname.Size;
end;
with IdMsgSend do begin
Body.Clear;
From.Text := Data.SDS_CompanyINFOX_EMAIL.Value;
ReplyTo.EMailAddresses := From.Text;
Recipients.EMailAddresses :=
Data.SDS_CompanyINFOX_SERVER_MAIL.Value; { To: header }
Subject := 'InfoStar InfoX Document -
('+Data.SDS_CompanyINFOX_CODE.Value+') - ('+DateTimeToStr(Now)+')'; {
Subject: header }
Priority := TIdMessagePriority(0); { Message Priority }
CCList.EMailAddresses := ''; {CC}
BccList.EMailAddresses := ''; {BBC}
ReceiptRecipient.Text := ''; {Clear to avoid read requets}
IdMsgSend.Body.Add('Sended by InfoStar Accounting.');
For c:=0 to ToSend.Count-1 do begin
Try
SetStatus('Adding '+ToSend[c]+' to message ...');
TIdAttachmentFile.Create(MessageParts, ToSend[c]);
SetStatus('Adding '+ToSend[c]+' to message succeeded.');
except
SetStatus('Adding '+ToSend[c]+' to message failed.');
end;
end;
// Dial Dial Connection
MailSize:=Trunc(MailSize * 1.4);
end;
end else begin
Note('There are no packages to sent.');
end;
finally
FindClose(FName);
end;
If not(Data.SDS_CompanyINFOX_DUN_MANUAL_DISC.Value=1) then begin
if Ras.RasAvailable then begin
RAS.EntryIndex:=GetInfoXRasIndex;
if RAS.EntryIndex <> -1 then begin
If Ras.Connected then begin
SetStatus('Dial-up Connection already connected!');
RasConnected(nil);
end else begin
Ras.Dial(RAs.EntryIndex);
end;
end else begin
Note('Your InfoX Dial-up Connection is invalid.'+cr+'Please
correct in the Company Setup -> InFoX');
Exit;
end;
end else Note('Dial Networking not availeble');
end else begin
RasConnected(nil);
end;
end;
> 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.
How is it possible to automatic parsing?
>
> 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?
>
object Msg: TIdMessage
AttachmentEncoding = 'MIME'
BccList = <>
CCList = <>
Encoding = meMIME
FromList = <
item
end>
Recipients = <>
ReplyTo = <>
ConvertPreamble = True
Left = 172
Top = 88
end
> 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;
As I said I cut out most of the checking out of code, but your code is
better and I will implement it. My main issue is still that
Msg.MessageParts.Count is zero.
Regards
Cornie