Bill Shannon wrote:
> Richard O. Hammer wrote:
> > When a SMTP server receives a message it needs to add a Received: header
> > at the top of the headers.  But InternetHeaders does not seem to offer
> > any way to add a header specifically at the top of the list.  This class
> > seems to offer no way for its users to learn or set the order of the
> > headers.
> >
> > As a consequence the code in James goes through an awkward workaround:
> > constructing a new InternetHeaders object, adding the new Received:
> > header, and then adding the remaining header lines by looping through
> > an Enumeration of header lines retrieved from the original incoming
> > InternetHeaders object.
>
> It's something of a kludge, but InternetHeaders already handles this in
> the addHeaders method.  It knows the preferred order for well-known
> headers, and it knows that Received headers should be added in reverse
> order.  The addHeaderLine method, on the other hand, always adds to the
> end.

There are several problems with InternetHeaders related to lack of control
over headers.

It only knows the preferred order for headers created with the
InternetHeaders() constructor.  It does not appear to know about the
preferred order when an InternetHeaders object is created from a stream.
This means that if you load an InternetHeaders object from a stream, and
then need to add a Return-Path to it, for example, the header cannot be
added to the beginning, where it belongs.

removeHeaders only sets the values to null, but leaves the placeholders in
place.  This means that if you have duplicates, such as Delivered-To
headers, the only way to remove them is with setHeader("Delivered-To",
null), since that does remove the other instances.  But that still leaves
the first one, which means there is no way to remove and reorder headers if
the order loaded isn't the desired one.

When combined with the interface on MimeMessage, there is no way to cleanly
adjust the contents of the message's Headers.  You cannot insert, you cannot
remove, you have very little control over the ordering.  Even using
addHeaderLine isn't enough, because there are some internal uses of
addHeader that can throw off the order.  It becomes a very frustrating dance
with the code that is thoroughly unnecessary.  If you have suggestions,
please share them because I'm encountering this problem right now.

        --- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to