1 /*****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
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 ****************************************************************/
19
20 package org.apache.james.transport.mailets;
21
22 import javax.mail.MessagingException;
23 import java.util.StringTokenizer;
24
25 /***
26 * This mailet will attach text to the end of the message (like a footer). Right
27 * now it only supports simple messages without multiple parts.
28 */
29 public class AddFooter extends AbstractAddFooter {
30
31 /***
32 * This is the plain text version of the footer we are going to add
33 */
34 String text = "";
35
36 /***
37 * Initialize the mailet
38 */
39 public void init() throws MessagingException {
40 text = getInitParameter("text");
41 }
42
43 /***
44 * This is exposed as a method for easy subclassing to provide alternate ways
45 * to get the footer text.
46 *
47 * @return the footer text
48 */
49 public String getFooterText() {
50 return text;
51 }
52
53 /***
54 * This is exposed as a method for easy subclassing to provide alternate ways
55 * to get the footer text. By default, this will take the footer text,
56 * converting the linefeeds to <br> tags.
57 *
58 * @return the HTML version of the footer text
59 */
60 public String getFooterHTML() {
61 String text = getFooterText();
62 StringBuffer sb = new StringBuffer();
63 StringTokenizer st = new StringTokenizer(text, "\r\n", true);
64 while (st.hasMoreTokens()) {
65 String token = st.nextToken();
66 if (token.equals("\r")) {
67 continue;
68 }
69 if (token.equals("\n")) {
70 sb.append("<br />\n");
71 } else {
72 sb.append(token);
73 }
74 }
75 return sb.toString();
76 }
77
78 /***
79 * Return a string describing this mailet.
80 *
81 * @return a string describing this mailet
82 */
83 public String getMailetInfo() {
84 return "AddFooter Mailet";
85 }
86 }