Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Sep : TidPOP3 Indy 9 problem

www.cryer.info
Managed Newsgroup Archive

TidPOP3 Indy 9 problem

Subject:TidPOP3 Indy 9 problem
Posted by:"Danila Vershinin" (profyprepatyandexdotru)
Date:Tue, 5 Sep 2006 23:13:56

Hello,
I am trying to save attachments that came via email using Indy 9's TIdPOP3.
Searched Google Groups, but failed to find anything good about using the
component from within BCB6
For a test I have one email on email server with a gif pictured attached to
it. Here is my code

void __fastcall TForm1::btn1Click(TObject *Sender)
{
pop->Connect  (-1);
int msgCount = pop->CheckMessages();

for (int i=0; i< msgCount; i++)
     {
      pop->Retrieve(i, msg);
      for (int j=0; j < msg->MessageParts->Count; j++)
          {
            if (msg->MessageParts->Items[j]->ClassNameIs("TIdAttachment"))
// is this correct?
               {
                 TIdAttachment* prt = msg->MessageParts->Items[j];
                 prt->SaveToFile("c:\temp\testattach3.gif");
               }
          }
     }

}
after clicking the button an exception is raised telling me about "error
while saving an attachment". When I check the folder where it's supposed to
be saved to, I see the file, but it's corrupted.
The following line
if (msg->MessageParts->Items[j]->ClassNameIs("TIdAttachment"))
was previously 3 lines, smth like this
TIdMessagePart *  prt = msg->MessageParts->Items[j];
TIdAttachment* atch = dynamic_cast <TIdAttachment*> (prt);
if (atch) ......
and it produced the same result. Please correct my mistakes :)

Replies:

www.cryer.info
Managed Newsgroup Archive