Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with encoding of from and to fields #478

Closed
boris-petrov opened this issue Aug 31, 2022 · 3 comments
Closed

Issue with encoding of from and to fields #478

boris-petrov opened this issue Aug 31, 2022 · 3 comments
Labels
backport_1_6_x Backport to old bugfixing branch 1.6.x bug
Milestone

Comments

@boris-petrov
Copy link
Contributor

Hi, I'm sending an email by doing something like:

def message = new MimeMessage(session)
// this intermediate `InternetAddress` is needed because of:
// https://stackoverflow.com/questions/31859901/java-mail-sender-address-gets-non-ascii-chars-removed/31865820#31865820
def address = new InternetAddress('"кирилица" <other@example.com>')
message.from = new InternetAddress(address.address, address.personal)
message.subject = 'some subject with кирилица'
message.content = ...
GreenMailUtil.sendMimeMessage(message)

(note the Cyrillic in the from address). In the debug logs I see:

10:10:43.065 [smtp:127.0.0.1:3025<-/127.0.0.1:33824] DEBUG c.i.greenmail.util.LineLoggingBuffer - C: From: =
?UTF-8?B?0LrQuNGA0LjQu9C40YbQsA==?= <other@example.com>\r\n

Which is what I would expect - i.e. the from header is correctly encoded and sent over the wire. A few lines down in the logs (where I've received the message):

10:10:43.155 [imap:127.0.0.1:3143<-/127.0.0.1:56364] DEBUG c.i.greenmail.util.LineLoggingBuffer - S: 8?Q?som
e_subject_?= =?UTF-8?Q?with_=D0=BA=D0=B8=D1=80=D0=B8=D0=BB=D0=B8=D1=86=D0=B0?=" (("????????" NIL "other" "exampl
e.com")) ([WRAP]

The first part is the subject which is correctly received. After that you see the from part which has question marks inside. After that, doing a message.getFrom()[0] on the received message returns these question marks. What is also strange is that message.getHeader("From")[0] returns the correct encoded value - not sure how that happens. But in any case, getFrom doesn't work which is not nice.

Am I doing something wrong or is this an issue in Greenmail? I spent a lot of time debugging this. 😄

@marcelmay
Copy link
Member

Hi @boris-petrov ,

can you provide a test case snippet, e.g. based on EncodingTest.java?

Which GreenMail version are you using - latest 1.6.10?

@boris-petrov
Copy link
Contributor Author

@marcelmay thanks for the answer! I've created a PR with a failing test: #479 The funny thing is that this fails only in the MessageCountListener - in greenMail.getReceivedMessages it is correct... no idea why.

@marcelmay marcelmay added the bug label Sep 3, 2022
@marcelmay marcelmay added this to the 2.0.0-alpha-3 milestone Sep 3, 2022
@marcelmay marcelmay added the backport_1_6_x Backport to old bugfixing branch 1.6.x label Sep 3, 2022
@marcelmay
Copy link
Member

Thx for the test case, that really helped.

`greenMail. getReceivedMessages' fetches the messages directly, without IMAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport_1_6_x Backport to old bugfixing branch 1.6.x bug
Projects
None yet
Development

No branches or pull requests

2 participants