FileDocCategorySizeDatePackage
GenericListservManager.javaAPI DocApache James 2.3.13992Fri Jan 12 12:56:28 GMT 2007org.apache.james.transport.mailets

GenericListservManager

public abstract class GenericListservManager extends org.apache.mailet.GenericMailet
An abstract implementation of a listserv manager. This mailet reads the address to find the command.

Fields Summary
Constructors Summary
Methods Summary
public abstract booleanaddAddress(org.apache.mailet.MailAddress address)
Adds an address to the listserv. Returns whether command was successful.

public abstract booleanexistsAddress(org.apache.mailet.MailAddress address)
Indicates whether an address already exists on the listserv. Returns whether the address exists.

public abstract booleanremoveAddress(org.apache.mailet.MailAddress address)
Removes an address from the listserv. Returns whether command was successful.

public final voidservice(org.apache.mailet.Mail mail)
Processes the message. Checks which command was sent based on the recipient address, and does the appropriate action.

        if (mail.getRecipients().size() != 1) {
            getMailetContext().bounce(mail, "You can only send one command at a time to this listserv manager.");
            return;
        }
        MailAddress address = (MailAddress)mail.getRecipients().iterator().next();
        if (address.getUser().endsWith("-off")) {
            if (existsAddress(mail.getSender())) {
                if (removeAddress(mail.getSender())) {
                    getMailetContext().bounce(mail, "Successfully removed from listserv.");
                } else {
                    getMailetContext().bounce(mail, "Unable to remove you from listserv for some reason.");
                }
            } else {
                getMailetContext().bounce(mail, "You are not subscribed to this listserv.");
            }
        } else if (address.getUser().endsWith("-on")) {
            if (existsAddress(mail.getSender())) {
                getMailetContext().bounce(mail, "You are already subscribed to this listserv.");
            } else {
                if (addAddress(mail.getSender())) {
                    getMailetContext().bounce(mail, "Successfully added to listserv.");
                } else {
                    getMailetContext().bounce(mail, "Unable to add you to the listserv for some reason");
                }
            }
        } else {
            getMailetContext().bounce(mail, "Could not understand the command you sent to this listserv manager.\r\n"
                                      + "Valid commands are <listserv>-on@domain.com and <listserv>-off@domain.com");
        }
        //Kill the command message
        mail.setState(Mail.GHOST);