Show
Ignore:
Timestamp:
08/26/08 08:06:55 PM (4 months ago)
Author:
octorian
Message:

Fix for quoted-printable decoding errors (#98)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/LogicMail-1.0/LogicMail/src/org/logicprobe/LogicMail/util/StringParser.java

    r274 r277  
    732732                    break; 
    733733                } 
    734                 try { 
    735                     int charVal = Integer.parseInt(text.substring(index+1, index+3), 16); 
    736                     buffer.append((char)charVal); 
    737                 } catch (NumberFormatException exp) { } 
    738                 index += 3; 
     734                else { 
     735                    char ch1 = text.charAt(index+1); 
     736                    char ch2 = text.charAt(index+2); 
     737                    if(ch1 == '\r' && ch2 == '\n') { 
     738                        index += 3; 
     739                    } 
     740                    else if(ch1 == '\n') { 
     741                        index += 2; 
     742                    } 
     743                    else { 
     744                        try { 
     745                            int charVal = Integer.parseInt(text.substring(index+1, index+3), 16); 
     746                            buffer.append((char)charVal); 
     747                        } catch (NumberFormatException exp) { } 
     748                        index += 3; 
     749                    } 
     750                } 
    739751            } 
    740752            else { 
     
    753765        char ch; 
    754766        String charStr; 
    755         for(int i=0; i<text.length(); i++) { 
     767        int length = text.length(); 
     768        for(int i=0; i<length; i++) { 
    756769            ch = text.charAt(i); 
    757             if(ch < 128) { 
     770            if(ch != '\t' && ch != ' ' && ch < 128) { 
     771                if(buffer.length() == 75 && i < length - 1) { 
     772                    buffer.append("=\r\n"); 
     773                } 
    758774                buffer.append(ch); 
    759775            } 
    760776            else { 
    761                 charStr = Integer.toHexString((int)ch); 
     777                if(buffer.length() == 73 && i < length - 3) { 
     778                    buffer.append("=\r\n"); 
     779                } 
     780                charStr = Integer.toHexString((int)ch).toUpperCase(); 
    762781                buffer.append('='); 
    763782                if(charStr.length() == 1) { 
     
    767786            } 
    768787        } 
     788         
    769789        return buffer.toString(); 
    770790    }