geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frederik Lindberg (JIRA)" <j...@apache.org>
Subject [jira] [Created] (GERONIMO-6165) Soft linebreaks in quoted-printable body result in loss of first character on next line
Date Tue, 20 Sep 2011 13:48:10 GMT
Soft linebreaks in quoted-printable body result in loss of first character on next line
---------------------------------------------------------------------------------------

                 Key: GERONIMO-6165
                 URL: https://issues.apache.org/jira/browse/GERONIMO-6165
             Project: Geronimo
          Issue Type: Bug
      Security Level: public (Regular issues)
          Components: mail
    Affects Versions: 2.1
         Environment: Google Appengine
            Reporter: Frederik Lindberg


http://code.google.com/p/googleappengine/issues/detail?id=2675

When emails with quoted-printable body and soft linebreaks are processed, the first character
after the soft break disappears, eg:

hello th=
ere!

becomes
hello thre!

This is due to geronimo/mail/util/QuotedPrintableEncoder.java (current trunk: Revision 1173142)
public int decode(byte[] data, int off, int length, OutputStream out) throws IOException incorrectly
looking for a line ending as "\r\n", whereas at this point line ending are "\n". So, the code:

            else if (ch == '=') {
                // we found an encoded character.  Reduce the 3 char sequence to one.
                // but first, make sure we have two characters to work with.
                if (off + 1 >= endOffset) {
                    throw new IOException("Invalid quoted printable encoding");
                }
                // convert the two bytes back from hex.
                byte b1 = data[off++];
                byte b2 = data[off++];

                // we've found an encoded carriage return.  The next char needs to be a newline
                if (b1 == '\r') {
                    if (b2 != '\n') {
                        throw new IOException("Invalid quoted printable encoding");
                    }
                    // this was a soft linebreak inserted by the encoding.  We just toss this
away
                    // on decode.
                }
                else {

does not recognize the line ending and instead takes '=' + '\n' + {next char} and looks it
up as a QP byte (which just becomes 0x00 via decodingTable without any Exceptions).

I believe the code should be:

    else if (ch == '=') {

if (off >= endOffset) {

    throw new IOException("Invalid quoted printable encoding");

}
byte b1 = data[off++];
if (b1 == '\n') {

    // do nothing, this is a soft linebreak

} else {

    if (off >= endOffset) {

        throw new IOException("Invalid quoted printable encoding");

    }
    b2 = data[off++];
    out.write((b1 << 4) | b2);

            // 3 bytes in, one byte out

    bytesWritten++;

}

Thanks!


Fred


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message