You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by db...@apache.org on 2003/09/04 04:14:41 UTC

cvs commit: incubator-geronimo/specs/javamail/src/java/javax/mail/internet ContentDisposition.java HeaderTokenizer.java InternetHeaders.java MailDateFormat.java MimePartDataSource.java NewsAddress.java ParameterList.java

dblevins    2003/09/03 19:14:40

  Modified:    specs/javamail/src/java/javax/mail/internet
                        ContentDisposition.java HeaderTokenizer.java
                        InternetHeaders.java MailDateFormat.java
                        MimePartDataSource.java NewsAddress.java
                        ParameterList.java
  Log:
  Patch: GERONIMO 58,59,60,61,62,63,65
  From:  Alex Blewitt
  
  o Implemented missing methods in HeaderTokenizer
  o Implemented InternetHeaders
  o Implemented javax.mail.MailDateFormat
  o Fixed bug in parsing ParameterList during null pointer
  o Provided unimplemented methods for MimePartDataSource
  o Added parse method for NewsAddress using StringTokenizer
  
  Revision  Changes    Path
  1.2       +24 -12    incubator-geronimo/specs/javamail/src/java/javax/mail/internet/ContentDisposition.java
  
  Index: ContentDisposition.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/ContentDisposition.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContentDisposition.java	16 Aug 2003 01:55:48 -0000	1.1
  +++ ContentDisposition.java	4 Sep 2003 02:14:40 -0000	1.2
  @@ -67,14 +67,22 @@
       private String _disposition;
       private ParameterList _list;
       public ContentDisposition() {
  +        setDisposition(null);
  +        setParameterList(null);
       }
       public ContentDisposition(String disposition) throws ParseException {
  -        // parse it
  -        // TODO implement
  +        ParameterList list = null;
  +        int semicolon;
  +        if (disposition != null && (semicolon = disposition.indexOf(";")) != -1) {
  +            list = new ParameterList(disposition.substring(semicolon + 1));
  +            disposition = disposition.substring(0, semicolon);
  +        }
  +        setDisposition(disposition);
  +        setParameterList(list);
       }
       public ContentDisposition(String disposition, ParameterList list) {
  -        _disposition = disposition;
  -        _list = list;
  +        setDisposition(disposition);
  +        setParameterList(list);
       }
       public String getDisposition() {
           return _disposition;
  @@ -93,17 +101,21 @@
           _disposition = string;
       }
       public void setParameter(String name, String value) {
  -        if (_list == null) {
  -            _list = new ParameterList();
  -        }
  +        _list = new ParameterList();
           _list.set(name, value);
       }
       public void setParameterList(ParameterList list) {
  -        _list = list;
  +        if (list == null) {
  +            _list = new ParameterList();
  +        } else {
  +            _list = list;
  +        }
       }
       public String toString() {
  -        // return RFC822 compliant ContentDisposition thingy
  -        // TODO Implement
  -        return null;
  +        if (_disposition == null && _list.size() == 0) {
  +            return null;
  +        }
  +        return (_disposition == null ? "" : _disposition)
  +            + (_list.size() == 0 ? "" : _list.toString());
       }
   }
  
  
  
  1.2       +84 -7     incubator-geronimo/specs/javamail/src/java/javax/mail/internet/HeaderTokenizer.java
  
  Index: HeaderTokenizer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/HeaderTokenizer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HeaderTokenizer.java	16 Aug 2003 01:55:48 -0000	1.1
  +++ HeaderTokenizer.java	4 Sep 2003 02:14:40 -0000	1.2
  @@ -81,14 +81,35 @@
           public String getValue() {
               return _value;
           }
  +        public String toString() {
  +            String type = "Unknown";
  +            switch (_type) {
  +                case ATOM :
  +                    type = "Atom";
  +                    break;
  +                case COMMENT :
  +                    type = "Comment";
  +                    break;
  +                case EOF :
  +                    type = "EOF";
  +                    break;
  +                case QUOTEDSTRING :
  +                    type = "String";
  +                    break;
  +            }
  +            return "[" + type + "] \"" + getValue() + "\"";
  +        }
       }
  +    private static final Token EOF = new Token(Token.EOF, null);
       // characters not allowed in MIME
       public static final String MIME = "[]()<>@.:,;\\\" \t?=";
       // charaters not allowed in RFC822
       public static final String RFC822 = "[]()<>@.:,;\\\" \t";
  +    private static final String WHITE = " \t\n\r";
       private String _delimiters;
       private String _header;
       private boolean _skip;
  +    private int pos;
       public HeaderTokenizer(String header) {
           this(header, RFC822);
       }
  @@ -104,15 +125,71 @@
           _delimiters = delimiters;
       }
       public String getRemainder() {
  -        // TODO Implement
  -        throw new NoSuchMethodError("Not yet implemented");
  +        return _header.substring(pos);
       }
       public Token next() throws ParseException {
  -        throw new NoSuchMethodError("Not yet implemented");
  -        // TODO Implement
  +        return readToken();
       }
       public Token peek() throws ParseException {
  -        throw new NoSuchMethodError("Not yet implemented");
  -        // TODO Implement
  +        int start = pos;
  +        try {
  +            return readToken();
  +        } finally {
  +            pos = start;
  +        }
  +    }
  +    /**
  +     * @return
  +     */
  +    private Token readAtomicToken() {
  +        // skip to next delimiter
  +        int start = pos;
  +        while (++pos < _header.length()
  +            && _delimiters.indexOf(_header.charAt(pos)) == -1);
  +        return new Token(Token.ATOM, _header.substring(start, pos));
  +    }
  +    private Token readToken() throws ParseException {
  +        if (pos >= _header.length()) {
  +            return EOF;
  +        } else {
  +            char c = _header.charAt(pos);
  +            if (c == '(') {
  +                Token comment = readUntil(')',Token.COMMENT);
  +                if (_skip) {
  +                    return readToken();
  +                } else {
  +                    return comment;
  +                }
  +            } else if (c == '\"') {
  +                    return readUntil('\"',Token.QUOTEDSTRING);
  +            } else if (WHITE.indexOf(c) != -1) {
  +                eatWhiteSpace();
  +                return readToken();
  +            } else if (_delimiters.indexOf(c) != -1) {
  +                pos++;
  +                return new Token(Token.ATOM, String.valueOf(c));
  +            } else {
  +                return readAtomicToken();
  +            }
  +        }
  +    }
  +    /**
  +     * @return
  +     */
  +    private Token readUntil(char end, int type) {
  +        int start = ++pos;
  +        // skip to end of comment/string
  +        while (++pos < _header.length()
  +            && _header.charAt(pos) != end);
  +        String value = _header.substring(start,pos++);
  +        return new Token(type,value);
  +    }
  +    /**
  +     * @return
  +     */
  +    private void eatWhiteSpace() {
  +        // skip to end of whitespace
  +        while (++pos < _header.length()
  +            && WHITE.indexOf(_header.charAt(pos)) != -1);
       }
   }
  
  
  
  1.2       +185 -73   incubator-geronimo/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java
  
  Index: InternetHeaders.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/InternetHeaders.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InternetHeaders.java	16 Aug 2003 01:55:48 -0000	1.1
  +++ InternetHeaders.java	4 Sep 2003 02:14:40 -0000	1.2
  @@ -59,47 +59,110 @@
   // DO NOT add / change / or delete method signatures!
   //
   package javax.mail.internet;
  -import java.io.*;
  -import javax.mail.*;
  -import java.util.*;
  +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.List;
  +import java.util.Map;
  +
  +import javax.mail.Header;
  +import javax.mail.MessagingException;
   /**
    * @version $Revision$ $Date$
    */
   public class InternetHeaders {
  -    // TODO This is probably bad, managing two copies of the same data structure
  -    // (maybe)
  +    private static final String[] STRING_ARRAY = new String[0];
  +    /**
  +     * 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>
  +     */
  +    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);
  +    }
  +    /**
  +     * 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.
  +     */
       private List _lines = new LinkedList();
       public InternetHeaders() {
       }
       public InternetHeaders(InputStream in) throws MessagingException {
           load(in);
       }
  -    public void load(InputStream in) throws MessagingException {
  -        // try and figure out what format it's in?
  -        try {
  -            BufferedReader br = new BufferedReader(new InputStreamReader(in));
  -            String line;
  -            while ((line = br.readLine()) != null && !line.equals("")) {
  -                addHeaderLine(line);
  -            }
  -        } catch (IOException e) {
  -            throw new MessagingException(e.getMessage());
  +    /**
  +     * 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.
  +     * @param header the pre-parsed header
  +     * @param line the header line
  +     */
  +    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);
       }
  -    private static final String[] STRING_ARRAY = new String[0];
       public String[] getHeader(String name) {
  -        List list = getHeaderList(name);
  -        if (list == null) {
  +        List headers = getHeaderList(name);
  +        if (headers == null) {
               return null;
           } else {
  -            return (String[]) list.toArray(STRING_ARRAY);
  +            List result = new LinkedList();
  +            Iterator it = headers.iterator();
  +            while (it.hasNext()) {
  +                Header element = (Header) it.next();
  +                result.add(element.getValue());
  +            }
  +            return (String[]) result.toArray(STRING_ARRAY);
           }
       }
  -    private List getHeaderList(String name) {
  -        List list = (List) _headers.get(name);
  -        return list;
  -    }
       public String getHeader(String name, String delimiter) {
           List list = getHeaderList(name);
           if (list == null || list.isEmpty()) {
  @@ -124,73 +187,122 @@
               return result.toString();
           }
       }
  -    public void setHeader(String name, String value) {
  -        List list = new LinkedList();
  -        list.add(new Header(name, value));
  -        _headers.put(name, list);
  +    private List getHeaderList(String name) {
  +        return (List) _headers.get(name.toUpperCase());
       }
  -    public void addHeader(String name, String value) {
  -        List list = (List) _headers.get(name);
  -        if (list == null) {
  -            list = new LinkedList();
  -            _headers.put(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.add(new Header(name, value));
  -    }
  -    public void removeHeader(String name) {
  -        _headers.remove(name);
  -    }
  -    public Enumeration getAllHeaders() {
  -        return Collections.enumeration(_headers.keySet());
  -    }
  -    public Enumeration getMatchingHeaders(String[] names) {
  -        return getHeaders(names, _headers);
  -    }
  -    private Enumeration getHeaders(String[] names, Map map) {
           List result = new LinkedList();
  -        for (int i = 0; i < names.length; i++) {
  -            String name = names[i];
  -            List list = (List) map.get(name);
  -            if (list != null) {
  -                result.addAll(list);
  +        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());
               }
           }
           return Collections.enumeration(result);
       }
  -    public Enumeration getNonMatchingHeaders(String[] names) {
  -        Map copy = new HashMap(_headers);
  +    private Enumeration getLines(String[] names, boolean match) {
  +        List matches = new ArrayList(names.length);
           for (int i = 0; i < names.length; i++) {
  -            String name = names[i];
  -            copy.remove(name);
  +            matches.add(names[i].toUpperCase());
           }
  -        return getHeaders(names, copy);
  +        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);
  +            }
  +
  +        }
  +        return Collections.enumeration(result);
       }
  -    public void addHeaderLine(String line) {
  -        _lines.add(line);
  -        // figure out if it's a header? Who knows?
  +    public Enumeration getMatchingHeaderLines(String[] names) {
  +        return getLines(names, true);
       }
  -    public Enumeration getAllHeaderLines() {
  -        return Collections.enumeration(_lines);
  +    public Enumeration getMatchingHeaders(String[] names) {
  +        return getHeaders(names, true);
       }
  -    public Enumeration getMatchingHeaderLines(String[] names) {
  -        return getLinesList(names, true);
  +    public Enumeration getNonMatchingHeaderLines(String[] names) {
  +        return getLines(names, false);
       }
  -    private Enumeration getLinesList(String[] names, boolean match) {
  +    public Enumeration getNonMatchingHeaders(String[] names) {
  +        return getHeaders(names, false);
  +    }
  +    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
  +                }
  +
  +            }
  +        } catch (IOException e) {
  +            throw new MessagingException(e.getMessage());
  +        }
  +    }
  +    public void removeHeader(String name) {
  +        String NAME = name.toUpperCase();
  +        _headers.remove(NAME);
  +        NAME = NAME + ":";
  +        // go through list as well
           Iterator it = _lines.iterator();
  -        List result = new LinkedList();
           while (it.hasNext()) {
               String line = (String) it.next();
  -            String upper = line.toUpperCase();
  -            for (int i = 0; i < names.length; i++) {
  -                String name = (names[i] + ":").toUpperCase();
  -                if (upper.startsWith(name) == match) {
  -                    result.add(line);
  -                }
  +            if (line.toUpperCase().startsWith(NAME)) {
  +                it.remove();
               }
           }
  -        return Collections.enumeration(result);
       }
  -    public Enumeration getNonMatchingHeaderLines(String[] names) {
  -        return getLinesList(names, false);
  +    public void setHeader(String name, String value) {
  +        removeHeader(name);
  +        addHeader(name, value);
       }
   }
  
  
  
  1.3       +11 -5     incubator-geronimo/specs/javamail/src/java/javax/mail/internet/MailDateFormat.java
  
  Index: MailDateFormat.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/MailDateFormat.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MailDateFormat.java	28 Aug 2003 13:32:09 -0000	1.2
  +++ MailDateFormat.java	4 Sep 2003 02:14:40 -0000	1.3
  @@ -62,13 +62,19 @@
   import java.text.NumberFormat;
   import java.text.SimpleDateFormat;
   import java.util.Calendar;
  -// Wed, 02 Jan 2003 23:59:59 -0100
   /**
  + * Parses dates of the form
  + * 
  + * <code>Wed, 02 Jan 2003 23:59:59 -0100 (GMT)</code>
  + * 
  + * <code>EEE,  d MMM yyyy HH:mm:ss Z (z)</code>
    * @version $Revision$ $Date$
    */
   public class MailDateFormat extends SimpleDateFormat {
  -    MailDateFormat() {
  -        super("EEE, d MMM yyyy HH:mm:ss Z");
  +    static final MailDateFormat INSTANCE = new MailDateFormat();
  +    private static final String pattern = "EEE, d MMM yyyy HH:mm:ss Z (z)";
  +    public MailDateFormat() {
  +        super(pattern);
       }
       //    public StringBuffer format(Date date, StringBuffer buffer, FieldPosition position) {
       //        return super.format(date,buffer,position);
  @@ -77,9 +83,9 @@
       //        return parse(string,position);
       //    }
       public void setCalendar(Calendar calendar) {
  -        throw new UnsupportedOperationException("Method not implemented");
  +        throw new UnsupportedOperationException();
       }
       public void setNumberFormat(NumberFormat format) {
  -        throw new UnsupportedOperationException("Method not implemented");
  +        throw new UnsupportedOperationException();
       }
   }
  
  
  
  1.2       +16 -4     incubator-geronimo/specs/javamail/src/java/javax/mail/internet/MimePartDataSource.java
  
  Index: MimePartDataSource.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/MimePartDataSource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MimePartDataSource.java	16 Aug 2003 01:55:48 -0000	1.1
  +++ MimePartDataSource.java	4 Sep 2003 02:14:40 -0000	1.2
  @@ -83,16 +83,28 @@
           }
       }
       public InputStream getInputStream() throws IOException {
  -        throw new UnknownServiceException("Method not implemented in base class");
  +        InputStream content;
  +        try {
  +            String encoding = _part.getEncoding();
  +            if (_part instanceof MimeMessage) {
  +                content = ((MimeMessage) _part).getContentStream();
  +            } else if (_part instanceof MimeBodyPart) {
  +                content = ((MimeBodyPart) _part).getContentStream();
  +            } else {
  +                throw new MessagingException("Unknown part");
  +            }
  +            return MimeUtility.decode(content, encoding);
  +        } catch (MessagingException e) {
  +            throw new IOException(e.toString());
  +        }
       }
       public synchronized MessageContext getMessageContext() {
  -        // TODO Don't really know what this is doing
           return new MessageContext(_part);
       }
       public String getName() {
           return "";
       }
       public OutputStream getOutputStream() throws IOException {
  -        throw new UnknownServiceException("Method not implemented in base class");
  +        throw new UnknownServiceException();
       }
   }
  
  
  
  1.2       +46 -47    incubator-geronimo/specs/javamail/src/java/javax/mail/internet/NewsAddress.java
  
  Index: NewsAddress.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/NewsAddress.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NewsAddress.java	16 Aug 2003 01:55:48 -0000	1.1
  +++ NewsAddress.java	4 Sep 2003 02:14:40 -0000	1.2
  @@ -61,44 +61,46 @@
   package javax.mail.internet;
   import java.util.LinkedList;
   import java.util.List;
  +import java.util.StringTokenizer;
  +
   import javax.mail.Address;
   /**
    * @version $Revision$ $Date$
    */
   public class NewsAddress extends Address {
       private static final String _separator = ",";
  -    protected String newsgroup;
  +    private static final NewsAddress[] NEWSADDRESS_ARRAY = new NewsAddress[0];
  +    public static NewsAddress[] parse(String addresses) throws AddressException {
  +        List result = new LinkedList();
  +        StringTokenizer tokenizer = new StringTokenizer(addresses, ",");
  +        while (tokenizer.hasMoreTokens()) {
  +            String address = tokenizer.nextToken();
  +            result.add(new NewsAddress(address));
  +        }
  +        return (NewsAddress[]) result.toArray(NEWSADDRESS_ARRAY);
  +    }
  +    public static String toString(Address[] addresses) {
  +        // build up a comma separated list of addresses
  +        StringBuffer result = new StringBuffer();
  +        for (int a = 0; a < addresses.length; a++) {
  +            result.append(addresses[a].toString());
  +            if (a > 0) {
  +                result.append(_separator);
  +            }
  +        }
  +        return result.toString();
  +    }
       protected String host;
  +    protected String newsgroup;
       public NewsAddress() {
       }
       public NewsAddress(String newsgroup) {
           setNewsgroup(newsgroup);
       }
  -    public void setNewsgroup(String newsgroup) {
  -        int at;
  -        if ((at = newsgroup.indexOf("@")) != -1) {
  -            this.newsgroup = newsgroup.substring(0, at);
  -            this.host = newsgroup.substring(at + 1);
  -        } else {
  -            this.newsgroup = newsgroup;
  -        }
  -    }
       public NewsAddress(String newsgroup, String host) {
           setNewsgroup(newsgroup);
           setHost(host);
       }
  -    public String getType() {
  -        return "news";
  -    }
  -    public String getHost() {
  -        return host;
  -    }
  -    public String getNewsgroup() {
  -        return newsgroup;
  -    }
  -    public void setHost(String string) {
  -        host = string;
  -    }
       public boolean equals(Object other) {
           if (other == null || other.getClass() != this.getClass()) {
               return false;
  @@ -110,35 +112,32 @@
                   || newsgroup != null
                   && newsgroup.equals(address.newsgroup));
       }
  -    public String toString() {
  -        return newsgroup + (host == null ? "" : "@" + host);
  +    public String getHost() {
  +        return host;
  +    }
  +    public String getNewsgroup() {
  +        return newsgroup;
  +    }
  +    public String getType() {
  +        return "news";
       }
       public int hashCode() {
           return toString().hashCode();
       }
  -    public static String toString(Address[] addresses) {
  -        // build up a comma separated list of addresses
  -        StringBuffer result = new StringBuffer();
  -        for (int a = 0; a < addresses.length; a++) {
  -            result.append(addresses[a].toString());
  -            if (a > 0) {
  -                result.append(_separator);
  -            }
  -        }
  -        return result.toString();
  +    public void setHost(String string) {
  +        host = string;
       }
  -    public static NewsAddress[] parse(String address) throws AddressException {
  -        List result = new LinkedList();
  -        address = address + _separator;
  -        int sep;
  -        int last = 0;
  -        String na;
  -        while ((sep = address.indexOf(_separator)) != -1) {
  -            na = address.substring(last, sep);
  -            result.add(new NewsAddress(na));
  -            last = sep + _separator.length();
  +    public void setNewsgroup(String newsgroup) {
  +        newsgroup = newsgroup.trim();
  +        int at;
  +        if ((at = newsgroup.indexOf("@")) != -1) {
  +            this.newsgroup = newsgroup.substring(0, at);
  +            this.host = newsgroup.substring(at + 1);
  +        } else {
  +            this.newsgroup = newsgroup;
           }
  -        return (NewsAddress[]) result.toArray(NEWSADDRESS_ARRAY);
       }
  -    private static final NewsAddress[] NEWSADDRESS_ARRAY = new NewsAddress[0];
  +    public String toString() {
  +        return newsgroup + (host == null ? "" : "@" + host);
  +    }
   }
  
  
  
  1.2       +18 -26    incubator-geronimo/specs/javamail/src/java/javax/mail/internet/ParameterList.java
  
  Index: ParameterList.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/internet/ParameterList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParameterList.java	16 Aug 2003 01:55:48 -0000	1.1
  +++ ParameterList.java	4 Sep 2003 02:14:40 -0000	1.2
  @@ -64,6 +64,7 @@
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.StringTokenizer;
   // Represents lists in things like
   // Content-Type: text/plain;charset=klingon
   //
  @@ -73,30 +74,23 @@
    */
   public class ParameterList {
       private Map _parameters = new HashMap();
  -    private static final String _separator = ";";
  -    private static final String _divider = "=";
       public ParameterList() {
       }
       public ParameterList(String list) throws ParseException {
  -        // TODO Parse List and add to parameters
  -        if (list != null) {
  -            int pos;
  -            int last = 0;
  -            list = list + ";"; // HACK so that it picks up the last one
  -            while ((pos = list.indexOf(_separator, last)) != -1) {
  -                if (pos == -1) {
  -                    pos = list.length();
  -                }
  -                String string = list.substring(last, pos);
  -                int div = string.indexOf(_divider);
  -                if (div == -1) {
  -                    throw new ParseException("Cannot parse " + string);
  +        if (list == null) {
  +            return;
  +        } else {
  +            StringTokenizer tokenizer = new StringTokenizer(list, ";");
  +            while (tokenizer.hasMoreTokens()) {
  +                String parameter = tokenizer.nextToken();
  +                int eq = parameter.indexOf("=");
  +                if (eq == -1) {
  +                    throw new ParseException(parameter);
                   } else {
  -                    set(
  -                        string.substring(0, div),
  -                        string.substring(div + _divider.length()));
  +                    String name = parameter.substring(0, eq);
  +                    String value = parameter.substring(eq + 1);
  +                    set(name, value);
                   }
  -                last = pos + _separator.length();
               }
           }
       }
  @@ -120,12 +114,10 @@
           StringBuffer result = new StringBuffer();
           while (it.hasNext()) {
               Map.Entry entry = (Map.Entry) it.next();
  -            result.append(
  -                entry.getKey()
  -                    + _divider
  -                    + " "
  -                    + entry.getValue()
  -                    + _separator);
  +            result.append(";");
  +            result.append(entry.getKey());
  +            result.append("=");
  +            result.append(entry.getValue());
           }
           return result.toString();
           // TODO Return in same list as parsed format