I'm trying to optimize the methods and ways I use to perform a search and retrieving the results.
Actually, I have one method which (for example) searches by body on mails. It uses a TextSearchQuery and so on and I retrieve the List of UniqueIds. I'm interested on working with MimeMessages which basically has everything I need to work with.
public IEnumerable<MimeMessage> BuscarEnCuerpoEmail(string texto, bool noLeidos = false, bool flagged = false)
{
List<MimeMessage> resultado = new List<MimeMessage>();
try
{
imap.Inbox.Open(FolderAccess.ReadOnly);
if (!String.IsNullOrWhiteSpace(texto)
&& !noleidos && !flagged) //Busca en todos los correos
{
var parametrosBusqueda = new TextSearchQuery(SearchTerm.BodyContains, texto)
.And(SearchQuery.All);
var resultadoBusqueda = imap.Inbox.Search(parametrosBusqueda);
return ObtenerMensajes(resultadoBusqueda);
} . . . .
I have a method which adds the MimeMessage to a collection and a GetMessage
each time...
public IEnumerable<MimeMessage> ObtenerMensajes(IEnumerable<UniqueId> ids)
{
List<MimeMessage> result = new List<MimeMessage>();
foreach (var id in ids)
{
var message = imap.Inbox.GetMessage(id);
result.Add(message);
//yield return message;
}
return result;
}
Is there any way to perform that GetMessage in the server and get a List of MimeMessages directly? Like GetBatchMimeMessages(List<UniqueId>)
or something could be interesting.
Thanks.
MailKit doesn't have any built-in way of downloading a collection of messages at a time. Generally you don't want to do that anyway since messages can be of any size and a collection of them can be massive.
IMAP is designed such that you don't really ever need to download multiple messages in full at a time anyway since the purpose of IMAP is to be a remote storage system for mail.