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