1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.transport.mailets.listservcommands;
23
24 import org.apache.james.transport.mailets.ICommandListservManager;
25 import org.apache.james.util.XMLResources;
26 import org.apache.mailet.Mail;
27 import org.apache.avalon.framework.configuration.Configuration;
28 import org.apache.avalon.framework.configuration.ConfigurationException;
29
30 import javax.mail.MessagingException;
31 import java.util.Properties;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class ErrorCommand extends BaseCommand {
56
57
58 protected XMLResources[] xmlResources;
59
60 protected static final int HEADER = 0;
61 protected static final int ERROR = 1;
62 protected static final int ADMIN_COMMANDS = 2;
63
64 public void init(ICommandListservManager commandListservManager, Configuration configuration) throws ConfigurationException {
65 super.init(commandListservManager, configuration);
66 xmlResources = initXMLResources(new String[]{"header", "error", "admincommands"});
67 }
68
69
70
71
72
73
74 public void onCommand(Mail mail) throws MessagingException {
75 onError(mail, "an unknown error occurred", "an unknown error occurred");
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90 public void onError(Mail mail, String subject, String errorMessage) throws MessagingException {
91
92 Properties props = getStandardProperties();
93 props.put("ERROR_MESSAGE", errorMessage);
94
95 StringBuffer plainTextMessage = new StringBuffer();
96 String header = xmlResources[HEADER].getString("text", props);
97 plainTextMessage.append(header);
98
99 String errorText = xmlResources[ERROR].getString("text", props);
100 plainTextMessage.append(errorText);
101
102 String adminCommands = xmlResources[ADMIN_COMMANDS].getString("text", props);
103 plainTextMessage.append(adminCommands);
104
105 sendStandardReply(mail, subject, plainTextMessage.toString(), null);
106 }
107 }