Issue Details (XML | Word | Printable)

Key: EMAIL-79
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Siegfried Goeschl
Reporter: Edvin Syse
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Commons Email

SimpleEmail#setMsg() with UTF-8 content honors correct charset in header, but doesn't encode the content correctly

Created: 26/May/08 01:36 PM   Updated: 05/Apr/09 08:17 PM
Return to search
Component/s: None
Affects Version/s: 1.1
Fix Version/s: 1.2

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works EMAIL-79-patch-v2.txt 2009-02-11 04:07 AM Corey Scott 4 kB
Text File Licensed for inclusion in ASF works EMAIL-79-patch.txt 2008-11-27 08:03 AM Corey Scott 3 kB
Zip Archive Licensed for inclusion in ASF works EmailTest.zip 2008-11-25 08:12 AM Edvin Syse 1 kB
Environment: Windows Vista, JDK 1.6.0_06

Resolution Date: 05/Apr/09 08:17 PM


 Description  « Hide
When I create a new SimpleEmail and use setMsg(some-utf8-text), the Content-Type header of the generated email correctly changes to UTF-8, but the content is not encoded correctly.

Adding setCharset("UTF-8") solves the problem, but that shouldn't be needed, as the change of Content-Type header indicates.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Corey Scott added a comment - 25/Nov/08 02:16 AM
Edvin,

I tried looking into this for you and were unable to come up with a test to prove this condition.
Could you please see if you can create one so I can move this forward for you?

Thanks


Edvin Syse added a comment - 25/Nov/08 08:12 AM
Please se attached MailTest.java and message.eml and the resulting email when recieved. You need to put commons-email-1.1.jar and mail-1.4.jar on the classpath to run the test. As you see, the subject is encoded correctly, but the body is qp-encoded with latin-1 charset instead of UTF-8. I ran the program with -Dfile.encoding="UTF-8". It's easy to spot, since the each qp-encoded letter in the body only consist of one encoded one-byte sequence instead of two.

Edvin Syse made changes - 25/Nov/08 08:12 AM
Field Original Value New Value
Attachment EmailTest.zip [ 12394636 ]
Corey Scott added a comment - 27/Nov/08 08:03 AM
Edvin,

I am not sure this is what you wanted but the changes contained are making the simple (and HTML) email classes utilize the charset and content type settings better than they were. (in some cases they werent being used previously)

You still have to do a email.setCharset() call in order to ensure both the subject and message bodies have the encoding set but I personally feel this is acceptable. Perhaps because I dont see how the encoding can be reliably determined dynamically or even if it could, it is in side the scope of this library.


Corey Scott made changes - 27/Nov/08 08:03 AM
Attachment EMAIL-79-patch.txt [ 12394818 ]
Edvin Syse added a comment - 01/Dec/08 01:33 PM
Thanks, hopefully that will do the trick! I agree that one cannot always determine the correct encoding, but I think it is reasonable that the same encoding should be used in both subject and body even if you don't supply something explicitely, don't you agree?

Corey Scott added a comment - 02/Dec/08 02:14 AM
That certainly seems logical.

Siegfried Goeschl made changes - 06/Feb/09 06:29 PM
Assignee Siegfried Goeschl [ sgoeschl ]
Siegfried Goeschl made changes - 06/Feb/09 06:30 PM
Status Open [ 1 ] In Progress [ 3 ]
Siegfried Goeschl added a comment - 06/Feb/09 06:30 PM
I applied the patch but it is breaking a few tests

testSendNoAttachments(org.apache.commons.mail.SendWithAttachmentsTest)
testSendWAttachments(org.apache.commons.mail.SendWithAttachmentsTest)
testSend(org.apache.commons.mail.HtmlEmailTest)
testSend2(org.apache.commons.mail.HtmlEmailTest)
testHtmlMailMimeLayout(org.apache.commons.mail.EmailLiveTest)
testSend(org.apache.commons.mail.MultiPartEmailTest)

I try to commit my pending changes so that you can have a look at the problems


Corey Scott added a comment - 11/Feb/09 04:07 AM
New version of the patch that replaces the earlier one.

Tests against the current trunk are working again.


Corey Scott made changes - 11/Feb/09 04:07 AM
Attachment EMAIL-79-patch-v2.txt [ 12399963 ]
Siegfried Goeschl made changes - 24/Feb/09 11:26 PM
Fix Version/s 1.2 [ 12313573 ]
Repository Revision Date User Message
ASF #762147 Sun Apr 05 20:14:13 UTC 2009 sgoeschl [EMAIL-79] SimpleEmail#setMsg() with UTF-8 content honors correct charset in header and encode the content correctly.
Files Changed
MODIFY /commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
MODIFY /commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java

Repository Revision Date User Message
ASF #762148 Sun Apr 05 20:16:32 UTC 2009 sgoeschl [EMAIL-79] SimpleEmail#setMsg() with UTF-8 content honors correct charset in header and encode the content correctly.
Files Changed
MODIFY /commons/proper/email/trunk/xdocs/changes.xml

Siegfried Goeschl added a comment - 05/Apr/09 08:17 PM
Works now - thx

Siegfried Goeschl made changes - 05/Apr/09 08:17 PM
Resolution Fixed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]