1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.transport.mailets;
21
22 import org.apache.mailet.base.FlowedMessageUtils;
23 import org.apache.mailet.base.GenericMailet;
24 import org.apache.mailet.Mail;
25 import org.apache.mailet.MailetException;
26
27 import javax.mail.MessagingException;
28
29 import java.io.IOException;
30
31
32
33
34 public class WrapText extends GenericMailet {
35 private static final String PARAMETER_NAME_FLOWED_DELSP = "delsp";
36 private static final String PARAMETER_NAME_WIDTH = "width";
37
38 private boolean optionFlowedDelsp = false;
39 private int optionWidth = FlowedMessageUtils.RFC2646_WIDTH;
40
41
42
43
44
45
46 public String getMailetInfo() {
47 return "WrapText";
48 }
49
50 private static boolean getBooleanParameter(String v, boolean def) {
51 return def ?
52 !(v != null && (v.equalsIgnoreCase("false") || v.equalsIgnoreCase("no"))) :
53 v != null && (v.equalsIgnoreCase("true") || v.equalsIgnoreCase("yes")) ;
54 }
55
56 public void init() throws MailetException {
57 optionFlowedDelsp = getBooleanParameter(getInitParameter(PARAMETER_NAME_FLOWED_DELSP), optionFlowedDelsp);
58 optionWidth = Integer.parseInt(getInitParameter(PARAMETER_NAME_WIDTH, "" + optionWidth));
59 }
60
61 public void service(Mail mail) throws MailetException {
62
63
64 try {
65 FlowedMessageUtils.flowMessage(mail.getMessage(), optionFlowedDelsp, optionWidth);
66
67 } catch (MessagingException e) {
68 throw new MailetException("Could not wrap message", e);
69
70 } catch (IOException e) {
71 throw new MailetException("Could not wrap message", e);
72 }
73
74 }
75 }