Attachments and POP3->Delete

Giganews Newsgroups
Subject: Attachments and POP3->Delete
Posted by:  duf (d…@wp.pl)
Date: Thu, 25 Sep 2008

When I receive one attachment in mail there is no problem with delete it.

for( int i = 1; i <= Form1->news; ++i )
{
  Form1->IdMessage1->Clear();
  Form1->POP3->Retrieve( i, Form1->IdMessage1 );

  for( int j = 0; j <= Form1->IdMessage1->MessageParts->Count-1; ++j )
  {
      TIdAttachment *Attachment = dynamic_cast<TIdAttachment*>( Form1->IdMessage1->MessageParts->Items[j] );

      if( Attachment )
      {
        Form1->POP3->Delete( i );                    
      }
  }
}

But there is problem when I receive one message with two attachments. I have to delete it like this:

for( int i = 1; i <= Form1->news; ++i )
{
  Form1->IdMessage1->Clear();
  Form1->POP3->Retrieve( i, Form1->IdMessage1 );

  for( int j = 0; j <= Form1->IdMessage1->MessageParts->Count-1; ++j )
  {
      TIdAttachment *Attachment = dynamic_cast<TIdAttachment*>( Form1->IdMessage1->MessageParts->Items[j] );

      if( Attachment )
      {
        if ( j == Form1->IdMessage1->MessageParts->Count-2 ) Form1->POP3->Delete( i );                     
      }
  }
}

Is it universal method to delete message with two or more attachments ?

Replies