1 17 18 package org.apache.james.transport.mailets.listservcommands; 19 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 import org.apache.james.services.UsersRepository; 23 import org.apache.james.transport.mailets.ICommandListservManager; 24 import org.apache.james.util.XMLResources; 25 import org.apache.mailet.Mail; 26 import org.apache.mailet.MailAddress; 27 28 import javax.mail.MessagingException ; 29 import java.util.Properties ; 30 31 56 public class UnSubscribe extends BaseCommand { 57 58 protected XMLResources xmlResources; 60 61 public void init(ICommandListservManager commandListservManager, Configuration configuration) throws ConfigurationException { 62 super.init(commandListservManager, configuration); 63 xmlResources = initXMLResources(new String []{"unsubscribe"})[0]; 64 } 65 66 72 public void onCommand(Mail mail) throws MessagingException { 73 if (checkSubscriptionStatus(mail)) { 74 Properties props = getStandardProperties(); 76 props.put("SENDER_ADDR", mail.getSender().toString()); 77 78 String confirmationMail = xmlResources.getString("text", props); 79 String subject = xmlResources.getString("confirm.unsubscribe.subject", props); 80 String replyAddress = xmlResources.getString("confirm.unsubscribe.address", props); 81 82 sendStandardReply(mail, subject, confirmationMail, replyAddress); 83 } 84 } 85 86 92 protected boolean checkSubscriptionStatus(Mail mail) throws MessagingException { 93 MailAddress mailAddress = mail.getSender(); 94 UsersRepository usersRepository = getUsersRepository(); 95 if (!usersRepository.contains(mailAddress.toString())) { 96 getCommandListservManager().onError(mail, 97 "Invalid request", 98 xmlResources.getString("not.subscribed", getStandardProperties())); 99 return false; 100 } 101 return true; 102 } 103 } 104 | Popular Tags |