geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bsny...@apache.org
Subject svn commit: r381393 [5/5] - in /geronimo/specs/trunk/geronimo-spec-javamail/src: main/java/javax/mail/internet/ main/java/org/apache/geronimo/mail/util/ main/resources/META-INF/ test/java/javax/mail/internet/
Date Mon, 27 Feb 2006 17:38:09 GMT
Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java?rev=381393&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java Mon Feb 27 09:38:03 2006
@@ -0,0 +1,147 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.mail.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class UUEncode {
+    private static final Encoder encoder = new UUEncoder();
+
+    /**
+     * encode the input data producing a UUEncoded byte array.
+     *
+     * @return a byte array containing the UUEncoded data.
+     */
+    public static byte[] encode(
+        byte[]    data)
+    {
+        return encode(data, 0, data.length);
+    }
+
+    /**
+     * encode the input data producing a UUEncoded byte array.
+     *
+     * @return a byte array containing the UUEncoded data.
+     */
+    public static byte[] encode(
+        byte[]    data,
+        int       off,
+        int       length)
+    {
+        ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
+
+        try
+        {
+            encoder.encode(data, off, length, bOut);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException("exception encoding UUEncoded string: " + e);
+        }
+
+        return bOut.toByteArray();
+    }
+
+    /**
+     * UUEncode the byte data writing it to the given output stream.
+     *
+     * @return the number of bytes produced.
+     */
+    public static int encode(
+        byte[]         data,
+        OutputStream   out)
+        throws IOException
+    {
+        return encoder.encode(data, 0, data.length, out);
+    }
+
+    /**
+     * UUEncode the byte data writing it to the given output stream.
+     *
+     * @return the number of bytes produced.
+     */
+    public static int encode(
+        byte[]         data,
+        int            off,
+        int            length,
+        OutputStream   out)
+        throws IOException
+    {
+        return encoder.encode(data, 0, data.length, out);
+    }
+
+    /**
+     * decode the UUEncoded input data. It is assumed the input data is valid.
+     *
+     * @return a byte array representing the decoded data.
+     */
+    public static byte[] decode(
+        byte[]    data)
+    {
+        ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
+
+        try
+        {
+            encoder.decode(data, 0, data.length, bOut);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException("exception decoding UUEncoded string: " + e);
+        }
+
+        return bOut.toByteArray();
+    }
+
+    /**
+     * decode the UUEncided String data.
+     *
+     * @return a byte array representing the decoded data.
+     */
+    public static byte[] decode(
+        String    data)
+    {
+        ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
+
+        try
+        {
+            encoder.decode(data, bOut);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException("exception decoding UUEncoded string: " + e);
+        }
+
+        return bOut.toByteArray();
+    }
+
+    /**
+     * decode the UUEncoded encoded String data writing it to the given output stream.
+     *
+     * @return the number of bytes produced.
+     */
+    public static int decode(
+        String          data,
+        OutputStream    out)
+        throws IOException
+    {
+        return encoder.decode(data, out);
+    }
+}
+

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java?rev=381393&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java Mon Feb 27 09:38:03 2006
@@ -0,0 +1,242 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.mail.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+public class UUEncoder implements Encoder {
+
+    // this is the maximum number of chars allowed per line, since we have to include a uuencoded length at
+    // the start of each line.
+    static private final int MAX_CHARS_PER_LINE = 45;
+
+
+    public UUEncoder()
+    {
+    }
+
+    /**
+     * encode the input data producing a UUEncoded output stream.
+     *
+     * @param data   The array of byte data.
+     * @param off    The starting offset within the data.
+     * @param length Length of the data to encode.
+     * @param out    The output stream the encoded data is written to.
+     *
+     * @return the number of bytes produced.
+     */
+    public int encode(byte[] data, int off, int length, OutputStream out) throws IOException
+    {
+        int byteCount = 0;
+
+        while (true) {
+            // keep writing complete lines until we've exhausted the data.
+            if (length > MAX_CHARS_PER_LINE) {
+                // encode another line and adjust the length and position
+                byteCount += encodeLine(data, off, MAX_CHARS_PER_LINE, out);
+                length -= MAX_CHARS_PER_LINE;
+                off += MAX_CHARS_PER_LINE;
+            }
+            else {
+                // last line.  Encode the partial and quit
+                byteCount += encodeLine(data, off, MAX_CHARS_PER_LINE, out);
+                break;
+            }
+        }
+        return byteCount;
+    }
+
+
+    /**
+     * Encode a single line of data (less than or equal to 45 characters).
+     *
+     * @param data   The array of byte data.
+     * @param off    The starting offset within the data.
+     * @param length Length of the data to encode.
+     * @param out    The output stream the encoded data is written to.
+     *
+     * @return The number of bytes written to the output stream.
+     * @exception IOException
+     */
+    private int encodeLine(byte[] data, int offset, int length, OutputStream out) throws IOException {
+        // write out the length of the data in this line, including the length byte.  This
+        // is uuencoded by basing it off of a ' ' character.
+        out.write((byte)(((length + 1) & 0x3F) + ' '));
+        byte a;
+        byte b;
+        byte c;
+
+        // count the bytes written...we add 2, one for the length and 1 for the linend terminator.
+        int bytesWritten = 2;
+
+        for (int i = 0; i < length;) {
+            // set the padding defauls
+            b = 1;
+            c = 1;
+            // get the next 3 bytes (if we have them)
+            a = data[offset + i++];
+            if (i < length) {
+                b = data[offset + i++];
+                if (i < length) {
+                    c = data[offset + i++];
+                }
+            }
+
+            byte d1 = (byte)(((a >>> 2) & 0x3F) + ' ');
+            byte d2 = (byte)(((( a << 4) & 0x30) | ((b >>> 4) & 0x0F)) + ' ');
+            byte d3 = (byte)((((b << 2) & 0x3C) | ((c >>> 6) & 0x3)) + ' ');
+            byte d4 = (byte)((c & 0x3F) + ' ');
+
+            out.write(d1);
+            out.write(d2);
+            out.write(d3);
+            out.write(d4);
+
+            bytesWritten += 4;
+        }
+
+        // terminate with a linefeed alone
+        out.write('\n');
+
+        return bytesWritten;
+    }
+
+
+    /**
+     * decode the uuencoded byte data writing it to the given output stream
+     *
+     * @param data   The array of byte data to decode.
+     * @param off    Starting offset within the array.
+     * @param length The length of data to encode.
+     * @param out    The output stream used to return the decoded data.
+     *
+     * @return the number of bytes produced.
+     * @exception IOException
+     */
+    public int decode(byte[] data, int off, int length, OutputStream out) throws IOException
+    {
+        int bytesWritten = 0;
+
+        while (length > 0) {
+            int lineOffset = off;
+
+            // scan forward looking for a EOL terminator for the next line of data.
+            while (length > 0 && data[off] != '\n') {
+                off++;
+                length--;
+            }
+
+            // go decode this line of data
+            bytesWritten += decodeLine(data, lineOffset, off - lineOffset, out);
+
+            // the offset was left pointing at the EOL character, so step over that one before
+            // scanning again.
+            off++;
+            length--;
+        }
+        return bytesWritten;
+    }
+
+
+    /**
+     * decode a single line of uuencoded byte data writing it to the given output stream
+     *
+     * @param data   The array of byte data to decode.
+     * @param off    Starting offset within the array.
+     * @param length The length of data to encode.
+     * @param out    The output stream used to return the decoded data.
+     *
+     * @return the number of bytes produced.
+     * @exception IOException
+     */
+    private int decodeLine(byte[] data, int off, int length, OutputStream out) throws IOException {
+        int count = data[off++];
+
+        // obtain and validate the count
+        if (count < ' ') {
+            throw new IOException("Invalid UUEncode line length");
+        }
+
+        count = (count - ' ') & 0x3F;
+
+        // get the rounded count of characters that should have been used to encode this.  The + 1 is for the
+        // terminating lineend character.
+        int requiredLength = (((count * 8) + 6) / 6) + 1;
+        if (length < requiredLength) {
+            throw new IOException("UUEncoded data and length do not match");
+        }
+
+        int bytesWritten = 0;
+        // now decode the bytes.
+        while (bytesWritten < count) {
+            // even one byte of data requires two bytes to encode, so we should have that.
+            byte a = (byte)((data[off++] - ' ') & 0x3F);
+            byte b = (byte)((data[off++] - ' ') & 0x3F);
+            byte c = 0;
+            byte d = 0;
+
+            // do the first byte
+            byte first = (byte)(((a << 2) & 0xFC) | ((b >>> 4) & 3));
+            out.write(first);
+            bytesWritten++;
+
+            // still have more bytes to decode? do the second byte of the second.  That requires
+            // a third byte from the data.
+            if (bytesWritten < count) {
+                c = (byte)((data[off++] - ' ') & 0x3F);
+                byte second = (byte)(((b << 4) & 0xF0) | ((c >>> 2) & 0x0F));
+                out.write(first);
+                bytesWritten++;
+
+                // need the third one?
+                if (bytesWritten < count) {
+                    d = (byte)((data[off++] - ' ') & 0x3F);
+                    byte third = (byte)(((c << 6) & 0xC0) | (d & 0x3F));
+                    out.write(first);
+                    bytesWritten++;
+                }
+            }
+        }
+        return bytesWritten;
+    }
+
+
+    /**
+     * decode the UUEncoded String data writing it to the given output stream.
+     *
+     * @param data   The String data to decode.
+     * @param out    The output stream to write the decoded data to.
+     *
+     * @return the number of bytes produced.
+     * @exception IOException
+     */
+    public int decode(String data, OutputStream out) throws IOException
+    {
+        try {
+            // just get the byte data and decode.
+            byte[] bytes = data.getBytes("US-ASCII");
+            return decode(bytes, 0, bytes.length, out);
+        } catch (UnsupportedEncodingException e) {
+            throw new IOException("Invalid UUEncoding");
+        }
+    }
+}
+
+

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java?rev=381393&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java Mon Feb 27 09:38:03 2006
@@ -0,0 +1,201 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.mail.util;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+/**
+ * An implementation of a FilterOutputStream that encodes the
+ * stream data in UUencoding format.  This version does the
+ * encoding "on the fly" rather than encoding a single block of
+ * data.  Since this version is intended for use by the MimeUtilty class,
+ * it also handles line breaks in the encoded data.
+ */
+public class UUEncoderStream extends FilterOutputStream {
+
+    // default values included on the "begin" prefix of the data stream.
+    protected static final int DEFAULT_MODE = 644;
+    protected static final String DEFAULT_NAME = "encoder.buf";
+
+    protected static final int MAX_CHARS_PER_LINE = 45;
+
+    // the configured name on the "begin" command.
+    protected String name;
+    // the configured mode for the "begin" command.
+    protected int mode;
+
+    // since this is a filtering stream, we need to wait until we have the first byte written for encoding
+    // to write out the "begin" marker.  A real pain, but necessary.
+    protected boolean beginWritten = false;
+
+
+    // our encoder utility class.
+    protected UUEncoder encoder = new UUEncoder();
+
+    // Data is generally written out in 45 character lines, so we're going to buffer that amount before
+    // asking the encoder to process this.
+
+    // the buffered byte count
+    protected int bufferedBytes = 0;
+
+    // we'll encode this part once it is filled up.
+    protected byte[] buffer = new byte[45];
+
+    /**
+     * Create a Base64 encoder stream that wraps a specifed stream
+     * using the default line break size.
+     *
+     * @param out    The wrapped output stream.
+     */
+    public UUEncoderStream(OutputStream out) {
+        this(out, DEFAULT_NAME, DEFAULT_MODE);
+    }
+
+
+    /**
+     * Create a Base64 encoder stream that wraps a specifed stream
+     * using the default line break size.
+     *
+     * @param out    The wrapped output stream.
+     * @param name   The filename placed on the "begin" command.
+     */
+    public UUEncoderStream(OutputStream out, String name) {
+        this(out, name, DEFAULT_MODE);
+    }
+
+
+    public UUEncoderStream(OutputStream out, String name, int mode) {
+        super(out);
+        // fill in the name and mode information.
+        this.name = name;
+        this.mode = mode;
+    }
+
+
+    private void checkBegin() throws IOException {
+        if (!beginWritten) {
+            // grumble...OutputStream doesn't directly support writing String data.  We'll wrap this in
+            // a PrintStream() to accomplish the task of writing the begin command.
+
+            PrintStream writer = new PrintStream(out);
+            // write out the stream with a CRLF marker
+            writer.print("begin " + mode + " " + name + "\r\n");
+            writer.flush();
+            beginWritten = true;
+        }
+    }
+
+    private void writeEnd() throws IOException {
+        PrintStream writer = new PrintStream(out);
+        // write out the stream with a CRLF marker
+        writer.print("\nbegin\r\n");
+        writer.flush();
+    }
+
+    private void flushBuffer() throws IOException {
+        // make sure we've written the begin marker first
+        checkBegin();
+        // ask the encoder to encode and write this out.
+        if (bufferedBytes != 0) {
+            encoder.encode(buffer, 0, bufferedBytes, out);
+            // reset the buffer count
+            bufferedBytes = 0;
+        }
+    }
+
+    private int bufferSpace() {
+        return MAX_CHARS_PER_LINE - bufferedBytes;
+    }
+
+    private boolean isBufferFull() {
+        return bufferedBytes >= MAX_CHARS_PER_LINE;
+    }
+
+
+    // in order for this to work, we need to override the 3 different signatures for write
+
+    public void write(int ch) throws IOException {
+        // store this in the buffer.
+        buffer[bufferedBytes++] = (byte)ch;
+
+        // if we filled this up, time to encode and write to the output stream.
+        if (isBufferFull()) {
+            flushBuffer();
+        }
+    }
+
+    public void write(byte [] data) throws IOException {
+        write(data, 0, data.length);
+    }
+
+    public void write(byte [] data, int offset, int length) throws IOException {
+        // first check to see how much space we have left in the buffer, and copy that over
+        int copyBytes = Math.min(bufferSpace(), length);
+
+        System.arraycopy(buffer, bufferedBytes, data, offset, copyBytes);
+        bufferedBytes += copyBytes;
+        offset += copyBytes;
+        length -= copyBytes;
+
+        // if we filled this up, time to encode and write to the output stream.
+        if (isBufferFull()) {
+            flushBuffer();
+        }
+
+        // we've flushed the leading part up to the line break.  Now if we have complete lines
+        // of data left, we can have the encoder process all of these lines directly.
+        if (length >= MAX_CHARS_PER_LINE) {
+            int fullLinesLength = (length / MAX_CHARS_PER_LINE) * MAX_CHARS_PER_LINE;
+            // ask the encoder to encode and write this out.
+            encoder.encode(data, offset, fullLinesLength, out);
+            offset += fullLinesLength;
+            length -= fullLinesLength;
+        }
+
+        // ok, now we're down to a potential trailing bit we need to move into the
+        // buffer for later processing.
+
+        if (length > 0) {
+            System.arraycopy(buffer, 0, data, offset, length);
+            bufferedBytes += length;
+            offset += length;
+            length -= length;
+        }
+    }
+
+    public void flush() throws IOException {
+        // flush any unencoded characters we're holding.
+        flushBuffer();
+        // write out the data end marker
+        writeEnd();
+        // and flush the output stream too so that this data is available.
+        out.flush();
+    }
+
+    public void close() throws IOException {
+        // flush all of the streams and close the target output stream.
+        flush();
+        out.close();
+    }
+
+}
+
+

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/UUEncoderStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/XTextEncoder.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/XTextEncoder.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/XTextEncoder.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/util/XTextEncoder.java Mon Feb 27 09:38:03 2006
@@ -59,6 +59,8 @@
         OutputStream    out)
         throws IOException
     {
+        int bytesWritten = 0;
+
         for (int i = off; i < (off + length); i++)
         {
             int    v = data[i] & 0xff;
@@ -67,14 +69,16 @@
                 out.write((byte)'+');
                 out.write(encodingTable[(v >>> 4)]);
                 out.write(encodingTable[v & 0xf]);
+                bytesWritten += 3;
             }
             else {
                 // add unchanged.
                 out.write((byte)v);
+                bytesWritten++;
             }
         }
 
-        return length * 2;
+        return bytesWritten;
     }
 
 

Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/javamail.charset.map
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/javamail.charset.map?rev=381393&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/javamail.charset.map (added)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/javamail.charset.map Mon Feb 27 09:38:03 2006
@@ -0,0 +1,55 @@
+### Character set mapping table loaded and used by the javax.mail.internet.MimeUtility class.
+
+### java character sets to MIME character set map.  This must be the first table.
+
+8859_1		ISO-8859-1
+iso8859_1	ISO-8859-1
+
+8859_2		ISO-8859-2
+iso8859_2	ISO-8859-2
+
+8859_3		ISO-8859-3
+iso8859_3	ISO-8859-3
+
+8859_4		ISO-8859-4
+iso8859_4	ISO-8859-4
+
+8859_5		ISO-8859-5
+iso8859_5	ISO-8859-5
+
+8859_6		ISO-8859-6
+iso8859_6	ISO-8859-6
+
+8859_7		ISO-8859-7
+iso8859_7	ISO-8859-7
+
+8859_8		ISO-8859-8
+iso8859_8	ISO-8859-8
+
+8859_9		ISO-8859-9
+iso8859_9	ISO-8859-9
+
+SJIS		Shift_JIS
+MS932		Shift_JIS
+JIS		ISO-2022-JP
+ISO2022JP	ISO-2022-JP
+EUC_JP		euc-jp
+KOI8_R		koi8-r
+EUC_CN		euc-cn
+EUC_TW		euc-tw
+EUC_KR		euc-kr
+
+--Table terminator.  The "--" at the beginning and end are required --
+
+#### MIME to java character set map
+
+iso-2022-cn     ISO2022CN
+iso-2022-kr     ISO2022KR
+utf-8           UTF8
+utf8		UTF8
+ja_jp.iso2022-7 ISO2022JP
+ja_jp.eucjp     EUCJIS
+euc-kr          KSC5601
+euckr           KSC5601
+us-ascii        ISO-8859-1
+x-us-ascii      ISO-8859-1

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentDispositionTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentDispositionTest.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentDispositionTest.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentDispositionTest.java Mon Feb 27 09:38:03 2006
@@ -26,7 +26,7 @@
     public ContentDispositionTest(String name) {
         super(name);
     }
-    
+
     public void testContentDisposition() throws ParseException {
         ContentDisposition c;
         c = new ContentDisposition();
@@ -38,15 +38,15 @@
         assertEquals("inline",c.getDisposition());
         c.setParameter("file","file.txt");
         assertEquals("file.txt",c.getParameterList().get("file"));
-        assertEquals("inline;file=file.txt",c.toString());
+        assertEquals("inline; file=file.txt",c.toString());
         c = new ContentDisposition("inline");
         assertEquals(0,c.getParameterList().size());
         assertEquals("inline",c.getDisposition());
-        c = new ContentDisposition("inline",new ParameterList("charset=us-ascii;content-type=text/plain"));
+        c = new ContentDisposition("inline",new ParameterList(";charset=us-ascii;content-type=\"text/plain\""));
         assertEquals("inline",c.getDisposition());
         assertEquals("us-ascii",c.getParameter("charset"));
         assertEquals("text/plain",c.getParameter("content-type"));
-        c = new ContentDisposition("attachment;content-type=text/html;charset=UTF-8");
+        c = new ContentDisposition("attachment;content-type=\"text/html\";charset=UTF-8");
         assertEquals("attachment",c.getDisposition());
         assertEquals("UTF-8",c.getParameter("charset"));
         assertEquals("text/html",c.getParameter("content-type"));

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentTypeTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentTypeTest.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentTypeTest.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ContentTypeTest.java Mon Feb 27 09:38:03 2006
@@ -25,43 +25,121 @@
         super(arg0);
     }
     public void testContentType() throws ParseException {
+        ContentType type = new ContentType();
+        assertNull(type.getPrimaryType());
+        assertNull(type.getSubType());
+        assertNull(type.getParameter("charset"));
+    }
+
+    public void testContentTypeStringStringParameterList() throws ParseException {
+        ContentType type;
+        ParameterList list = new ParameterList(";charset=us-ascii");
+        type = new ContentType("text", "plain", list);
+        assertEquals("text", type.getPrimaryType());
+        assertEquals("plain", type.getSubType());
+        assertEquals("text/plain", type.getBaseType());
+        ParameterList parameterList = type.getParameterList();
+        assertEquals("us-ascii", parameterList.get("charset"));
+        assertEquals("us-ascii", type.getParameter("charset"));
+
+    }
+
+    public void testContentTypeString() throws ParseException {
         ContentType type;
         type = new ContentType("text/plain");
         assertEquals("text", type.getPrimaryType());
         assertEquals("plain", type.getSubType());
-        assertEquals(null, type.getParameterList());
+        assertEquals("text/plain", type.getBaseType());
+        assertNotNull(type.getParameterList());
+        assertNull(type.getParameter("charset"));
         type = new ContentType("image/audio;charset=us-ascii");
         ParameterList parameterList = type.getParameterList();
         assertEquals("image", type.getPrimaryType());
         assertEquals("audio", type.getSubType());
+        assertEquals("image/audio", type.getBaseType());
         assertEquals("us-ascii", parameterList.get("charset"));
+        assertEquals("us-ascii", type.getParameter("charset"));
     }
-    public void testContentTypeStringStringParameterList() {
+    public void testGetPrimaryType() throws ParseException {
     }
-    public void testContentTypeString() {
+    public void testGetSubType() throws ParseException {
     }
-    public void testGetPrimaryType() {
+    public void testGetBaseType() throws ParseException {
     }
-    public void testGetSubType() {
+    public void testGetParameter() throws ParseException {
     }
-    public void testGetBaseType() {
+    public void testGetParameterList() throws ParseException {
     }
-    public void testGetParameter() {
-    }
-    public void testGetParameterList() {
-    }
-    public void testSetPrimaryType() {
-    }
-    public void testSetSubType() {
-    }
-    public void testSetParameter() {
+    public void testSetPrimaryType() throws ParseException {
+        ContentType type = new ContentType("text/plain");
+        type.setPrimaryType("binary");
+        assertEquals("binary", type.getPrimaryType());
+        assertEquals("plain", type.getSubType());
+        assertEquals("binary/plain", type.getBaseType());
     }
-    public void testSetParameterList() {
+    public void testSetSubType() throws ParseException {
+        ContentType type = new ContentType("text/plain");
+        type.setSubType("html");
+        assertEquals("text", type.getPrimaryType());
+        assertEquals("html", type.getSubType());
+        assertEquals("text/html", type.getBaseType());
     }
-    public void testToString() {
+    public void testSetParameter() throws ParseException {
     }
-    public void testMatchContentType() {
+    public void testSetParameterList() throws ParseException {
     }
-    public void testMatchString() {
+    public void testToString() throws ParseException {
+        ContentType type = new ContentType("text/plain");
+        System.out.println("Type string value is " + type.toString());
+        assertEquals("text/plain", type.toString());
+        type.setParameter("foo", "bar");
+        assertEquals("text/plain; foo=bar", type.toString());
+        type.setParameter("bar", "me@apache.org");
+        assertEquals("text/plain; foo=bar; bar=\"me@apache.org\"", type.toString());
+    }
+    public void testMatchContentType() throws ParseException {
+        ContentType type = new ContentType("text/plain");
+
+        ContentType test = new ContentType("text/plain");
+
+        assertTrue(type.match(test));
+
+        test = new ContentType("TEXT/plain");
+        assertTrue(type.match(test));
+        assertTrue(test.match(type));
+
+        test = new ContentType("text/PLAIN");
+        assertTrue(type.match(test));
+        assertTrue(test.match(type));
+
+        test = new ContentType("text/*");
+        assertTrue(type.match(test));
+        assertTrue(test.match(type));
+
+        test = new ContentType("text/xml");
+        assertFalse(type.match(test));
+        assertFalse(test.match(type));
+
+        test = new ContentType("binary/plain");
+        assertFalse(type.match(test));
+        assertFalse(test.match(type));
+
+        test = new ContentType("*/plain");
+        assertFalse(type.match(test));
+        assertFalse(test.match(type));
+    }
+    public void testMatchString() throws ParseException {
+        ContentType type = new ContentType("text/plain");
+        assertTrue(type.match("text/plain"));
+        assertTrue(type.match("TEXT/plain"));
+        assertTrue(type.match("text/PLAIN"));
+        assertTrue(type.match("TEXT/PLAIN"));
+        assertTrue(type.match("TEXT/*"));
+
+        assertFalse(type.match("text/xml"));
+        assertFalse(type.match("binary/plain"));
+        assertFalse(type.match("*/plain"));
+        assertFalse(type.match(""));
+        assertFalse(type.match("text/plain/yada"));
     }
 }

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/HeaderTokenizerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/HeaderTokenizerTest.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/HeaderTokenizerTest.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/HeaderTokenizerTest.java Mon Feb 27 09:38:03 2006
@@ -30,43 +30,103 @@
         HeaderTokenizer ht;
         ht =
             new HeaderTokenizer("To: \"Geronimo List\" <geronimo-dev@apache.org>, \n\r Geronimo User <geronimo-user@apache.org>");
-        assertEquals("To", ht.peek().getValue());
-        assertEquals("To", ht.next().getValue());
-        assertEquals(":", ht.peek().getValue());
-        assertEquals(":", ht.next().getValue());
-        t = ht.next();
-        assertEquals("Geronimo List", t.getValue());
-        assertEquals(Token.QUOTEDSTRING, t.getType());
-        assertEquals("<", ht.next().getValue());
-        assertEquals("geronimo-dev", ht.next().getValue());
-        assertEquals("@", ht.next().getValue());
-        assertEquals("apache", ht.next().getValue());
-        assertEquals(".", ht.next().getValue());
-        assertEquals("org", ht.next().getValue());
-        assertEquals(">", ht.next().getValue());
-        assertEquals(",", ht.next().getValue());
-        assertEquals("Geronimo", ht.next().getValue());
-        assertEquals("User", ht.next().getValue());
-        assertEquals("<", ht.next().getValue());
-        assertEquals("geronimo-user", ht.next().getValue());
-        assertEquals("@", ht.next().getValue());
-        assertEquals("apache", ht.next().getValue());
-        assertEquals(".", ht.next().getValue());
+        validateToken(ht.peek(), Token.ATOM, "To");
+        validateToken(ht.next(), Token.ATOM, "To");
+        validateToken(ht.peek(), ':', ":");
+        validateToken(ht.next(), ':', ":");
+        validateToken(ht.next(), Token.QUOTEDSTRING, "Geronimo List");
+        validateToken(ht.next(), '<', "<");
+        validateToken(ht.next(), Token.ATOM, "geronimo-dev");
+        validateToken(ht.next(), '@', "@");
+        validateToken(ht.next(), Token.ATOM, "apache");
+        validateToken(ht.next(), '.', ".");
+        validateToken(ht.next(), Token.ATOM, "org");
+        validateToken(ht.next(), '>', ">");
+        validateToken(ht.next(), ',', ",");
+        validateToken(ht.next(), Token.ATOM, "Geronimo");
+        validateToken(ht.next(), Token.ATOM, "User");
+        validateToken(ht.next(), '<', "<");
+        validateToken(ht.next(), Token.ATOM, "geronimo-user");
+        validateToken(ht.next(), '@', "@");
+        validateToken(ht.next(), Token.ATOM, "apache");
+        validateToken(ht.next(), '.', ".");
         assertEquals("org>", ht.getRemainder());
-        assertEquals("org", ht.peek().getValue());
-        assertEquals("org>", ht.getRemainder());
-        assertEquals("org", ht.next().getValue());
-        assertEquals(">", ht.next().getValue());
+        validateToken(ht.peek(), Token.ATOM, "org");
+        validateToken(ht.next(), Token.ATOM, "org");
+        validateToken(ht.next(), '>', ">");
         assertEquals(Token.EOF, ht.next().getType());
         ht = new HeaderTokenizer("   ");
         assertEquals(Token.EOF, ht.next().getType());
         ht = new HeaderTokenizer("J2EE");
-        assertEquals("J2EE", ht.next().getValue());
+        validateToken(ht.next(), Token.ATOM, "J2EE");
         assertEquals(Token.EOF, ht.next().getType());
         // test comments
         doComment(true);
         doComment(false);
     }
+
+    public void testErrors() throws ParseException {
+        checkParseError("(Geronimo");
+        checkParseError("((Geronimo)");
+        checkParseError("\"Geronimo");
+        checkParseError("\"Geronimo\\");
+    }
+
+
+    public void testQuotedLiteral() throws ParseException {
+        checkTokenParse("\"\"", Token.QUOTEDSTRING, "");
+        checkTokenParse("\"\\\"\"", Token.QUOTEDSTRING, "\"");
+        checkTokenParse("\"\\\"\"", Token.QUOTEDSTRING, "\"");
+        checkTokenParse("\"A\r\nB\"", Token.QUOTEDSTRING, "AB");
+        checkTokenParse("\"A\nB\"", Token.QUOTEDSTRING, "A\nB");
+    }
+
+
+    public void testComment() throws ParseException {
+        checkTokenParse("()", Token.COMMENT, "");
+        checkTokenParse("(())", Token.COMMENT, "()");
+        checkTokenParse("(Foo () Bar)", Token.COMMENT, "Foo () Bar");
+        checkTokenParse("(\"Foo () Bar)", Token.COMMENT, "\"Foo () Bar");
+        checkTokenParse("(\\()", Token.COMMENT, "(");
+        checkTokenParse("(Foo \r\n Bar)", Token.COMMENT, "Foo  Bar");
+        checkTokenParse("(Foo \n Bar)", Token.COMMENT, "Foo \n Bar");
+    }
+
+    public void checkTokenParse(String text, int type, String value) throws ParseException {
+        HeaderTokenizer ht;
+        ht = new HeaderTokenizer(text, HeaderTokenizer.RFC822, false);
+        validateToken(ht.next(), type, value);
+    }
+
+
+    public void checkParseError(String text) throws ParseException {
+        Token t;
+        HeaderTokenizer ht;
+
+        System.out.println("Doing error test with " + text);
+        ht = new HeaderTokenizer(text);
+        doNextError(ht);
+        ht = new HeaderTokenizer(text);
+        doPeekError(ht);
+    }
+
+    public void doNextError(HeaderTokenizer ht) {
+        try {
+            ht.next();
+            fail("Expected ParseException");
+        } catch (ParseException e) {
+        }
+    }
+
+    public void doPeekError(HeaderTokenizer ht) {
+        try {
+            ht.peek();
+            fail("Expected ParseException");
+        } catch (ParseException e) {
+        }
+    }
+
+
     public void doComment(boolean ignore) throws ParseException {
         HeaderTokenizer ht;
         Token t;
@@ -75,17 +135,28 @@
                 "Apache(Geronimo)J2EE",
                 HeaderTokenizer.RFC822,
                 ignore);
-        t = ht.next();
-        assertEquals("Apache", t.getValue());
-        assertEquals(Token.ATOM, t.getType());
+        validateToken(ht.next(), Token.ATOM, "Apache");
+        if (!ignore) {
+            validateToken(ht.next(), Token.COMMENT, "Geronimo");
+        }
+        validateToken(ht.next(), Token.ATOM, "J2EE");
+        assertEquals(Token.EOF, ht.next().getType());
+
+        ht =
+            new HeaderTokenizer(
+                "Apache(Geronimo (Project))J2EE",
+                HeaderTokenizer.RFC822,
+                ignore);
+        validateToken(ht.next(), Token.ATOM, "Apache");
         if (!ignore) {
-            t = ht.next();
-            assertEquals("Geronimo", t.getValue());
-            assertEquals(Token.COMMENT, t.getType());
+            validateToken(ht.next(), Token.COMMENT, "Geronimo (Project)");
         }
-        t = ht.next();
-        assertEquals("J2EE", t.getValue());
-        assertEquals(Token.ATOM, t.getType());
+        validateToken(ht.next(), Token.ATOM, "J2EE");
         assertEquals(Token.EOF, ht.next().getType());
+    }
+
+    private void validateToken(HeaderTokenizer.Token token, int type, String value) {
+        assertEquals(token.getType(), type);
+        assertEquals(token.getValue(), value);
     }
 }

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeMessageTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeMessageTest.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeMessageTest.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/MimeMessageTest.java Mon Feb 27 09:38:03 2006
@@ -17,12 +17,19 @@
 
 package javax.mail.internet;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Properties;
-import javax.mail.MessagingException;
-import javax.mail.Session;
+
 import javax.activation.CommandMap;
 import javax.activation.MailcapCommandMap;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
 
 import junit.framework.TestCase;
 
@@ -36,6 +43,7 @@
     public void testWriteTo() throws MessagingException, IOException {
         MimeMessage msg = new MimeMessage(session);
         msg.setSender(new InternetAddress("foo"));
+        msg.setHeader("foo", "bar");
         MimeMultipart mp = new MimeMultipart();
         MimeBodyPart part1 = new MimeBodyPart();
         part1.setHeader("foo", "bar");
@@ -45,8 +53,323 @@
         part2.setContent("Hello Again", "text/plain");
         mp.addBodyPart(part2);
         msg.setContent(mp);
-        msg.writeTo(System.out);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        msg.writeTo(out);
+
+        InputStream in = new ByteArrayInputStream(out.toByteArray());
+
+        MimeMessage newMessage = new MimeMessage(session, in);
+
+        assertEquals(((InternetAddress)newMessage.getSender()).getAddress(), "foo");
+
+        String[] headers = newMessage.getHeader("foo");
+        System.out.println("Get header returned " + headers);
+        assertTrue(headers.length == 1);
+        assertEquals(headers[0], "bar");
+
+
+        newMessage = new MimeMessage(msg);
+
+        assertEquals(((InternetAddress)newMessage.getSender()).getAddress(), "foo");
+        assertEquals(newMessage.getHeader("foo")[0], "bar");
+    }
+
+
+    public void testFrom() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        msg.setSender(dev);
+
+        Address[] from = msg.getFrom();
+        assertTrue(from.length == 1);
+        assertEquals(from[0], dev);
+
+        msg.setFrom(user);
+        from = msg.getFrom();
+        assertTrue(from.length == 1);
+        assertEquals(from[0], user);
+
+        msg.addFrom(new Address[] { dev });
+        from = msg.getFrom();
+        assertTrue(from.length == 2);
+        assertEquals(from[0], user);
+        assertEquals(from[1], dev);
+
+        msg.setFrom();
+        InternetAddress local = InternetAddress.getLocalAddress(session);
+        from = msg.getFrom();
+
+        assertTrue(from.length == 1);
+        assertEquals(local, from[0]);
+
+        msg.setFrom(null);
+        from = msg.getFrom();
+
+        assertTrue(from.length == 0);
+    }
+
+
+    public void testSender() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        msg.setSender(dev);
+
+        Address[] from = msg.getFrom();
+        assertTrue(from.length == 1);
+        assertEquals(from[0], dev);
+
+        assertEquals(msg.getSender(), dev);
+
+        msg.setSender(null);
+        assertNull(msg.getSender());
     }
+
+    public void testGetAllRecipients() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+        InternetAddress user1 = new InternetAddress("geronimo-user1@apache.org");
+        InternetAddress user2 = new InternetAddress("geronimo-user2@apache.org");
+        NewsAddress group = new NewsAddress("comp.lang.rexx");
+
+        Address[] recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 0);
+
+        msg.setRecipients(Message.RecipientType.TO, new Address[] { dev });
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(Message.RecipientType.BCC, new Address[] { user });
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.addRecipients(Message.RecipientType.CC, new Address[] { user1, user2} );
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 4);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user1);
+        assertEquals(recipients[2], user2);
+        assertEquals(recipients[3], user);
+
+
+        msg.addRecipients(MimeMessage.RecipientType.NEWSGROUPS, new Address[] { group } );
+
+        recipients = msg.getAllRecipients();
+        assertTrue(recipients.length == 5);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user1);
+        assertEquals(recipients[2], user2);
+        assertEquals(recipients[3], user);
+        assertEquals(recipients[4], group);
+
+        msg.setRecipients(Message.RecipientType.CC, (String)null);
+
+        recipients = msg.getAllRecipients();
+
+        System.out.println("Get all recipients returns " + recipients.length);
+        assertTrue(recipients.length == 3);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+        assertEquals(recipients[2], group);
+    }
+
+    public void testGetRecipients() throws MessagingException {
+        doRecipientTest(Message.RecipientType.TO);
+        doRecipientTest(Message.RecipientType.CC);
+        doRecipientTest(Message.RecipientType.BCC);
+        doNewsgroupRecipientTest(MimeMessage.RecipientType.NEWSGROUPS);
+    }
+
+    private void doRecipientTest(Message.RecipientType type) throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        Address[] recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, "geronimo-dev@apache.org");
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, "geronimo-user@apache.org");
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (String)null);
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 0);
+
+        msg.setRecipients(type, new Address[] { dev });
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, new Address[] { user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (Address[])null);
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 0);
+
+        msg.setRecipients(type, new Address[] { dev, user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+    }
+
+
+    private void doNewsgroupRecipientTest(Message.RecipientType type) throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        Address dev = new NewsAddress("geronimo-dev");
+        Address user = new NewsAddress("geronimo-user");
+
+        Address[] recipients = msg.getRecipients(type);
+        assertNull(recipients);
+
+        msg.setRecipients(type, "geronimo-dev");
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        System.out.println("Received address " + recipients[0] + " of type " + recipients[0].getType());
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, "geronimo-user");
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (String)null);
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 0);
+
+        msg.setRecipients(type, new Address[] { dev });
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.addRecipients(type, new Address[] { user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setRecipients(type, (Address[])null);
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 0);
+
+        msg.setRecipients(type, new Address[] { dev, user });
+
+        recipients = msg.getRecipients(type);
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+    }
+
+    public void testReplyTo() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        InternetAddress dev = new InternetAddress("geronimo-dev@apache.org");
+        InternetAddress user = new InternetAddress("geronimo-user@apache.org");
+
+        msg.setReplyTo(new Address[] { dev });
+
+        Address[] recipients = msg.getReplyTo();
+        assertTrue(recipients.length == 1);
+        assertEquals(recipients[0], dev);
+
+        msg.setReplyTo(new Address[] { dev, user });
+
+        recipients = msg.getReplyTo();
+        assertTrue(recipients.length == 2);
+        assertEquals(recipients[0], dev);
+        assertEquals(recipients[1], user);
+
+        msg.setReplyTo(null);
+
+        recipients = msg.getReplyTo();
+        assertTrue(recipients.length == 0);
+    }
+
+
+    public void testSetSubject() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        String simpleSubject = "Yada, yada";
+
+        String complexSubject = "Yada, yada\u0081";
+
+        String mungedSubject = "Yada, yada\u003F";
+
+        msg.setSubject(simpleSubject);
+        assertEquals(msg.getSubject(), simpleSubject);
+
+        msg.setSubject(complexSubject, "UTF-8");
+        assertEquals(msg.getSubject(), complexSubject);
+
+        msg.setSubject(complexSubject);
+        assertEquals(msg.getSubject(), mungedSubject);
+
+        msg.setSubject(null);
+        assertNull(msg.getSubject());
+    }
+
+
+    public void testSetDescription() throws MessagingException {
+        MimeMessage msg = new MimeMessage(session);
+
+        String simpleSubject = "Yada, yada";
+
+        String complexSubject = "Yada, yada\u0081";
+
+        String mungedSubject = "Yada, yada\u003F";
+
+        msg.setDescription(simpleSubject);
+        assertEquals(msg.getDescription(), simpleSubject);
+
+        msg.setDescription(complexSubject, "UTF-8");
+        assertEquals(msg.getDescription(), complexSubject);
+
+        msg.setDescription(complexSubject);
+        assertEquals(msg.getDescription(), mungedSubject);
+
+        msg.setDescription(null);
+        assertNull(msg.getDescription());
+    }
+
+
 
     protected void setUp() throws Exception {
         defaultMap = CommandMap.getDefaultCommandMap();

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/NewsAddressTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/NewsAddressTest.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/NewsAddressTest.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/NewsAddressTest.java Mon Feb 27 09:38:03 2006
@@ -28,7 +28,7 @@
         assertEquals("geronimo-dev", na.getNewsgroup());
         assertEquals("news.apache.org", na.getHost());
         assertEquals("news", na.getType());
-        assertEquals("geronimo-dev@news.apache.org", na.toString());
+        assertEquals("geronimo-dev", na.toString());
         NewsAddress[] nas =
             NewsAddress.parse(
                 "geronimo-dev@news.apache.org, geronimo-user@news.apache.org");

Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ParameterListTest.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ParameterListTest.java?rev=381393&r1=381392&r2=381393&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ParameterListTest.java (original)
+++ geronimo/specs/trunk/geronimo-spec-javamail/src/test/java/javax/mail/internet/ParameterListTest.java Mon Feb 27 09:38:03 2006
@@ -26,14 +26,14 @@
     }
     public void testParameters() throws ParseException {
         ParameterList list =
-            new ParameterList("thing=value;thong=vulue;thung=git");
+            new ParameterList(";thing=value;thong=vulue;thung=git");
         assertEquals("value", list.get("thing"));
         assertEquals("vulue", list.get("thong"));
         assertEquals("git", list.get("thung"));
     }
 
     public void testQuotedParameter() throws ParseException {
-        ParameterList list = new ParameterList("foo=one;bar=\"two\"");
+        ParameterList list = new ParameterList(";foo=one;bar=\"two\"");
         assertEquals("one", list.get("foo"));
         assertEquals("two", list.get("bar"));
     }



Mime
View raw message