Uploaded image for project: 'Commons Email'
  1. Commons Email
  2. EMAIL-138

Czech/Slovak diacritic marks in the file name of the attached file screw whole sent email

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.3.2
    • Fix Version/s: 1.3.3
    • Labels:
    • Environment:

      Windows 7, JDK 7 (6 compatible).

      Description

      Czech/Slovak diacritic marks in the file name of the attached file screw whole sent email. Email will arrive but it's content will be messy. An example of a filename which does this is "nazevřšččššě.txt". Optionally put some text in email and in file. I tried HtmlEmail.

        Activity

        Hide
        tn Thomas Neidhart added a comment -

        The filename is not correctly encoded in case of non-ascii names.

        As a work-around you can do the following:

        HtmlEmail email = ...
        File fileToAttach = ...
        
        EmailAttachment attachment = new EmailAttachment();
        attachment.setName(MimeUtility.encodeText(fileToAttach.getName()));
        attachment.setDescription("blabla");
        attachment.setPath(fileToAttach.getAbsolutePath());
        email.attach(attachment);
        
        Show
        tn Thomas Neidhart added a comment - The filename is not correctly encoded in case of non-ascii names. As a work-around you can do the following: HtmlEmail email = ... File fileToAttach = ... EmailAttachment attachment = new EmailAttachment(); attachment.setName(MimeUtility.encodeText(fileToAttach.getName())); attachment.setDescription("blabla"); attachment.setPath(fileToAttach.getAbsolutePath()); email.attach(attachment);
        Hide
        tn Thomas Neidhart added a comment -

        Fixed in r1592866.

        Thanks for the report!

        Show
        tn Thomas Neidhart added a comment - Fixed in r1592866. Thanks for the report!
        Hide
        nitulkukadia Nit added a comment -

        Hi Thomas Neidhart or qed , I found that the solution provided for this fix works only for systems which have default system encoding set to UTF-8.

        You should use MimeUtility.encodeText(fileToAttach.getName()), "UTF-8", null) to resolve this issue.
        Thanks

        Show
        nitulkukadia Nit added a comment - Hi Thomas Neidhart or qed , I found that the solution provided for this fix works only for systems which have default system encoding set to UTF-8. You should use MimeUtility.encodeText(fileToAttach.getName()), "UTF-8", null) to resolve this issue. Thanks
        Hide
        qed qed added a comment -

        @Nit: If it is as you say, then this issue shall be reopened. My tests were successful. I think my default codepage is Cp1250 for java. No problems reported so far. So if you have tested bugfix in 1.3.3 and it is as you say, please, report new issue.

        Show
        qed qed added a comment - @Nit: If it is as you say, then this issue shall be reopened. My tests were successful. I think my default codepage is Cp1250 for java. No problems reported so far. So if you have tested bugfix in 1.3.3 and it is as you say, please, report new issue.
        Hide
        tn Thomas Neidhart added a comment -

        I have tried to reproduce the problem now with different system charsets (property mail.mime.charset):

        for ISO-8859-15:

        Content-Disposition: attachment;
        filename="=?ISO-8859-15?Q?Test_Attachment_-_a>=E4,_o>=F6,_u>=FC,_au>=E4u?="
        

        for UTF-8:

        Content-Disposition: attachment;
        filename="=?utf-8?Q?Test_Attachment_-_a>=C3=A4,_o>=C3=B6,_u>=C3=BC,_au>=C3=A4u?="
        

        So you can see that the respective charset is used during the encoding of the filename and also part of the resulting mime message. When opening the resulting email with thunderbird, the correct filename is displayed.

        Can you more precisely specify the problem you are seeing?

        Show
        tn Thomas Neidhart added a comment - I have tried to reproduce the problem now with different system charsets (property mail.mime.charset): for ISO-8859-15: Content-Disposition: attachment; filename="=?ISO-8859-15?Q?Test_Attachment_-_a>=E4,_o>=F6,_u>=FC,_au>=E4u?=" for UTF-8: Content-Disposition: attachment; filename="=?utf-8?Q?Test_Attachment_-_a>=C3=A4,_o>=C3=B6,_u>=C3=BC,_au>=C3=A4u?=" So you can see that the respective charset is used during the encoding of the filename and also part of the resulting mime message. When opening the resulting email with thunderbird, the correct filename is displayed. Can you more precisely specify the problem you are seeing?
        Hide
        sgoeschl Siegfried Goeschl added a comment -

        Hi folks, doing some JIRA grooming - any updates on the issues?

        Show
        sgoeschl Siegfried Goeschl added a comment - Hi folks, doing some JIRA grooming - any updates on the issues?
        Hide
        sebb@apache.org Sebb added a comment -

        Associated commit:

        URL:
        http://svn.apache.org/r1592866
        Log: EMAIL-138 Filenames of attachments were not properly encoded. Thanks to qed.

        Added:
        commons/proper/email/trunk/src/test/resources/eml/html-attachment-encoded-filename.eml
        Modified:
        commons/proper/email/trunk/src/changes/changes.xml
        commons/proper/email/trunk/src/main/java/org/apache/commons/mail/MultiPartEmail.java
        commons/proper/email/trunk/src/test/java/org/apache/commons/mail/SendWithAttachmentsTest.java
        commons/proper/email/trunk/src/test/java/org/apache/commons/mail/util/MimeMessageParserTest.java

        Show
        sebb@apache.org Sebb added a comment - Associated commit: URL: http://svn.apache.org/r1592866 Log: EMAIL-138 Filenames of attachments were not properly encoded. Thanks to qed. Added: commons/proper/email/trunk/src/test/resources/eml/html-attachment-encoded-filename.eml Modified: commons/proper/email/trunk/src/changes/changes.xml commons/proper/email/trunk/src/main/java/org/apache/commons/mail/MultiPartEmail.java commons/proper/email/trunk/src/test/java/org/apache/commons/mail/SendWithAttachmentsTest.java commons/proper/email/trunk/src/test/java/org/apache/commons/mail/util/MimeMessageParserTest.java
        Hide
        sebb@apache.org Sebb added a comment -

        AFAICT, the filename should not be encoded by Commons Email.

        See the Javadoc for MimeBodyPart#setFileName(String) [1]

        Commons Email is a wrapper for JavaMail, so it should not be doing its own encoding. Encoding should be left to JavaMail.

        I think this 'fix' needs to be reverted.

        However the Commons Javadoc should be updated to point to [1]

        [1] https://javamail.java.net/nonav/docs/api/javax/mail/internet/MimeBodyPart.html#setFileName-java.lang.String-

        Show
        sebb@apache.org Sebb added a comment - AFAICT, the filename should not be encoded by Commons Email. See the Javadoc for MimeBodyPart#setFileName(String) [1] Commons Email is a wrapper for JavaMail, so it should not be doing its own encoding. Encoding should be left to JavaMail. I think this 'fix' needs to be reverted. However the Commons Javadoc should be updated to point to [1] [1] https://javamail.java.net/nonav/docs/api/javax/mail/internet/MimeBodyPart.html#setFileName-java.lang.String-

          People

          • Assignee:
            Unassigned
            Reporter:
            qed qed
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Development