Commons Email
  1. Commons Email
  2. EMAIL-16

[email] Issue with cid URLs generated by .embed(...) in HtmlEmail.java

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Nightly Builds
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: All

      Description

      There seems to be an issue with the content-id (cid) returned by the
      .embed(...) member in HtmlEmail.java. The function sometimes returns cids
      with may also contain single quotes ' or double quotes " (all within ascii
      range 32-126). These random strings break the HTML code when a cid is
      referenced in an img-tag, e.g. <img src="cid:hju4"4u23">. Since this is a
      random function, it only happens from time to time. Tests with Outlook,
      Lotus Notes and Apple Mail clients show that they cannot render those
      images, because their html parser only returns a portion of the actual cid.
      I have tried to encode the cid (with commons URLCodec), but that doesn't work
      either.

      Fixed it by using RandomStringUtils.randomAlphabetic(...) in the .embed()
      function in HtmlEmail.java, instead of .randomAscii(...). Could also be
      fixed by using a combination of .randomNumeric(...) +
      .randomAlphabetic(...), but the result should not contain url-offending
      characters Also consider to use the commons-id package as soon as it is
      stable.

      This patch works for me so far:

      % cvs diff HtmlEmail.java

      Index: HtmlEmail.java
      ===================================================================
      RCS file:
      /home/cvspublic/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java,v
      retrieving revision 1.8
      diff -r1.8 HtmlEmail.java
      145c145
      < String cid = RandomStringUtils.randomAscii(10);

      > String cid = RandomStringUtils.randomAlphabetic(10);

        Activity

        Hide
        David Eric Pugh added a comment -

        Been tested, now closing.

        Show
        David Eric Pugh added a comment - Been tested, now closing.
        Hide
        Mark Lowe added a comment -

        I've tested the output on a email client and the problem is resolved. Everytime I build all the test cases
        are run and I spam myself with all the test mails.

        Subject:Test HTML Send #1 Subject (w charset)

        Displays correctly.. Before it did until a pesky < or > got in there.

        Show
        Mark Lowe added a comment - I've tested the output on a email client and the problem is resolved. Everytime I build all the test cases are run and I spam myself with all the test mails. Subject:Test HTML Send #1 Subject (w charset) Displays correctly.. Before it did until a pesky < or > got in there.
        Hide
        David Eric Pugh added a comment -

        I applied the fix. Can you verify it again? And if it looks good, close the bug?

        Show
        David Eric Pugh added a comment - I applied the fix. Can you verify it again? And if it looks good, close the bug?
        Hide
        Mark Lowe added a comment -

        Created an attachment (id=13242)
        [email] changed cid generator to alfanumeric.

        Show
        Mark Lowe added a comment - Created an attachment (id=13242) [email] changed cid generator to alfanumeric.
        Hide
        Mark Lowe added a comment -

        The bug appears to be valid, I'll submit a patch with using random alfa numberic toLowerCase() to make
        sure thus doesn't happen. When the code contains < or > it fails to display the image.

        Show
        Mark Lowe added a comment - The bug appears to be valid, I'll submit a patch with using random alfa numberic toLowerCase() to make sure thus doesn't happen. When the code contains < or > it fails to display the image.
        Hide
        David Eric Pugh added a comment -

        Okay, that is what I thought.. I'll mark this one invalid.

        Show
        David Eric Pugh added a comment - Okay, that is what I thought.. I'll mark this one invalid.
        Hide
        Mark Lowe added a comment -

        I dont think so, since the real problem is that the cid needs setting between <cid> and then the cid
        without gt and lt signs need returning . There's a patch i submitted with the details.

        Show
        Mark Lowe added a comment - I dont think so, since the real problem is that the cid needs setting between <cid> and then the cid without gt and lt signs need returning . There's a patch i submitted with the details.
        Hide
        David Eric Pugh added a comment -

        Is this bug still relevant?

        Show
        David Eric Pugh added a comment - Is this bug still relevant?
        Hide
        Corey Scott added a comment -
            • COM-1258 has been marked as a duplicate of this bug. ***
        Show
        Corey Scott added a comment - COM-1258 has been marked as a duplicate of this bug. ***
        Hide
        Corey Scott added a comment -

        Here is the patch that does as suggested (generates an alphanumeric string)
        with no unacceptable chars:

        Index: HtmlEmail.java
        ===================================================================
        RCS file: /home/cvspublic/jakarta-commons-
        sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java,v
        retrieving revision 1.9
        diff -u -r1.9 HtmlEmail.java
        — HtmlEmail.java 18 Oct 2004 20:59:11 -0000 1.9
        +++ HtmlEmail.java 20 Oct 2004 15:22:18 -0000
        @@ -158,8 +158,9 @@
        mbp.setDataHandler ( new DataHandler( new URLDataSource( url ) ) );
        mbp.setFileName( name );
        mbp.setDisposition( "inline" );

        • String cid = RandomStringUtils.randomAscii( 10 );
        • mbp.addHeader( "Content-ID", cid );
          +
          + String cid = RandomStringUtils.randomAlphanumeric(10);
          + mbp.addHeader( "Content-ID", cid );

        this.inlineImages.add( mbp );
        return mbp.getContentID();

        Show
        Corey Scott added a comment - Here is the patch that does as suggested (generates an alphanumeric string) with no unacceptable chars: Index: HtmlEmail.java =================================================================== RCS file: /home/cvspublic/jakarta-commons- sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java,v retrieving revision 1.9 diff -u -r1.9 HtmlEmail.java — HtmlEmail.java 18 Oct 2004 20:59:11 -0000 1.9 +++ HtmlEmail.java 20 Oct 2004 15:22:18 -0000 @@ -158,8 +158,9 @@ mbp.setDataHandler ( new DataHandler( new URLDataSource( url ) ) ); mbp.setFileName( name ); mbp.setDisposition( "inline" ); String cid = RandomStringUtils.randomAscii( 10 ); mbp.addHeader( "Content-ID", cid ); + + String cid = RandomStringUtils.randomAlphanumeric(10); + mbp.addHeader( "Content-ID", cid ); this.inlineImages.add( mbp ); return mbp.getContentID();

          People

          • Assignee:
            Unassigned
            Reporter:
            Thorsten Vogel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development