01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.transport.mailets;
19:
20: import org.apache.avalon.framework.service.ServiceException;
21: import org.apache.avalon.framework.service.ServiceManager;
22: import org.apache.james.Constants;
23: import org.apache.james.services.UsersRepository;
24: import org.apache.james.services.UsersStore;
25: import org.apache.mailet.MailAddress;
26:
27: /**
28: * Adds or removes an email address to a listserv.
29: *
30: * <p>Sample configuration:
31: * <br><mailet match="CommandForListserv=james@list.working-dogs.com" class="AvalonListservManager">
32: * <br><repositoryName>name of user repository configured in UsersStore block </repositoryName>
33: * <br></mailet>
34: *
35: * @version This is $Revision: 494012 $
36: */
37: public class AvalonListservManager extends GenericListservManager {
38:
39: private UsersRepository members;
40:
41: /**
42: * Initialize the mailet
43: */
44: public void init() {
45: ServiceManager compMgr = (ServiceManager) getMailetContext()
46: .getAttribute(Constants.AVALON_COMPONENT_MANAGER);
47: try {
48: UsersStore usersStore = (UsersStore) compMgr
49: .lookup(UsersStore.ROLE);
50: String repName = getInitParameter("repositoryName");
51:
52: members = (UsersRepository) usersStore
53: .getRepository(repName);
54: } catch (ServiceException cnfe) {
55: log("Failed to retrieve Store component:"
56: + cnfe.getMessage());
57: } catch (Exception e) {
58: log("Failed to retrieve Store component:" + e.getMessage());
59: }
60: }
61:
62: /**
63: * Add an address to the list.
64: *
65: * @param address the address to add
66: *
67: * @return true if successful, false otherwise
68: */
69: public boolean addAddress(MailAddress address) {
70: members.addUser(address.toString(), "");
71: return true;
72: }
73:
74: /**
75: * Remove an address from the list.
76: *
77: * @param address the address to remove
78: *
79: * @return true if successful, false otherwise
80: */
81: public boolean removeAddress(MailAddress address) {
82: members.removeUser(address.toString());
83: return true;
84: }
85:
86: public boolean existsAddress(MailAddress address) {
87: return members.contains(address.toString());
88: }
89:
90: /**
91: * Return a string describing this mailet.
92: *
93: * @return a string describing this mailet
94: */
95: public String getMailetInfo() {
96: return "AvalonListservManager Mailet";
97: }
98: }
|