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

Problems with unicode in sent message #460

Closed
StefanLiebig opened this issue Jun 29, 2022 · 3 comments
Closed

Problems with unicode in sent message #460

StefanLiebig opened this issue Jun 29, 2022 · 3 comments
Assignees
Labels
backport_1_6_x Backport to old bugfixing branch 1.6.x bug
Milestone

Comments

@StefanLiebig
Copy link

Using GreenMail 1.6.9

With the test code from https://greenmail-mail-test.github.io/greenmail/#examples (Testing your sending code (simple)) slightly modified with unicode character and umlaute (Kotlin):

val greenMail = GreenMail() //uses test ports by default
greenMail.start()
GreenMailUtil.sendTextEmailTest(
    "to@localhost", "from@localhost", "some subject",
    "This is a test with ünicöde: \uD83C\uDF36"
) // --- Place your sending code here

assertEquals("This is a test with ünicöde: \uD83C\uDF36", GreenMailUtil.getBody(greenMail.receivedMessages[0]))
greenMail.stop()

The assertion fails.
Expected is: "This is a test with ünicöde: 🌶"
but is: "This is a test with =C3=BCnic=C3=B6de: =F0=9F=8C=B6"

Is this supposed to work?

@marcelmay
Copy link
Member

Hi @StefanLiebig ,

you should use msg.content, as GreenMailUtil.getBody would fetch the body part structure as text:

@file:DependsOn("com.icegreen:greenmail:1.6.9")
@file:DependsOn("org.jetbrains.kotlin:kotlin-test:1.7.0")

import com.icegreen.greenmail.util.GreenMail
import com.icegreen.greenmail.util.GreenMailUtil
import kotlin.script.experimental.dependencies.DependsOn
import kotlin.test.DefaultAsserter.assertEquals

val greenMail = GreenMail()
greenMail.start()

val content = "This is a test with ünicöde: \uD83C\uDF36"
val subject = "Some sübject"

GreenMailUtil.sendTextEmailTest(
    "to@localhost", "from@localhost", subject,
    content
)

val msg = greenMail.receivedMessages[0]
assertEquals("Checking subject",subject, msg.subject)
assertEquals("Checking content type", "text/plain; charset=UTF-8", msg.contentType)
assertEquals("Checking content", content,  msg.content) // Fetch content
greenMail.stop()

This should work, but there seems to be a bug with the content (strange eol?):

java.lang.AssertionError: Checking content. Expected <This is a test with ünicöde: 🌶>, actual <This is a test with ünicöde: 🌶
>.

@marcelmay marcelmay self-assigned this Jun 29, 2022
@marcelmay marcelmay added the bug label Jun 29, 2022
@marcelmay marcelmay added this to the 2.0.0-alpha-3 milestone Jun 29, 2022
@marcelmay marcelmay added the backport_1_6_x Backport to old bugfixing branch 1.6.x label Jun 29, 2022
@StefanLiebig
Copy link
Author

Hi @marcelmay ,

Yes, the actual msg.content contains additional "\r\n".

The tests "Testing your sending code (advanced)" do trim() the content!

@marcelmay
Copy link
Member

The trailing "\r\n" seems to be a bug in GreenMail SMTP.

This now works for retrieving using IMAP and msg.content.

Unfortunately, this fails for POP3, where JavaMail at the end of a message - CONTENT+'\r\n.\r\n' - only strips '.\r\n' - so there is always a CONTENT+'\r\n':
com.sun.mail.pop3.Protocol#retr:L523: -> #readMultilineResponse :

It would be nice if JavaMail msg.content would behave transparent to IMAP or POP3 being used...

marcelmay added a commit that referenced this issue Jul 30, 2022
Backport of #460:

Fixes trailing \r\n for IMAP msg.getContent()

SmtpConnection now strips the last \r\n before terminating dot of a
received message.

So for an IMAP plain text message, msg.getContent() equals to the sent
plain text content, without being forced to trim off '\r\n' from the received
content.

Note that messages retrieved with POP3 still have trailing '\r\n'.
derTobsch added a commit to urlaubsverwaltung/urlaubsverwaltung that referenced this issue Aug 1, 2022
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