jakartaee / jakartaee/mail-api

Error decoding a string with Cyrillic characters to search an e-mail by subject via IMAP protocol

Open
#717 9 comments 0 reactions 0 assignees Claimed by @jmehrens View on GitHub
bug duplicate
Dominant language
Java
Stars
285
Forks
109
Avg merge
15h 19m
Merged PRs (30d)
1

Description

**Describe the bug**
I'm trying to find a subject line email in my Gmail inbox.

Store store = imapConnectionPool.getStore(account);
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.CONTENT_INFO);
fp.add(FetchProfile.Item.FLAGS);

Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.search(new SubjectTerm("привет!"));
inbox.fetch(messages,fp);
return messages;

But the library does not encode it correctly "привет!", because if we look through the debug what commands the imap client sends to the server, we will see that it leaves incomprehensible characters.

DEBUG: setDebug: Jakarta Mail version 2.1.1
DEBUG: getProvider() returning jakarta.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: protocolConnect returning false, host=imap.gmail.com, user=kuznetsovvs, password=
DEBUG IMAP: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from 95.25.2.187 2adb3069b0e04-512b35b608cmb63806781e87
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER
A0 OK Thats all she wrote! 2adb3069b0e04-512b35b608cmb63806781e87
DEBUG IMAP: AUTH: XOAUTH2
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: PLAIN-CLIENTTOKEN
DEBUG IMAP: AUTH: OAUTHBEARER
DEBUG IMAP: protocolConnect login, host=imap.gmail.com, user=ostenzvuk@gmail.com, password=
DEBUG IMAP: AUTHENTICATE XOAUTH2 command trace suppressed
DEBUG IMAP: AUTHENTICATE XOAUTH2 command result: A1 OK ostenzvuk@gmail.com authenticated (Success)
A2 ENABLE UTF8=ACCEPT
* ENABLED UTF8=ACCEPT
A2 OK Success
DEBUG IMAP: IMAPProtocol noop
A3 NOOP
A3 OK Success
DEBUG IMAP: connection available -- size: 1
A4 EXAMINE INBOX
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $NotPhishing $Phishing)
* OK [PERMANENTFLAGS ()] Flags permitted.
* OK [UIDVALIDITY 1] UIDs valid.
* 712 EXISTS
* 0 RECENT
* OK [UIDNEXT 5454] Predicted next UID.
* OK [HIGHESTMODSEQ 829444]
A4 OK [READ-ONLY] INBOX selected. (Success)
A5 SEARCH SUBJECT ?@825B! ALL
* SEARCH
A5 OK SEARCH completed (Success)
I don't think that's right "? @825B!" and the topics in English are fine. It searches for them and finds them. Problem with Russian and Ukrainian

**Mail server:**
- Protocol being used: imap
- Vendor/product: Google
- Mail service URL: imap.gmail.com

Contributor guide

Open the contributing guide

Research direction

Review the existing open pull request #131 first, then reproduce the case using SubjectTerm("привет!") with inbox.search and the IMAP debug trace shown here. Compare the generated SEARCH command for Cyrillic and English subjects; done means Cyrillic subject searches are encoded correctly and return matching messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.