2 Replies Latest reply: May 8, 2012 5:15 PM by Hamit Hasanhocaoglu RSS

    Delivery status & disposition notification parsing problem

    Hamit Hasanhocaoglu
      Hi everybody;

      I'am trying to parse DSN and MDN messages using dsn.jar (using version 1.4.5 maven artifact). It is in my classpath and everything is fine until i try to get report fields. Reading the source and debugging; it seems that both DispostionNotification and DeliveryStatus classes parse "headers" and "fields" of the report body part (2. part in a multipart report) incorrectly. For example when fetching an MDN similar to the following (which is the sample MDN from RFC-3798):

      Content-Type: multipart/report; report-type=disposition-notification;
      boundary="RAA14128.773615765/example.com"

      --RAA14128.773615765/example.com

      [human  readable part]

      --RAA14128.773615765/example.com
      content-type: message/disposition-notification // part header ?

      Reporting-UA: joes-pc.cs.example.com; Foomail 97.1 // report fields ?
      Original-Recipient: rfc822;Joe_Recipient@example.com
      Final-Recipient: rfc822;Joe_Recipient@example.com
      Original-Message-ID: <199509192301.23456@example.org>
      Disposition: manual-action/MDN-sent-manually; displayed

      DispositionNotification class uses InternetHeaders to parse notifications and i get a single field: content-type: message/disposition-notification (which is a header of the part) instead of 5. InternetHeaders stops parsing when it see the new line after the content-type header and fields are not parsed. I was expecting that "headers" of the report body part must be skipped before parsing report fields. Same issue applies to the DeliveryStatus and messageDSN, per-recipientDSNs fields seems to be incorrectly parsed.

      Am i doing something wrong or is there a way to make Report classes skip body part headers before parsing fields ?

      Thank you.
        • 1. Re: Delivery status & disposition notification parsing problem
          Bill Shannon-Oracle
          It seems to be working for me. I modified the msgshow.java demo program as follows:
          ***************
          *** 35,40 ****
          --- 35,42 ----
            import javax.mail.event.*;
            import javax.mail.internet.*;
            
          + import com.sun.mail.dsn.*;
          + 
            /*
             * Demo app that exercises the Message interfaces.
             * Show information about and contents of messages.
          ***************
          *** 274,279 ****
          --- 276,296 ----
                     pr("---------------------------");
                     if (!showStructure && !saveAttachments)
                      System.out.println((String)p.getContent());
          +      } else if (p.isMimeType("multipart/report")) {
          +          pr("This is a MultipartReport");
          +          pr("---------------------------");
          +          MultipartReport mp = (MultipartReport)p.getContent();
          +          level++;
          +          Report r = mp.getReport();
          +          if (r instanceof DispositionNotification) {
          +           DispositionNotification dn = (DispositionNotification)r;
          +           pr("Report is a DispositionNotification");
          +           pr("---------------------------");
          +           InternetHeaders h = dn.getNotifications();
          +           for (Enumeration e = h.getAllHeaderLines(); e.hasMoreElements();)
          +               pr((String)e.nextElement());
          +          }
          +          level--;
                 } else if (p.isMimeType("multipart/*")) {
                     pr("This is a Multipart");
                     pr("---------------------------");
          Running that on your sample message gives:
          This is the message envelope
          ---------------------------
          SUBJECT: null
          SendDate: UNKNOWN
          FLAGS: 
          X-Mailer NOT available
          CONTENT-TYPE: multipart/report; report-type=disposition-notification; 
               boundary="RAA14128.773615765/example.com"
          This is a MultipartReport
          ---------------------------
          Report is a DispositionNotification
          ---------------------------
          Reporting-UA: joes-pc.cs.example.com; Foomail 97.1
          Original-Recipient: rfc822;Joe_Recipient@example.com
          Final-Recipient: rfc822;Joe_Recipient@example.com
          Original-Message-ID: <199509192301.23456@example.org>
          Disposition: manual-action/MDN-sent-manually; displayed
          Do you have sample code showing how it fails for you?
          • 2. Re: Delivery status & disposition notification parsing problem
            Hamit Hasanhocaoglu
            Hi Bill,

            It turned out that there was a problem with the server when sending the part content (as report parts were fetched when needed). Server reply for report content (whihc DispostionNotication uses to parse) now doesnt contain the headers of the part, report fields only.

            Problem solved. Thank you for trying it out.

            Regards.