title: How can I delete a message by message id with MailKit POP3 client?
body: <p>I want to use the MailKit <code>Pop3Client</code> to retrieve messages from a POP3 mailbox, and then delete these messages after processing. The retrieval code is something like:</p>
  
  <pre><code>Public Function GetMessages(Optional logPath As String = Nothing) As List(Of MimeMessage)
  
      Dim client As Pop3Client
      Dim messages = New List(Of MimeMessage)()
  
      Using client
          ConnectPop3(client)
          Dim count = client.GetMessageCount()
          For i As Integer = 0 To count - 1
              Dim msg = client.GetMessage(i)
              messages.Add(msg)
          Next
      End Using
  
      Return messages
  
  End Function
  </code></pre>
  
  <p>My problem here is in order to delete a message in another message, I need an index, but that is long gone once I exit <code>GetMessages</code>. All I have is the info available on a <code>MimeMessage</code> object, but that has no index property, only <code>MessageId</code>, but in my Delete method, I would have to read all mails again, in order to look up an index value. </p>
  
  <p>Now <code>Pop3Client</code> has a <code>GetMessageUid(int index)</code> method, which returns a mysterious string (looks like int) value with no apparent relation at all to the Mime MessageID, but it seems this is all I have. Then I have to store the MailKit Uid with each message, making my retrieval code something like this, using a dictionary to store uid-message pairs:</p>
  
  <pre><code>Public Function GetMessages(Optional delete As Boolean = False, Optional logPath As String = Nothing) As List(Of MimeMessage)
  
      Dim client As Pop3Client
      Dim messages = New Dictionary(Of String, MimeMessage)
  
      Using client
          ConnectPop3(client)
          Dim count = client.GetMessageCount()
          For i As Integer = 0 To count - 1
              Dim msg = client.GetMessage(i)
              Dim u = client.GetMessageUid(i)
              messages.Add(u, msg)
          Next
          client.Disconnect(True)
      End Using
  
      Return messages
  
  End Function
  </code></pre>
  
  <p>I am really hoping I'm missing something here and what should be a really simple process is indeed simple, but I can't find anything else on my own.</p>