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

SetMimeHeader

public class SetMimeHeader extends org.apache.mailet.GenericMailet
Adds a specified header and value to the message. Sample configuration: X-MailetHeader TheHeaderValue
version
1.0.0, 2002-09-11

Fields Summary
private String
headerName
The name of the header to be added.
private String
headerValue
The value to be set for the header.
Constructors Summary
Methods Summary
public java.lang.StringgetMailetInfo()
Return a string describing this mailet.

return
a string describing this mailet

        return "SetMimeHeader Mailet" ;
    
public voidinit()
Initialize the mailet.

        headerName = getInitParameter("name");
        headerValue = getInitParameter("value");
        
        // Check if needed config values are used
        if (headerName == null || headerName.equals("") || headerValue == null
                || headerValue.equals("")) {
            throw new MessagingException("Please configure a name and a value");
        }
    
public voidservice(org.apache.mailet.Mail mail)
Takes the message and adds a header to it.

param
mail the mail being processed
throws
MessagingException if an error arises during message processing

        try {
            MimeMessage message = mail.getMessage () ;

            //Set the header name and value (supplied at init time).
            message.setHeader(headerName, headerValue);
            message.saveChanges();
        } catch (javax.mail.MessagingException me) {
            log (me.getMessage());
        }