1 17 18 package org.apache.james.transport.mailets; 19 20 import org.apache.mailet.GenericMailet; 21 import org.apache.mailet.Mail; 22 import org.apache.mailet.MailAddress; 23 24 import javax.mail.Address ; 25 import javax.mail.internet.InternetAddress ; 26 import javax.mail.internet.MimeMessage ; 27 import java.util.HashSet ; 28 import java.util.Set ; 29 30 36 public class ServerTime extends GenericMailet { 37 44 public void service(Mail mail) throws javax.mail.MessagingException { 45 MimeMessage response = (MimeMessage )mail.getMessage().reply(false); 46 response.setSubject("The time is now..."); 47 StringBuffer textBuffer = 48 new StringBuffer (128) 49 .append("This mail server thinks it's ") 50 .append((new java.util.Date ()).toString()) 51 .append("."); 52 response.setText(textBuffer.toString()); 53 54 59 if (response.getFrom() == null) { 60 response.setFrom(((MailAddress)mail.getRecipients().iterator().next()).toInternetAddress()); 61 } 62 63 if (response.getAllRecipients() == null) { 64 response.setRecipients(MimeMessage.RecipientType.TO, mail.getSender().toString()); 65 } 66 67 response.saveChanges(); 68 getMailetContext().sendMail(response); 69 } 70 71 76 public String getMailetInfo() { 77 return "ServerTime Mailet"; 78 } 79 } 80 81 | Popular Tags |