FileDocCategorySizeDatePackage
MailHeaders.javaAPI DocApache James 2.3.15172Fri Jan 12 12:56:22 GMT 2007org.apache.james.core

MailHeaders

public class MailHeaders extends InternetHeaders implements Serializable, Cloneable
This interface defines a container for mail headers. Each header must use MIME format:
name: value
.

Fields Summary
Constructors Summary
public MailHeaders()
No argument constructor

throws
MessagingException if the super class cannot be properly instantiated

        super();
    
public MailHeaders(InputStream in)
Constructor that takes an InputStream containing the contents of the set of mail headers.

param
in the InputStream containing the header data
throws
MessagingException if the super class cannot be properly instantiated based on the stream

        super();
        load(in);
    
Methods Summary
public voidaddHeader(java.lang.String arg0, java.lang.String arg1)
If the new header is a Return-Path we get sure that we add it to the top Javamail, at least until 1.4.0 does the wrong thing if it loaded a stream with a return-path in the middle.

see
javax.mail.internet.InternetHeaders#addHeader(java.lang.String, java.lang.String)

        if (RFC2822Headers.RETURN_PATH.equalsIgnoreCase(arg0)) {
            headers.add(0, new InternetHeader(arg0, arg1));
        } else {
            super.addHeader(arg0, arg1);
        }
    
protected java.lang.Objectclone()

        // TODO Auto-generated method stub
        return super.clone();
    
public booleanisSet(java.lang.String name)
Check if a particular header is present.

return
true if the header is present, false otherwise

        String[] value = super.getHeader(name);
        return (value != null && value.length != 0);
    
public booleanisValid()
Check if all REQUIRED headers fields as specified in RFC 822 are present.

return
true if the headers are present, false otherwise

        return (isSet(RFC2822Headers.DATE) && isSet(RFC2822Headers.TO) && isSet(RFC2822Headers.FROM));
    
public voidsetHeader(java.lang.String arg0, java.lang.String arg1)
If the new header is a Return-Path we get sure that we add it to the top Javamail, at least until 1.4.0 does the wrong thing if it loaded a stream with a return-path in the middle.

see
javax.mail.internet.InternetHeaders#setHeader(java.lang.String, java.lang.String)

        if (RFC2822Headers.RETURN_PATH.equalsIgnoreCase(arg0)) {
            super.removeHeader(arg0);
        }
        super.setHeader(arg0, arg1);
    
public byte[]toByteArray()
Generate a representation of the headers as a series of bytes.

return
the byte array containing the headers

        ByteArrayOutputStream headersBytes = new ByteArrayOutputStream();
        writeTo(headersBytes);
        return headersBytes.toByteArray();
    
public voidwriteTo(java.io.OutputStream out)
Write the headers to an output stream

param
writer the stream to which to write the headers

        PrintStream pout;
        if (out instanceof PrintStream) {
            pout = (PrintStream)out;
        } else {
            pout = new PrintStream(out);
        }
        for (Enumeration e = super.getAllHeaderLines(); e.hasMoreElements(); ) {
            pout.print((String) e.nextElement());
            pout.print("\r\n");
        }
        // Print trailing CRLF
        pout.print("\r\n");