jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
240 stars 100 forks source link

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

Open vadetcka999 opened 4 months ago

vadetcka999 commented 4 months ago

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=<null>
    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=<non-null>
    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:

vadetcka999 commented 4 months ago

HEEEELP MEE, and for BodyTerm same situation

 A5 SEARCH BODY "@825B" ALL
jmehrens commented 4 months ago

Duplicate of #474

synim503 commented 4 months ago

Duplicate of #474

Where's the solution to this problem?????

jmehrens commented 4 months ago

No workarounds that I'm aware of at this time. The draft PR for this has been linked to this ticket above that comment and in the development section. Explanation of the problems are in that PR. Work is in progress and it would help if there are people willing to test the snapshot once it is ready.

synim503 commented 4 months ago

No workarounds that I'm aware of at this time. The draft PR for this has been linked to this ticket above that comment and in the development section. Explanation of the problems are in that PR. Work is in progress and it would help if there are people willing to test the snapshot once it is ready.

This needs to be addressed, it's a serious problem for some people including myself and people I know....

synim503 commented 4 months ago

No workarounds that I'm aware of at this time. The draft PR for this has been linked to this ticket above that comment and in the development section. Explanation of the problems are in that PR. Work is in progress and it would help if there are people willing to test the snapshot once it is ready.

Is there any way I can compile a draft solution and test it now?

jmehrens commented 4 months ago

This needs to be addressed, it's a serious problem for some people including myself and people I know.... Is there any way I can compile a draft solution and test it now?

Agreed. I recognize the priority and importance of this issue as the first message in the linked the draft PR. I've also noted that this PR is going to take me some time to fully complete. I think the basic idea and approach is correct in that PR.

I pushed my latest changes to https://github.com/eclipse-ee4j/angus-mail/pull/131 which builds now but test at your own risk. There are a few things that may not be correct. Put feedback in that PR.