FileDocCategorySizeDatePackage
SubscribeConfirm.javaAPI DocApache James 2.3.14794Fri Jan 12 12:56:30 GMT 2007org.apache.james.transport.mailets.listservcommands

SubscribeConfirm

public class SubscribeConfirm extends BaseCommand
Subscribe handles the subscribe-confirm command. It is configured by:
<command name="subscribe-confirm" class="SubscribeConfirm"/>


It uses the formatted text-based resources for its return mail body:
  • subscribe-confirm
  • admincommands


After formatting the text, the message is delivered with {@link #sendStandardReply}

This command basically sends the welcome message and adds the user to the mailing list.
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
since
2.2.0
see
Subscribe

Fields Summary
protected org.apache.james.util.XMLResources[]
xmlResources
protected static final int
SUBSCRIBE_CONFIRM
protected static final int
ADMIN_COMMANDS
Constructors Summary
Methods Summary
protected booleancheckSubscriptionStatus(org.apache.mailet.Mail mail)
Checks to see if this user is already subscribed, if so return false and send a message

param
mail
return
false if the user is subscribed, true otherwise
throws
MessagingException

        MailAddress mailAddress = mail.getSender();
        UsersRepository usersRepository = getUsersRepository();
        if (usersRepository.contains(mailAddress.toString())) {
            getCommandListservManager().onError(mail,
                    "Invalid request",
                    xmlResources[SUBSCRIBE_CONFIRM].getString("already.subscribed", getStandardProperties()));
            return false;
        }
        return true;
    
public voidinit(org.apache.james.transport.mailets.ICommandListservManager commandListservManager, org.apache.avalon.framework.configuration.Configuration configuration)


            
        super.init(commandListservManager, configuration);
        xmlResources = initXMLResources(new String[]{"subscribeConfirm", "admincommands"});
    
public voidonCommand(org.apache.mailet.Mail mail)
After ensuring that the user isn't already subscribed, add the user to the mailing list, and send a welcome message.

It uses the formatted text-based resources for its return mail body:
  • {@link #SUBSCRIBE_CONFIRM}
  • {@link #ADMIN_COMMANDS}

param
mail
throws
MessagingException

        if (checkSubscriptionStatus(mail)) {
            getUsersRepository().addUser(mail.getSender().toString(), "");

            //send mail
            Properties props = getStandardProperties();
            props.put("SENDER_ADDR", mail.getSender().toString());

            String confirmationMail = xmlResources[SUBSCRIBE_CONFIRM].getString("text", props);
            String adminCommands = xmlResources[ADMIN_COMMANDS].getString("text", props);
            String subject = xmlResources[SUBSCRIBE_CONFIRM].getString("welcome.subscribe.address", props);

            sendStandardReply(mail, subject, confirmationMail + adminCommands, null);
        }