Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 24006 invoked from network); 10 Feb 2006 19:40:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Feb 2006 19:40:43 -0000 Received: (qmail 60983 invoked by uid 500); 10 Feb 2006 19:40:41 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 60959 invoked by uid 500); 10 Feb 2006 19:40:41 -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 List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 60948 invoked by uid 99); 10 Feb 2006 19:40:41 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Feb 2006 11:40:41 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 10 Feb 2006 11:40:39 -0800 Received: (qmail 23886 invoked by uid 65534); 10 Feb 2006 19:40:19 -0000 Message-ID: <20060210194019.23885.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r376811 - in /geronimo/specs/trunk: geronimo-spec-activation/src/main/java/javax/activation/ geronimo-spec-javamail/src/main/java/javax/mail/internet/ geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/ geronimo-spec-jav... Date: Fri, 10 Feb 2006 19:40:16 -0000 To: scm@geronimo.apache.org From: adc@apache.org X-Mailer: svnmailer-1.0.6 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: adc Date: Fri Feb 10 11:40:13 2006 New Revision: 376811 URL: http://svn.apache.org/viewcvs?rev=376811&view=rev Log: GERONIMO-1619 Using Geronimo version of javamail with AXIS2 uncovers multiple errors. Submitted by: Rick McGuire Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/HtmlHandler.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MessageHandler.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MultipartHandler.java Modified: geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/DataHandler.java geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/MailcapCommandMap.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeUtility.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/ParameterList.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/XMLHandler.java geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/mailcap Modified: geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/DataHandler.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/DataHandler.java?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/DataHandler.java (original) +++ geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/DataHandler.java Fri Feb 10 11:40:13 2006 @@ -241,19 +241,39 @@ localFactory = originalFactory; } if (dch == null) { - String contentType = ds.getContentType(); + // get the main mime-type portion of the content. + String mimeType = getMimeType(ds.getContentType()); if (localFactory != null) { - dch = localFactory.createDataContentHandler(contentType); + dch = localFactory.createDataContentHandler(mimeType); } if (dch == null) { if (commandMap != null) { - dch = commandMap.createDataContentHandler(contentType); + dch = commandMap.createDataContentHandler(mimeType); } else { - dch = CommandMap.getDefaultCommandMap().createDataContentHandler(contentType); + dch = CommandMap.getDefaultCommandMap().createDataContentHandler(mimeType); } } } return dch; + } + + /** + * Retrieve the base MIME type from a content type. This parses + * the type into its base components, stripping off any parameter + * information. + * + * @param contentType + * The content type string. + * + * @return The MIME type identifier portion of the content type. + */ + private String getMimeType(String contentType) { + try { + MimeType mimeType = new MimeType(contentType); + return mimeType.getBaseType(); + } catch (MimeTypeParseException e) { + } + return contentType; } /** Modified: geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/MailcapCommandMap.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/MailcapCommandMap.java?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/MailcapCommandMap.java (original) +++ geronimo/specs/trunk/geronimo-spec-activation/src/main/java/javax/activation/MailcapCommandMap.java Fri Feb 10 11:40:13 2006 @@ -26,12 +26,14 @@ import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; +import java.security.Security; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Collections; /** * @version $Rev$ $Date$ @@ -39,10 +41,12 @@ public class MailcapCommandMap extends CommandMap { private final Map preferredCommands = new HashMap(); private final Map allCommands = new HashMap(); + // commands identified as fallbacks...these are used last, and also used as wildcards. + private final Map fallbackCommands = new HashMap(); private URL url; - private ClassLoader cl; public MailcapCommandMap() { + ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); // process /META-INF/mailcap.default try { InputStream is = MailcapCommandMap.class.getResourceAsStream("/META-INF/mailcap.default"); @@ -59,8 +63,7 @@ // process /META-INF/mailcap resources try { - cl = MailcapCommandMap.class.getClassLoader(); - Enumeration e = cl.getResources("META-INF/mailcap"); + Enumeration e = contextLoader.getResources("META-INF/mailcap"); while (e.hasMoreElements()) { url = ((URL) e.nextElement()); try { @@ -171,9 +174,13 @@ index = getToken(mail_cap, index); mimeType = mimeType + '/' + mail_cap.substring(start, index); } else { + mimeType = mimeType + "/*"; } + // we record all mappings using the lowercase version. + mimeType = mimeType.toLowerCase(); + // skip spaces after mime type index = skipSpace(mail_cap, index); @@ -187,6 +194,12 @@ return; } + // we don't know which list this will be added to until we finish parsing, as there + // can be an x-java-fallback-entry parameter that moves this to the fallback list. + List commandList = new ArrayList(); + // but by default, this is not a fallback. + boolean fallback = false; + // parse fields while (index < mail_cap.length() && mail_cap.charAt(index) == ';') { index = skipSpace(mail_cap, index + 1); @@ -202,31 +215,70 @@ index = skipSpace(mail_cap, index); if (fieldName.startsWith("x-java-") && fieldName.length() > 7) { String command = fieldName.substring(7); - addCommand(mimeType, command, value.trim()); + value = value.trim(); + if (command.equals("fallback-entry")) { + if (value.equals("true")) { + fallback = true; + } + } + else { + // create a CommandInfo item and add it the accumulator + CommandInfo info = new CommandInfo(command, value); + commandList.add(info); + } } } } + addCommands(mimeType, commandList, fallback); + } + /** + * Add a parsed list of commands to the appropriate command list. + * + * @param mimeType The mimeType name this is added under. + * @param commands A List containing the command information. + * @param fallback The target list identifier. + */ + private void addCommands(String mimeType, List commands, boolean fallback) { + // the target list changes based on the type of entry. + Map target = fallback ? fallbackCommands : preferredCommands; + + // now process + for (Iterator i = commands.iterator(); i.hasNext();) { + CommandInfo info = (CommandInfo)i.next(); + addCommand(target, mimeType, info); + // if this is not a fallback position, then this to the allcommands list. + if (!fallback) { + List cmdList = (List) allCommands.get(mimeType); + if (cmdList == null) { + cmdList = new ArrayList(); + allCommands.put(mimeType, cmdList); + } + cmdList.add(info); + } + } } - private void addCommand(String mimeType, String cmdName, String commandClass) { - CommandInfo info = new CommandInfo(cmdName, commandClass); - Map commands = (Map) preferredCommands.get(mimeType); + /** + * Add a command to a target command list (preferred or fallback). + * + * @param commandList + * The target command list. + * @param mimeType The MIME type the command is associated with. + * @param command The command information. + */ + private void addCommand(Map commandList, String mimeType, CommandInfo command) { + + Map commands = (Map) commandList.get(mimeType); if (commands == null) { commands = new HashMap(); - preferredCommands.put(mimeType, commands); - } - commands.put(info.getCommandName(), info); - - List cmdList = (List) allCommands.get(mimeType); - if (cmdList == null) { - cmdList = new ArrayList(); - allCommands.put(mimeType, cmdList); + commandList.put(mimeType, commands); } - cmdList.add(info); + commands.put(command.getCommandName(), command); } + private int skipSpace(String s, int index) { while (index < s.length() && Character.isWhitespace(s.charAt(index))) { index++; @@ -259,16 +311,59 @@ } public synchronized CommandInfo[] getPreferredCommands(String mimeType) { - Map commands = (Map) preferredCommands.get(mimeType.toLowerCase()); + // get the mimetype as a lowercase version. + mimeType = mimeType.toLowerCase(); + + Map commands = (Map) preferredCommands.get(mimeType); if (commands == null) { commands = (Map) preferredCommands.get(getWildcardMimeType(mimeType)); } + + Map fallbackCommands = getFallbackCommands(mimeType); + + // if we have fall backs, then we need to merge this stuff. + if (fallbackCommands != null) { + // if there's no command list, we can just use this as the master list. + if (commands == null) { + commands = fallbackCommands; + } + else { + // merge the two lists. The ones in the commands list will take precedence. + commands = mergeCommandMaps(commands, fallbackCommands); + } + } + + // now convert this into an array result. if (commands == null) { return new CommandInfo[0]; } return (CommandInfo[]) commands.values().toArray(new CommandInfo[commands.size()]); } + private Map getFallbackCommands(String mimeType) { + Map commands = (Map) fallbackCommands.get(mimeType); + + // now we also need to search this as if it was a wildcard. If we get a wildcard hit, + // we have to merge the two lists. + Map wildcardCommands = (Map)fallbackCommands.get(getWildcardMimeType(mimeType)); + // no wildcard version + if (wildcardCommands == null) { + return commands; + } + // we need to merge these. + return mergeCommandMaps(commands, wildcardCommands); + } + + + private Map mergeCommandMaps(Map main, Map fallback) { + // create a cloned copy of the second map. We're going to use a PutAll operation to + // overwrite any duplicates. + Map result = new HashMap(fallback); + result.putAll(main); + + return result; + } + public synchronized CommandInfo[] getAllCommands(String mimeType) { mimeType = mimeType.toLowerCase(); List exactCommands = (List) allCommands.get(mimeType); @@ -279,7 +374,14 @@ if (wildCommands == null) { wildCommands = Collections.EMPTY_LIST; } - CommandInfo[] result = new CommandInfo[exactCommands.size() + wildCommands.size()]; + + Map fallbackCommands = getFallbackCommands(mimeType); + if (fallbackCommands == null) { + fallbackCommands = Collections.EMPTY_MAP; + } + + + CommandInfo[] result = new CommandInfo[exactCommands.size() + wildCommands.size() + fallbackCommands.size()]; int j = 0; for (int i = 0; i < exactCommands.size(); i++) { result[j++] = (CommandInfo) exactCommands.get(i); @@ -287,6 +389,10 @@ for (int i = 0; i < wildCommands.size(); i++) { result[j++] = (CommandInfo) wildCommands.get(i); } + + for (Iterator i = fallbackCommands.keySet().iterator(); i.hasNext();) { + result[j++] = (CommandInfo) fallbackCommands.get((String)i.next()); + } return result; } @@ -299,12 +405,20 @@ } // search for an exact match - Map commands = (Map) preferredCommands.get(mimeType.toLowerCase()); + Map commands = (Map) preferredCommands.get(mimeType); if (commands == null) { + // then a wild card match commands = (Map) preferredCommands.get(getWildcardMimeType(mimeType)); - } - if (commands == null) { - return null; + if (commands == null) { + // then fallback searches, both standard and wild card. + commands = (Map) fallbackCommands.get(mimeType); + if (commands == null) { + commands = (Map) fallbackCommands.get(getWildcardMimeType(mimeType)); + } + if (commands == null) { + return null; + } + } } return (CommandInfo) commands.get(cmdName.toLowerCase()); } @@ -319,6 +433,7 @@ } public synchronized DataContentHandler createDataContentHandler(String mimeType) { + CommandInfo info = getCommand(mimeType, "content-handler"); if (info == null) { return null; Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeUtility.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeUtility.java?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeUtility.java (original) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/MimeUtility.java Fri Feb 10 11:40:13 2006 @@ -31,12 +31,14 @@ * @version $Rev$ $Date$ */ public class MimeUtility { + private MimeUtility() { } public static final int ALL = -1; private static String defaultJavaCharset; + private static String escapedChars = "\"\\\r\n"; public static InputStream decode(InputStream in, String encoding) throws MessagingException { // TODO - take account of encoding @@ -93,9 +95,71 @@ return "binary"; } + public static String fold(int used, String s) { + // TODO actually do some folding. + return s; + } + + + /** + * Quote a "word" value. If the word contains any character from + * the specified "specials" list, this value is returned as a + * quoted strong. Otherwise, it is returned unchanged (an "atom"). + * + * @param word The word requiring quoting. + * @param specials The set of special characters that can't appear in an unquoted + * string. + * + * @return The quoted value. This will be unchanged if the word doesn't contain + * any of the designated special characters. + */ public static String quote(String word, String specials) { - // TODO Check for specials + int wordLength = word.length(); + boolean requiresQuoting = false; + // scan the string looking for problem characters + for (int i =0; i < wordLength; i++) { + char ch = word.charAt(i); + // special escaped characters require escaping, which also implies quoting. + if (escapedChars.indexOf(ch) >= 0) { + return quoteAndEscapeString(word); + } + // now check for control characters or the designated special characters. + if (ch < 32 || ch >= 127 || specials.indexOf(ch) >= 0) { + // we know this requires quoting, but we still need to scan the entire string to + // see if contains chars that require escaping. Just go ahead and treat it as if it does. + return quoteAndEscapeString(word); + } + } return word; + } + + /** + * Take a string and return it as a formatted quoted string, with + * all characters requiring escaping handled properly. + * + * @param word The string to quote. + * + * @return The quoted string. + */ + private static String quoteAndEscapeString(String word) { + int wordLength = word.length(); + // allocate at least enough for the string and two quotes plus a reasonable number of escaped chars. + StringBuffer buffer = new StringBuffer(wordLength + 10); + // add the leading quote. + buffer.append('"'); + + for (int i = 0; i < wordLength; i++) { + char ch = word.charAt(i); + // is this an escaped char? + if (escapedChars.indexOf(ch) >= 0) { + // add the escape marker before appending. + buffer.append('\\'); + } + buffer.append(ch); + } + // now the closing quote + buffer.append('"'); + return buffer.toString(); } public static String javaCharset(String charset) { Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/ParameterList.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/ParameterList.java?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/ParameterList.java (original) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/javax/mail/internet/ParameterList.java Fri Feb 10 11:40:13 2006 @@ -87,12 +87,17 @@ while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); result.append(";"); - result.append(entry.getKey()); + String key = (String)entry.getKey(); + // we occasionally end up with null entries. If we encounter one, just skip over it. + if (key == null || key.length() == 0) { + continue; + } + result.append(key); result.append("="); - result.append(entry.getValue()); + // this could contain special characters, so make sure it gets quoted if required. + result.append(MimeUtility.quote((String)entry.getValue(), HeaderTokenizer.MIME)); } return result.toString(); - // TODO Return in same list as parsed format } private static String[] split(String str, char separatorChar) { Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/HtmlHandler.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/HtmlHandler.java?rev=376811&view=auto ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/HtmlHandler.java (added) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/HtmlHandler.java Fri Feb 10 11:40:13 2006 @@ -0,0 +1,25 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.mail.handlers; + +import javax.activation.ActivationDataFlavor; + +public class HtmlHandler extends TextHandler { + public HtmlHandler() { + super(new ActivationDataFlavor(java.lang.String.class, "text/html", "HTML String")); + } +} + Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MessageHandler.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MessageHandler.java?rev=376811&view=auto ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MessageHandler.java (added) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MessageHandler.java Fri Feb 10 11:40:13 2006 @@ -0,0 +1,126 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.mail.handlers; + +import javax.activation.ActivationDataFlavor; +import javax.activation.DataContentHandler; +import javax.activation.DataSource; +import javax.mail.internet.ContentType; +import javax.mail.Message; +import javax.mail.MessageAware; +import javax.mail.MessageContext; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeUtility; +import javax.mail.internet.ParseException; +import java.awt.datatransfer.DataFlavor; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; + +public class MessageHandler implements DataContentHandler { + /** + * Field dataFlavor + */ + ActivationDataFlavor dataFlavor; + + public MessageHandler(){ + dataFlavor = new ActivationDataFlavor(java.lang.String.class, "message/rfc822", "Text"); + } + + + /** + * Method getDF + * + * @return dataflavor + */ + protected ActivationDataFlavor getDF() { + return dataFlavor; + } + + /** + * Method getTransferDataFlavors + * + * @return dataflavors + */ + public DataFlavor[] getTransferDataFlavors() { + return (new DataFlavor[]{dataFlavor}); + } + + /** + * Method getTransferData + * + * @param dataflavor + * @param datasource + * @return + * @throws IOException + */ + public Object getTransferData(DataFlavor dataflavor, DataSource datasource) + throws IOException { + if (getDF().equals(dataflavor)) { + return getContent(datasource); + } + return null; + } + + /** + * Method getContent + * + * @param datasource + * @return + * @throws IOException + */ + public Object getContent(DataSource datasource) throws IOException { + + try { + // if this is a proper message, it implements the MessageAware interface. We need this to + // get the associated session. + if (datasource instanceof MessageAware) { + MessageContext context = ((MessageAware)datasource).getMessageContext(); + // construct a mime message instance from the stream, associating it with the + // data source session. + return new MimeMessage(context.getSession(), datasource.getInputStream()); + } + } catch (MessagingException e) { + // we need to transform any exceptions into an IOException. + throw new IOException("Exception writing MimeMultipart: " + e.toString()); + } + return null; + } + + /** + * Method writeTo + * + * @param object + * @param s + * @param outputstream + * @throws IOException + */ + public void writeTo(Object object, String s, OutputStream outputstream) throws IOException { + // proper message type? + if (object instanceof Message) { + try { + ((Message)object).writeTo(outputstream); + } catch (MessagingException e) { + throw new IOException("Error parsing message: " + e.toString()); + } + } + } +} + Added: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MultipartHandler.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MultipartHandler.java?rev=376811&view=auto ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MultipartHandler.java (added) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/MultipartHandler.java Fri Feb 10 11:40:13 2006 @@ -0,0 +1,118 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.mail.handlers; + +import javax.activation.ActivationDataFlavor; +import javax.activation.DataContentHandler; +import javax.activation.DataSource; +import java.awt.datatransfer.DataFlavor; +import java.io.IOException; +import java.io.OutputStream; + +import javax.mail.internet.MimeMultipart; +import javax.mail.internet.MimeMessage; +import javax.mail.MessagingException; + +public class MultipartHandler implements DataContentHandler { + /** + * Field dataFlavor + */ + ActivationDataFlavor dataFlavor; + + public MultipartHandler(){ + dataFlavor = new ActivationDataFlavor(javax.mail.internet.MimeMultipart.class, "multipart/mixed", "Multipart"); + } + + /** + * Constructor TextHandler + * + * @param dataFlavor + */ + public MultipartHandler(ActivationDataFlavor dataFlavor) { + this.dataFlavor = dataFlavor; + } + + /** + * Method getDF + * + * @return dataflavor + */ + protected ActivationDataFlavor getDF() { + return dataFlavor; + } + + /** + * Method getTransferDataFlavors + * + * @return dataflavors + */ + public DataFlavor[] getTransferDataFlavors() { + return (new DataFlavor[]{dataFlavor}); + } + + /** + * Method getTransferData + * + * @param dataflavor + * @param datasource + * @return + * @throws IOException + */ + public Object getTransferData(DataFlavor dataflavor, DataSource datasource) + throws IOException { + if (getDF().equals(dataflavor)) { + return getContent(datasource); + } + return null; + } + + /** + * Method getContent + * + * @param datasource + * @return + * @throws IOException + */ + public Object getContent(DataSource datasource) throws IOException { + try { + return new MimeMultipart(datasource); + } catch (MessagingException e) { + // if there is a syntax error from the datasource parsing, the content is + // just null. + return null; + } + } + + /** + * Method writeTo + * + * @param object + * @param s + * @param outputstream + * @throws IOException + */ + public void writeTo(Object object, String s, OutputStream outputstream) throws IOException { + // if this object is a MimeMultipart, then delegate to the part. + if (object instanceof MimeMultipart) { + try { + ((MimeMultipart)object).writeTo(outputstream); + } catch (MessagingException e) { + // we need to transform any exceptions into an IOException. + throw new IOException("Exception writing MimeMultipart: " + e.toString()); + } + } + } +} Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java (original) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/TextHandler.java Fri Feb 10 11:40:13 2006 @@ -15,12 +15,6 @@ */ package org.apache.geronimo.mail.handlers; -import javax.activation.ActivationDataFlavor; -import javax.activation.DataContentHandler; -import javax.activation.DataSource; -import javax.mail.internet.ContentType; -import javax.mail.internet.MimeUtility; -import javax.mail.internet.ParseException; import java.awt.datatransfer.DataFlavor; import java.io.IOException; import java.io.InputStreamReader; @@ -29,6 +23,13 @@ import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import javax.activation.ActivationDataFlavor; +import javax.activation.DataContentHandler; +import javax.activation.DataSource; +import javax.mail.internet.ContentType; +import javax.mail.internet.MimeUtility; +import javax.mail.internet.ParseException; + public class TextHandler implements DataContentHandler { /** * Field dataFlavor @@ -36,7 +37,7 @@ ActivationDataFlavor dataFlavor; public TextHandler(){ - dataFlavor = new ActivationDataFlavor(java.lang.String.class, "text/plain", "Text"); + dataFlavor = new ActivationDataFlavor(java.lang.String.class, "text/plain", "Text String"); } /** Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/XMLHandler.java URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/XMLHandler.java?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/XMLHandler.java (original) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/java/org/apache/geronimo/mail/handlers/XMLHandler.java Fri Feb 10 11:40:13 2006 @@ -19,6 +19,6 @@ public class XMLHandler extends TextHandler { public XMLHandler() { - super(new ActivationDataFlavor(java.lang.String.class, "text/xml", "XML")); + super(new ActivationDataFlavor(java.lang.String.class, "text/xml", "XML String")); } } Modified: geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/mailcap URL: http://svn.apache.org/viewcvs/geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/mailcap?rev=376811&r1=376810&r2=376811&view=diff ============================================================================== --- geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/mailcap (original) +++ geronimo/specs/trunk/geronimo-spec-javamail/src/main/resources/META-INF/mailcap Fri Feb 10 11:40:13 2006 @@ -1,2 +1,20 @@ +# +# Copyright 2004,2005 The Apache Software Foundation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# text/plain;; x-java-content-handler=org.apache.geronimo.mail.handlers.TextHandler text/xml;; x-java-content-handler=org.apache.geronimo.mail.handlers.XMLHandler +text/html;; x-java-content-handler=org.apache.geronimo.mail.handlers.HtmlHandler +message/rfc822;; x-java-content-handler=org.apache.geronimo.mail.handlers.MessageHandler +multipart/*;; x-java-content-handler=org.apache.geronimo.mail.handlers.MultipartHandler; x-java-fallback-entry=true