Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 53739 invoked from network); 1 Feb 2005 01:08:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 1 Feb 2005 01:08:07 -0000 Received: (qmail 90844 invoked by uid 500); 1 Feb 2005 01:08:06 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 90795 invoked by uid 500); 1 Feb 2005 01:08:05 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@geronimo.apache.org Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 90744 invoked by uid 99); 1 Feb 2005 01:08:05 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 31 Jan 2005 17:08:04 -0800 Received: (qmail 53570 invoked by uid 65534); 1 Feb 2005 01:08:03 -0000 Message-ID: <20050201010803.53569.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Tue, 01 Feb 2005 01:08:03 -0000 Subject: svn commit: r149345 - geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart.java To: scm@geronimo.apache.org From: jboynes@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: jboynes Date: Mon Jan 31 17:08:02 2005 New Revision: 149345 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D149345 Log: initial impl Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart= .java Modified: geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBo= dyPart.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/javamail/src/java/j= avax/mail/internet/MimeBodyPart.java?view=3Ddiff&r1=3D149344&r2=3D149345 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart= .java (original) +++ geronimo/trunk/specs/javamail/src/java/javax/mail/internet/MimeBodyPart= .java Mon Jan 31 17:08:02 2005 @@ -17,6 +17,7 @@ =20 package javax.mail.internet; =20 +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -30,203 +31,240 @@ * @version $Rev$ $Date$ */ public class MimeBodyPart extends BodyPart implements MimePart { + /** + * 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 SharedInputSt= ream} + * then this is another such stream representing the content of this m= essage; + * if this field is non-null, then {@link #content} will be null. + */ protected InputStream contentStream; - protected DataHandler dh; + /** + * This message's headers. + */ protected InternetHeaders headers; =20 public MimeBodyPart() { + headers =3D new InternetHeaders(); } =20 public MimeBodyPart(InputStream in) throws MessagingException { this.contentStream =3D in; } =20 - public MimeBodyPart(InternetHeaders headers, byte[] content) - throws MessagingException { + public MimeBodyPart(InternetHeaders headers, byte[] content) throws Me= ssagingException { this.headers =3D headers; this.content =3D content; } =20 - public void addHeader(String name, String value) - throws MessagingException { - headers.addHeader(name, value); + public int getSize() throws MessagingException { + if (content !=3D null) { + return content.length; + } + return -1; } =20 - public void addHeaderLine(String line) throws MessagingException { - headers.addHeaderLine(line); + public int getLineCount() throws MessagingException { + return -1; } =20 - public Enumeration getAllHeaderLines() throws MessagingException { - return headers.getAllHeaderLines(); + public String getContentType() throws MessagingException { + String value =3D getSingleHeader("Content-Type"); + if (value =3D=3D null) { + value =3D "text/plain"; + } + return value; } =20 - public Enumeration getAllHeaders() throws MessagingException { - return headers.getAllHeaders(); + public boolean isMimeType(String type) throws MessagingException { + return new ContentType(getContentType()).match(type); } =20 - public Object getContent() throws IOException, MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public String getDisposition() throws MessagingException { + return getSingleHeader("Content-Disposition"); + } + + public void setDisposition(String disposition) throws MessagingExcepti= on { + setHeader("Content-Disposition", disposition); + } + + public String getEncoding() throws MessagingException { + return getSingleHeader("Content-Transfer-Encoding"); } =20 public String getContentID() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + return getSingleHeader("Content-ID"); } =20 - public String[] getContentLanguage() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setContentID(String cid) throws MessagingException { + setHeader("Content-ID", cid); } =20 public String getContentMD5() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + return getSingleHeader("Content-MD5"); } =20 - protected InputStream getContentStream() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setContentMD5(String md5) throws MessagingException { + setHeader("Content-MD5", md5); } =20 - public String getContentType() throws MessagingException { - return dh.getContentType(); + public String[] getContentLanguage() throws MessagingException { + return getHeader("Content-Language"); } =20 - public DataHandler getDataHandler() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setContentLanguage(String[] languages) throws MessagingExc= eption { + if (languages =3D=3D null || languages.length =3D=3D 0) { + removeHeader("Content-Language"); + } else if (languages.length =3D=3D 1) { + setHeader("Content-Language", languages[0]); + } else { + StringBuffer buf =3D new StringBuffer(languages.length * 20); + buf.append(languages[0]); + for (int i =3D 1; i < languages.length; i++) { + buf.append(',').append(languages[i]); + } + setHeader("Content-Language", buf.toString()); + } } =20 public String getDescription() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + return getSingleHeader("Content-Description"); } =20 - public String getDisposition() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setDescription(String description) throws MessagingExcepti= on { + setHeader("Content-Description", description); } =20 - public String getEncoding() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setDescription(String description, String charset) throws = MessagingException { + // todo encoding + setHeader("Content-Description", description); } =20 public String getFileName() throws MessagingException { + // TODO Implement method throw new UnsupportedOperationException("Method not yet implemente= d"); } =20 - public String[] getHeader(String name) throws MessagingException { - return headers.getHeader(name); - } - - public String getHeader(String name, String delimiter) - throws MessagingException { - return headers.getHeader(name, delimiter); + public void setFileName(String name) throws MessagingException { + // TODO Implement method + throw new UnsupportedOperationException("Method not yet implemente= d"); } =20 - public InputStream getInputStream() - throws IOException, MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public InputStream getInputStream() throws MessagingException, IOExcep= tion { + return getDataHandler().getInputStream(); } =20 - public int getLineCount() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + protected InputStream getContentStream() throws MessagingException { + if (content !=3D null) { + return new ByteArrayInputStream(content); + } else { + throw new MessagingException("No content"); + } } =20 - public Enumeration getMatchingHeaderLines(String[] names) - throws MessagingException { - return headers.getMatchingHeaderLines(names); + public InputStream getRawInputStream() throws MessagingException { + return getContentStream(); } =20 - public Enumeration getMatchingHeaders(String[] name) - throws MessagingException { - return headers.getMatchingHeaders(name); + public synchronized DataHandler getDataHandler() throws MessagingExcep= tion { + if (dh =3D=3D null) { + dh =3D new DataHandler(new MimePartDataSource(this)); + } + return dh; } =20 - public Enumeration getNonMatchingHeaderLines(String[] names) - throws MessagingException { - return headers.getNonMatchingHeaderLines(names); + public Object getContent() throws MessagingException, IOException { + return getDataHandler().getContent(); } =20 - public Enumeration getNonMatchingHeaders(String[] name) - throws MessagingException { - return headers.getNonMatchingHeaders(name); + public void setDataHandler(DataHandler handler) throws MessagingExcept= ion { + dh =3D handler; } =20 - public InputStream getRawInputStream() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setContent(Object content, String type) throws MessagingEx= ception { + setDataHandler(new DataHandler(content, type)); } =20 - public int getSize() throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setText(String text) throws MessagingException { + setText(text, MimeUtility.getDefaultJavaCharset()); } =20 - public boolean isMimeType(String type) throws MessagingException { - ContentType c1 =3D new ContentType(type); - ContentType c2 =3D new ContentType(dh.getContentType()); - return c1.match(c2); + public void setText(String text, String charset) throws MessagingExcep= tion { + setContent(text, "text/plain; charset=3D" + charset); } =20 - 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); } =20 - public void setContent(Multipart content) throws MessagingException { + public void writeTo(OutputStream out) throws IOException, MessagingExc= eption { throw new UnsupportedOperationException("Method not yet implemente= d"); } =20 - public void setContent(Object content, String type) - throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public String[] getHeader(String name) throws MessagingException { + return headers.getHeader(name); } =20 - public void setContentID(String cid) throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public String getHeader(String name, String delimiter) throws Messagin= gException { + return headers.getHeader(name, delimiter); } =20 - public void setContentLanguage(String[] languages) - throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void setHeader(String name, String value) throws MessagingExcep= tion { + headers.setHeader(name, value); } =20 - public void setContentMD5(String md5) throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void addHeader(String name, String value) throws MessagingExcep= tion { + headers.addHeader(name, value); } =20 - public void setDataHandler(DataHandler handler) throws MessagingExcept= ion { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void removeHeader(String name) throws MessagingException { + headers.removeHeader(name); } =20 - public void setDescription(String description) throws MessagingExcepti= on { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public Enumeration getAllHeaders() throws MessagingException { + return headers.getAllHeaders(); } =20 - public void setDescription(String description, String charset) - throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public Enumeration getMatchingHeaders(String[] name) throws MessagingE= xception { + return headers.getMatchingHeaders(name); } =20 - public void setDisposition(String disposition) throws MessagingExcepti= on { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public Enumeration getNonMatchingHeaders(String[] name) throws Messagi= ngException { + return headers.getNonMatchingHeaders(name); } =20 - public void setFileName(String name) throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public void addHeaderLine(String line) throws MessagingException { + headers.addHeaderLine(line); } =20 - public void setHeader(String name, String value) - throws MessagingException { - headers.setHeader(name, value); + public Enumeration getAllHeaderLines() throws MessagingException { + return headers.getAllHeaderLines(); } =20 - public void setText(String text) throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public Enumeration getMatchingHeaderLines(String[] names) throws Messa= gingException { + return headers.getMatchingHeaderLines(names); } =20 - public void setText(String text, String charset) - throws MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + public Enumeration getNonMatchingHeaderLines(String[] names) throws Me= ssagingException { + return headers.getNonMatchingHeaderLines(names); } =20 protected void updateHeaders() throws MessagingException { } =20 - public void writeTo(OutputStream out) - throws IOException, MessagingException { - throw new UnsupportedOperationException("Method not yet implemente= d"); + private String getSingleHeader(String name) throws MessagingException { + String[] values =3D getHeader(name); + if (values =3D=3D null || values.length =3D=3D 0) { + return null; + } else { + return values[0]; + } } }