FileDocCategorySizeDatePackage
ServerTime.javaAPI DocApache James 2.3.13215Fri Jan 12 12:56:30 GMT 2007org.apache.james.transport.mailets

ServerTime

public class ServerTime extends org.apache.mailet.GenericMailet
Returns the current time for the mail server. Sample configuration:

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetMailetInfo()
Return a string describing this mailet.

return
a string describing this mailet

        return "ServerTime Mailet";
    
public voidservice(org.apache.mailet.Mail mail)
Sends a message back to the sender indicating what time the server thinks it is.

param
mail the mail being processed
throws
MessagingException if an error is encountered while formulating the reply message

        MimeMessage response = (MimeMessage)mail.getMessage().reply(false);
        response.setSubject("The time is now...");
        StringBuffer textBuffer =
            new StringBuffer(128)
                    .append("This mail server thinks it's ")
                    .append((new java.util.Date()).toString())
                    .append(".");
        response.setText(textBuffer.toString());

        // Someone manually checking the server time by hand may send
        // an formatted message, lacking From and To headers.  If the
        // response fields are null, try setting them from the SMTP
        // MAIL FROM/RCPT TO commands used to send the inquiry.

        if (response.getFrom() == null) {
            response.setFrom(((MailAddress)mail.getRecipients().iterator().next()).toInternetAddress());
        }

        if (response.getAllRecipients() == null) {
            response.setRecipients(MimeMessage.RecipientType.TO, mail.getSender().toString());
        }

        response.saveChanges();
        getMailetContext().sendMail(response);