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

UnSubscribeConfirm

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


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


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

This command basically sends a goodbye message and removes the user from the mailing list.
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
since
2.2.0
see
UnSubscribe

Fields Summary
protected org.apache.james.util.XMLResources
xmlResources
Constructors Summary
Methods Summary
protected booleancheckSubscriptionStatus(org.apache.mailet.Mail mail)
Checks to see that this user is already subscribed, if not return false and send a message

param
mail
return
false if the user isn't subscribed, true otherwise
throws
MessagingException

        MailAddress mailAddress = mail.getSender();
        UsersRepository usersRepository = getUsersRepository();
        if (!usersRepository.contains(mailAddress.toString())) {
            getCommandListservManager().onError(mail,
                    "Invalid request",
                    xmlResources.getString("not.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[]{"unsubscribeConfirm"})[0];
    
public voidonCommand(org.apache.mailet.Mail mail)
After ensuring that the user is currently subscribed, remove the user to the mailing list, and send a goodbye message.

param
mail
throws
MessagingException

        if (checkSubscriptionStatus(mail)) {
            getUsersRepository().removeUser(mail.getSender().toString());

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

            String confirmationMail = xmlResources.getString("text", props);
            String subject = xmlResources.getString("goodbye.subscribe.address", props);

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