title: MailKit IMAP search by UID and download individual MIME parts
body: <p>I've been able to retrieve the list of <strong>UIDs</strong> that come after the last one message I've checked, so I can get from the IMAP server <strong>only the new messages</strong>:</p>
  
  <pre><code>using(var client = new ImapClient())
  {
     //client authentication code...
  
     var inbox = client.Inbox;
     inbox.Open(FolderAccess.ReadOnly);
  
     //msgIdx contains the UID of the last message I've checked,
     // so I can retrieve all the new messages after this one.
      var range = new UniqueIdRange(new UniqueId((uint) msgIdx), UniqueId.MaxValue);
  
  
      IList&lt;UniqueId&gt; uids = inbox.Search(range, SearchQuery.All);
      foreach(var uid in uids)
      {
         //With the following instruction I download the whole message...
         var message = inbox.GetMessage(uid);
         LblMessageLog.Text += uid + " Subject:" + message.Subject + " []&lt;br/&gt;";
      }
      client.Disconnect(true);
  }
  </code></pre>
  
  <p>The problem is that I don't want to download the whole message, but <strong>only a specific attachment</strong>, as I know it will exist always, in all messages.</p>
  
  <p>There is an example on the MailKit website but it goes in conflict with the search I do above:</p>
  
  <pre><code>foreach (var summary in inbox.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure)) {
      if (summary.Body is BodyPartMultipart) {
          var multipart = (BodyPartMultipart) summary.Body;
  
          var attachment = multipart.BodyParts.OfType&lt;BodyPartBasic&gt; ().FirstOrDefault (x =&gt; x.FileName == "cert.xml");
          if (attachment != null) {
              // this will download *just* the attachment
              var part = inbox.GetBodyPart (summary.UniqueId, attachment);
          }
      }
  }
  </code></pre>
  
  <p>How can I do both processes of <strong>filtering data</strong> on UID and then <strong>download only a part</strong> of the email message?</p>