A Linefeed at the beginning of messageID causes the imapclient.listMessages(...) to throw an exception

Continuing the discussion from Error while connecting IMAP Account :

When the message_id starts with a Linefeed character (ASCII 10) the call of imapclient.listMessages(…) on (imap) server, throws an exception as below:

class com.aspose.email.system.exceptions.ArgumentException: Value does not fall within the expected range.
com.aspose.email.ahw.b(SourceFile:546)
com.aspose.email.MailMessage.setMessageId(SourceFile:734)
com.aspose.email.sz.d(SourceFile:404)
com.aspose.email.sz.a(SourceFile:246)
com.aspose.email.sz.b(SourceFile:189)
com.aspose.email.sz.f(SourceFile:179)
com.aspose.email.aax.b(SourceFile:259)
com.aspose.email.dj.a(SourceFile:306)
com.aspose.email.ayj.a(SourceFile:193)
com.aspose.email.internal.af.g.a(Unknown Source)
com.aspose.email.internal.af.h.run(Unknown Source)
java.lang.Thread.run(Thread.java:748)
at com.aspose.email.ahw.b(SourceFile:546)
at com.aspose.email.MailMessage.setMessageId(SourceFile:734)
at com.aspose.email.sz.d(SourceFile:404)
at com.aspose.email.sz.a(SourceFile:246)
at com.aspose.email.sz.b(SourceFile:189)
at com.aspose.email.sz.f(SourceFile:179)
at com.aspose.email.aax.b(SourceFile:259)
at com.aspose.email.dj.a(SourceFile:306)
at com.aspose.email.ayj.a(SourceFile:193)
at com.aspose.email.internal.af.g.a(Unknown Source)
at com.aspose.email.internal.af.h.run(Unknown Source)
at java.lang.Thread.run(Thread.java:748)

The test data shown below is from java.sun.mail API (as we couldn’t fetch the data from Aspose ):

  1. The message id without LineFeed (ok) :
    ‘[34418943-3D6E-49C3-8870-41A811A833EB@xxxxxxxx](mailto:34418943-3D6E-49C3-8870-41A811A833EB@xxxxxxxx)’
    [60, 51, 52, 52, 49, 56, 57, 52, 51, 45, 51, 68, 54, 69, 45, 52, 57, 67, 51, 45, 56, 56, 55, 48, 45, 52, 49, 65, 56, 49, 49, 65, 56, 51, 51, 69, 66, 64, 107, 97, 110, 122,…]
  2. The message id with LineFeed at the begining (failed ):

    [AM6PR10MB24884F4E59157EBFBD173058A70F0@xxxxxEURPRD10.PROD.OUTLOOK.COM](mailto:AM6PR10MB24884F4E59157EBFBD173058A70F0@xxxxxEURPRD10.PROD.OUTLOOK.COM)’
    [10, 32, 60, 65, 77, 54, 80, 82, 49, 48, 77, 66, 50, 52, 56, 56, 52,…, 54, 80, 82, 49, 48, 77, 66, 50, 52, 56, 56, 46, 69, 85, 82, 80, 82, 68, 49, 48, 46, 80, 82, 79, 68, 46, 79, 85, 84, 76, 79, 79, 75, 46, 67, 79, 77, 62]

The above shown two example cases of messageIds were not fetched using Aspose (due to exception caused by the messageId with LineFeed at the begining) and java.sun.mail API was used to fetch these example test data.

Because of the exception in listMessages(…) method, we cannot skip these mails that has LineFeed as starting character in messageId. This stops our customers from receiving any mails, as long as a mail with linefeed in the message_id was not removed from the server.
we assume these message_id are produced when sending with outlook365.

Kindly investigate the issue further and provide a fix.

Thank you,
Arne Stocker

@arne411,

Can you please share the sample problematic messages with us for further investigation at our end? We need these to append to our test account and fetch using ImapClient for reproducing the issue. Your cooperation is highly appreciated in this regard.

We will be providing you an exclusive private mail account which contains the problematic mail(s) in it. Please share your/relevant team’s email address for us to send the necessary credentials of the test imap account.

This account is exclusively created for testing and kindly not share the credentials outside of the relevant team.

We have found that the error occurs only when the mail was sent from the outlook365 exchange account.

@arne411,

Please share the credentials in a private message. You can send a private message by clicking the username as shown in the attached image. PrivateMessage.png (17.0 KB)

We have sent the credentials in private message.

@arne411,

We have received the credentials. We will look into it and let you know as soon as we have additional information.

@arne411,

We were able to reproduce the issue reported by you. We have logged a ticket as EMAILJAVA-34416 in our issue tracking system. We will update you here as soon as we have additional information.

Hi, I’m also having same problem when reading message coming from office365. I’m using the .net versoon Aspose.Email 18.8.0. Emails coming from non-office365 are working fine. Do you have fix for this?

It throws ‘Value does not fall within the expected range.’ error everytime I call .ListMessage() method if messages returned is coming from Office365.

Here is my code snippet:

var builder = new ImapQueryBuilder();
builder.HasNoFlags(ImapMessageFlags.IsRead); /* get unread messages. */

var query = builder.GetQuery();

var messages = _client.ListMessages(query, 1);

@eldridge,

This issue has been logged as EMAILJAVA-34416 and is under investigation. We will let you know as soon as we have additional information.

@muhammadahmad do you have updates from this? Do we have any workaround for now?

@eldridge,

The fix to this issue will be available in the upcoming release of Aspose.Email for Java 18.9. It is expected to be released at the start of next month.

@muhammadahmad thanks thats good to know. Does it also include the .NET release at the same time?

@eldridge,

We observed this issue in Aspose.Email for .NET as well. In such cases, the issue is fixed in the .NET version first. Later it is ported to the Java version.
This fix will be available in Aspose.Email for .NET 18.9, which is expected to be released by the end of this month.

@muhammadahmad Great.

The issues you have found earlier (filed as EMAILJAVA-34416) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan