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.transport.mailets.ICommandListservManager; 23 import org.apache.james.util.XMLResources; 24 import org.apache.james.services.UsersRepository; 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 UnSubscribeConfirm 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 []{"unsubscribeConfirm"})[0]; 64 } 65 66 73 public void onCommand(Mail mail) throws MessagingException { 74 if (checkSubscriptionStatus(mail)) { 75 getUsersRepository().removeUser(mail.getSender().toString()); 76 77 Properties props = getStandardProperties(); 79 props.put("SENDER_ADDR", mail.getSender().toString()); 80 81 String confirmationMail = xmlResources.getString("text", props); 82 String subject = xmlResources.getString("goodbye.subscribe.address", props); 83 84 sendStandardReply(mail, subject, confirmationMail, null); 85 } 86 } 87 88 94 protected boolean checkSubscriptionStatus(Mail mail) throws MessagingException { 95 MailAddress mailAddress = mail.getSender(); 96 UsersRepository usersRepository = getUsersRepository(); 97 if (!usersRepository.contains(mailAddress.toString())) { 98 getCommandListservManager().onError(mail, 99 "Invalid request", 100 xmlResources.getString("not.subscribed", getStandardProperties())); 101 return false; 102 } 103 return true; 104 } 105 } 106 | Popular Tags |