Methods Summary |
---|
public org.apache.james.transport.mailets.listservcommands.IListServCommand | getCommand(java.lang.String name)Get a specific command specified by the 'commands' configuration block.
For instance:
<commands>
<command name="subscribe" class="Subscribe"/>
<command name="subscribe-confirm" class="SubscribeConfirm"/>
<command name="unsubscribe" class="UnSubscribe"/>
<command name="unsubscribe-confirm" class="UnSubscribeConfirm"/>
<command name="error" class="ErrorCommand"/>
<command name="owner" class="Owner"/>
<command name="info" class="Info"/>
</commands>
return (IListServCommand) commandMap.get(name.toLowerCase(Locale.US));
|
protected java.lang.String | getCommandName(org.apache.mailet.MailAddress mailAddress)Get the name of the command
String user = mailAddress.getUser();
int index = user.indexOf('-", listName.length());
String commandName = user.substring(++index);
return commandName;
|
public org.apache.james.transport.mailets.listservcommands.IListServCommand | getCommandTarget(org.apache.mailet.MailAddress mailAddress)Based on the to address get a valid or command or null
String commandName = getCommandName(mailAddress);
return getCommand(commandName);
|
public java.util.Map | getCommands()Get all the available commands
return commandMap;
|
protected static java.lang.Object | getField(java.lang.Object instance, java.lang.String name)Retrieves a data field, potentially defined by a super class.
Class clazz = instance.getClass();
Field[] fields;
while (clazz != null) {
fields = clazz.getDeclaredFields();
for (int index = 0; index < fields.length; index++) {
Field field = fields[index];
if (field.getName().equals(name)) {
field.setAccessible(true);
return field.get(instance);
}
}
clazz = clazz.getSuperclass();
}
return null;
|
public java.lang.String | getListDomain()Get the domain of the list specified by the config param: 'listDomain'.
eg: <listDomain>localhost</listDomain>
return listDomain;
|
public java.lang.String | getListName(boolean displayFormat)Get the name of this list specified by the config param: 'listName'.
eg: <listName>announce</listName>
return displayFormat ? displayName : listName;
|
public java.lang.String | getListOwner()Gets the owner of this list specified by the config param: 'listOwner'.
eg: <listOwner>owner@localhost</listOwner>
return listOwner;
|
public java.lang.String | getResourcesFile()
return getInitParameter("resources");
|
public java.util.Properties | getStandardProperties()Use this to get standard properties for future calls to {@link org.apache.james.util.XMLResources}
Properties standardProperties = new Properties();
standardProperties.put("LIST_NAME", getListName(false));
standardProperties.put("DISPLAY_NAME", getListName(true));
standardProperties.put("DOMAIN_NAME", getListDomain());
return standardProperties;
|
public org.apache.james.services.UsersRepository | getUsersRepository()Get the current user repository for this list serv
return usersRepository;
|
public void | init()
try {
//Well, i want a more complex configuration structure
//of my mailet, so i have to cheat... and cheat i will...
Configuration configuration = (Configuration) getField(getMailetConfig(), "configuration");
//get name
listName = configuration.getChild("listName").getValue();
displayName = configuration.getChild("displayName").getValue();
listOwner = configuration.getChild("listOwner").getValue();
listDomain = configuration.getChild("listDomain").getValue();
//initialize resources
initializeResources();
//get users store
initUsersRepository();
//get command packages
loadCommandPackages(configuration);
//load commands
loadCommands(configuration);
//register w/context
getMailetContext().setAttribute(ICommandListservManager.ID + listName, this);
} catch (Exception e) {
throw new MessagingException(e.getMessage(), e);
}
|
protected void | initUsersRepository()Fetch the repository of users
ServiceManager compMgr = (ServiceManager) getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
try {
UsersStore usersStore = (UsersStore) compMgr.lookup(UsersStore.ROLE);
String repName = getInitParameter("repositoryName");
usersRepository = usersStore.getRepository(repName);
} catch (Exception e) {
log("Failed to retrieve Store component:" + e.getMessage());
}
|
public org.apache.james.util.XMLResources[] | initXMLResources(java.lang.String[] names)Initializes an array of resources
try {
File xmlFile = new File(getResourcesFile());
Properties props = getStandardProperties();
String listName = props.getProperty("LIST_NAME");
XMLResources[] xmlResources = new XMLResources[names.length];
for (int index = 0; index < names.length; index++) {
xmlResources[index] = new XMLResources();
xmlResources[index].init(xmlFile, names[index], listName, props);
}
return xmlResources;
} catch (Exception e) {
log(e.getMessage(), e);
throw new ConfigurationException("Can't initialize:", e);
}
|
protected void | initializeResources()initialize the resources
xmlResources = initXMLResources(new String[]{"List Manager"})[0];
|
protected void | loadCommand(java.lang.String commandName, java.lang.String className, org.apache.avalon.framework.configuration.Configuration configuration)Loads and initializes a single command
ClassLoader theClassLoader = getClass().getClassLoader();
for (Iterator it = commandPackages.iterator(); it.hasNext();) {
String packageName = (String) it.next();
IListServCommand listServCommand = null;
try {
listServCommand = (IListServCommand) theClassLoader.loadClass(packageName + className).newInstance();
} catch (Exception e) {
//ignore
continue;
}
listServCommand.init(this, configuration);
commandMap.put(commandName, listServCommand);
return;
}
throw new ConfigurationException("Unable to load listservcommand: " + commandName);
|
protected void | loadCommandPackages(org.apache.avalon.framework.configuration.Configuration configuration)loads all of the packages for the commands
commandPackages.add("");
final Configuration packageConfiguration = configuration.getChild("commandpackages");
final Configuration[] pkgConfs = packageConfiguration.getChildren("commandpackage");
for (int index = 0; index < pkgConfs.length; index++) {
Configuration conf = pkgConfs[index];
String packageName = conf.getValue().trim();
if (!packageName.endsWith(".")) {
packageName += ".";
}
commandPackages.add(packageName);
}
|
protected void | loadCommands(org.apache.avalon.framework.configuration.Configuration configuration)Load an initialize all of the available commands
final Configuration commandConfigurations = configuration.getChild("commands");
final Configuration[] commandConfs = commandConfigurations.getChildren("command");
for (int index = 0; index < commandConfs.length; index++) {
Configuration commandConf = commandConfs[index];
String commandName = commandConf.getAttribute("name").toLowerCase();
String className = commandConf.getAttribute("class");
loadCommand(commandName, className, commandConf);
}
|
public void | onError(org.apache.mailet.Mail mail, java.lang.String subject, java.lang.String errorMessage)An error occurred, send some sort of message
ErrorCommand errorCommand = (ErrorCommand) getCommand("error");
errorCommand.onError(mail, subject, errorMessage);
|
public void | service(org.apache.mailet.Mail mail)Called by the mailet container to allow the mailet to process a
message.
This method is declared abstract so subclasses must override it.
if (mail.getRecipients().size() != 1) {
getMailetContext().bounce(mail, "You can only send one command at a time to this listserv manager.");
return;
}
MailAddress mailAddress = (MailAddress) mail.getRecipients().iterator().next();
IListServCommand command = getCommandTarget(mailAddress);
if (command == null) {
//don't recognize the command
Properties props = getStandardProperties();
props.setProperty("COMMAND", getCommandName(mailAddress));
onError(mail, "unknown command", xmlResources.getString("command.not.understood", props));
} else {
command.onCommand(mail);
}
// onError or onCommand would have done the job, so regardless
// of which get rid of this e-mail. This is something that we
// should review, and decide if there is any reason to allow a
// passthrough.
mail.setState(Mail.GHOST);
|