01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.transport.mailets;
19:
20: import javax.mail.MessagingException;
21: import java.util.StringTokenizer;
22:
23: /**
24: * This mailet will attach text to the end of the message (like a footer). Right
25: * now it only supports simple messages without multiple parts.
26: */
27: public class AddFooter extends AbstractAddFooter {
28:
29: /**
30: * This is the plain text version of the footer we are going to add
31: */
32: String text = "";
33:
34: /**
35: * Initialize the mailet
36: */
37: public void init() throws MessagingException {
38: text = getInitParameter("text");
39: }
40:
41: /**
42: * This is exposed as a method for easy subclassing to provide alternate ways
43: * to get the footer text.
44: *
45: * @return the footer text
46: */
47: public String getFooterText() {
48: return text;
49: }
50:
51: /**
52: * This is exposed as a method for easy subclassing to provide alternate ways
53: * to get the footer text. By default, this will take the footer text,
54: * converting the linefeeds to <br> tags.
55: *
56: * @return the HTML version of the footer text
57: */
58: public String getFooterHTML() {
59: String text = getFooterText();
60: StringBuffer sb = new StringBuffer();
61: StringTokenizer st = new StringTokenizer(text, "\r\n", true);
62: while (st.hasMoreTokens()) {
63: String token = st.nextToken();
64: if (token.equals("\r")) {
65: continue;
66: }
67: if (token.equals("\n")) {
68: sb.append("<br />\n");
69: } else {
70: sb.append(token);
71: }
72: }
73: return sb.toString();
74: }
75:
76: /**
77: * Return a string describing this mailet.
78: *
79: * @return a string describing this mailet
80: */
81: public String getMailetInfo() {
82: return "AddFooter Mailet";
83: }
84: }
|