svn commit: r413624 - in /james/server/trunk/src/java/org/apache/james/transport/mailets: AbstractAddFooter.java AddFooter.java CommandListservFooter.java
Author: norman Date: Mon Jun 12 03:19:59 2006 New Revision: 413624 URL: http://svn.apache.org/viewvc?rev=413624view=rev Log: Add an abstract class for adding a Footer. Change AddFooter and CommandListservFooter to extend this class Added: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/AddFooter.java james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservFooter.java Added: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java?rev=413624view=auto == --- james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java (added) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java Mon Jun 12 03:19:59 2006 @@ -0,0 +1,189 @@ +/*** + * Copyright (c) 2006 The Apache Software Foundation. * + * All rights reserved.* + * --- * + * 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.james.transport.mailets; + +import org.apache.mailet.GenericMailet; +import org.apache.mailet.Mail; +import org.apache.mailet.RFC2822Headers; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; +import javax.mail.internet.MimePart; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +/** + * An abstract implementation of a mailet that add a Footer to an email + */ +public abstract class AbstractAddFooter extends GenericMailet { + +/** + * Takes the message and attaches a footer message to it. Right now, it only + * supports simple messages. Needs to have additions to make it support + * messages with alternate content types or with attachments. + * + * @param mail the mail being processed + * + * @throws MessagingException if an error arises during message processing + */ +public void service(Mail mail) throws MessagingException { +try { +MimeMessage message = mail.getMessage(); + +if (attachFooter(message)) { +message.saveChanges(); +} else { +log(Unable to add footer to mail + mail.getName()); +} +} catch (UnsupportedEncodingException e) { +log(UnsupportedEncoding Unable to add footer to mail ++ mail.getName()); +} catch (IOException ioe) { +throw new MessagingException(Could not read message, ioe); +} +} + +/** + * Prepends the content of the MimePart as text to the existing footer + * + * @param part the MimePart to attach + * + * @throws MessagingException + * @throws IOException + */ +protected void addToText(MimePart part) throws MessagingException, +IOException { +//log(Trying to add footer to + part.getContent().toString()); +String contentType = part.getContentType(); +String content = (String) part.getContent(); + +if (!content.endsWith(\n)) { +content += \r\n; +} +content += getFooterText(); + +part.setContent(content, contentType); +part.setHeader(RFC2822Headers.CONTENT_TYPE, contentType); +//log(After adding footer: + part.getContent().toString()); +} + +/** + * Prepends the content of the MimePart as HTML to the existing footer + * + * @param part the MimePart to attach + * + * @throws MessagingException + * @throws IOException + */ +protected void addToHTML(MimePart part) throws MessagingException, +IOException { +
Re: svn commit: r413624 - in /james/server/trunk/src/java/org/apache/james/transport/mailets: AbstractAddFooter.java AddFooter.java CommandListservFooter.java
I whould like to put it in 2.3 branch also cause we have fixed some bugs in the AddFooter mailet (which i used as template for the abstract class) before which never was fixed ( as i know) in CommandListservFooter. Anyone see problems with this code ? bye Norman Am Montag, den 12.06.2006, 10:20 + schrieb [EMAIL PROTECTED]: Author: norman Date: Mon Jun 12 03:19:59 2006 New Revision: 413624 URL: http://svn.apache.org/viewvc?rev=413624view=rev Log: Add an abstract class for adding a Footer. Change AddFooter and CommandListservFooter to extend this class Added: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/AddFooter.java james/server/trunk/src/java/org/apache/james/transport/mailets/CommandListservFooter.java Added: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java?rev=413624view=auto == --- james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java (added) +++ james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractAddFooter.java Mon Jun 12 03:19:59 2006 @@ -0,0 +1,189 @@ +/*** + * Copyright (c) 2006 The Apache Software Foundation. * + * All rights reserved.* + * --- * + * 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.james.transport.mailets; + +import org.apache.mailet.GenericMailet; +import org.apache.mailet.Mail; +import org.apache.mailet.RFC2822Headers; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeBodyPart; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; +import javax.mail.internet.MimePart; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +/** + * An abstract implementation of a mailet that add a Footer to an email + */ +public abstract class AbstractAddFooter extends GenericMailet { + +/** + * Takes the message and attaches a footer message to it. Right now, it only + * supports simple messages. Needs to have additions to make it support + * messages with alternate content types or with attachments. + * + * @param mail the mail being processed + * + * @throws MessagingException if an error arises during message processing + */ +public void service(Mail mail) throws MessagingException { +try { +MimeMessage message = mail.getMessage(); + +if (attachFooter(message)) { +message.saveChanges(); +} else { +log(Unable to add footer to mail + mail.getName()); +} +} catch (UnsupportedEncodingException e) { +log(UnsupportedEncoding Unable to add footer to mail ++ mail.getName()); +} catch (IOException ioe) { +throw new MessagingException(Could not read message, ioe); +} +} + +/** + * Prepends the content of the MimePart as text to the existing footer + * + * @param part the MimePart to attach + * + * @throws MessagingException + * @throws IOException + */ +protected void addToText(MimePart part) throws MessagingException, +IOException { +//log(Trying to add footer to + part.getContent().toString()); +String contentType = part.getContentType(); +String content = (String) part.getContent(); + +if (!content.endsWith(\n)) { +content += \r\n; +} +content += getFooterText(); + +part.setContent(content, contentType); +