I suggest we add a high-level factory for header fields. I would like
to simply call it Fields. Here is an outline that illustrates the
design for the Date field:

public class Fields {

    public static DateTimeField date(String fieldValue) {
        return date("Date", fieldValue);
    }

    public static DateTimeField date(String fieldName, String fieldValue) {
        return (DateTimeField) Field.parse(fieldName + ": " + fieldValue);
    }

    public static DateTimeField date(String fieldName, Date date,
TimeZone zone) {
        DateFormat df = RFC822_DATE_FORMAT.get();
        if (zone != null) {
            df.setTimeZone(zone);
        }
        return date(fieldName, df.format(date));
    }
    ....
}

Obviously that class would need to have a lot of methods for the
various header fields.

It should also be possible to automatically use encoded words when
creating a Subject field, for example. This could help with MIME4J-69.

In Message I would also like to add convenience methods that use the
Fields factory. Again an outline for the Date field:

public class Message extends Entity implements Body {
    ...
    public Date getDate() {
        Header header = getHeader();
        if (header == null)
            return null;

        DateTimeField dateField = (DateTimeField) header.getField("Date");
        if (dateField == null)
            return null;

        return dateField.getDate();
    }

    public void setDate(Date date) {
        setDate(date, null);
    }

    public void setDate(Date date, TimeZone zone) {
        Header header = getOrCreateHeader();

        if (date == null) {
            header.removeFields("Date");
        } else {
            header.setField(Fields.date("Date", date, zone));
        }
    }
    ....
}

Any objections?

Markus

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to