You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2009/10/13 13:25:59 UTC
svn commit: r824701 - in
/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main:
java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java
resources/META-INF/mailcap
Author: rickmcguire
Date: Tue Oct 13 11:25:59 2009
New Revision: 824701
URL: http://svn.apache.org/viewvc?rev=824701&view=rev
Log:
GERONIMO-4904 Add handler for message/rfc822 MIME type
Added:
geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java (with props)
Modified:
geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/resources/META-INF/mailcap
Added: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java?rev=824701&view=auto
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java (added)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java Tue Oct 13 11:25:59 2009
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.javamail.handlers;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import javax.activation.ActivationDataFlavor;
+import javax.activation.DataContentHandler;
+import javax.activation.DataSource;
+import javax.mail.Message;
+import javax.mail.MessageAware;
+import javax.mail.MessageContext;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+/**
+ * Content handler for RFC-822 compliant messages.
+ * @version $Rev$ $Date$
+ */
+public class RFC822MessageHandler implements DataContentHandler {
+ // the data flavor defines what this looks like, and is fixed once the
+ // handler is instantiated
+ protected final DataFlavor flavour;
+
+ public RFC822MessageHandler() {
+ flavour = new ActivationDataFlavor(Message.class, "message/rfc822", "Message");
+ }
+
+ /**
+ * Return all of the flavors processed by this handler. This
+ * is just the singleton flavor.
+ *
+ * @return An array of the transfer flavors supported by this handler.
+ */
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[] { flavour };
+ }
+
+ /**
+ * Retrieve the transfer data from the data source, but
+ * only if the requested flavor matches what we support.
+ *
+ * @param df The requested data flavor.
+ * @param ds The source DataSource.
+ *
+ * @return The extracted content object, or null if there is a
+ * mismatch of flavors.
+ * @exception UnsupportedFlavorException
+ * @exception IOException
+ */
+ public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException {
+ return flavour.equals(df) ? getContent(ds) : null;
+ }
+
+ /**
+ * Extract the RFC822 Message content from a DataSource.
+ *
+ * @param ds The source data source.
+ *
+ * @return An extracted MimeMessage object.
+ * @exception IOException
+ */
+ public Object getContent(DataSource ds) throws IOException {
+ try {
+ // creating a MimeMessage instance requires a session. If the DataSource
+ // is a MessageAware one, we can get the session information from the MessageContext.
+ // This is generally the case, but if it is not available, then just retrieve
+ // the default instance and use it.
+ if (ds instanceof MessageAware) {
+ MessageContext context = ((MessageAware)ds).getMessageContext();
+ return new MimeMessage(context.getSession(), ds.getInputStream());
+ }
+ else {
+ return new MimeMessage(Session.getDefaultInstance(new Properties(), null), ds.getInputStream());
+ }
+ } catch (MessagingException e) {
+ throw (IOException) new IOException(e.getMessage()).initCause(e);
+ }
+ }
+
+ /**
+ * Write an RFC 822 message object out to an output stream.
+ *
+ * @param obj The source message object.
+ * @param mimeType The target mimetype
+ * @param os The target output stream.
+ *
+ * @exception IOException
+ */
+ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException {
+ // we only handle message instances here
+ if (obj instanceof Message) {
+ Message message = (Message) obj;
+ try {
+ message.writeTo(os);
+ } catch (MessagingException e) {
+ throw (IOException) new IOException(e.getMessage()).initCause(e);
+ }
+ }
+ }
+}
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/handlers/RFC822MessageHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/resources/META-INF/mailcap
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/resources/META-INF/mailcap?rev=824701&r1=824700&r2=824701&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/resources/META-INF/mailcap (original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/resources/META-INF/mailcap Tue Oct 13 11:25:59 2009
@@ -24,4 +24,5 @@
image/gif;; x-java-content-handler=org.apache.geronimo.javamail.handlers.ImageGifHandler
image/jpeg;; x-java-content-handler=org.apache.geronimo.javamail.handlers.ImageJpegHandler
-multipart/*;; x-java-content-handler=org.apache.geronimo.javamail.handlers.MultipartHandler
\ No newline at end of file
+multipart/*;; x-java-content-handler=org.apache.geronimo.javamail.handlers.MultipartHandler
+message/rfc822;; x-java-content-handler=org.apache.geronimo.javamail.handlers.RFC822MessageHandler