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
21
22 package org.apache.james.transport.mailets;
23
24 import javax.mail.MessagingException;
25 import java.util.StringTokenizer;
26
27 /**
28 * This mailet will attach text to the end of the message (like a footer). Right
29 * now it only supports simple messages without multiple parts.
30 */
31 public class AddFooter extends AbstractAddFooter {
32
33 /**
34 * This is the plain text version of the footer we are going to add
35 */
36 String text = "";
37
38 /**
39 * Initialize the mailet
40 */
41 public void init() throws MessagingException {
42 text = getInitParameter("text");
43 }
44
45 /**
46 * This is exposed as a method for easy subclassing to provide alternate ways
47 * to get the footer text.
48 *
49 * @return the footer text
50 */
51 public String getFooterText() {
52 return text;
53 }
54
55 /**
56 * This is exposed as a method for easy subclassing to provide alternate ways
57 * to get the footer text. By default, this will take the footer text,
58 * converting the linefeeds to <br> tags.
59 *
60 * @return the HTML version of the footer text
61 */
62 public String getFooterHTML() {
63 String text = getFooterText();
64 StringBuffer sb = new StringBuffer();
65 StringTokenizer st = new StringTokenizer(text, "\r\n", true);
66 while (st.hasMoreTokens()) {
67 String token = st.nextToken();
68 if (token.equals("\r")) {
69 continue;
70 }
71 if (token.equals("\n")) {
72 sb.append("<br />\n");
73 } else {
74 sb.append(token);
75 }
76 }
77 return sb.toString();
78 }
79
80 /**
81 * Return a string describing this mailet.
82 *
83 * @return a string describing this mailet
84 */
85 public String getMailetInfo() {
86 return "AddFooter Mailet";
87 }
88 }