Can Not Filter Specific Sender from Server Using IMAP Client

use the code to filter Specific Sender:

import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import org.junit.Test;
import com.aspose.email.DateComparisonType;
import com.aspose.email.ImapClient;
import com.aspose.email.ImapMessageInfoCollection;
import com.aspose.email.ImapQueryBuilder;
import com.aspose.email.MailQuery;

public class TestEmailFilling {

@Test
public void listMsgInfoByFilter() {

ImapQueryBuilder builder = new ImapQueryBuilder(StandardCharsets.UTF_8);
// date range
Calendar queryDate = Calendar.getInstance();
builder.getInternalDate().since(queryDate.getTime(), DateComparisonType.ByDate);
builder.getInternalDate().beforeOrEqual(queryDate.getTime(), DateComparisonType.ByDate);

// Specific Sender
builder.getFrom().contains("test@hotmail.com", Boolean.TRUE);

MailQuery query = builder.getQuery();
ImapMessageInfoCollection imapMessageInfos = new ImapMessageInfoCollection();

 //email config
ImapClient client = new ImapClient("host", port, "username",
    "password", securityOptions);
client.selectFolder("Inbox");
imapMessageInfos.addRange(client.listMessages(query));
System.out.print("imapMessageInfos.size:"+imapMessageInfos.size());

}

}

error message:
AE_1_1_0009 NO [BADCHARSET (US-ASCII)] The specified charset is not supported.
com.aspose.email.ImapException: AE_1_1_0009 NO [BADCHARSET (US-ASCII)] The specified charset is not supported.
at com.aspose.email.zem.a(SourceFile:113)
at com.aspose.email.zem.f(SourceFile:96)
at com.aspose.email.zbac.f(SourceFile:97)
at com.aspose.email.zaeh.b(SourceFile:264)
at com.aspose.email.zeg.a(SourceFile:340)
at com.aspose.email.zbft.a(SourceFile:193)
at com.aspose.email.internal.ah.zd.a(SourceFile:65)
at com.aspose.email.internal.ah.ze.run(SourceFile:117)
at java.base/java.lang.Thread.run(Thread.java:834)

@andr9427,
Thank you for posting the query. Unfortunately, I cannot use your code snippet to investigate this case because it contains unknown classes and variables. Please share a comprehensive code example or a simple standalone project.

Thank you for your help. I have change the code. Plese test it again.

1 Like

@andr9427,
Thank you for the updated code example. I logged the issue with ID EMAILJAVA-34944 in our tracking system. Our development team will investigate this case. We will inform you of any progress.

@andr9427,
Our development team investigated the issue. It seems to be your server does not support UTF8 encoding for IMAP protocol. This feature is not required in RFC 3501. You can check it by enabling IMAP activity logging as shown below:

imapClient.setLogFileName("file_path");

In CAPABILITY data, you will not see “UTF8=ACCEPT” string.

But you can use ImapQueryBuilder instance without specifying encoding like this:

ImapQueryBuilder builder = new ImapQueryBuilder(/*StandardCharsets.UTF_8*/);

Another way is to use EWSClient class.

API Reference: ImapQueryBuilder Class, EWSClient Class