Skary
Skary

Reputation: 1362

C# Pop3 DeleteMessage does not delete email

Actually i would like to delete a mail message by mail unique id (i use ActiveUp.Net.Mail.Pop3Client)

To do so i use the following code :

private void DeleteMessageByUID ( string uid , Pop3Client popClient )
{
     for (int i = 1; i <= popClient.MessageCount; i++)
     {
          Header email = popClient.RetrieveHeaderObject(i);

          if (email.MessageId == uid )
          {
                popClient.DeleteMessage(i);
                break;
          }
     }

     popClient.Disconnect();
}

But after about two hour starting from when i delete all messages (initally the messages disappear from mailbox) i will able to find them back (with the same UIDs as the previously deleted messages).

I am not sure if the cause of the problem is in my program, i guess is a missconfiguration of the mailbox, but i would be sure about that before i contact the sysadmin.

Upvotes: 2

Views: 4076

Answers (1)

jstedfast
jstedfast

Reputation: 38573

The way POP3 works is that the DELE command that is sent by the DeleteMessage() method doesn't actually delete the message, all it does is mark it for future deletion when the POP3 client disconnects using the QUIT command.

I'm not sure how ActiveUp's POP3 client works, but mine (MailKit) will only send the QUIT command if you call client.Disconnect (true); (true is the quit argument).

Also, FWIW, the Message-Id header is not the same as a unique id. Be careful using that as your mechanism for identifying messages in any sort of unique way as Message-Ids are not necessarily unique nor is it a secure way of identifying messages. Clients that use Message-Ids in this way are open to DoS attacks where a hacker can send you an email with an identical Message-Id and force you to map it to the wrong message.

Upvotes: 5

Related Questions