1 17 18 package org.apache.james.transport.mailets.listservcommands; 19 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 import org.apache.james.services.UsersRepository; 23 import org.apache.james.transport.mailets.ICommandListservManager; 24 import org.apache.james.util.XMLResources; 25 import org.apache.mailet.Mail; 26 27 import javax.mail.MessagingException ; 28 import java.util.Iterator ; 29 import java.util.Properties ; 30 31 55 public class Info extends BaseCommand { 56 57 protected XMLResources[] xmlResources; 59 60 protected static final int HEADER = 0; 61 protected static final int INFO = 1; 62 protected static final int ADMIN_COMMANDS = 2; 63 64 public void init(ICommandListservManager commandListservManager, Configuration configuration) throws ConfigurationException { 65 super.init(commandListservManager, configuration); 66 xmlResources = initXMLResources(new String []{"header", "info", "admincommands"}); 67 } 68 69 79 public void onCommand(Mail mail) throws MessagingException { 80 Properties props = getStandardProperties(); 82 props.put("MEMBER_LIST", getMemberList()); 83 84 StringBuffer plainTextMessage = new StringBuffer (); 85 String header = xmlResources[HEADER].getString("text", props); 86 plainTextMessage.append(header); 87 88 String infoMail = xmlResources[INFO].getString("text", props); 89 plainTextMessage.append(infoMail); 90 91 String adminCommands = xmlResources[ADMIN_COMMANDS].getString("text", props); 92 plainTextMessage.append(adminCommands); 93 94 String subject = xmlResources[INFO].getString("info.subject", props); 95 96 sendStandardReply(mail, subject, plainTextMessage.toString(), null); 97 } 98 99 105 protected String getMemberList() { 106 107 StringBuffer buffer = new StringBuffer (0x1000); 108 buffer.append("\r\n"); 109 UsersRepository usersRepository = getUsersRepository(); 110 for (Iterator it = usersRepository.list(); it.hasNext();) { 111 String userName = (String ) it.next(); 112 buffer.append(" ").append(userName); 113 buffer.append("\r\n"); 114 } 115 116 return buffer.toString(); 117 } 118 } 119 | Popular Tags |