Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Message-ID vs. Message-Id Header

883146Jun 27 2014 — edited Jul 2 2014

My code logs the message ID and other headers of incoming mail messages. I recently changed the IMAP server from which I'm reading incoming messages. When I did so, about 20% of the messages had "null" for the message ID.

I discovered that some messages had a "Message-ID" header, while the others had a "Message-Id" header (the only difference being the case of the last letter in the header name).  So my code now looks like this:

String id = null;

    String[] idHeaders = message.getHeader("Message-ID");

    if (idHeaders != null && idHeaders.length > 0)

      id = idHeaders[0];

    else

      {

      System.out.println("\"Message-ID\" header not found during message conversion; trying \"Message-Id\".");

      idHeaders = message.getHeader("Message-Id");

      if (idHeaders != null && idHeaders.length > 0)

        id = idHeaders[0];

      else

        {

        System.out.println("No message ID headers found during message conversion; generating an artificial one.");

        IObjectRetriever<String> idRetriever = getIDRetriever();

        id = idRetriever.retrieveObject();

        }

      }

As you can see, I have to check for the existence of the "Message-ID" first. If it doesn't exist, then I check for the "Message-Id" header.

I examined what I think is the javamail source code at https://java.net/projects/javamail/sources/mercurial/content/mail/src/main/java/javax/mail/internet/InternetHeaders.java, and it appears that the matching on header names is case insensitive. So while I've found a workaround for my problem, I don't understand why it's necessary.

This post has been answered by Bill Shannon-Oracle on Jul 1 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 30 2014
Added on Jun 27 2014
6 comments
11,758 views