RE: JavaMail InternetHeaders could be more friendly to server developers
> 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. I shouldn't need to know this, but IIRC (I'm not testing this specifically): InternetHeaders headers = new InternetHeaders(is); headers.setHeader("Return-Path", ...); headers.setHeader("MIME-Version", "1.0"); and InternetHeaders headers = new InternetHeaders(); headers.load(is); headers.setHeader("Return-Path", ...); headers.setHeader("MIME-Version", "1.0"); are not the same. Assuming that neither header exists in the stream, in the first case, the Return-Path will follow other headers, and in the latter case, the MIME-Version will appear before headers loaded from the stream, since those headers are loaded as lines after the invisible placeholders. --- Noel - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JavaMail InternetHeaders could be more friendly to server developers
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]
Re: JavaMail InternetHeaders could be more friendly to server developers
Richard O. Hammer wrote: Three months ago in November we exchanged a few ideas about how the JavaMail API might be made more useful for development of mail servers -- as distinct from development of mail clients. Now I have discovered one more point that I would like to add. I might be mistaken again because of my incomplete understanding of the API, but I hope this is right. My comment concerns javax.mail.internet.InternetHeaders. 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. (I am referencing the JavaDocs for JavaMail 1.3). 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. This workaround relies upon behavior which I have not seen documented, namely that the addHeaderLine() method always adds to the bottom of the list of headers. So, I would suggest that InternetHeaders could be improved, for the use of server developers, by addition of a method addHeaderLineAtTop(), and by promising and documenting the present behavior of addHeaderLine(), that it adds to the bottom. 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. I suppose some part of that ought to be part of the spec. :-) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
JavaMail InternetHeaders could be more friendly to server developers
Three months ago in November we exchanged a few ideas about how the JavaMail API might be made more useful for development of mail servers -- as distinct from development of mail clients. Now I have discovered one more point that I would like to add. I might be mistaken again because of my incomplete understanding of the API, but I hope this is right. My comment concerns javax.mail.internet.InternetHeaders. 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. (I am referencing the JavaDocs for JavaMail 1.3). 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. This workaround relies upon behavior which I have not seen documented, namely that the addHeaderLine() method always adds to the bottom of the list of headers. So, I would suggest that InternetHeaders could be improved, for the use of server developers, by addition of a method addHeaderLineAtTop(), and by promising and documenting the present behavior of addHeaderLine(), that it adds to the bottom. Rich Hammer Hillsborough, N.C. *The code in James to which I refer is in: org.apache.james.smtpserver.SMTPHandler.processMailHeaders(InternetHeaders) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]