ImapQueryBuilder problems

Hi,


we are facing few problems using the Query Engine for the IMAP client. We’re using the version of aspose.email 6.6.0. The problems we’re describing here occur at two IMAP servers.

Context: we want to implement a move operation of messages between folders using the IMAP protocol. Here is our algorithm:

1) We copy the original message to the destination folder.
2) We expect to get the email server id of the copied message, but up to version 6.3, the feature is not implemented in ImapClient, and in the current version 6.6 the operation is supported if the IMAP server supports UIDPLUS. Therefore we chose to perform a query against the destination folder, to obtain the id of the new copied message
3) We perform the query using the following two email fields:
- from
- sent date
4) If an id is returned, the original message is then deleted from the source folder
5) The new message id is given back to the caller

Here we encounter several problems in performing the query:

1) The sent date can match one of the two ImapMessageInfo.Date of ImapMessageInfo.InternalDate. As result we have to try both values in order to successfully execute the query
2) The from (as well as the subject) doesn’t support accents. If strings with accents are given to the query, this results in an exception (malformed query)
3) Even if the problem 1 and 2 are solved via workarounds, in some cases such a queries return no results. We noticed that this is particularly true if the number of messages in the folder is big (> 1000)

The problem 3) is thus crucial to us. If the id of the new message cannot be returned, we cannot complete the procedure, the operation fails, and the algorithm is not reliable.

Are there already known problems regarding IMAP queries ? How could the process be more reliable ? Is it possible to solve these bugs ?

Thanks

Hi Luk,

Thank you for writing to Aspose Support team.

We need further information from you in this regard in addition to sharing our own knowledge based on this [link](http://www.aspose.com/docs/display/emailnet/Filtering+Messages+from+IMAP+Mailbox+Based+on+Sender%2C+Recipient+or+Date#FilteringMessagesfromIMAPMailboxBasedonSender%2CRecipientorDate-CaseSensitiveSearch).

  1. The IMAP Query Builder provide supports for combining queries with OR that you can use to make a combination of Date and InternalDate if you need to. Please try it at our end and let us know your feedback if it doesn’t fulfill your requirements.

  2. Can you please share the specific accent words that we could try at our end and assist you further.

  3. Please share your complete sample code (in combination with the above 2 points as well) that you are trying at your end.

There have been issues related to IMAP queries in past, but those were of different nature. Please share your sample code and other requirements mentioned above for further assistance in this regard.

Hi,


this is the piece of code we use to build the IMAP query:

private MailQuery BuildQuery(String[] fromParts, DateTime date, DateTime internalDate)
{
ImapQueryBuilder imapQueryBuilder = new ImapQueryBuilder();
foreach (String from in fromParts)
{
if (!String.IsNullOrEmpty(from))
{
imapQueryBuilder.From.Contains(from, true);
}
}

imapQueryBuilder.SentDate.On(date);

// For some emails is it necessary to query the SentDate based on
// the InternalDate, because the comparison
// with Date returns no results
ImapQueryBuilder imapQueryBuilderForInternalDate = new ImapQueryBuilder();
foreach (String from in fromParts)
{
if (!String.IsNullOrEmpty(from))
{
imapQueryBuilderForInternalDate.From.Contains(from);
}
}
imapQueryBuilderForInternalDate.SentDate.On(internalDate);

// Get the two queries from the builders
MailQuery imapQuery = imapQueryBuilder.GetQuery();
MailQuery imapQueryForInternalDate = imapQueryBuilderForInternalDate.GetQuery();

// Join the result
ImapQueryBuilder joinQueryBuilder = new ImapQueryBuilder();
return joinQueryBuilder.Or(imapQuery, imapQueryForInternalDate);
}

We split the from in parts to avoid querying special characters (that results in an error).

We are working to reproduce the mentioned errors at our side. We will be back to you as soon as the environment is ready.

Thanks

Hi Luk,


Thank you for the feedback and we will be waiting for your response once issue is reproduced at your end.
Hi,

we solved the problem 3). It was due to an error in our code, once solved the aspose.email API works as expected. Thanks for the support.

There are still issues 1) and 2) open.

1) We already use support for combining queries with OR, and this helps us to execute the query correctly. Is it anyway possible to solve this problem directly in aspose.email ?

2) The list of characters that we exclude in the query are the following:

ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ

What we do here is to split the display name in substrings, if any of these characters are found in the From, and we add them all in the query clause. The problem here may be related to the character encoding of the email, which is not always UTF8. Could you confirm this at your side ?

2.a) There is another issue when building a query against the From field. We noticed that using the MailMessageInfo.From.Address as value brings us no results. In those cases we have to perform again the query using MailMessageInfo.From.DisplayName as value and then we get results as expected. Thus it seems that the From field in the query is sometimes matched with the address and sometimes with the display name. This is why we experienced the problem 2), since display names may contain characters with accents.

Thanks

Hi,

Could you please confirm to us if you are using the latest version of the API at your end? We have tested your issues as follow and found no exception or error at our end.

1. We executed the following code but it didn’t raise any issue at our end. Can you also please specify the Encoding in ImapQueryBuilder constructor and see if that helps you? If the issue doesn’t solve, please share sample code with us having accent letters in query that gives raise to issue as in our example below. We’ll further investigate it at our end.

Sample Code:

ImapQueryBuilder builder = new ImapQueryBuilder(Encoding.UTF8);

builder.From.Contains(“ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ”, true);

MailQuery mailQuery = builder.GetQuery();

2. I sent an email to our Office365 account and tested it for sent as well as internal date. All the emails were retrieved without any issue and getting missed. However, as mentioned in our documentation section, Filtering and Display Messages based on Internal Date, sometimes server does not return all messages as visible in the inbox. Its reason can be the server timezone because it may not be UTC for all the servers like GMAIL. Aspose sends commands like 008 SEARCH ON 4-May-2014 as per the IMAP protocol. However, results can differ due to server timezone settings. In such case, searching by InternalDate can be helpful.

Still for testing purpose, you can send some emails to online test account on Office365 at UserTwo@AsposeJun2016.onmicrosoft.com and check it for results. Following are the credentials for this test account.

Username: UserTwo@AsposeJun2016.onmicrosoft.com

Password: Aspose1234

2.a. We have tested this stance at our end and were not able to reproduce the problem. Could you please be kind enough to send some test message to the above mentioned test account that exhibits such problem and then let us know so that we can reproduce the behavior at our end?

PS: It will be better and beneficial for you as well as us if you could report the problems as 1 problem per thread. This makes it easy for keeping track of the issue raised in a thread and provide to-the-point assistance to our valued customers. I suggest you to please create new post per new issue where we could assist you more effectively.

Hi,

Could you please confirm to us if you are using the latest version of the API at your end? We have tested your issues as follow and found no exception or error at our end.

1. We executed the following code but it didn’t raise any issue at our end. Can you also please specify the Encoding in ImapQueryBuilder constructor and see if that helps you? If the issue doesn’t solve, please share sample code with us having accent letters in query that gives raise to issue as in our example below. We’ll further investigate it at our end.

Sample Code:

ImapQueryBuilder builder = new ImapQueryBuilder(Encoding.UTF8);

builder.From.Contains(“ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ”, true);

MailQuery mailQuery = builder.GetQuery();

2. I sent an email to our Office365 account and tested it for sent as well as internal date. All the emails were retrieved without any issue and getting missed. However, as mentioned in our documentation section, [Filtering and Display Messages based on Internal Date ](http://www.aspose.com/docs/display/emailnet/Filtering+Messages+from+IMAP+Mailbox+Based+on+Sender%2C+Recipient+or+Date#FilteringMessagesfromIMAPMailboxBasedonSender%2CRecipientorDate-newsletter), sometimes server does not return all messages as visible in the inbox. Its reason can be the server timezone because it may not be UTC for all the servers like GMAIL. Aspose sends commands like 008 SEARCH ON 4-May-2014 as per the IMAP protocol. However, results can differ due to server timezone settings. In such case, searching by InternalDate can be helpful.

Still for testing purpose, you can send some emails to online test account on Office365 at UserTwo@AsposeJun2016.onmicrosoft.com and check it for results. Following are the credentials for this test account.

Username: [UserTwo@AsposeJun2016.onmicrosoft.com]

Password: Aspose1234

2.a. We have tested this stance at our end and were not able to reproduce the problem. Could you please be kind enough to send some test message to the above mentioned test account that exhibits such problem and then let us know so that we can reproduce the behavior at our end?

PS: It will be better and beneficial for you as well as us if you could report the problems as 1 problem per thread. This makes it easy for keeping track of the issue raised in a thread and provide to-the-point assistance to our valued customers. I suggest you to please create new post per new issue where we could assist you more effectively.