commits@javamail.java.net

[mercurial:96] If mail.mime.parameters.strict=false, allow parameter values to start wi

From: <shannon_at_kenai.com>
Date: Tue, 9 Dec 2008 23:06:49 +0000 (GMT)

Repository: mercurial
Revision: 96
Author: Bill Shannon <bill.shannon_at_sun.com>
Date: 2008-12-09 22:52:52 UTC

Log Message:
-----------
If mail.mime.parameters.strict=false, allow parameter values to start
with
special characters. Also, trim trailing whitespace from parameter
values
that aren't quoted strings.

Modified Paths:
--------------
    doc/release/CHANGES.txt
    mail/src/main/java/javax/mail/internet/HeaderTokenizer.java
    mail/src/oldtest/java/javax/mail/internet/paramdatanostrict
    mail/src/oldtest/java/javax/mail/internet/paramtest.java

Diffs:
-----
diff -r 7d457a491607 -r 63ebf52122e9 doc/release/CHANGES.txt
--- a/doc/release/CHANGES.txt Wed Dec 03 17:05:34 2008 -0800
+++ b/doc/release/CHANGES.txt Tue Dec 09 14:52:52 2008 -0800
@@ -53,6 +53,7 @@
 <no id> avoid creating IMAPMessage objects until they're
actually needed
 <no id> IMAPStore.isConnected might return true even though not
connected
 <no id> add support for Message Delivery Notifications (RFC
3798) to dsn.jar
+<no id> if mail.mime.parameters.strict=false, param vals can
start with specials
 
 
                  CHANGES IN THE 1.4.1 RELEASE
diff -r 7d457a491607 -r 63ebf52122e9
mail/src/main/java/javax/mail/internet/HeaderTokenizer.java
--- a/mail/src/main/java/javax/mail/internet/HeaderTokenizer.java
Wed Dec 03 17:05:34 2008 -0800
+++ b/mail/src/main/java/javax/mail/internet/HeaderTokenizer.java
Tue Dec 09 14:52:52 2008 -0800
@@ -312,6 +312,11 @@
        
        // Check for SPECIAL or CTL
        if (c < 040 || c >= 0177 || delimiters.indexOf(c) >= 0) {
+ if (endOfAtom > 0 && c != endOfAtom) {
+ // not expecting a special character here,
+ // pretend it's a quoted string
+ return collectString(endOfAtom);
+ }
            currentPos++; // re-position currentPos
            char ch[] = new char[1];
            ch[0] = c;
@@ -356,8 +361,10 @@
                else
                    s = string.substring(start, currentPos-1);
 
- if (c != '"')
- currentPos--;
+ if (c != '"') { // not a real quoted string
+ s = trimWhiteSpace(s);
+ currentPos--; // back up before the eos char
+ }
 
                return new Token(Token.QUOTEDSTRING, s);
            }
@@ -375,6 +382,7 @@
            s = filterToken(string, start, currentPos);
        else
            s = string.substring(start, currentPos);
+ s = trimWhiteSpace(s);
        return new Token(Token.QUOTEDSTRING, s);
     }
 
@@ -386,6 +394,21 @@
                (c != '\t') && (c != '\r') && (c != '\n'))
                return currentPos;
        return Token.EOF;
+ }
+
+ // Trim SPACE, HT, CR and NL from end of string
+ private static String trimWhiteSpace(String s) {
+ char c;
+ int i;
+ for (i = s.length() - 1; i >= 0; i--) {
+ if (((c = s.charAt(i)) != ' ') &&
+ (c != '\t') && (c != '\r') && (c != '\n'))
+ break;
+ }
+ if (i <= 0)
+ return "";
+ else
+ return s.substring(0, i + 1);
     }
 
     /* Process escape sequences and embedded LWSPs from a comment or
diff -r 7d457a491607 -r 63ebf52122e9
mail/src/oldtest/java/javax/mail/internet/paramdatanostrict
--- a/mail/src/oldtest/java/javax/mail/internet/paramdatanostrict
Wed Dec 03 17:05:34 2008 -0800
+++ b/mail/src/oldtest/java/javax/mail/internet/paramdatanostrict
Tue Dec 09 14:52:52 2008 -0800
@@ -18,10 +18,37 @@
        creation-date=Tue, 22 Jul 2008 10:03:09 GMT
        filename=test1kb.file
        modification-date=Tue, 22 Jul 2008 10:03:24 GMT
+Comment: embedded whitespace
 Content-Type: text/plain; name=file name.txt
+Expect: 1
+ name=file name.txt
+Comment: trailing whitespace
+Content-Type: text/plain; name=file name.txt
+Expect: 1
+ name=file name.txt
+Comment: leading and trailing whitespace
+Content-Type: text/plain; name= file name.txt
+Expect: 1
+ name=file name.txt
+Comment: trailing newline
+Content-Type: text/plain; name=file name.txt
+ ;
 Expect: 1
        name=file name.txt
 Content-Type: text/plain; name=file name.txt ; time= now
 Expect: 2
- name=file name.txt
+ name=file name.txt
        time=now
+Content-Type: text/plain; name=file name.txt ;
+ time= now
+Expect: 2
+ name=file name.txt
+ time=now
+Content-Type: text/plain; name=file name.txt
+ ; time = now
+Expect: 2
+ name=file name.txt
+ time=now
+Content-Type: text/plain;
filename==?Windows-1251?B?8OXq4ujn6PL7IMjPLmRvYw?=
+Expect: 1
+ filename==?Windows-1251?B?8OXq4ujn6PL7IMjPLmRvYw?=
diff -r 7d457a491607 -r 63ebf52122e9
mail/src/oldtest/java/javax/mail/internet/paramtest.java
--- a/mail/src/oldtest/java/javax/mail/internet/paramtest.java Wed Dec
03 17:05:34 2008 -0800
+++ b/mail/src/oldtest/java/javax/mail/internet/paramtest.java Tue Dec
09 14:52:52 2008 -0800
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the
GNU
  * General Public License Version 2 only ("GPL") or the Common
Development
@@ -178,7 +178,7 @@
                        int nexpect = Integer.parseInt(s.substring(8));
                        expect = new String[nexpect];
                        for (i = 0; i < nexpect; i++)
- expect[i] = in.readLine().trim();
+ expect[i] = trim(in.readLine());
                    } catch (NumberFormatException e) {
                        try {
                            if (s.substring(8, 17).equals("Exception"))
{
@@ -210,6 +210,16 @@
            }
            header = s;
        }
+ }
+
+ /**
+ * Like String.trim, but only the left side.
+ */
+ public static String trim(String s) {
+ int i = 0;
+ while (i < s.length() && s.charAt(i) <= ' ')
+ i++;
+ return s.substring(i);
     }
 
     /**
@@ -376,7 +386,7 @@
                int nexpect = Integer.parseInt(s.substring(8));
                expect = new String[nexpect];
                for (int i = 0; i < nexpect; i++)
- expect[i] = in.readLine().trim();
+ expect[i] = trim(in.readLine());
            } catch (NumberFormatException e) {
                try {
                    if (s.substring(8, 17).equals("Exception")) {