You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2008/06/19 12:48:19 UTC

svn commit: r669445 - in /geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet: ContentDisposition.java ContentType.java InternetHeaders.java ParameterList.java

Author: rickmcguire
Date: Thu Jun 19 03:48:18 2008
New Revision: 669445

URL: http://svn.apache.org/viewvc?rev=669445&view=rev
Log:
GERONIMO-4127 Problems generating a new simple/basic mail (both from API and from InputStream)
GERONIMO-4128 geronimo javamail uses Message-Id instead of Message-ID

Fixes for multiple header problems uncovered by the James test suite. 


Modified:
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentDisposition.java
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentType.java
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/InternetHeaders.java
    geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ParameterList.java

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentDisposition.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentDisposition.java?rev=669445&r1=669444&r2=669445&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentDisposition.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentDisposition.java Thu Jun 19 03:48:18 2008
@@ -107,6 +107,6 @@
 
         // format this for use on a Content-Disposition header, which means we need to
         // account for the length of the header part too.
-        return _disposition + _list.toString(21 + _disposition.length());
+        return _disposition + _list.toString("Content-Disposition".length() + _disposition.length());
     }
 }

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentType.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentType.java?rev=669445&r1=669444&r2=669445&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentType.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ContentType.java Thu Jun 19 03:48:18 2008
@@ -116,8 +116,16 @@
         if (_major == null || _minor == null) {
             return null;
         }
-
-        return getBaseType() + (_list == null ? "" : _list.toString());
+        
+        // We need to format this as if we're doing it to set into the Content-Type
+        // header.  So the parameter list gets added on as if the header name was 
+        // also included. 
+        String baseType = getBaseType(); 
+        if (_list != null) {
+            baseType += _list.toString(baseType.length() + "Content-Type: ".length()); 
+        }
+        
+        return baseType;
     }
 
     public boolean match(ContentType other) {

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/InternetHeaders.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/InternetHeaders.java?rev=669445&r1=669444&r2=669445&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/InternetHeaders.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/InternetHeaders.java Thu Jun 19 03:48:18 2008
@@ -110,93 +110,81 @@
      */
     public void load(InputStream in) throws MessagingException {
         try {
-            StringBuffer name = new StringBuffer(32);
-            StringBuffer value = new StringBuffer(128);
-            boolean foundColon = false; 
-            done: while (true) {
-                int c = in.read();
-                char ch = (char) c;
-                if (c == -1) {
-                    break;
-                } else if (c == 13) {
-                    // empty line terminates header
-                    in.read(); // skip LF
-                    break;
-                } else if ( c == 10) {
-                	// Line feed terminates header
-                	break;
-                } else if (Character.isWhitespace(ch)) {
-                    // handle continuation
-                    do {
-                        c = in.read();
-                        if (c == -1) {
-                            break done;
-                        }
-                        ch = (char) c;
-                    } while (Character.isWhitespace(ch));
-                } else {
-                    // new header
-                    if (name.length() > 0) {
-                        if (foundColon) {
-                            addHeader(name.toString().trim(), value.toString().trim());
-                        }
-                        else {
-                            addHeader(name.toString().trim(), name.toString().trim());
-                        }
+            StringBuffer buffer = new StringBuffer(128); 
+            String line; 
+            // loop until we hit the end or a null line 
+            while ((line = readLine(in)) != null) {
+                // lines beginning with white space get special handling 
+                if (line.startsWith(" ") || line.startsWith("\t")) {
+                    // this gets handled using the logic defined by 
+                    // the addHeaderLine method.  If this line is a continuation, but 
+                    // there's nothing before it, just call addHeaderLine to add it 
+                    // to the last header in the headers list 
+                    if (buffer.length() == 0) {
+                        addHeaderLine(line); 
                     }
-                    name.setLength(0);
-                    value.setLength(0);
-                    foundColon = false; 
-                    while (true) {
-                        name.append((char) c);
-                        c = in.read();
-                        if (c == -1) {
-                            break done;
-                        } else if (c == ':') {
-                            foundColon = true; 
-                            break;
-                        } else if (c == 13 || c == 10) {
-                            break;
-                        }
-                    }
-                    // only read this if we found a separator 
-                    if (foundColon) {
-                        c = in.read();
-                        if (c == -1) {
-                            break done;
-                        }
+                    else {
+                        // preserve the line break and append the continuation 
+                        buffer.append("\r\n"); 
+                        buffer.append(line); 
                     }
                 }
-
-                while (c != 13 && c != 10) {
-                    ch = (char) c;
-                    value.append(ch);
-                    c = in.read();
-                    if (c == -1) {
-                        break done;
+                else {
+                    // if we have a line pending in the buffer, flush it 
+                    if (buffer.length() > 0) {
+                        addHeaderLine(buffer.toString()); 
+                        buffer.setLength(0); 
                     }
-                }
-                // skip LF
-                if (c == 13) {
-                	c = in.read();
-                }
-                
-                if (c == -1) {
-                    break;
+                    // add this to the accumulator 
+                    buffer.append(line); 
                 }
             }
-            if (name.length() > 0) {
-                if (foundColon) {
-                    addHeader(name.toString().trim(), value.toString().trim());
-                }
-                else {
-                    addHeader(name.toString().trim(), name.toString().trim());
-                }
+            
+            // if we have a line pending in the buffer, flush it 
+            if (buffer.length() > 0) {
+                addHeaderLine(buffer.toString()); 
             }
         } catch (IOException e) {
             throw new MessagingException("Error loading headers", e);
         }
     }
+    
+    
+    /**
+     * Read a single line from the input stream 
+     * 
+     * @param in     The source stream for the line
+     * 
+     * @return The string value of the line (without line separators)
+     */
+    private String readLine(InputStream in) throws IOException {
+        StringBuffer buffer = new StringBuffer(128); 
+        
+        int c; 
+        
+        while ((c = in.read()) != -1) {
+            // a linefeed is a terminator, always.  
+            if (c == '\n') {
+                break; 
+            }
+            // just ignore the CR.  The next character SHOULD be an NL.  If not, we're 
+            // just going to discard this 
+            else if (c == '\r') {
+                continue; 
+            }
+            else {
+                // just add to the buffer 
+                buffer.append((char)c); 
+            }
+        }
+        
+        // no characters found...this was either an eof or a null line. 
+        if (buffer.length() == 0) {
+            return null; 
+        }
+        
+        return buffer.toString(); 
+    }
 
 
     /**
@@ -277,8 +265,10 @@
             InternetHeader header = (InternetHeader)headers.get(i);
             // found a matching header
             if (name.equalsIgnoreCase(header.getName())) {
-                // just update the header value
+                // we update both the name and the value for a set so that 
+                // the header ends up with the same case as what is getting set
                 header.setValue(value);
+                header.setName(name); 
                 // remove all of the headers from this point
                 removeHeaders(name, i + 1);
                 return;
@@ -601,6 +591,15 @@
     }
 
 
+    /**
+     * Write out the set of headers, except for any 
+     * headers specified in the optional ignore list. 
+     * 
+     * @param out    The output stream.
+     * @param ignore The optional ignore list.
+     * 
+     * @exception IOException
+     */
     void writeTo(OutputStream out, String[] ignore) throws IOException {
         if (ignore == null) {
             // write out all header lines with non-null values
@@ -618,7 +617,7 @@
                 InternetHeader header = (InternetHeader)headers.get(i);
                 // we only include headers with real values, no placeholders
                 if (header.getValue() != null) {
-                    if (matchHeader(header.getName(), ignore)) {
+                    if (!matchHeader(header.getName(), ignore)) {
                         header.writeTo(out);
                     }
                 }
@@ -667,6 +666,16 @@
             this.value = value;
         }
 
+
+        /**
+         * Package scope method for setting the name value.
+         *
+         * @param name   The new header name   
+         */
+        void setName(String name) {
+            this.name = name;     
+        }
+
         /**
          * Package scope method for extending a header value.
          *

Modified: geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ParameterList.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ParameterList.java?rev=669445&r1=669444&r2=669445&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ParameterList.java (original)
+++ geronimo/specs/trunk/geronimo-javamail_1.4_spec/src/main/java/javax/mail/internet/ParameterList.java Thu Jun 19 03:48:18 2008
@@ -226,10 +226,11 @@
 
             // too big for the current header line?
             if ((used + name.length() + value.length() + 1) > HEADER_SIZE_LIMIT) {
-                // and a CRLF-whitespace combo.
-                stringValue.append("\r\n ");
+                // and a CRLF-combo combo.
+                stringValue.append("\r\n\t");
                 // reset the counter for a fresh line
-                used = 3;
+                // note we use use 8 because we're using a rather than a blank 
+                used = 8;
             }
             // now add the keyword/value pair.
             stringValue.append(name);