geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r149170 - in geronimo/trunk/specs/javamail/src: java/javax/mail/internet/ test/javax/mail/internet/
Date Sun, 30 Jan 2005 22:21:12 GMT
Author: jboynes
Date: Sun Jan 30 14:21:08 2005
New Revision: 149170

URL: http://svn.apache.org/viewcvs?view=rev&rev=149170
Log:
partial impl of MimeMessage and MimeMultipart

Removed:
    geronimo/trunk/specs/javamail/src/test/javax/mail/internet/InternetHeadersTest.java
Modified:
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetAddress.java
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMessage.java
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java
    geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeUtility.java

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetAddress.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetAddress.java?view=diff&r1=149169&r2=149170
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetAddress.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetAddress.java Sun Jan 30 14:21:08 2005
@@ -503,7 +503,11 @@
      */
     private static InternetAddress[] parse(String addresses, boolean strict, boolean veryStrict) throws AddressException {
         List addrs = new ArrayList();
+        parseHeader(addrs, addresses, strict, veryStrict);
+        return (InternetAddress[]) addrs.toArray(new InternetAddress[addrs.size()]);
+    }
 
+    static void parseHeader(List target, String addresses, boolean strict, boolean veryStrict) throws AddressException {
         // todo we need to parse the addresses per the RFC822 spec with certain relaxations which are not documented by JavaMail
         // for now, we ignore all flags and simply tokenize based on commas
 
@@ -515,10 +519,8 @@
             if (strict || veryStrict) {
                 addr.validate();
             }
-            addrs.add(addr);
+            target.add(addr);
         }
-
-        return (InternetAddress[]) addrs.toArray(new InternetAddress[addrs.size()]);
     }
 
     private static void init(InternetAddress addr, String text) {

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java?view=diff&r1=149169&r2=149170
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java Sun Jan 30 14:21:08 2005
@@ -17,273 +17,264 @@
 
 package javax.mail.internet;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
+import javax.mail.Address;
 import javax.mail.Header;
 import javax.mail.MessagingException;
 
 /**
+ * Class that represents the RFC822 headers associated with a message.
+ *
  * @version $Rev$ $Date$
  */
 public class InternetHeaders {
-    private static final String[] STRING_ARRAY = new String[0];
+    // RFC822 imposes an ordering on its headers so we use a LinkedHashedMap
+    private final LinkedHashMap headers = new LinkedHashMap();
 
     /**
-     * Parse the line into a <code>Header</code?
-     *
-     * @param line in the form <code>To: Apache Geronimo Users &lt;geronimo-user@apache.org&gt;</code>
-     * @return the parsed <code>Header</code>
+     * Create an empty InternetHeaders
      */
-    private static Header parse(String line) {
-        // Could use HeaderTokenizer here, but not really much point
-        int colon = line.indexOf(":");
-        String name = line.substring(0, colon).trim();
-        String value = line.substring(colon + 1).trim();
-        return new Header(name, value);
+    public InternetHeaders() {
+        // we need to initialize the headers in the correct order
+        // fields: dates source destination optional-field
+        // dates:
+        setHeaderList("Date", null);
+        setHeaderList("Resent-Date", null);
+        // source: trace originator resent
+        // trace: return received
+        setHeaderList("Return-path", null);
+        setHeaderList("Received", null);
+        // originator: authentic reply-to
+        setHeaderList("Sender", null);
+        setHeaderList("From", null);
+        setHeaderList("Reply-To", null);
+        // resent: resent-authentic resent-reply-to
+        setHeaderList("Resent-Sender", null);
+        setHeaderList("Resent-From", null);
+        setHeaderList("Resent-Reply-To", null);
+        // destination:
+        setHeaderList("To", null);
+        setHeaderList("Resent-To", null);
+        setHeaderList("cc", null);
+        setHeaderList("Resent-cc", null);
+        setHeaderList("bcc", null);
+        setHeaderList("Resent-bcc", null);
+        // optional-field:
+        setHeaderList("Message-ID", null);
+        setHeaderList("Resent-Message-ID", null);
+        setHeaderList("In-Reply-To", null);
+        setHeaderList("References", null);
+        setHeaderList("Keywords", null);
+        setHeaderList("Subject", null);
+        setHeaderList("Comments", null);
+        setHeaderList("Encrypted", null);
     }
 
     /**
-     * Stores the list of Headers, indexed by name (uppercased)
-     */
-    private Map _headers = new HashMap();
-    /**
-     * The last <code>Header</code> we added
-     */
-    private Header _last;
-    /**
-     * Stores the list of lines, in the order they were entered.
+     * Create a new InternetHeaders initialized by reading headers from the stream.
+     *
+     * @param in the RFC822 input stream to load from
+     * @throws MessagingException if there is a problem pasring the stream
      */
-    private List _lines = new LinkedList();
-
-    public InternetHeaders() {
-    }
-
     public InternetHeaders(InputStream in) throws MessagingException {
         load(in);
     }
 
     /**
-     * Add the given header and original line into the store.
-     * A maximum of one of the arguments can be null; if it is, it
-     * is dynamically created from the other. If both are <code>null</code>,
-     * then a <code>NullPointerException</code> will be raised.
+     * Read and parse the supplied stream and add all headers to the current set.
      *
-     * @param header the pre-parsed header
-     * @param line   the header line
+     * @param in the RFC822 input stream to load from
+     * @throws MessagingException if there is a problem pasring the stream
      */
-    private void add(Header header, String line) {
-        if (line == null) {
-            line = header.getName() + ": " + header.getValue();
-        } else if (header == null) {
-            header = parse(line);
-        }
-        String NAME = header.getName().toUpperCase();
-        List list = (List) _headers.get(NAME);
-        if (list == null) {
-            list = new LinkedList();
-            _headers.put(NAME, list);
-        }
-        list.add(header);
-        _lines.add(line);
-        _last = header;
-    }
-
-    public void addHeader(String name, String value) {
-        add(new Header(name, value), null);
-    }
-
-    public void addHeaderLine(String line) {
-        add(null, line);
-    }
-
-    public Enumeration getAllHeaderLines() {
-        return Collections.enumeration(_lines);
-    }
-
-    public Enumeration getAllHeaders() {
-        List result = new LinkedList();
-        Iterator it = _headers.values().iterator();
-        while (it.hasNext()) {
-            List list = (List) it.next();
-            result.addAll(list);
-        }
-        return Collections.enumeration(result);
+    public void load(InputStream in) throws MessagingException {
+        // todo implement
+        throw new UnsupportedOperationException();
     }
 
+    /**
+     * Return all the values for the specified header.
+     * @param name the header to return
+     * @return the values for that header, or null if the header is not present
+     */
     public String[] getHeader(String name) {
         List headers = getHeaderList(name);
         if (headers == null) {
             return null;
         } else {
-            List result = new LinkedList();
-            Iterator it = headers.iterator();
-            while (it.hasNext()) {
-                Header element = (Header) it.next();
-                result.add(element.getValue());
+            String[] result = new String[headers.size()];
+            for (int i = 0; i < headers.size(); i++) {
+                InternetHeader header = (InternetHeader) headers.get(i);
+                result[i] = header.getValue();
             }
-            return (String[]) result.toArray(STRING_ARRAY);
+            return result;
         }
     }
 
+    /**
+     * Return the values for the specified header as a single String.
+     * If the header has more than one value then all values are concatenated
+     * together separated by the supplied delimiter.
+     *
+     * @param name the header to return
+     * @param delimiter the delimiter used in concatenation
+     * @return the header as a single String
+     */
     public String getHeader(String name, String delimiter) {
         List list = getHeaderList(name);
-        if (list == null || list.isEmpty()) {
+        if (list == null) {
             return null;
+        } else if (list.isEmpty()) {
+            return "";
+        } else if (list.size() == 1) {
+            return ((InternetHeader)list.get(0)).getValue();
         } else {
-            Iterator it = list.iterator();
-            StringBuffer result = new StringBuffer();
-            boolean first = true;
-            while (it.hasNext()) {
-                if (first) {
-                    first = false;
-                } else {
-                    if (delimiter == null) {
-                        break;
-                    } else {
-                        result.append(delimiter);
-                    }
-                }
-                Header header = (Header) it.next();
-                result.append(header.getValue());
+            StringBuffer buf = new StringBuffer(20 * list.size());
+            buf.append(((InternetHeader)list.get(0)).getValue());
+            for (int i = 1; i < list.size(); i++) {
+                buf.append(delimiter);
+                buf.append(((InternetHeader) list.get(i)).getValue());
             }
-            return result.toString();
+            return buf.toString();
         }
     }
 
-    private List getHeaderList(String name) {
-        return (List) _headers.get(name.toUpperCase());
+    /**
+     * Set the value of the header to the supplied value; any existing
+     * headers are removed.
+     *
+     * @param name the name of the header
+     * @param value the new value
+     */
+    public void setHeader(String name, String value) {
+        List list = new ArrayList();
+        list.add(new InternetHeader(name, value));
+        setHeaderList(name, list);
     }
 
-    private Enumeration getHeaders(String[] names, boolean match) {
-        List matches = new ArrayList(names.length);
-        for (int i = 0; i < names.length; i++) {
-            matches.add(names[i].toUpperCase());
-        }
-        List result = new LinkedList();
-        Iterator entries = _headers.entrySet().iterator();
-        while (entries.hasNext()) {
-            Map.Entry entry = (Map.Entry) entries.next();
-            if (matches.contains(entry.getKey()) == match) {
-                result.addAll((Collection) entry.getValue());
-            }
+    /**
+     * Add a new value to the header with the supplied name.
+     * @param name the name of the header to add a new value for
+     * @param value another value
+     */
+    public void addHeader(String name, String value) {
+        List list = getHeaderList(name);
+        if (list == null) {
+            list = new ArrayList();
         }
-        return Collections.enumeration(result);
+        list.add(new InternetHeader(name, value));
     }
 
-    private Enumeration getLines(String[] names, boolean match) {
-        List matches = new ArrayList(names.length);
-        for (int i = 0; i < names.length; i++) {
-            matches.add(names[i].toUpperCase());
-        }
-        Iterator it = _lines.iterator();
-        List result = new LinkedList();
-        while (it.hasNext()) {
-            String line = (String) it.next();
-            int colon = line.indexOf(":");
-            String name = line.substring(0, colon).toUpperCase();
-            if (matches.contains(name) == match) {
-                result.add(line);
-            }
+    /**
+     * Remove all header entries with the supplied name
+     * @param name the header to remove
+     */
+    public void removeHeader(String name) {
+        List list = getHeaderList(name);
+        list.clear();
+    }
 
+    /**
+     * Return all headers.
+     * @return an Enumeration<Header> containing all headers
+     */
+    public Enumeration getAllHeaders() {
+        List result = new ArrayList(headers.size() * 2);
+        Iterator it = headers.values().iterator();
+        while (it.hasNext()) {
+            List list = (List) it.next();
+            result.addAll(list);
         }
         return Collections.enumeration(result);
     }
 
-    public Enumeration getMatchingHeaderLines(String[] names) {
-        return getLines(names, true);
+    public Enumeration getMatchingHeaders(String[] names) {
+        // todo implement
+        throw new UnsupportedOperationException();
     }
 
-    public Enumeration getMatchingHeaders(String[] names) {
-        return getHeaders(names, true);
+    public Enumeration getNonMatchingHeaders(String[] names) {
+        // todo implement
+        throw new UnsupportedOperationException();
     }
 
-    public Enumeration getNonMatchingHeaderLines(String[] names) {
-        return getLines(names, false);
+    public void addHeaderLine(String line) {
+        // todo implement
+        throw new UnsupportedOperationException();
     }
 
-    public Enumeration getNonMatchingHeaders(String[] names) {
-        return getHeaders(names, false);
+    public Enumeration getAllHeaderLines() {
+        // todo implement
+        throw new UnsupportedOperationException();
     }
 
-    public void load(InputStream in) throws MessagingException {
-        try {
-            StringBuffer buffer = new StringBuffer();
-            boolean cr = false;
-            boolean lf = false;
-            boolean flush = true;
-            String line = null;
-            while (true) {
-                int c = in.read();
-                boolean start = buffer.length() == 0;
-                boolean white = c == '\t' || c == ' ';
-                if (start) {
-                    if (line != null) {
-                        if (white) {
-                            // skip any further whitespace
-                            while (c == '\t' || c == ' ')
-                                c = in.read();
-                            buffer.append(line);
-                            buffer.append(' ');
-                            // and replace with single whitespace char
-                        } else {
-                            addHeaderLine(line);
-                            line = null;
-                        }
-                    }
-                }
-                if (c == '\r') {
-                    cr = true;
-                } else if (c == '\n') {
-                    lf = true;
-                } else {
-                    buffer.append((char) c);
-                    // if we've only got one of them,
-                    // followed by a non\r\n character,
-                    // pretend we've seen both
-                    if (cr || lf) {
-                        cr = lf = true;
-                    }
-                }
-                if (cr && lf) {
-                    line = buffer.toString().trim();
-                    if (line.length() == 0) {
-                        break;
-                    }
-                    buffer = new StringBuffer();
-                    cr = lf = false; // reset for next line
-                }
+    public Enumeration getMatchingHeaderLines(String[] names) {
+        // todo implement
+        throw new UnsupportedOperationException();
+    }
 
-            }
-        } catch (IOException e) {
-            throw new MessagingException(e.getMessage());
+    public Enumeration getNonMatchingHeaderLines(String[] names) {
+        // todo implement
+        throw new UnsupportedOperationException();
+    }
+
+
+    /**
+     * Return a header as a list of InternetAddresses
+     *
+     * @param name   the header to get
+     * @param strict whether the header should be strictly parser; see {@link InternetAddress#parseHeader(java.util.List, String, boolean, boolean)}
+     * @return
+     */
+    InternetAddress[] getHeaderAsAddresses(String name, boolean strict) throws MessagingException {
+        List addrs = new ArrayList();
+        List headers = getHeaderList(name);
+        if (headers == null) {
+            return null;
         }
+        for (Iterator i = headers.iterator(); i.hasNext();) {
+            String header = (String) i.next();
+            InternetAddress.parseHeader(addrs, header, strict, true);
+        }
+        return (InternetAddress[]) addrs.toArray(new InternetAddress[addrs.size()]);
     }
 
-    public void removeHeader(String name) {
-        String NAME = name.toUpperCase();
-        _headers.remove(NAME);
-        NAME = NAME + ":";
-        // go through list as well
-        Iterator it = _lines.iterator();
-        while (it.hasNext()) {
-            String line = (String) it.next();
-            if (line.toUpperCase().startsWith(NAME)) {
-                it.remove();
-            }
+    void setHeader(String name, Address[] addresses) {
+        List list = new ArrayList(addresses.length);
+        for (int i = 0; i < addresses.length; i++) {
+            Address address = addresses[i];
+            list.add(address.toString());
         }
+        headers.put(name, list);
     }
 
-    public void setHeader(String name, String value) {
-        removeHeader(name);
-        addHeader(name, value);
+    private List getHeaderList(String name) {
+        return (List) headers.get(name.toLowerCase());
+    }
+
+    private void setHeaderList(String name, List list) {
+        headers.put(name.toLowerCase(), list);
+    }
+
+    private static class InternetHeader extends Header {
+        public InternetHeader(String name, String value) {
+            super(name, value);
+        }
+
+        public boolean equals(Object obj) {
+            if (this == obj) return true;
+            if (obj instanceof InternetHeader == false) return false;
+            final InternetHeader other = (InternetHeader) obj;
+            return getName().equalsIgnoreCase(other.getName());
+        }
+
+        public int hashCode() {
+            return getName().toLowerCase().hashCode();
+        }
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMessage.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMessage.java?view=diff&r1=149169&r2=149170
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMessage.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMessage.java Sun Jan 30 14:21:08 2005
@@ -32,22 +32,28 @@
 import javax.mail.Multipart;
 import javax.mail.Session;
 
-// TODO there's a bunch of methods that overlap between MimeMessaeg and MimeBodyPart.
-// If we can implement one in terms of the other it would be more efficient, and
-// it's fairly likely that we can ...
-
 /**
  * @version $Rev$ $Date$
  */
 public class MimeMessage extends Message implements MimePart {
+    /**
+     * Extends {@link javax.mail.Message.RecipientType} to support addition recipient types.
+     */
     public static class RecipientType extends Message.RecipientType {
-        public static final RecipientType NEWSGROUPS =
-                new RecipientType("Newsgroups");
+        /**
+         * Recipient type for Usenet news.
+         */
+        public static final RecipientType NEWSGROUPS = new RecipientType("Newsgroups");
 
         protected RecipientType(String type) {
             super(type);
         }
 
+        /**
+         * Ensure the singleton is returned.
+         *
+         * @return resolved object
+         */
         protected Object readResolve() throws ObjectStreamException {
             if (this.type.equals("Newsgroups")) {
                 return NEWSGROUPS;
@@ -57,130 +63,260 @@
         }
     }
 
+    /**
+     * The {@link DataHandler} for this Message's content.
+     */
+    protected DataHandler dh;
+    /**
+     * This message's content (unless sourced from a SharedInputStream).
+     */
     protected byte content[];
+    /**
+     * If the data for this message was supplied by a {@link SharedInputStream}
+     * then this is another such stream representing the content of this message;
+     * if this field is non-null, then {@link #content} will be null.
+     */
     protected InputStream contentStream;
-    protected DataHandler dh;
-    protected Flags flags;
+    /**
+     * This message's headers.
+     */
     protected InternetHeaders headers;
+    /**
+     * This message's flags.
+     */
+    protected Flags flags;
+    /**
+     * Flag indicating that the message has been modified; set to true when
+     * an empty message is created or when {@link #saveChanges()} is called.
+     */
     protected boolean modified;
+    /**
+     * Flag indicating that the message has been saved.
+     */
     protected boolean saved;
 
-    protected MimeMessage(Folder folder, InputStream in, int number)
-            throws MessagingException {
+    /**
+     * Create a new MimeMessage.
+     * An empty message is created, with empty {@link #headers} and empty {@link #flags}.
+     * The {@link #modified} flag is set.
+     *
+     * @param session the session for this message
+     */
+    public MimeMessage(Session session) {
+        super(session);
+        headers = new InternetHeaders();
+        flags = new Flags();
+        modified = true;
+    }
+
+    /**
+     * Create a MimeMessage by reading an parsing the data from the supplied stream.
+     * @param session the session for this message
+     * @param in the stream to load from
+     * @throws MessagingException if there is a problem reading or parsing the stream
+     */
+    public MimeMessage(Session session, InputStream in) throws MessagingException {
+        super(session);
+        parse(in);
+    }
+
+    /**
+     * Copy a MimeMessage.
+     * @param message the message to copy
+     * @throws MessagingException is there was a problem copying the message
+     */
+    public MimeMessage(MimeMessage message) throws MessagingException {
+        super(message.session);
+        // todo copy the message - how?
+        throw new UnsupportedOperationException();
     }
 
+    /**
+     * Create an new MimeMessage in the supplied {@link Folder} and message number.
+     * @param folder the Folder that contains the new message
+     * @param number the message number of the new message
+     */
     protected MimeMessage(Folder folder, int number) {
+        super(folder, number);
+        headers = new InternetHeaders();
+        flags = new Flags();
+        modified = true;
+    }
+
+    /**
+     * Create a MimeMessage by reading an parsing the data from the supplied stream.
+     * @param folder the folder for this message
+     * @param in the stream to load from
+     * @param number the message number of the new message
+     * @throws MessagingException if there is a problem reading or parsing the stream
+     */
+    protected MimeMessage(Folder folder, InputStream in, int number) throws MessagingException {
+        super(folder, number);
+        parse(in);
+    }
+
+    /**
+     * Create a MimeMessage with the supplied headers and content.
+     * @param folder the folder for this message
+     * @param headers the headers for the new message
+     * @param content the content of the new message
+     * @param number the message number of the new message
+     * @throws MessagingException if there is a problem reading or parsing the stream
+     */
+    protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int number) throws MessagingException {
+        super(folder, number);
+        this.headers = headers;
+        this.content = content;
+        modified = true;
+    }
+
+    /**
+     * Parse the supplied stream and initialize {@link #headers} and {@link #content} appropriately.
+     * @param in the stream to read
+     * @throws MessagingException if there was a problem parsing the stream
+     */
+    protected void parse(InputStream in) throws MessagingException {
+        // TODO Implement method
+        throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    protected MimeMessage(Folder folder,
-                          InternetHeaders headers,
-                          byte[] content,
-                          int number)
-            throws MessagingException {
+    public Address[] getFrom() throws MessagingException {
+        boolean strict = isStrictAddressing();
+        Address[] result = getHeaderAsAddresses("From", strict);
+        if (result == null) {
+            result = getHeaderAsAddresses("Sender", strict);
+        }
+        return result;
     }
 
-    public MimeMessage(MimeMessage message) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void setFrom(Address address) throws MessagingException {
+        setHeader("From", address);
     }
 
-    public MimeMessage(Session session) {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    /**
+     * Set the "From" header using the value returned by {@link InternetAddress#getLocalAddress(javax.mail.Session)}.
+     * @throws MessagingException if there was a problem setting the header
+     */
+    public void setFrom() throws MessagingException {
+        setFrom(InternetAddress.getLocalAddress(session));
+    }
+
+    public void addFrom(Address[] addresses) throws MessagingException {
+        addHeader("From", addresses);
     }
 
-    public MimeMessage(Session session, InputStream in)
-            throws MessagingException {
-        this.session = session;
-        contentStream = in;
+    /**
+     * Return the "Sender" header as an address.
+     * @return the "Sender" header as an address, or null if not present
+     * @throws MessagingException if there was a problem parsing the header
+     */
+    public Address getSender() throws MessagingException {
+        InternetAddress[] addrs = getHeaderAsAddresses("Sender", isStrictAddressing());
+        return addrs.length > 0 ? addrs[0] : null;
     }
 
-    public void addFrom(Address[] address) throws MessagingException {
+    /**
+     * Set the "Sender" header.
+     * @param address the new Sender address
+     * @throws MessagingException if there was a problem setting the header
+     */
+    public void setSender(Address address) throws MessagingException {
+        setHeader("Sender", address);
+    }
+
+    public Address[] getRecipients(Message.RecipientType type) throws MessagingException {
+        return getHeaderAsAddresses(getHeaderForRecipientType(type), isStrictAddressing());
+    }
+
+    public Address[] getAllRecipients() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void addHeader(String name, String value)
-            throws MessagingException {
-        headers.addHeader(name, value);
+    public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
+        setHeader(getHeaderForRecipientType(type), addresses);
     }
 
-    public void addHeaderLine(String line) throws MessagingException {
-        headers.addHeaderLine(line);
+    public void setRecipients(Message.RecipientType type, String address) throws MessagingException {
+        setHeader(getHeaderForRecipientType(type), address);
     }
 
-    public void addRecipients(Message.RecipientType type, Address[] address)
-            throws MessagingException {
+    public void addRecipients(Message.RecipientType type, Address[] address) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void addRecipients(Message.RecipientType type, String address)
-            throws MessagingException {
-        addRecipients(type, InternetAddress.parse(address));
+    public void addRecipients(Message.RecipientType type, String address) throws MessagingException {
+        addHeader(getHeaderForRecipientType(type), address);
     }
 
-    protected InternetHeaders createInternetHeaders(InputStream in)
-            throws MessagingException {
+    public Address[] getReplyTo() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Enumeration getAllHeaderLines() throws MessagingException {
-        return headers.getAllHeaderLines();
+    public void setReplyTo(Address[] address) throws MessagingException {
+        // TODO Implement method
+        throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Enumeration getAllHeaders() throws MessagingException {
-        return headers.getAllHeaders();
+    public String getSubject() throws MessagingException {
+        // TODO Implement method
+        throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Address[] getAllRecipients() throws MessagingException {
+    public void setSubject(String subject) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Object getContent() throws MessagingException, IOException {
+    public void setSubject(String subject, String charset) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getContentID() throws MessagingException {
+    public Date getSentDate() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String[] getContentLanguage() throws MessagingException {
+    public void setSentDate(Date sent) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getContentMD5() throws MessagingException {
+    public Date getReceivedDate() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    protected InputStream getContentStream() throws MessagingException {
+    public int getSize() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getContentType() throws MessagingException {
+    public int getLineCount() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public synchronized DataHandler getDataHandler()
-            throws MessagingException {
+    public String getContentType() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getDescription() throws MessagingException {
+    public boolean isMimeType(String type) throws MessagingException {
+        ContentType c1 = new ContentType(type);
+        ContentType c2 = new ContentType(dh.getContentType());
+        return c1.match(c2);
+    }
+
+    public String getDisposition() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getDisposition() throws MessagingException {
+    public void setDisposition(String disposition) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
@@ -190,126 +326,107 @@
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getFileName() throws MessagingException {
+    public String getContentID() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public synchronized Flags getFlags() throws MessagingException {
+    public void setContentID(String cid) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Address[] getFrom() throws MessagingException {
+    public String getContentMD5() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String[] getHeader(String name) throws MessagingException {
+    public void setContentMD5(String md5) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public String getHeader(String name, String delimiter)
-            throws MessagingException {
+    public String getDescription() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public InputStream getInputStream() throws MessagingException, IOException {
+    public void setDescription(String description) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public int getLineCount() throws MessagingException {
+    public void setDescription(String description, String charset) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Enumeration getMatchingHeaderLines(String[] names)
-            throws MessagingException {
-        return headers.getMatchingHeaderLines(names);
+    public String[] getContentLanguage() throws MessagingException {
+        // TODO Implement method
+        throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Enumeration getMatchingHeaders(String[] names)
-            throws MessagingException {
-        return getMatchingHeaders(names);
+    public void setContentLanguage(String[] languages) throws MessagingException {
+        // TODO Implement method
+        throw new UnsupportedOperationException("Method not yet implemented");
     }
 
     public String getMessageID() throws MessagingException {
         return headers.getHeader("Message-ID", null);
     }
 
-    public Enumeration getNonMatchingHeaderLines(String[] names)
-            throws MessagingException {
-        return headers.getNonMatchingHeaderLines(names);
-    }
-
-    public Enumeration getNonMatchingHeaders(String[] names)
-            throws MessagingException {
-        return headers.getNonMatchingHeaders(names);
-    }
-
-    public InputStream getRawInputStream() throws MessagingException {
+    public String getFileName() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Date getReceivedDate() throws MessagingException {
+    public void setFileName(String name) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Address[] getRecipients(Message.RecipientType type)
-            throws MessagingException {
+    public InputStream getInputStream() throws MessagingException, IOException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Address[] getReplyTo() throws MessagingException {
+    protected InputStream getContentStream() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Address getSender() throws MessagingException {
+    public InputStream getRawInputStream() throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public Date getSentDate() throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public synchronized DataHandler getDataHandler() throws MessagingException {
+        return dh;
     }
 
-    public int getSize() throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public Object getContent() throws MessagingException, IOException {
+        return getDataHandler().getContent();
     }
 
-    public String getSubject() throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void setDataHandler(DataHandler handler) throws MessagingException {
+        dh = handler;
     }
 
-    public boolean isMimeType(String type) throws MessagingException {
-        ContentType c1 = new ContentType(type);
-        ContentType c2 = new ContentType(dh.getContentType());
-        return c1.match(c2);
+    public void setContent(Object content, String type) throws MessagingException {
+        setDataHandler(new DataHandler(content, type));
     }
 
-    public synchronized boolean isSet(Flags.Flag flag)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void setText(String text) throws MessagingException {
+        setText(text, MimeUtility.getDefaultJavaCharset());
     }
 
-    protected void parse(InputStream in) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void setText(String text, String charset) throws MessagingException {
+        setContent(text, "text/plain; charset=" + charset);
     }
 
-    public void removeHeader(String name) throws MessagingException {
-        headers.removeHeader(name);
+    public void setContent(Multipart part) throws MessagingException {
+        setDataHandler(new DataHandler(part, part.getContentType()));
+        part.setParent(this);
     }
 
     public Message reply(boolean replyToAll) throws MessagingException {
@@ -317,124 +434,131 @@
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void saveChanges() throws MessagingException {
-        updateHeaders();
-    }
-
-    public void setContent(Multipart part) throws MessagingException {
+    public void writeTo(OutputStream out) throws MessagingException, IOException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void setContent(Object content, String type)
-            throws MessagingException {
+    public void writeTo(OutputStream out, String[] ignoreHeaders) throws MessagingException, IOException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void setContentID(String cid) throws MessagingException {
+    public String[] getHeader(String name) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void setContentLanguage(String[] languages)
-            throws MessagingException {
+    public String getHeader(String name, String delimiter) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void setContentMD5(String md5) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void setHeader(String name, String value) throws MessagingException {
+        headers.setHeader(name, value);
     }
 
-    public void setDataHandler(DataHandler handler) throws MessagingException {
-        dh = handler;
+    public void addHeader(String name, String value) throws MessagingException {
+        headers.addHeader(name, value);
     }
 
-    public void setDescription(String description) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void removeHeader(String name) throws MessagingException {
+        headers.removeHeader(name);
     }
 
-    public void setDescription(String description, String charset)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public Enumeration getAllHeaders() throws MessagingException {
+        return headers.getAllHeaders();
     }
 
-    public void setDisposition(String disposition) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public Enumeration getMatchingHeaders(String[] names) throws MessagingException {
+        return getMatchingHeaders(names);
     }
 
-    public void setFileName(String name) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {
+        return headers.getNonMatchingHeaders(names);
     }
 
-    public synchronized void setFlags(Flags flags, boolean set)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void addHeaderLine(String line) throws MessagingException {
+        headers.addHeaderLine(line);
     }
 
-    public void setFrom() throws MessagingException {
-        setFrom(InternetAddress.getLocalAddress(session));
+    public Enumeration getAllHeaderLines() throws MessagingException {
+        return headers.getAllHeaderLines();
     }
 
-    public void setFrom(Address address) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {
+        return headers.getMatchingHeaderLines(names);
     }
 
-    public void setHeader(String name, String value)
-            throws MessagingException {
-        headers.setHeader(name, value);
+    public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {
+        return headers.getNonMatchingHeaderLines(names);
     }
 
-    public void setRecipients(Message.RecipientType type, Address[] address)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public synchronized Flags getFlags() throws MessagingException {
+        return (Flags) flags.clone();
     }
 
-    public void setRecipients(Message.RecipientType type, String address)
-            throws MessagingException {
-        setRecipients(type, InternetAddress.parse(address));
+    public synchronized boolean isSet(Flags.Flag flag) throws MessagingException {
+        return flags.contains(flag);
     }
 
-    public void setReplyTo(Address[] address) throws MessagingException {
+    public synchronized void setFlags(Flags flags, boolean set) throws MessagingException {
         // TODO Implement method
         throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void setSentDate(Date sent) throws MessagingException {
+    public void saveChanges() throws MessagingException {
+        updateHeaders();
     }
 
-    public void setSubject(String subject) throws MessagingException {
+    protected void updateHeaders() throws MessagingException {
     }
 
-    public void setSubject(String subject, String charset)
-            throws MessagingException {
+    protected InternetHeaders createInternetHeaders(InputStream in) throws MessagingException {
+        // TODO Implement method
+        throw new UnsupportedOperationException("Method not yet implemented");
     }
 
-    public void setText(String text) throws MessagingException {
+    private InternetAddress[] getHeaderAsAddresses(String header, boolean strict) throws MessagingException {
+        return headers.getHeaderAsAddresses(header, strict);
     }
 
-    public void setText(String text, String charset)
-            throws MessagingException {
+    private boolean isStrictAddressing() {
+        String property = session.getProperty("mail.mime.address.strict");
+        return property == null ? true: Boolean.valueOf(property).booleanValue();
     }
 
-    protected void updateHeaders() throws MessagingException {
+    private void setHeader(String header, Address address) {
+        if (address == null) {
+            headers.removeHeader(header);
+        } else {
+            headers.setHeader(header, address.toString());
+        }
     }
 
-    public void writeTo(OutputStream out) throws MessagingException, IOException {
+    private void setHeader(String header, Address[] addresses) {
+        if (addresses == null) {
+            headers.removeHeader(header);
+        } else {
+            headers.setHeader(header, addresses);
+        }
     }
 
-    public void writeTo(OutputStream out, String[] ignoreHeaders) throws MessagingException, IOException {
+    private void addHeader(String header, Address[] addresses) {
+        headers.addHeader(header, InternetAddress.toString(addresses));
     }
 
-    public void setSender(Address address) throws MessagingException {
+    private String getHeaderForRecipientType(Message.RecipientType type) throws MessagingException {
+        if (RecipientType.TO == type) {
+            return "To";
+        } else if (RecipientType.CC == type) {
+            return "Cc";
+        } else if (RecipientType.BCC == type) {
+            return "Bcc";
+        } else if (RecipientType.NEWSGROUPS == type) {
+            return "Newsgroups";
+        } else {
+            throw new MessagingException("Unsupported recipient type: " + type.toString());
+        }
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java?view=diff&r1=149169&r2=149170
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeMultipart.java Sun Jan 30 14:21:08 2005
@@ -20,86 +20,146 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.PrintStream;
 import javax.activation.DataSource;
 import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.mail.Multipart;
+import javax.mail.MultipartDataSource;
 
 /**
  * @version $Rev$ $Date$
  */
 public class MimeMultipart extends Multipart {
+    /**
+     * DataSource that provides our InputStream.
+     */
     protected DataSource ds;
+    /**
+     * Indicates if the data has been parsed.
+     */
     protected boolean parsed;
 
-    public MimeMultipart() {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
-    }
+    private transient ContentType type;
 
-    public MimeMultipart(DataSource dataSource) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    /**
+     * Create an empty MimeMultipart with content type "multipart/mixed"
+     */
+    public MimeMultipart() {
+        this("mixed");
     }
 
+    /**
+     * Create an empty MimeMultipart with the subtype supplied.
+     *
+     * @param subtype the subtype
+     */
     public MimeMultipart(String subtype) {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+        type = new ContentType("multipart", subtype, null);
+        type.setParameter("boundary", getBoundary());
+        contentType = type.toString();
     }
 
-    protected InternetHeaders createInternetHeaders(InputStream in)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    /**
+     * Create a MimeMultipart from the supplied DataSource.
+     *
+     * @param dataSource the DataSource to use
+     * @throws MessagingException
+     */
+    public MimeMultipart(DataSource dataSource) throws MessagingException {
+        ds = dataSource;
+        if (dataSource instanceof MultipartDataSource) {
+            super.setMultipartDataSource((MultipartDataSource) dataSource);
+            parsed = true;
+        } else {
+            type = new ContentType(ds.getContentType());
+            contentType = type.toString();
+            parsed = false;
+        }
     }
 
-    protected MimeBodyPart createMimeBodyPart(InputStream in)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public void setSubType(String subtype) throws MessagingException {
+        type.setSubType(subtype);
+        contentType = type.toString();
     }
 
-    protected MimeBodyPart createMimeBodyPart(InternetHeaders headers,
-                                              byte[] data)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public int getCount() throws MessagingException {
+        parse();
+        return super.getCount();
     }
 
-    public synchronized BodyPart getBodyPart(int part)
-            throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    public synchronized BodyPart getBodyPart(int part) throws MessagingException {
+        parse();
+        return super.getBodyPart(part);
     }
 
     public BodyPart getBodyPart(String cid) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+        parse();
+        for (int i = 0; i < parts.size(); i++) {
+            MimeBodyPart bodyPart = (MimeBodyPart) parts.get(i);
+            if (cid.equals(bodyPart.getContentID())) {
+                return bodyPart;
+            }
+        }
+        return null;
     }
 
-    public int getCount() throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    protected void updateHeaders() throws MessagingException {
+        parse();
+        for (int i = 0; i < parts.size(); i++) {
+            MimeBodyPart bodyPart = (MimeBodyPart) parts.get(i);
+            bodyPart.updateHeaders();
+        }
+    }
+
+    private static byte[] dash = { '-', '-' };
+
+    public void writeTo(OutputStream out) throws IOException, MessagingException {
+        parse();
+        String boundary = type.getParameter("boundary");
+        byte[] bytes = boundary.getBytes();
+        PrintStream pos = new PrintStream(out, false);
+        for (int i = 0; i < parts.size(); i++) {
+            BodyPart bodyPart = (BodyPart) parts.get(i);
+            pos.print(dash);
+            pos.println(bytes);
+            bodyPart.writeTo(pos);
+            pos.println();
+        }
+        pos.print(dash);
+        pos.print(bytes);
+        pos.println(dash);
+        pos.flush();
     }
 
     protected void parse() throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+        if (parsed) {
+            return;
+        }
+        parsed = true;
     }
 
-    public void setSubType(String subtype) throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    protected InternetHeaders createInternetHeaders(InputStream in) throws MessagingException {
+        return new InternetHeaders(in);
     }
 
-    protected void updateHeaders() throws MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    protected MimeBodyPart createMimeBodyPart(InternetHeaders headers, byte[] data) throws MessagingException {
+        return new MimeBodyPart(headers, data);
     }
 
-    public void writeTo(OutputStream out)
-            throws IOException, MessagingException {
-        // TODO Implement method
-        throw new UnsupportedOperationException("Method not yet implemented");
+    protected MimeBodyPart createMimeBodyPart(InputStream in) throws MessagingException {
+        return new MimeBodyPart(in);
+    }
+
+    private static int part;
+
+    private synchronized static String getBoundary() {
+        int i;
+        synchronized(MimeMultipart.class) {
+            i = part++;
+        }
+        StringBuffer buf = new StringBuffer(64);
+        buf.append("----=_Part_").append(i).append('.').append(System.currentTimeMillis());
+        return buf.toString();
     }
 }

Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeUtility.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeUtility.java?view=diff&r1=149169&r2=149170
==============================================================================
--- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeUtility.java (original)
+++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeUtility.java Sun Jan 30 14:21:08 2005
@@ -34,73 +34,55 @@
     private MimeUtility() {
     }
 
-    // From J2SE 1.4 API Docs (Constant Values)
     public static final int ALL = -1;
 
-    public static InputStream decode(InputStream in, String encoding)
-            throws MessagingException {
+    private static String defaultJavaCharset;
+
+    public static InputStream decode(InputStream in, String encoding) throws MessagingException {
         // TODO - take account of encoding
         return in;
     }
 
-    public static String decodeText(String word)
-            throws UnsupportedEncodingException {
+    public static String decodeText(String word) throws UnsupportedEncodingException {
         // TODO - take account of encoding
         return word;
     }
 
-    public static String decodeWord(String word)
-            throws ParseException, UnsupportedEncodingException {
+    public static String decodeWord(String word) throws ParseException, UnsupportedEncodingException {
         // TODO - take account of encoding
         return word;
     }
 
-    public static OutputStream encode(OutputStream out, String encoding)
-            throws MessagingException {
+    public static OutputStream encode(OutputStream out, String encoding) throws MessagingException {
         // TODO - take account of encoding
         return out;
     }
 
-    public static OutputStream encode(OutputStream out,
-                                      String encoding,
-                                      String filename)
-            throws MessagingException {
+    public static OutputStream encode(OutputStream out, String encoding, String filename) throws MessagingException {
         // TODO - take account of encoding
         return out;
     }
 
-    public static String encodeText(String word)
-            throws UnsupportedEncodingException {
+    public static String encodeText(String word) throws UnsupportedEncodingException {
         // TODO - take account of encoding
         return word;
     }
 
-    public static String encodeText(String word,
-                                    String characterset,
-                                    String encoding)
-            throws UnsupportedEncodingException {
+    public static String encodeText(String word, String characterset, String encoding) throws UnsupportedEncodingException {
         // TODO - take account of encoding
         return word;
     }
 
-    public static String encodeWord(String word)
-            throws UnsupportedEncodingException {
+    public static String encodeWord(String word) throws UnsupportedEncodingException {
         // TODO - take account of encoding
         return word;
     }
 
-    public static String encodeWord(String word,
-                                    String characteset,
-                                    String encoding)
-            throws UnsupportedEncodingException {
+    public static String encodeWord(String word, String characteset, String encoding) throws UnsupportedEncodingException {
         // TODO - take account of encoding
         return word;
     }
 
-    public static String getDefaultJavaCharset() {
-        return "utf-8";
-    }
-
     public static String getEncoding(DataHandler handler) {
         // TODO figure what type of data it is
         return "binary";
@@ -111,8 +93,13 @@
         return "binary";
     }
 
+    public static String quote(String word, String specials) {
+        // TODO Check for specials
+        return word;
+    }
+
     public static String javaCharset(String charset) {
-        // TODO Perform translations as appropriate        
+        // TODO Perform translations as appropriate
         return charset;
     }
 
@@ -121,8 +108,19 @@
         return charset;
     }
 
-    public static String quote(String word, String specials) {
-        // TODO Check for specials
-        return word;
+    public static String getDefaultJavaCharset() {
+        try {
+            String charset = System.getProperty("mail.mime.charset");
+            if (charset != null) {
+                return javaCharset(charset);
+            }
+            charset = System.getProperty("file.encoding");
+            if (charset != null) {
+                return charset;
+            }
+        } catch (SecurityException e) {
+                // ignore
+        }
+        return "utf-8";
     }
 }



Mime
View raw message