You need to use foreach loop for that:
using(Imap imap = new Imap())
{
imap.Connect("imap.example.com"); // or ConnectSSL for SSL
imap.UseBestLogin("user", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.All);
foreach (long uid in uids)
{
IMail email = new MailBuilder()
.CreateFromEml(imap.GetMessageByUID(uid));
string subject = email.Subject;
int attachmentCount = email.Attachments.Count;
}
imap.Close();
}
If you only need most common email fields (e.g. you need to fill an list with all emails on the server) consider using GetMessageInfoByUID method. This method is very fast:
using (Imap imap = new Imap())
{
imap.Connect("imap.example.com"); // or ConnectSSL
imap.UseBestLogin("user", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Unseen);
List<MessageInfo> infos = imap.GetMessageInfoByUID(uids);
foreach (MessageInfo info in infos)
{
string subject = info.Envelope.Subject;
IList<MailBox> from = info.Envelope.From;
IList<MailAddress> to = info.Envelope.To;
foreach (MimeStructure attachment in info.BodyStructure.Attachments)
{
string fileName = attachment.SafeFileName;
long size = attachment.Size;
}
}
imap.Close();
}