1 17 18 package org.apache.james.transport.mailets; 19 20 import java.util.Enumeration ; 21 import javax.mail.MessagingException ; 22 import javax.mail.internet.MimeMessage ; 23 24 import org.apache.james.core.MailImpl; 25 import org.apache.mailet.GenericMailet; 26 import org.apache.mailet.Mail; 27 28 35 public class LogHeaders extends GenericMailet { 36 37 41 private boolean passThrough = true; 42 43 46 public void init() { 47 try { 48 passThrough = (getInitParameter("passThrough") == null) ? true : new Boolean (getInitParameter("debug")).booleanValue(); 49 } catch (Exception e) { 50 } 52 } 53 54 59 public void service(Mail genericmail) { 60 MailImpl mail = (MailImpl)genericmail; 61 log(new StringBuffer (160).append("Logging mail ").append(mail.getName()).toString()); 62 try { 63 log(getMessageHeaders(mail.getMessage())); 64 } 65 catch (MessagingException e) { 66 log("Error logging headers."); 67 } 68 if (!passThrough) { 69 mail.setState(Mail.GHOST); 70 } 71 } 72 73 77 private String getMessageHeaders(MimeMessage message) throws MessagingException { 78 Enumeration heads = message.getAllHeaderLines(); 79 StringBuffer headBuffer = new StringBuffer (1024).append("\n"); 80 while(heads.hasMoreElements()) { 81 headBuffer.append(heads.nextElement().toString()).append("\n"); 82 } 83 return headBuffer.toString(); 84 } 85 86 91 public String getMailetInfo() { 92 return "LogHeaders Mailet"; 93 } 94 } 95 | Popular Tags |