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 57 public class SubscribeConfirm extends BaseCommand { 58 59 protected XMLResources[] xmlResources; 61 62 protected static final int SUBSCRIBE_CONFIRM = 0; 63 protected static final int ADMIN_COMMANDS = 1; 64 65 public void init(ICommandListservManager commandListservManager, Configuration configuration) throws ConfigurationException { 66 super.init(commandListservManager, configuration); 67 xmlResources = initXMLResources(new String []{"subscribeConfirm", "admincommands"}); 68 } 69 70 86 public void onCommand(Mail mail) throws MessagingException { 87 if (checkSubscriptionStatus(mail)) { 88 getUsersRepository().addUser(mail.getSender().toString(), ""); 89 90 Properties props = getStandardProperties(); 92 props.put("SENDER_ADDR", mail.getSender().toString()); 93 94 String confirmationMail = xmlResources[SUBSCRIBE_CONFIRM].getString("text", props); 95 String adminCommands = xmlResources[ADMIN_COMMANDS].getString("text", props); 96 String subject = xmlResources[SUBSCRIBE_CONFIRM].getString("welcome.subscribe.address", props); 97 98 sendStandardReply(mail, subject, confirmationMail + adminCommands, null); 99 } 100 } 101 102 108 protected boolean checkSubscriptionStatus(Mail mail) throws MessagingException { 109 MailAddress mailAddress = mail.getSender(); 110 UsersRepository usersRepository = getUsersRepository(); 111 if (usersRepository.contains(mailAddress.toString())) { 112 getCommandListservManager().onError(mail, 113 "Invalid request", 114 xmlResources[SUBSCRIBE_CONFIRM].getString("already.subscribed", getStandardProperties())); 115 return false; 116 } 117 return true; 118 } 119 } 120 | Popular Tags |