1 17 18 package org.apache.james.transport.mailets; 19 20 import org.apache.avalon.framework.component.ComponentException; 21 import org.apache.avalon.framework.component.ComponentManager; 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 import javax.mail.internet.ParseException ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.ArrayList ; 31 32 66 public class AvalonListserv extends GenericListserv { 67 68 71 protected boolean membersOnly = false; 72 73 76 protected boolean attachmentsAllowed = true; 77 78 81 protected boolean replyToList = true; 82 83 87 protected String subjectPrefix = null; 88 89 92 protected boolean autoBracket = true; 93 94 97 private UsersRepository members; 98 99 102 public void init() { 103 try { 104 membersOnly = new Boolean (getInitParameter("membersonly")).booleanValue(); 105 } catch (Exception e) { 106 } 108 try { 109 attachmentsAllowed = new Boolean (getInitParameter("attachmentsallowed")).booleanValue(); 110 } catch (Exception e) { 111 } 113 try { 114 replyToList = new Boolean (getInitParameter("replytolist")).booleanValue(); 115 } catch (Exception e) { 116 } 118 subjectPrefix = getInitParameter("subjectprefix"); 119 120 try { 121 autoBracket = new Boolean (getInitParameter("autobracket")).booleanValue(); 122 } catch (Exception e) { 123 } 125 126 ComponentManager compMgr = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER); 127 try { 128 UsersStore usersStore = (UsersStore)compMgr.lookup("org.apache.james.services.UsersStore"); 129 String repName = getInitParameter("repositoryName"); 130 131 members = (UsersRepository)usersStore.getRepository( repName ); 132 } catch (ComponentException cnfe) { 133 log("Failed to retrieve Store component:" + cnfe.getMessage()); 134 } catch (Exception e) { 135 log("Failed to retrieve Store component:" + e.getMessage()); 136 } 137 } 138 139 public Collection getMembers() throws ParseException { 140 Collection reply = new ArrayList (); 141 for (Iterator it = members.list(); it.hasNext(); ) { 142 String member = it.next().toString(); 143 try { 144 reply.add(new MailAddress(member)); 145 } 146 catch(Exception e) { 147 StringBuffer logBuffer = 150 new StringBuffer (1024) 151 .append("Invalid subscriber address: ") 152 .append(member) 153 .append(" caused: ") 154 .append(e.getMessage()); 155 log(logBuffer.toString()); 156 } 157 } 158 return reply; 159 } 160 161 166 public boolean isMembersOnly() { 167 return membersOnly; 168 } 169 170 175 public boolean isAttachmentsAllowed() { 176 return attachmentsAllowed; 177 } 178 179 185 public boolean isReplyToList() { 186 return replyToList; 187 } 188 189 194 public String getSubjectPrefix() { 195 return subjectPrefix; 196 } 197 198 203 public boolean isPrefixAutoBracketed() { 204 return autoBracket; 205 } 206 207 212 public String getMailetInfo() { 213 return "AvalonListserv Mailet"; 214 } 215 } 216 | Popular Tags |