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;
23
24 import org.apache.mailet.base.GenericMailet;
25 import org.apache.mailet.Mail;
26 import org.apache.mailet.MailAddress;
27
28 import javax.mail.MessagingException;
29
30
31
32
33
34 public abstract class GenericListservManager extends GenericMailet {
35
36
37
38
39
40 public abstract boolean addAddress(MailAddress address);
41
42
43
44
45
46 public abstract boolean removeAddress(MailAddress address);
47
48
49
50
51
52
53 public abstract boolean existsAddress(MailAddress address);
54
55
56
57
58
59 public final void service(Mail mail) throws MessagingException {
60 if (mail.getRecipients().size() != 1) {
61 getMailetContext().bounce(mail, "You can only send one command at a time to this listserv manager.");
62 return;
63 }
64 MailAddress address = (MailAddress)mail.getRecipients().iterator().next();
65 if (address.getUser().endsWith("-off")) {
66 if (existsAddress(mail.getSender())) {
67 if (removeAddress(mail.getSender())) {
68 getMailetContext().bounce(mail, "Successfully removed from listserv.");
69 } else {
70 getMailetContext().bounce(mail, "Unable to remove you from listserv for some reason.");
71 }
72 } else {
73 getMailetContext().bounce(mail, "You are not subscribed to this listserv.");
74 }
75 } else if (address.getUser().endsWith("-on")) {
76 if (existsAddress(mail.getSender())) {
77 getMailetContext().bounce(mail, "You are already subscribed to this listserv.");
78 } else {
79 if (addAddress(mail.getSender())) {
80 getMailetContext().bounce(mail, "Successfully added to listserv.");
81 } else {
82 getMailetContext().bounce(mail, "Unable to add you to the listserv for some reason");
83 }
84 }
85 } else {
86 getMailetContext().bounce(mail, "Could not understand the command you sent to this listserv manager.\r\n"
87 + "Valid commands are <listserv>-on@domain.com and <listserv>-off@domain.com");
88 }
89
90 mail.setState(Mail.GHOST);
91 }
92 }