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 Subscribe extends BaseCommand { 57 58 protected XMLResources xmlResources; 60 61 62 63 public void init(ICommandListservManager commandListservManager, Configuration configuration) throws ConfigurationException { 64 super.init(commandListservManager, configuration); 65 xmlResources = initXMLResources(new String []{"subscribe"})[0]; 66 } 67 68 75 public void onCommand(Mail mail) throws MessagingException { 76 if (checkSubscriptionStatus(mail)) { 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("confirm.subscribe.subject", props); 83 String replyAddress = xmlResources.getString("confirm.subscribe.address", props); 84 85 sendStandardReply(mail, subject, confirmationMail, replyAddress); 86 } 87 } 88 89 95 protected boolean checkSubscriptionStatus(Mail mail) throws MessagingException { 96 MailAddress mailAddress = mail.getSender(); 97 UsersRepository usersRepository = getUsersRepository(); 98 if (usersRepository.contains(mailAddress.toString())) { 99 getCommandListservManager().onError(mail, 100 "Invalid request", 101 xmlResources.getString("already.subscribed", getStandardProperties())); 102 return false; 103 } 104 return true; 105 } 106 } 107 | Popular Tags |