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.avalon.framework.configuration.DefaultConfiguration; 23 import org.apache.james.Constants; 24 import org.apache.james.core.MailImpl; 25 import org.apache.james.services.MailRepository; 26 import org.apache.james.services.MailStore; 27 import org.apache.mailet.GenericMailet; 28 import org.apache.mailet.Mail; 29 30 38 public class ToRepository extends GenericMailet { 39 40 43 private MailRepository repository; 44 45 49 private boolean passThrough = false; 50 51 54 private String repositoryPath; 55 56 59 public void init() { 60 repositoryPath = getInitParameter("repositoryPath"); 61 try { 62 passThrough = new Boolean (getInitParameter("passThrough")).booleanValue(); 63 } catch (Exception e) { 64 } 66 67 ComponentManager compMgr = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER); 68 try { 69 MailStore mailstore = (MailStore) compMgr.lookup("org.apache.james.services.MailStore"); 70 DefaultConfiguration mailConf 71 = new DefaultConfiguration("repository", "generated:ToRepository"); 72 mailConf.setAttribute("destinationURL", repositoryPath); 73 mailConf.setAttribute("type", "MAIL"); 74 repository = (MailRepository) mailstore.select(mailConf); 75 } catch (ComponentException cnfe) { 76 log("Failed to retrieve Store component:" + cnfe.getMessage()); 77 } catch (Exception e) { 78 log("Failed to retrieve Store component:" + e.getMessage()); 79 } 80 81 } 82 83 88 public void service(Mail genericmail) throws javax.mail.MessagingException { 89 MailImpl mail = (MailImpl)genericmail; 90 StringBuffer logBuffer = 91 new StringBuffer (160) 92 .append("Storing mail ") 93 .append(mail.getName()) 94 .append(" in ") 95 .append(repositoryPath); 96 log(logBuffer.toString()); 97 repository.store(mail); 98 if (!passThrough) { 99 mail.setState(Mail.GHOST); 100 } 101 } 102 103 108 public String getMailetInfo() { 109 return "ToRepository Mailet"; 110 } 111 } 112 | Popular Tags |