-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add a test for an attachment with UTF-8 symbols #483
base: master
Are you sure you want to change the base?
Add a test for an attachment with UTF-8 symbols #483
Conversation
@boris-petrov , thx alot! I will investigate the issue(s) next week |
Getting the same issue when trying to read emails from Greenmail using Apache Camel. |
Thanks alot, @boris-petrov and @Mulgish . I created a separate issue #498 (and for 1.6.x backport #499 ). Looks like something breaks (CRLF in header Content-Disposition) when creating/sending the mail, |
1045510
to
2b1863b
Compare
@marcelmay thanks for the new release! It fixed the test that I had written here. However, I pushed another commit which just adds a check for the attachment's file name. And it fails. Please check it out. I believe it should be passing? |
Thanks again @boris-petrov for another failing example. Will investigate the issue. |
2b1863b
to
21e6e08
Compare
Use MimeUtility.decodeText(....getFileName()) when fetching the name, or set |
@marcelmay |
@boris-petrov , just added #541 which simplifies adding such custom session properties like 'mail.mime.decodefilename' by default. Will be available with versions 1.6.14 / 2.0.x . Otherwise you'd have to do something like this: Session smtpSession = greenMail.getSmtp().createSession();
smtpSession.getProperties().setProperty("mail.mime.encodefilename","true");
MimeMessage mimeMessage = new MimeMessage(smtpSession);
...
Session imapSession = greenMail.getImap().createSession();
imapSession.getProperties().setProperty("mail.mime.decodefilename","true");
... // Receive mail using IMAP session |
@boris-petrov , I believe this PR was accidentally re-opened by your force-push (see history above, search for force-pushed) => I would close this PR, as it was merged before. |
I believe this comment was meant for some other PR? This hasn't been merged.
That's great! How do I use that in this test? I want to set that option ( P.S. I rebased on |
21e6e08
to
b03880b
Compare
@boris-petrov , you can set the properties for the whole test via @Rule
public GreenMailRule greenMail = new GreenMailRule(new ServerSetup[]{
ServerSetupTest.SMTP.mailSessionProperty("mail.mime.encodefilename", "true"),
ServerSetupTest.IMAP.mailSessionProperty("mail.mime.decodefilename", "true")
}); ... or in the test itself via public void testAttachmentWithUTF8NameAndGreenMailApi() throws MessagingException, IOException {
greenMail.setUser("to@localhost", "pwd");
final Session imapSession = greenMail.getImap().createSession();
imapSession.getProperties().setProperty("mail.mime.decodefilename","true"); // For reading
final IMAPStore store = (IMAPStore) imapSession.getStore();
....
GreenMailUtil.sendAttachmentEmail(
"to@localhost", "from@localhost", "subject", "body",
new byte[]{0, 1, 2}, "image/gif", fileName,
"testimage_description",
greenMail.getSmtp().getServerSetup()
.mailSessionProperty("mail.mime.encodefilename", "true")); // For sending
.... |
b03880b
to
e66399f
Compare
@marcelmay thanks for the help and sorry for the delay! I pushed another commit that does what you suggest - it sets |
my fault as I assumed it is a session property. This property is actually a JavaMail system property, not a JavaMail session property:
|
e66399f
to
abb33a9
Compare
OK, like that? Check the last commit. The test still doesn't work unfortunately. Am I missing something else? |
... which fails with:
That's because of
MimeUtility.encodeText
. If I remove that method call, the test passes. Not sure what's going on but I believe this is a bug in Greenmail.cc @marcelmay