james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r778457 [5/13] - in /james/mime4j/trunk: benchmark/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/ core/src/main/java/org/apache/james/mime4j/codec/ core/src/main/java/org/apache/james/mime4j/descriptor/ c...
Date Mon, 25 May 2009 17:20:52 GMT
Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/parser/BaseNode.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/parser/BaseNode.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/parser/BaseNode.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/parser/BaseNode.java Mon May 25 17:20:48 2009
@@ -1,28 +1,28 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.field.address.parser;
-
-
-public abstract class BaseNode implements Node {
-  
-  public Token firstToken;
-  public Token lastToken;
-
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.field.address.parser;
+
+
+public abstract class BaseNode implements Node {
+  
+  public Token firstToken;
+  public Token lastToken;
+
 }
\ No newline at end of file

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/address/parser/BaseNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java Mon May 25 17:20:48 2009
@@ -1,165 +1,165 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.field.datetime;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-public class DateTime {
-    private final Date date;
-    private final int year;
-    private final int month;
-    private final int day;
-    private final int hour;
-    private final int minute;
-    private final int second;
-    private final int timeZone;
-
-    public DateTime(String yearString, int month, int day, int hour, int minute, int second, int timeZone) {
-        this.year = convertToYear(yearString);
-        this.date = convertToDate(year, month, day, hour, minute, second, timeZone);
-        this.month = month;
-        this.day = day;
-        this.hour = hour;
-        this.minute = minute;
-        this.second = second;
-        this.timeZone = timeZone;
-    }
-
-    private int convertToYear(String yearString) {
-        int year = Integer.parseInt(yearString);
-        switch (yearString.length()) {
-            case 1:
-            case 2:
-                if (year >= 0 && year < 50)
-                    return 2000 + year;
-                else
-                    return 1900 + year;
-            case 3:
-                return 1900 + year;
-            default:
-                return year;
-        }
-    }
-
-    public static Date convertToDate(int year, int month, int day, int hour, int minute, int second, int timeZone) {
-        Calendar c = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));
-        c.set(year, month - 1, day, hour, minute, second);
-        c.set(Calendar.MILLISECOND, 0);
-
-        if (timeZone != Integer.MIN_VALUE) {
-            int minutes = ((timeZone / 100) * 60) + timeZone % 100;
-            c.add(Calendar.MINUTE, -1 * minutes);
-        }
-
-        return c.getTime();
-    }
-
-    public Date getDate() {
-        return date;
-    }
-
-    public int getYear() {
-        return year;
-    }
-
-    public int getMonth() {
-        return month;
-    }
-
-    public int getDay() {
-        return day;
-    }
-
-    public int getHour() {
-        return hour;
-    }
-
-    public int getMinute() {
-        return minute;
-    }
-
-    public int getSecond() {
-        return second;
-    }
-
-    public int getTimeZone() {
-        return timeZone;
-    }
-
-    public void print() {
-        System.out.println(toString());
-    }
-
-    @Override
-    public String toString() {
-        return getYear() + " " + getMonth() + " " + getDay() + "; " + getHour() + " " + getMinute() + " " + getSecond() + " " + getTimeZone();
-    }
-
-    @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ((date == null) ? 0 : date.hashCode());
-        result = PRIME * result + day;
-        result = PRIME * result + hour;
-        result = PRIME * result + minute;
-        result = PRIME * result + month;
-        result = PRIME * result + second;
-        result = PRIME * result + timeZone;
-        result = PRIME * result + year;
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final DateTime other = (DateTime) obj;
-        if (date == null) {
-            if (other.date != null)
-                return false;
-        } else if (!date.equals(other.date))
-            return false;
-        if (day != other.day)
-            return false;
-        if (hour != other.hour)
-            return false;
-        if (minute != other.minute)
-            return false;
-        if (month != other.month)
-            return false;
-        if (second != other.second)
-            return false;
-        if (timeZone != other.timeZone)
-            return false;
-        if (year != other.year)
-            return false;
-        return true;
-    }
-
-    
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.field.datetime;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+public class DateTime {
+    private final Date date;
+    private final int year;
+    private final int month;
+    private final int day;
+    private final int hour;
+    private final int minute;
+    private final int second;
+    private final int timeZone;
+
+    public DateTime(String yearString, int month, int day, int hour, int minute, int second, int timeZone) {
+        this.year = convertToYear(yearString);
+        this.date = convertToDate(year, month, day, hour, minute, second, timeZone);
+        this.month = month;
+        this.day = day;
+        this.hour = hour;
+        this.minute = minute;
+        this.second = second;
+        this.timeZone = timeZone;
+    }
+
+    private int convertToYear(String yearString) {
+        int year = Integer.parseInt(yearString);
+        switch (yearString.length()) {
+            case 1:
+            case 2:
+                if (year >= 0 && year < 50)
+                    return 2000 + year;
+                else
+                    return 1900 + year;
+            case 3:
+                return 1900 + year;
+            default:
+                return year;
+        }
+    }
+
+    public static Date convertToDate(int year, int month, int day, int hour, int minute, int second, int timeZone) {
+        Calendar c = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));
+        c.set(year, month - 1, day, hour, minute, second);
+        c.set(Calendar.MILLISECOND, 0);
+
+        if (timeZone != Integer.MIN_VALUE) {
+            int minutes = ((timeZone / 100) * 60) + timeZone % 100;
+            c.add(Calendar.MINUTE, -1 * minutes);
+        }
+
+        return c.getTime();
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public int getYear() {
+        return year;
+    }
+
+    public int getMonth() {
+        return month;
+    }
+
+    public int getDay() {
+        return day;
+    }
+
+    public int getHour() {
+        return hour;
+    }
+
+    public int getMinute() {
+        return minute;
+    }
+
+    public int getSecond() {
+        return second;
+    }
+
+    public int getTimeZone() {
+        return timeZone;
+    }
+
+    public void print() {
+        System.out.println(toString());
+    }
+
+    @Override
+    public String toString() {
+        return getYear() + " " + getMonth() + " " + getDay() + "; " + getHour() + " " + getMinute() + " " + getSecond() + " " + getTimeZone();
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((date == null) ? 0 : date.hashCode());
+        result = PRIME * result + day;
+        result = PRIME * result + hour;
+        result = PRIME * result + minute;
+        result = PRIME * result + month;
+        result = PRIME * result + second;
+        result = PRIME * result + timeZone;
+        result = PRIME * result + year;
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final DateTime other = (DateTime) obj;
+        if (date == null) {
+            if (other.date != null)
+                return false;
+        } else if (!date.equals(other.date))
+            return false;
+        if (day != other.day)
+            return false;
+        if (hour != other.hour)
+            return false;
+        if (minute != other.minute)
+            return false;
+        if (month != other.month)
+            return false;
+        if (second != other.second)
+            return false;
+        if (timeZone != other.timeZone)
+            return false;
+        if (year != other.year)
+            return false;
+        return true;
+    }
+
+    
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/BufferedLineReaderInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/EOLConvertingInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/EOLConvertingInputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/EOLConvertingInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/EOLConvertingInputStream.java Mon May 25 17:20:48 2009
@@ -1,107 +1,107 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.io;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-
-/**
- * InputStream which converts <code>\r</code>
- * bytes not followed by <code>\n</code> and <code>\n</code> not 
- * preceded by <code>\r</code> to <code>\r\n</code>.
- */
-public class EOLConvertingInputStream extends InputStream {
-    /** Converts single '\r' to '\r\n' */
-    public static final int CONVERT_CR   = 1;
-    /** Converts single '\n' to '\r\n' */
-    public static final int CONVERT_LF   = 2;
-    /** Converts single '\r' and '\n' to '\r\n' */
-    public static final int CONVERT_BOTH = 3;
-    
-    private PushbackInputStream in = null;
-    private int previous = 0;
-    private int flags = CONVERT_BOTH;
-    
-    /**
-     * Creates a new <code>EOLConvertingInputStream</code>
-     * instance converting bytes in the given <code>InputStream</code>.
-     * The flag <code>CONVERT_BOTH</code> is the default.
-     * 
-     * @param in the <code>InputStream</code> to read from.
-     */
-    public EOLConvertingInputStream(InputStream in) {
-        this(in, CONVERT_BOTH);
-    }
-    /**
-     * Creates a new <code>EOLConvertingInputStream</code>
-     * instance converting bytes in the given <code>InputStream</code>.
-     * 
-     * @param in the <code>InputStream</code> to read from.
-     * @param flags one of <code>CONVERT_CR</code>, <code>CONVERT_LF</code> or
-     *        <code>CONVERT_BOTH</code>.
-     */
-    public EOLConvertingInputStream(InputStream in, int flags) {
-        super();
-        
-        this.in = new PushbackInputStream(in, 2);
-        this.flags = flags;
-    }
-
-    /**
-     * Closes the underlying stream.
-     * 
-     * @throws IOException on I/O errors.
-     */
-    @Override
-    public void close() throws IOException {
-        in.close();
-    }
-    
-    /**
-     * @see java.io.InputStream#read()
-     */
-    @Override
-    public int read() throws IOException {
-        int b = in.read();
-        
-        if (b == -1) {
-            return -1;
-        }
-        
-        if ((flags & CONVERT_CR) != 0 && b == '\r') {
-            int c = in.read();
-            if (c != -1) {
-                in.unread(c);
-            }
-            if (c != '\n') {
-                in.unread('\n');
-            }
-        } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') {
-            b = '\r';
-            in.unread('\n');
-        }
-        
-        previous = b;
-        
-        return b;
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+
+/**
+ * InputStream which converts <code>\r</code>
+ * bytes not followed by <code>\n</code> and <code>\n</code> not 
+ * preceded by <code>\r</code> to <code>\r\n</code>.
+ */
+public class EOLConvertingInputStream extends InputStream {
+    /** Converts single '\r' to '\r\n' */
+    public static final int CONVERT_CR   = 1;
+    /** Converts single '\n' to '\r\n' */
+    public static final int CONVERT_LF   = 2;
+    /** Converts single '\r' and '\n' to '\r\n' */
+    public static final int CONVERT_BOTH = 3;
+    
+    private PushbackInputStream in = null;
+    private int previous = 0;
+    private int flags = CONVERT_BOTH;
+    
+    /**
+     * Creates a new <code>EOLConvertingInputStream</code>
+     * instance converting bytes in the given <code>InputStream</code>.
+     * The flag <code>CONVERT_BOTH</code> is the default.
+     * 
+     * @param in the <code>InputStream</code> to read from.
+     */
+    public EOLConvertingInputStream(InputStream in) {
+        this(in, CONVERT_BOTH);
+    }
+    /**
+     * Creates a new <code>EOLConvertingInputStream</code>
+     * instance converting bytes in the given <code>InputStream</code>.
+     * 
+     * @param in the <code>InputStream</code> to read from.
+     * @param flags one of <code>CONVERT_CR</code>, <code>CONVERT_LF</code> or
+     *        <code>CONVERT_BOTH</code>.
+     */
+    public EOLConvertingInputStream(InputStream in, int flags) {
+        super();
+        
+        this.in = new PushbackInputStream(in, 2);
+        this.flags = flags;
+    }
+
+    /**
+     * Closes the underlying stream.
+     * 
+     * @throws IOException on I/O errors.
+     */
+    @Override
+    public void close() throws IOException {
+        in.close();
+    }
+    
+    /**
+     * @see java.io.InputStream#read()
+     */
+    @Override
+    public int read() throws IOException {
+        int b = in.read();
+        
+        if (b == -1) {
+            return -1;
+        }
+        
+        if ((flags & CONVERT_CR) != 0 && b == '\r') {
+            int c = in.read();
+            if (c != -1) {
+                in.unread(c);
+            }
+            if (c != '\n') {
+                in.unread('\n');
+            }
+        } else if ((flags & CONVERT_LF) != 0 && b == '\n' && previous != '\r') {
+            b = '\r';
+            in.unread('\n');
+        }
+        
+        previous = b;
+        
+        return b;
+    }
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/EOLConvertingInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberInputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberInputStream.java Mon May 25 17:20:48 2009
@@ -1,67 +1,67 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.io;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * <code>InputStream</code> used by the parser to wrap the original user
- * supplied stream. This stream keeps track of the current line number.
- */
-public class LineNumberInputStream extends FilterInputStream implements
-        LineNumberSource {
-    private int lineNumber = 1;
-
-    /**
-     * Creates a new <code>LineNumberInputStream</code>.
-     * 
-     * @param is
-     *            the stream to read from.
-     */
-    public LineNumberInputStream(InputStream is) {
-        super(is);
-    }
-
-    public int getLineNumber() {
-        return lineNumber;
-    }
-
-    @Override
-    public int read() throws IOException {
-        int b = in.read();
-        if (b == '\n') {
-            lineNumber++;
-        }
-        return b;
-    }
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        int n = in.read(b, off, len);
-        for (int i = off; i < off + n; i++) {
-            if (b[i] == '\n') {
-                lineNumber++;
-            }
-        }
-        return n;
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.io;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <code>InputStream</code> used by the parser to wrap the original user
+ * supplied stream. This stream keeps track of the current line number.
+ */
+public class LineNumberInputStream extends FilterInputStream implements
+        LineNumberSource {
+    private int lineNumber = 1;
+
+    /**
+     * Creates a new <code>LineNumberInputStream</code>.
+     * 
+     * @param is
+     *            the stream to read from.
+     */
+    public LineNumberInputStream(InputStream is) {
+        super(is);
+    }
+
+    public int getLineNumber() {
+        return lineNumber;
+    }
+
+    @Override
+    public int read() throws IOException {
+        int b = in.read();
+        if (b == '\n') {
+            lineNumber++;
+        }
+        return b;
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        int n = in.read(b, off, len);
+        for (int i = off; i < off + n; i++) {
+            if (b[i] == '\n') {
+                lineNumber++;
+            }
+        }
+        return n;
+    }
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberSource.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberSource.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberSource.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberSource.java Mon May 25 17:20:48 2009
@@ -1,30 +1,30 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.io;
-
-public interface LineNumberSource {
-    /**
-     * Gets the current line number starting at 1 (the number of
-     * <code>\r\n</code> read so far plus 1).
-     * 
-     * @return the current line number.
-     */
-    int getLineNumber();
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.io;
+
+public interface LineNumberSource {
+    /**
+     * Gets the current line number starting at 1 (the number of
+     * <code>\r\n</code> read so far plus 1).
+     * 
+     * @return the current line number.
+     */
+    int getLineNumber();
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineNumberSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java Mon May 25 17:20:48 2009
@@ -1,48 +1,48 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.io;
-
-import org.apache.james.mime4j.util.ByteArrayBuffer;
-
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Input stream capable of reading lines of text. 
- */
-public abstract class LineReaderInputStream extends FilterInputStream {
-
-    protected LineReaderInputStream(InputStream in) {
-        super(in);
-    }
-
-    /**
-     * Reads one line of text into the given {@link ByteArrayBuffer}.
-     *  
-     * @param dst Destination
-     * @return number of bytes copied or <code>-1</code> if the end of 
-     * the stream has been reached.
-     * 
-     * @throws IOException in case of an I/O error.
-     */
-    public abstract int readLine(final ByteArrayBuffer dst) throws IOException;
-    
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.io;
+
+import org.apache.james.mime4j.util.ByteArrayBuffer;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Input stream capable of reading lines of text. 
+ */
+public abstract class LineReaderInputStream extends FilterInputStream {
+
+    protected LineReaderInputStream(InputStream in) {
+        super(in);
+    }
+
+    /**
+     * Reads one line of text into the given {@link ByteArrayBuffer}.
+     *  
+     * @param dst Destination
+     * @return number of bytes copied or <code>-1</code> if the end of 
+     * the stream has been reached.
+     * 
+     * @throws IOException in case of an I/O error.
+     */
+    public abstract int readLine(final ByteArrayBuffer dst) throws IOException;
+    
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/LineReaderInputStreamAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java Mon May 25 17:20:48 2009
@@ -1,298 +1,298 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.io;
-
-import org.apache.james.mime4j.util.ByteArrayBuffer;
-
-import java.io.IOException;
-
-/**
- * Stream that constrains itself to a single MIME body part.
- * After the stream ends (i.e. read() returns -1) {@link #isLastPart()}
- * can be used to determine if a final boundary has been seen or not.
- */
-public class MimeBoundaryInputStream extends LineReaderInputStream {
-
-    private final byte[] boundary;
-    
-    private boolean eof;
-    private int limit;
-    private boolean atBoundary;
-    private int boundaryLen;
-    private boolean lastPart;
-    private boolean completed;
-
-    private BufferedLineReaderInputStream buffer;
-
-    /**
-     * Creates a new MimeBoundaryInputStream.
-     * 
-     * @param inbuffer The underlying stream.
-     * @param boundary Boundary string (not including leading hyphens).
-     * @throws IllegalArgumentException when boundary is too long
-     */
-    public MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, String boundary) 
-            throws IOException {
-        super(inbuffer);
-        if (inbuffer.capacity() <= boundary.length()) {
-            throw new IllegalArgumentException("Boundary is too long");
-        }
-        this.buffer = inbuffer;
-        this.eof = false;
-        this.limit = -1;
-        this.atBoundary = false;
-        this.boundaryLen = 0;
-        this.lastPart = false;
-        this.completed = false;
-        
-        this.boundary = new byte[boundary.length() + 2];
-        this.boundary[0] = (byte) '-';
-        this.boundary[1] = (byte) '-';
-        for (int i = 0; i < boundary.length(); i++) {
-            byte ch = (byte) boundary.charAt(i);
-            if (ch == '\r' || ch == '\n') {
-                throw new IllegalArgumentException("Boundary may not contain CR or LF");
-            }
-            this.boundary[i + 2] = ch;
-        }
-        fillBuffer();
-    }
-
-    /**
-     * Closes the underlying stream.
-     * 
-     * @throws IOException on I/O errors.
-     */
-    @Override
-    public void close() throws IOException {
-    }
-
-    /**
-     * @see java.io.InputStream#markSupported()
-     */
-    @Override
-    public boolean markSupported() {
-        return false;
-    }
-
-    /**
-     * @see java.io.InputStream#read()
-     */
-    @Override
-    public int read() throws IOException {
-        if (completed) {
-            return -1;
-        }
-        if (endOfStream() && !hasData()) {
-            skipBoundary();            
-            return -1;
-        }
-        for (;;) {
-            if (hasData()) {
-                return buffer.read();
-            } else if (endOfStream()) {
-                skipBoundary();            
-                return -1;
-            }
-            fillBuffer();
-        }
-    }
-    
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        if (completed) {
-            return -1;
-        }
-        if (endOfStream() && !hasData()) {
-            skipBoundary();            
-            return -1;
-        }
-        fillBuffer();
-        if (!hasData()) {
-            return read(b, off, len);
-        }
-        int chunk = Math.min(len, limit - buffer.pos());
-        return buffer.read(b, off, chunk);
-    }
-
-    @Override
-    public int readLine(final ByteArrayBuffer dst) throws IOException {
-        if (dst == null) {
-            throw new IllegalArgumentException("Destination buffer may not be null");
-        }
-        if (completed) {
-            return -1;
-        }
-        if (endOfStream() && !hasData()) {
-            skipBoundary();            
-            return -1;
-        }
-
-        int total = 0;
-        boolean found = false;
-        int bytesRead = 0;
-        while (!found) {
-            if (!hasData()) {
-                bytesRead = fillBuffer();
-                if (!hasData() && endOfStream()) {
-                    skipBoundary();
-                    bytesRead = -1;
-                    break;
-                }
-            }
-            int len = this.limit - this.buffer.pos();
-            int i = this.buffer.indexOf((byte)'\n', this.buffer.pos(), len);
-            int chunk;
-            if (i != -1) {
-                found = true;
-                chunk = i + 1 - this.buffer.pos();
-            } else {
-                chunk = len;
-            }
-            if (chunk > 0) {
-                dst.append(this.buffer.buf(), this.buffer.pos(), chunk);
-                this.buffer.skip(chunk);
-                total += chunk;
-            }
-        }
-        if (total == 0 && bytesRead == -1) {
-            return -1;
-        } else {
-            return total;
-        }
-    }
-    
-    private boolean endOfStream() {
-        return eof || atBoundary;
-    }
-    
-    private boolean hasData() {
-        return limit > buffer.pos() && limit <= buffer.limit();
-    }
-    
-    private int fillBuffer() throws IOException {
-        if (eof) {
-            return -1;
-        }
-        int bytesRead;
-        if (!hasData()) {
-            bytesRead = buffer.fillBuffer();
-        } else {
-            bytesRead = 0;
-        }
-        eof = bytesRead == -1;
-        
-        
-        int i = buffer.indexOf(boundary);
-        // NOTE this currently check only for LF. It doesn't check for canonical CRLF
-        // and neither for isolated CR. This will require updates according to MIME4J-60
-        while (i > 0 && buffer.charAt(i-1) != '\n') {
-            // skip the "fake" boundary (it does not contain LF or CR so we cannot have
-            // another boundary starting before this is complete.
-            i = i + boundary.length;
-            i = buffer.indexOf(boundary, i, buffer.limit() - i);
-        }
-        if (i != -1) {
-            limit = i;
-            atBoundary = true;
-            calculateBoundaryLen();
-        } else {
-            if (eof) {
-                limit = buffer.limit();
-            } else {
-                limit = buffer.limit() - (boundary.length + 1); 
-                                          // \r\n + (boundary - one char)
-            }
-        }
-        return bytesRead;
-    }
-    
-    private void calculateBoundaryLen() throws IOException {
-        boundaryLen = boundary.length;
-        int len = limit - buffer.pos();
-        if (len > 0) {
-            if (buffer.charAt(limit - 1) == '\n') {
-                boundaryLen++;
-                limit--;
-            }
-        }
-        if (len > 1) {
-            if (buffer.charAt(limit - 1) == '\r') {
-                boundaryLen++;
-                limit--;
-            }
-        }
-    }
-    
-    private void skipBoundary() throws IOException {
-        if (!completed) {
-            completed = true;
-            buffer.skip(boundaryLen);
-            boolean checkForLastPart = true;
-            for (;;) {
-                if (buffer.length() > 1) {
-                    int ch1 = buffer.charAt(buffer.pos());
-                    int ch2 = buffer.charAt(buffer.pos() + 1);
-                    
-                    if (checkForLastPart) if (ch1 == '-' && ch2 == '-') {
-                        this.lastPart = true;
-                        buffer.skip(2);
-                        checkForLastPart = false;
-                        continue;
-                    }
-                    
-                    if (ch1 == '\r' && ch2 == '\n') {
-                        buffer.skip(2);
-                        break;
-                    } else if (ch1 == '\n') {
-                        buffer.skip(1);
-                        break;
-                    } else {
-                        // ignoring everything in a line starting with a boundary.
-                        buffer.skip(1);
-                    }
-                    
-                } else {
-                    if (eof) {
-                        break;
-                    }
-                    fillBuffer();
-                }
-            }
-        }
-    }
-    
-    public boolean isLastPart() {
-        return lastPart;        
-    }
-    
-    public boolean eof() {
-        return eof && !buffer.hasBufferedData();
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder buffer = new StringBuilder("MimeBoundaryInputStream, boundary ");
-        for (byte b : boundary) {
-            buffer.append((char) b);
-        }
-        return buffer.toString();
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.io;
+
+import org.apache.james.mime4j.util.ByteArrayBuffer;
+
+import java.io.IOException;
+
+/**
+ * Stream that constrains itself to a single MIME body part.
+ * After the stream ends (i.e. read() returns -1) {@link #isLastPart()}
+ * can be used to determine if a final boundary has been seen or not.
+ */
+public class MimeBoundaryInputStream extends LineReaderInputStream {
+
+    private final byte[] boundary;
+    
+    private boolean eof;
+    private int limit;
+    private boolean atBoundary;
+    private int boundaryLen;
+    private boolean lastPart;
+    private boolean completed;
+
+    private BufferedLineReaderInputStream buffer;
+
+    /**
+     * Creates a new MimeBoundaryInputStream.
+     * 
+     * @param inbuffer The underlying stream.
+     * @param boundary Boundary string (not including leading hyphens).
+     * @throws IllegalArgumentException when boundary is too long
+     */
+    public MimeBoundaryInputStream(BufferedLineReaderInputStream inbuffer, String boundary) 
+            throws IOException {
+        super(inbuffer);
+        if (inbuffer.capacity() <= boundary.length()) {
+            throw new IllegalArgumentException("Boundary is too long");
+        }
+        this.buffer = inbuffer;
+        this.eof = false;
+        this.limit = -1;
+        this.atBoundary = false;
+        this.boundaryLen = 0;
+        this.lastPart = false;
+        this.completed = false;
+        
+        this.boundary = new byte[boundary.length() + 2];
+        this.boundary[0] = (byte) '-';
+        this.boundary[1] = (byte) '-';
+        for (int i = 0; i < boundary.length(); i++) {
+            byte ch = (byte) boundary.charAt(i);
+            if (ch == '\r' || ch == '\n') {
+                throw new IllegalArgumentException("Boundary may not contain CR or LF");
+            }
+            this.boundary[i + 2] = ch;
+        }
+        fillBuffer();
+    }
+
+    /**
+     * Closes the underlying stream.
+     * 
+     * @throws IOException on I/O errors.
+     */
+    @Override
+    public void close() throws IOException {
+    }
+
+    /**
+     * @see java.io.InputStream#markSupported()
+     */
+    @Override
+    public boolean markSupported() {
+        return false;
+    }
+
+    /**
+     * @see java.io.InputStream#read()
+     */
+    @Override
+    public int read() throws IOException {
+        if (completed) {
+            return -1;
+        }
+        if (endOfStream() && !hasData()) {
+            skipBoundary();            
+            return -1;
+        }
+        for (;;) {
+            if (hasData()) {
+                return buffer.read();
+            } else if (endOfStream()) {
+                skipBoundary();            
+                return -1;
+            }
+            fillBuffer();
+        }
+    }
+    
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        if (completed) {
+            return -1;
+        }
+        if (endOfStream() && !hasData()) {
+            skipBoundary();            
+            return -1;
+        }
+        fillBuffer();
+        if (!hasData()) {
+            return read(b, off, len);
+        }
+        int chunk = Math.min(len, limit - buffer.pos());
+        return buffer.read(b, off, chunk);
+    }
+
+    @Override
+    public int readLine(final ByteArrayBuffer dst) throws IOException {
+        if (dst == null) {
+            throw new IllegalArgumentException("Destination buffer may not be null");
+        }
+        if (completed) {
+            return -1;
+        }
+        if (endOfStream() && !hasData()) {
+            skipBoundary();            
+            return -1;
+        }
+
+        int total = 0;
+        boolean found = false;
+        int bytesRead = 0;
+        while (!found) {
+            if (!hasData()) {
+                bytesRead = fillBuffer();
+                if (!hasData() && endOfStream()) {
+                    skipBoundary();
+                    bytesRead = -1;
+                    break;
+                }
+            }
+            int len = this.limit - this.buffer.pos();
+            int i = this.buffer.indexOf((byte)'\n', this.buffer.pos(), len);
+            int chunk;
+            if (i != -1) {
+                found = true;
+                chunk = i + 1 - this.buffer.pos();
+            } else {
+                chunk = len;
+            }
+            if (chunk > 0) {
+                dst.append(this.buffer.buf(), this.buffer.pos(), chunk);
+                this.buffer.skip(chunk);
+                total += chunk;
+            }
+        }
+        if (total == 0 && bytesRead == -1) {
+            return -1;
+        } else {
+            return total;
+        }
+    }
+    
+    private boolean endOfStream() {
+        return eof || atBoundary;
+    }
+    
+    private boolean hasData() {
+        return limit > buffer.pos() && limit <= buffer.limit();
+    }
+    
+    private int fillBuffer() throws IOException {
+        if (eof) {
+            return -1;
+        }
+        int bytesRead;
+        if (!hasData()) {
+            bytesRead = buffer.fillBuffer();
+        } else {
+            bytesRead = 0;
+        }
+        eof = bytesRead == -1;
+        
+        
+        int i = buffer.indexOf(boundary);
+        // NOTE this currently check only for LF. It doesn't check for canonical CRLF
+        // and neither for isolated CR. This will require updates according to MIME4J-60
+        while (i > 0 && buffer.charAt(i-1) != '\n') {
+            // skip the "fake" boundary (it does not contain LF or CR so we cannot have
+            // another boundary starting before this is complete.
+            i = i + boundary.length;
+            i = buffer.indexOf(boundary, i, buffer.limit() - i);
+        }
+        if (i != -1) {
+            limit = i;
+            atBoundary = true;
+            calculateBoundaryLen();
+        } else {
+            if (eof) {
+                limit = buffer.limit();
+            } else {
+                limit = buffer.limit() - (boundary.length + 1); 
+                                          // \r\n + (boundary - one char)
+            }
+        }
+        return bytesRead;
+    }
+    
+    private void calculateBoundaryLen() throws IOException {
+        boundaryLen = boundary.length;
+        int len = limit - buffer.pos();
+        if (len > 0) {
+            if (buffer.charAt(limit - 1) == '\n') {
+                boundaryLen++;
+                limit--;
+            }
+        }
+        if (len > 1) {
+            if (buffer.charAt(limit - 1) == '\r') {
+                boundaryLen++;
+                limit--;
+            }
+        }
+    }
+    
+    private void skipBoundary() throws IOException {
+        if (!completed) {
+            completed = true;
+            buffer.skip(boundaryLen);
+            boolean checkForLastPart = true;
+            for (;;) {
+                if (buffer.length() > 1) {
+                    int ch1 = buffer.charAt(buffer.pos());
+                    int ch2 = buffer.charAt(buffer.pos() + 1);
+                    
+                    if (checkForLastPart) if (ch1 == '-' && ch2 == '-') {
+                        this.lastPart = true;
+                        buffer.skip(2);
+                        checkForLastPart = false;
+                        continue;
+                    }
+                    
+                    if (ch1 == '\r' && ch2 == '\n') {
+                        buffer.skip(2);
+                        break;
+                    } else if (ch1 == '\n') {
+                        buffer.skip(1);
+                        break;
+                    } else {
+                        // ignoring everything in a line starting with a boundary.
+                        buffer.skip(1);
+                    }
+                    
+                } else {
+                    if (eof) {
+                        break;
+                    }
+                    fillBuffer();
+                }
+            }
+        }
+    }
+    
+    public boolean isLastPart() {
+        return lastPart;        
+    }
+    
+    public boolean eof() {
+        return eof && !buffer.hasBufferedData();
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder("MimeBoundaryInputStream, boundary ");
+        for (byte b : boundary) {
+            buffer.append((char) b);
+        }
+        return buffer.toString();
+    }
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/PositionInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/PositionInputStream.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/PositionInputStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/PositionInputStream.java Mon May 25 17:20:48 2009
@@ -1,91 +1,91 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-
-package org.apache.james.mime4j.io;
-
-import java.io.FilterInputStream;
-import java.io.InputStream;
-import java.io.IOException;
-
-public class PositionInputStream extends FilterInputStream {
-
-    protected long position = 0;
-    private long markedPosition = 0;
-
-    public PositionInputStream(InputStream inputStream) {
-        super(inputStream);
-    }
-
-    public long getPosition() {
-        return position;
-    }
-
-    @Override
-    public int available() throws IOException {
-        return in.available();
-    }
-
-    @Override
-    public int read() throws IOException {
-        int b = in.read();
-        if (b != -1)
-            position++;
-        return b;
-    }
-
-    @Override
-    public void close() throws IOException {
-        in.close();
-    }
-
-    @Override
-    public void reset() throws IOException {
-        in.reset();
-        position = markedPosition;
-    }
-
-    @Override
-    public boolean markSupported() {
-        return in.markSupported();
-    }
-
-    @Override
-    public void mark(int readlimit) {
-        in.mark(readlimit);
-        markedPosition = position;
-    }
-
-    @Override
-    public long skip(long n) throws IOException {
-        final long c = in.skip(n);
-        if (c > 0) 
-            position += c;
-        return c;
-    }
-
-    @Override
-    public int read(byte b[], int off, int len) throws IOException {
-        final int c = in.read(b, off, len);
-        if (c > 0) 
-            position += c;
-        return c;
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.mime4j.io;
+
+import java.io.FilterInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+public class PositionInputStream extends FilterInputStream {
+
+    protected long position = 0;
+    private long markedPosition = 0;
+
+    public PositionInputStream(InputStream inputStream) {
+        super(inputStream);
+    }
+
+    public long getPosition() {
+        return position;
+    }
+
+    @Override
+    public int available() throws IOException {
+        return in.available();
+    }
+
+    @Override
+    public int read() throws IOException {
+        int b = in.read();
+        if (b != -1)
+            position++;
+        return b;
+    }
+
+    @Override
+    public void close() throws IOException {
+        in.close();
+    }
+
+    @Override
+    public void reset() throws IOException {
+        in.reset();
+        position = markedPosition;
+    }
+
+    @Override
+    public boolean markSupported() {
+        return in.markSupported();
+    }
+
+    @Override
+    public void mark(int readlimit) {
+        in.mark(readlimit);
+        markedPosition = position;
+    }
+
+    @Override
+    public long skip(long n) throws IOException {
+        final long c = in.skip(n);
+        if (c > 0) 
+            position += c;
+        return c;
+    }
+
+    @Override
+    public int read(byte b[], int off, int len) throws IOException {
+        final int c = in.read(b, off, len);
+        if (c > 0) 
+            position += c;
+        return c;
+    }
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/PositionInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java Mon May 25 17:20:48 2009
@@ -1,33 +1,33 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.message;
-
-/**
- * A body containing binary data.
- */
-public abstract class BinaryBody extends SingleBody {
-
-    /**
-     * Sole constructor.
-     */
-    protected BinaryBody() {
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+/**
+ * A body containing binary data.
+ */
+public abstract class BinaryBody extends SingleBody {
+
+    /**
+     * Sole constructor.
+     */
+    protected BinaryBody() {
+    }
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BinaryBody.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Body.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Body.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Body.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Body.java Mon May 25 17:20:48 2009
@@ -1,46 +1,46 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.message;
-
-/**
- * Encapsulates the body of an entity (see RFC 2045).
- * <p>
- * A body can be a {@link Message}, a {@link Multipart} or a {@link SingleBody}.
- * This interface should not be implemented directly by classes other than
- * those.
- */
-public interface Body extends Disposable {
-
-    /**
-     * Gets the parent of this body.
-     * 
-     * @return the parent.
-     */
-    Entity getParent();
-
-    /**
-     * Sets the parent of this body.
-     * 
-     * @param parent
-     *            the parent.
-     */
-    void setParent(Entity parent);
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+/**
+ * Encapsulates the body of an entity (see RFC 2045).
+ * <p>
+ * A body can be a {@link Message}, a {@link Multipart} or a {@link SingleBody}.
+ * This interface should not be implemented directly by classes other than
+ * those.
+ */
+public interface Body extends Disposable {
+
+    /**
+     * Gets the parent of this body.
+     * 
+     * @return the parent.
+     */
+    Entity getParent();
+
+    /**
+     * Sets the parent of this body.
+     * 
+     * @param parent
+     *            the parent.
+     */
+    void setParent(Entity parent);
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Body.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyCopier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java Mon May 25 17:20:48 2009
@@ -1,54 +1,54 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.message;
-
-/**
- * Represents a MIME body part  (see RFC 2045).
- */
-public class BodyPart extends Entity {
-
-    /**
-     * Creates a new empty <code>BodyPart</code>.
-     */
-    public BodyPart() {
-    }
-
-    /**
-     * Creates a new <code>BodyPart</code> from the specified
-     * <code>BodyPart</code>. The <code>BodyPart</code> instance is initialized
-     * with copies of header and body of the specified <code>BodyPart</code>.
-     * The parent entity of the new body part is <code>null</code>.
-     * 
-     * @param other
-     *            body part to copy.
-     * @throws UnsupportedOperationException
-     *             if <code>other</code> contains a {@link SingleBody} that
-     *             does not support the {@link SingleBody#copy() copy()}
-     *             operation.
-     * @throws IllegalArgumentException
-     *             if <code>other</code> contains a <code>Body</code> that
-     *             is neither a {@link Message}, {@link Multipart} or
-     *             {@link SingleBody}.
-     */
-    public BodyPart(BodyPart other) {
-        super(other);
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+/**
+ * Represents a MIME body part  (see RFC 2045).
+ */
+public class BodyPart extends Entity {
+
+    /**
+     * Creates a new empty <code>BodyPart</code>.
+     */
+    public BodyPart() {
+    }
+
+    /**
+     * Creates a new <code>BodyPart</code> from the specified
+     * <code>BodyPart</code>. The <code>BodyPart</code> instance is initialized
+     * with copies of header and body of the specified <code>BodyPart</code>.
+     * The parent entity of the new body part is <code>null</code>.
+     * 
+     * @param other
+     *            body part to copy.
+     * @throws UnsupportedOperationException
+     *             if <code>other</code> contains a {@link SingleBody} that
+     *             does not support the {@link SingleBody#copy() copy()}
+     *             operation.
+     * @throws IllegalArgumentException
+     *             if <code>other</code> contains a <code>Body</code> that
+     *             is neither a {@link Message}, {@link Multipart} or
+     *             {@link SingleBody}.
+     */
+    public BodyPart(BodyPart other) {
+        super(other);
+    }
+
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/BodyPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Entity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Header.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Message.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/MessageWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/Multipart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java?rev=778457&r1=778456&r2=778457&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java Mon May 25 17:20:48 2009
@@ -1,109 +1,109 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mime4j.message;
-
-import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.codec.Base64InputStream;
-import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
-import org.apache.james.mime4j.descriptor.BodyDescriptor;
-import org.apache.james.mime4j.field.AbstractField;
-import org.apache.james.mime4j.parser.AbstractContentHandler;
-import org.apache.james.mime4j.parser.Field;
-import org.apache.james.mime4j.util.MimeUtil;
-
-import java.io.InputStream;
-import java.io.IOException;
-
-/**
- * Abstract implementation of ContentHandler that automates common
- * tasks. Currently performs header parsing and applies content-transfer
- * decoding to body parts.
- *
- * 
- */
-public abstract class SimpleContentHandler extends  AbstractContentHandler {
-
-    /**
-     * Called after headers are parsed.
-     */
-    public abstract void headers(Header header);
-
-    /**
-     * Called when the body of a discrete (non-multipart) entity is encountered.
-
-     * @param bd encapsulates the values (either read from the
-     *        message stream or, if not present, determined implictly
-     *        as described in the
-     *        MIME rfc:s) of the <code>Content-Type</code> and
-     *        <code>Content-Transfer-Encoding</code> header fields.
-     * @param is the contents of the body. Base64 or quoted-printable
-     *        decoding will be applied transparently.
-     * @throws IOException should be thrown on I/O errors.
-     */
-    public abstract void bodyDecoded(BodyDescriptor bd, InputStream is) throws IOException;
-
-
-    /* Implement introduced callbacks. */
-
-    private Header currHeader;
-
-    /**
-     * @see org.apache.james.mime4j.parser.AbstractContentHandler#startHeader()
-     */
-    @Override
-    public final void startHeader() {
-        currHeader = new Header();
-    }
-
-    /**
-     * @see org.apache.james.mime4j.parser.AbstractContentHandler#field(Field)
-     */
-    @Override
-    public final void field(Field field) throws MimeException {
-        Field parsedField = AbstractField.parse(field.getRaw()); 
-        currHeader.addField(parsedField);
-    }
-
-    /**
-     * @see org.apache.james.mime4j.parser.AbstractContentHandler#endHeader()
-     */
-    @Override
-    public final void endHeader() {
-        Header tmp = currHeader;
-        currHeader = null;
-        headers(tmp);
-    }
-
-    /**
-     * @see org.apache.james.mime4j.parser.AbstractContentHandler#body(org.apache.james.mime4j.descriptor.BodyDescriptor, java.io.InputStream)
-     */
-    @Override
-    public final void body(BodyDescriptor bd, InputStream is) throws IOException {
-        if (MimeUtil.isBase64Encoding(bd.getTransferEncoding())) {
-            bodyDecoded(bd, new Base64InputStream(is));
-        }
-        else if (MimeUtil.isQuotedPrintableEncoded(bd.getTransferEncoding())) {
-            bodyDecoded(bd, new QuotedPrintableInputStream(is));
-        }
-        else {
-            bodyDecoded(bd, is);
-        }
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.codec.Base64InputStream;
+import org.apache.james.mime4j.codec.QuotedPrintableInputStream;
+import org.apache.james.mime4j.descriptor.BodyDescriptor;
+import org.apache.james.mime4j.field.AbstractField;
+import org.apache.james.mime4j.parser.AbstractContentHandler;
+import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.util.MimeUtil;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Abstract implementation of ContentHandler that automates common
+ * tasks. Currently performs header parsing and applies content-transfer
+ * decoding to body parts.
+ *
+ * 
+ */
+public abstract class SimpleContentHandler extends  AbstractContentHandler {
+
+    /**
+     * Called after headers are parsed.
+     */
+    public abstract void headers(Header header);
+
+    /**
+     * Called when the body of a discrete (non-multipart) entity is encountered.
+
+     * @param bd encapsulates the values (either read from the
+     *        message stream or, if not present, determined implictly
+     *        as described in the
+     *        MIME rfc:s) of the <code>Content-Type</code> and
+     *        <code>Content-Transfer-Encoding</code> header fields.
+     * @param is the contents of the body. Base64 or quoted-printable
+     *        decoding will be applied transparently.
+     * @throws IOException should be thrown on I/O errors.
+     */
+    public abstract void bodyDecoded(BodyDescriptor bd, InputStream is) throws IOException;
+
+
+    /* Implement introduced callbacks. */
+
+    private Header currHeader;
+
+    /**
+     * @see org.apache.james.mime4j.parser.AbstractContentHandler#startHeader()
+     */
+    @Override
+    public final void startHeader() {
+        currHeader = new Header();
+    }
+
+    /**
+     * @see org.apache.james.mime4j.parser.AbstractContentHandler#field(Field)
+     */
+    @Override
+    public final void field(Field field) throws MimeException {
+        Field parsedField = AbstractField.parse(field.getRaw()); 
+        currHeader.addField(parsedField);
+    }
+
+    /**
+     * @see org.apache.james.mime4j.parser.AbstractContentHandler#endHeader()
+     */
+    @Override
+    public final void endHeader() {
+        Header tmp = currHeader;
+        currHeader = null;
+        headers(tmp);
+    }
+
+    /**
+     * @see org.apache.james.mime4j.parser.AbstractContentHandler#body(org.apache.james.mime4j.descriptor.BodyDescriptor, java.io.InputStream)
+     */
+    @Override
+    public final void body(BodyDescriptor bd, InputStream is) throws IOException {
+        if (MimeUtil.isBase64Encoding(bd.getTransferEncoding())) {
+            bodyDecoded(bd, new Base64InputStream(is));
+        }
+        else if (MimeUtil.isQuotedPrintableEncoded(bd.getTransferEncoding())) {
+            bodyDecoded(bd, new QuotedPrintableInputStream(is));
+        }
+        else {
+            bodyDecoded(bd, is);
+        }
+    }
+}

Propchange: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/message/SimpleContentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message