home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libmime / mimemsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  18.8 KB  |  644 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* mimemsg.c --- definition of the MimeMessage class (see mimei.h)
  20.    Created: Jamie Zawinski <jwz@netscape.com>, 15-May-96.
  21.  */
  22.  
  23. #include "mimemsg.h"
  24.  
  25. #define MIME_SUPERCLASS mimeContainerClass
  26. MimeDefClass(MimeMessage, MimeMessageClass, mimeMessageClass,
  27.              &MIME_SUPERCLASS);
  28.  
  29. static int MimeMessage_initialize (MimeObject *);
  30. static void MimeMessage_finalize (MimeObject *);
  31. static int MimeMessage_add_child (MimeObject *, MimeObject *);
  32. static int MimeMessage_parse_begin (MimeObject *);
  33. static int MimeMessage_parse_line (char *, int32, MimeObject *);
  34. static int MimeMessage_parse_eof (MimeObject *, XP_Bool);
  35. static int MimeMessage_close_headers (MimeObject *obj);
  36. static int MimeMessage_write_headers_html (MimeObject *);
  37.  
  38. extern MimeObjectClass mimeFilterClass;
  39.  
  40. #ifdef XP_UNIX
  41. extern void MimeHeaders_do_unix_display_hook_hack(MimeHeaders *);
  42. #endif /* XP_UNIX */
  43.  
  44. #if defined(DEBUG) && defined(XP_UNIX)
  45. static int MimeMessage_debug_print (MimeObject *, FILE *, int32 depth);
  46. #endif
  47.  
  48. extern MimeObjectClass mimeMultipartClass;
  49.  
  50. static int
  51. MimeMessageClassInitialize(MimeMessageClass *class)
  52. {
  53.   MimeObjectClass    *oclass = (MimeObjectClass *)    class;
  54.   MimeContainerClass *cclass = (MimeContainerClass *) class;
  55.  
  56.   XP_ASSERT(!oclass->class_initialized);
  57.   oclass->initialize  = MimeMessage_initialize;
  58.   oclass->finalize    = MimeMessage_finalize;
  59.   oclass->parse_begin = MimeMessage_parse_begin;
  60.   oclass->parse_line  = MimeMessage_parse_line;
  61.   oclass->parse_eof   = MimeMessage_parse_eof;
  62.   cclass->add_child   = MimeMessage_add_child;
  63.  
  64. #if defined(DEBUG) && defined(XP_UNIX)
  65.   oclass->debug_print = MimeMessage_debug_print;
  66. #endif
  67.   return 0;
  68. }
  69.  
  70.  
  71. static int
  72. MimeMessage_initialize (MimeObject *object)
  73. {
  74.   return ((MimeObjectClass*)&MIME_SUPERCLASS)->initialize(object);
  75. }
  76.  
  77. static void
  78. MimeMessage_finalize (MimeObject *object)
  79. {
  80.   MimeMessage *msg = (MimeMessage *)object;
  81.   if (msg->hdrs)
  82.     MimeHeaders_free(msg->hdrs);
  83.   msg->hdrs = 0;
  84.   ((MimeObjectClass*)&MIME_SUPERCLASS)->finalize(object);
  85. }
  86.  
  87. static int
  88. MimeMessage_parse_begin (MimeObject *obj)
  89. {
  90.   int status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_begin(obj);
  91.   if (status < 0) return status;
  92.  
  93.   /* Messages have separators before the headers, except for the outermost
  94.      message. */
  95.   return MimeObject_write_separator(obj);
  96. }
  97.  
  98.  
  99. static int
  100. MimeMessage_parse_line (char *line, int32 length, MimeObject *obj)
  101. {
  102.   MimeMessage *msg = (MimeMessage *) obj;
  103.   int status = 0;
  104.  
  105.   XP_ASSERT(line && *line);
  106.   if (!line || !*line) return -1;
  107.  
  108.   /* If we're supposed to write this object, but aren't supposed to convert
  109.      it to HTML, simply pass it through unaltered.  (But, if we're supposed
  110.      to decrypt... uh, do something else.)
  111.    */
  112.   if (obj->output_p &&
  113.       obj->options &&
  114.       !obj->options->write_html_p &&
  115.       !obj->options->decrypt_p &&
  116.       obj->options->output_fn)
  117.     return MimeObject_write(obj, line, length, TRUE);
  118.  
  119.   /* If we already have a child object, then we're done parsing headers,
  120.      and all subsequent lines get passed to the inferior object without
  121.      further processing by us.  (Our parent will stop feeding us lines
  122.      when this MimeMessage part is out of data.)
  123.    */
  124.   if (msg->container.nchildren)
  125.     {
  126.       MimeObject *kid = msg->container.children[0];
  127.       XP_Bool nl;
  128.       XP_ASSERT(kid);
  129.       if (!kid) return -1;
  130.  
  131.       /* Don't allow MimeMessage objects to not end in a newline, since it
  132.          would be inappropriate for any following part to appear on the same
  133.          line as the last line of the message.
  134.  
  135.          #### This assumes that the only time the `parse_line' method is
  136.          called with a line that doesn't end in a newline is when that line
  137.          is the last line.
  138.        */
  139.       nl = (length > 0 && (line[length-1] == CR || line[length-1] == LF));
  140.  
  141. #ifdef MIME_DRAFTS
  142.       if ( !mime_typep (kid, (MimeObjectClass*) &mimeMessageClass) &&
  143.            obj->options &&
  144.            obj->options->decompose_file_p &&
  145.            ! obj->options->is_multipart_msg &&
  146.            obj->options->decompose_file_output_fn )
  147.         {
  148.           if (!obj->options->decrypt_p) {
  149.               status = obj->options->decompose_file_output_fn (line,
  150.                                                                length,
  151.                                                      obj->options->stream_closure);
  152.               if (status < 0) return status;
  153.               if (!nl) {
  154.                 status = obj->options->decompose_file_output_fn (LINEBREAK,
  155.                                                                  LINEBREAK_LEN,
  156.                                                      obj->options->stream_closure);
  157.                 if (status < 0) return status;
  158.               }
  159.               return status;
  160.           }
  161.         }
  162. #endif /* MIME_DRAFTS */
  163.  
  164.  
  165.       if (nl)
  166.         return kid->class->parse_buffer (line, length, kid);
  167.       else
  168.         {
  169.           /* Hack a newline onto the end. */
  170.           char *s = XP_ALLOC(length + LINEBREAK_LEN + 1);
  171.           if (!s) return MK_OUT_OF_MEMORY;
  172.           XP_MEMCPY(s, line, length);
  173.           XP_STRCPY(s + length, LINEBREAK);
  174.           status = kid->class->parse_buffer (s, length + LINEBREAK_LEN, kid);
  175.           XP_FREE(s);
  176.           return status;
  177.         }
  178.     }
  179.  
  180.   /* Otherwise we don't yet have a child object, which means we're not
  181.      done parsing our headers yet.
  182.    */
  183.   if (!msg->hdrs)
  184.     {
  185.       msg->hdrs = MimeHeaders_new();
  186.       if (!msg->hdrs) return MK_OUT_OF_MEMORY;
  187.     }
  188.  
  189. #ifdef MIME_DRAFTS
  190.   if ( obj->options &&
  191.        obj->options->decompose_file_p &&
  192.        ! obj->options->is_multipart_msg &&
  193.        obj->options->done_parsing_outer_headers &&
  194.        obj->options->decompose_file_output_fn ) {
  195.     status =  obj->options->decompose_file_output_fn ( line,
  196.                                                        length,
  197.                                                 obj->options->stream_closure );
  198.     if (status < 0) return status;
  199.   }
  200. #endif /* MIME_DRAFTS */
  201.  
  202.   status = MimeHeaders_parse_line(line, length, msg->hdrs);
  203.   if (status < 0) return status;
  204.  
  205.   /* If this line is blank, we're now done parsing headers, and should
  206.      examine our content-type to create our "body" part.
  207.    */
  208.   if (*line == CR || *line == LF)
  209.     {
  210.       status = MimeMessage_close_headers(obj);
  211.       if (status < 0) return status;
  212.     }
  213.  
  214.   return 0;
  215. }
  216.  
  217. static int
  218. MimeMessage_close_headers (MimeObject *obj)
  219. {
  220.   MimeMessage *msg = (MimeMessage *) obj;
  221.   int status = 0;
  222.   char *ct = 0;            /* Content-Type header */
  223.   MimeObject *body;
  224.  
  225.   if (msg->hdrs)
  226.     {
  227.       XP_Bool outer_p = !obj->headers; /* is this the outermost message? */
  228.  
  229.  
  230. #ifdef MIME_DRAFTS
  231.       if (outer_p &&
  232.           obj->options &&
  233.           obj->options->decompose_file_p &&
  234.           obj->options->decompose_headers_info_fn)
  235.         {
  236.           if (obj->options->decrypt_p && 
  237.               !mime_crypto_object_p (msg->hdrs, FALSE))
  238.               obj->options->decrypt_p = FALSE;
  239.           status = obj->options->decompose_headers_info_fn (
  240.                                                  obj->options->stream_closure,
  241.                                                              msg->hdrs );
  242.         }
  243. #endif /* MIME_DRAFTS */
  244.  
  245.  
  246.       /* If this is the outermost message, we need to run the
  247.          `generate_header' callback.  This happens here instead of
  248.          in `parse_begin', because it's only now that we've parsed
  249.          our headers.  However, since this is the outermost message,
  250.          we have yet to write any HTML, so that's fine.
  251.        */
  252.       if (outer_p &&
  253.           obj->output_p &&
  254.           obj->options &&
  255.           obj->options->write_html_p &&
  256.           obj->options->generate_header_html_fn)
  257.         {
  258.           int status = 0;
  259.           char *html = 0;
  260.  
  261.           /* The generate_header_html_fn might return HTML, so it's important
  262.              that the output stream be set up with the proper type before we
  263.              make the MimeObject_write() call below. */
  264.           if (!obj->options->state->first_data_written_p)
  265.             {
  266.               status = MimeObject_output_init (obj, TEXT_HTML);
  267.               if (status < 0) return status;
  268.               XP_ASSERT(obj->options->state->first_data_written_p);
  269.             }
  270.  
  271.           html = obj->options->generate_header_html_fn(NULL,
  272.                                                    obj->options->html_closure,
  273.                                                        msg->hdrs);
  274.           if (html)
  275.             {
  276.               status = MimeObject_write(obj, html, XP_STRLEN(html), FALSE);
  277.               XP_FREE(html);
  278.               if (status < 0) return status;
  279.             }
  280.         }
  281.  
  282.  
  283.       /* Find the content-type of the body of this message.
  284.        */
  285.       {
  286.         XP_Bool ok = TRUE;
  287.         char *mv = MimeHeaders_get (msg->hdrs, HEADER_MIME_VERSION,
  288.                                     TRUE, FALSE);
  289.  
  290. #ifdef REQUIRE_MIME_VERSION_HEADER
  291.         /* If this is the outermost message, it must have a MIME-Version
  292.            header with the value 1.0 for us to believe what might be in
  293.            the Content-Type header.  If the MIME-Version header is not
  294.            present, we must treat this message as untyped.
  295.          */
  296.         ok = (mv && !XP_STRCMP(mv, "1.0"));
  297. #else
  298.         /* #### actually, we didn't check this in Mozilla 2.0, and checking
  299.            it now could cause some compatibility nonsense, so for now, let's
  300.            just believe any Content-Type header we see.
  301.          */
  302.         ok = TRUE;
  303. #endif
  304.  
  305.         if (ok)
  306.           {
  307.             ct = MimeHeaders_get (msg->hdrs, HEADER_CONTENT_TYPE, TRUE, FALSE);
  308.  
  309.             /* If there is no Content-Type header, but there is a MIME-Version
  310.                header, then assume that this *is* in fact a MIME message.
  311.                (I've seen messages with
  312.  
  313.                   MIME-Version: 1.0
  314.                   Content-Transfer-Encoding: quoted-printable
  315.  
  316.                and no Content-Type, and we should treat those as being of type
  317.                MimeInlineTextPlain rather than MimeUntypedText.)
  318.              */
  319.             if (mv && !ct)
  320.               ct = XP_STRDUP(TEXT_PLAIN);
  321.           }
  322.  
  323.         FREEIF(mv);  /* done with this now. */
  324.       }
  325.  
  326.  
  327.       /* If this message has a body which is encrypted, and we're going to
  328.          decrypt it (without converting it to HTML, since decrypt_p and
  329.          write_html_p ar never true at the same time.)
  330.        */
  331.       if (obj->output_p &&
  332.           obj->options->decrypt_p &&
  333.           !mime_crypto_object_p (msg->hdrs, FALSE))
  334.         {
  335.           /* The body of this message is not an encrypted object, so we need
  336.              to turn off the decrypt_p flag (to prevent us from s#$%ing the
  337.              body of the internal object up into this one.)  In this case,
  338.              our output will end up being identical to our input.
  339.            */
  340.           if (obj->options)
  341.             obj->options->decrypt_p = FALSE;
  342.         }
  343.  
  344.  
  345.       /* Emit the HTML for this message's headers.  Do this before
  346.          creating the object representing the body.
  347.        */
  348.       if (obj->output_p &&
  349.           obj->options &&
  350.           obj->options->write_html_p)
  351.         {
  352.           /* If citation headers are on, and this is not the outermost message,
  353.              turn them off. */
  354.           if (obj->options->headers == MimeHeadersCitation && !outer_p)
  355.             obj->options->headers = MimeHeadersSome;
  356.  
  357.           /* Emit a normal header block. */
  358.           status = MimeMessage_write_headers_html(obj);
  359.           if (status < 0) return status;
  360.         }
  361.       else if (obj->output_p)
  362.         {
  363.           /* Dump the headers, raw. */
  364.           status = MimeObject_write(obj, "", 0, FALSE);  /* initialize */
  365.           if (status < 0) return status;
  366.           status = MimeHeaders_write_raw_headers(msg->hdrs, obj->options,
  367.                                                  obj->options->decrypt_p);
  368.           if (status < 0) return status;
  369.         }
  370.  
  371. #ifdef XP_UNIX
  372.       if (outer_p && obj->output_p)
  373.         /* Kludge from mimehdrs.c */
  374.         MimeHeaders_do_unix_display_hook_hack(msg->hdrs);
  375. #endif /* XP_UNIX */
  376.     }
  377.  
  378.   /* Never put out a separator after a message header block. */
  379.   if (obj->options && obj->options->state)
  380.     obj->options->state->separator_suppressed_p = TRUE;
  381.  
  382. #ifdef MIME_DRAFTS
  383.   if ( !obj->headers &&    /* outer most message header */
  384.        obj->options && 
  385.        obj->options->decompose_file_p && 
  386.        ct )
  387.     obj->options->is_multipart_msg = XP_STRSTR(ct, "multipart/") != NULL;
  388. #endif /* MIME_DRAFTS */
  389.  
  390.  
  391.   body = mime_create(ct, msg->hdrs, obj->options);
  392.  
  393.   FREEIF(ct);
  394.   if (!body) return MK_OUT_OF_MEMORY;
  395.   status = ((MimeContainerClass *) obj->class)->add_child (obj, body);
  396.   if (status < 0)
  397.     {
  398.       mime_free(body);
  399.       return status;
  400.     }
  401.  
  402.   /* Now that we've added this new object to our list of children,
  403.      start its parser going. */
  404.   status = body->class->parse_begin(body);
  405.   if (status < 0) return status;
  406.   return 0;
  407. }
  408.  
  409.  
  410.  
  411. static int 
  412. MimeMessage_parse_eof (MimeObject *obj, XP_Bool abort_p)
  413. {
  414.   int status;
  415.   XP_Bool outer_p;
  416.   MimeMessage *msg = (MimeMessage *)obj;
  417.   if (obj->closed_p) return 0;
  418.   
  419.   /* Run parent method first, to flush out any buffered data. */
  420.   status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p);
  421.   if (status < 0) return status;
  422.  
  423.   outer_p = !obj->headers;    /* is this the outermost message? */
  424.  
  425.   if (outer_p &&
  426.       obj->options &&
  427.       obj->options->write_html_p &&
  428.       obj->options->generate_footer_html_fn)
  429.     {
  430.       char *html =
  431.         obj->options->generate_footer_html_fn (NULL,
  432.                                                obj->options->html_closure,
  433.                                                msg->hdrs);
  434.       if (html)
  435.         {
  436.           int status = MimeObject_write(obj, html, XP_STRLEN(html), FALSE);
  437.           XP_FREE(html);
  438.           if (status < 0) return status;
  439.         }
  440.     }
  441.  
  442. #ifdef MIME_DRAFTS
  443.   if ( obj->options &&
  444.        obj->options->decompose_file_p &&
  445.        obj->options->done_parsing_outer_headers &&
  446.        ! obj->options->is_multipart_msg &&
  447.        ! mime_typep(obj, (MimeObjectClass*) &mimeFilterClass) &&
  448.        obj->options->decompose_file_close_fn ) {
  449.     status = obj->options->decompose_file_close_fn (
  450.                                                obj->options->stream_closure );
  451.  
  452.     if ( status < 0 ) return status;
  453.   }
  454. #endif /* MIME_DRAFTS */
  455.  
  456.  
  457.   /* Put out a separator after every message/rfc822 object. */
  458.   if (!abort_p)
  459.     {
  460.       status = MimeObject_write_separator(obj);
  461.       if (status < 0) return status;
  462.     }
  463.  
  464.   return 0;
  465. }
  466.  
  467.  
  468. static int
  469. MimeMessage_add_child (MimeObject *parent, MimeObject *child)
  470. {
  471.   MimeContainer *cont = (MimeContainer *) parent;
  472.   XP_ASSERT(parent && child);
  473.   if (!parent || !child) return -1;
  474.  
  475.   /* message/rfc822 containers can only have one child. */
  476.   XP_ASSERT(cont->nchildren == 0);
  477.   if (cont->nchildren != 0) return -1;
  478.  
  479. #ifdef MIME_DRAFTS
  480.   if ( parent->options &&
  481.        parent->options->decompose_file_p &&
  482.        ! parent->options->is_multipart_msg &&
  483.        ! mime_typep(child, (MimeObjectClass*) &mimeFilterClass) &&
  484.        parent->options->decompose_file_init_fn ) {
  485.     int status = 0;
  486.     status = parent->options->decompose_file_init_fn (
  487.                                               parent->options->stream_closure,
  488.                                               ((MimeMessage*)parent)->hdrs );
  489.     if ( status < 0 ) return status;
  490.   }
  491. #endif /* MIME_DRAFTS */
  492.   
  493.   return ((MimeContainerClass*)&MIME_SUPERCLASS)->add_child (parent, child);
  494. }
  495.  
  496.  
  497. static int
  498. MimeMessage_write_headers_html (MimeObject *obj)
  499. {
  500.   MimeMessage *msg = (MimeMessage *) obj;
  501.   XP_Bool crypto_p;
  502.   int status;
  503.   if (!obj->options ||
  504.       !obj->options->output_fn)
  505.     return 0;
  506.  
  507.   XP_ASSERT(obj->output_p && obj->options->write_html_p);
  508.  
  509.   if (!obj->options->state->first_data_written_p)
  510.     {
  511.       status = MimeObject_output_init (obj, TEXT_HTML);
  512.       if (status < 0) return status;
  513.       XP_ASSERT(obj->options->state->first_data_written_p);
  514.     }
  515.  
  516.   crypto_p = (msg && msg->hdrs && mime_crypto_object_p(msg->hdrs, TRUE));
  517.  
  518.   /* If this message contains crypto data, wrap the headers so that we can
  519.      put a crypto stamp next to it.  (But don't do this if in FO_QUOTE_MESSAGE
  520.      mode.)
  521.    */
  522.   if (crypto_p &&
  523.       obj->options->headers != MimeHeadersCitation &&
  524.       obj->options->write_html_p &&
  525.       obj->options->output_fn)
  526.     {
  527.       /* This assumes that the code in the crypto-object classes will close
  528.          off this table before writing out the body. */
  529.       char *s = MimeHeaders_open_crypto_stamp();
  530.       if (!s) return MK_OUT_OF_MEMORY;
  531.       status = MimeObject_write(obj, s, XP_STRLEN(s), FALSE);
  532.       XP_FREE(s);
  533.       if (status < 0) return status;
  534.       XP_ASSERT(!msg->crypto_stamped_p);
  535.       msg->crypto_stamped_p = TRUE;
  536.     }
  537.  
  538.   status = MimeHeaders_write_headers_html (msg->hdrs, obj->options);
  539.   if (status < 0) return status;
  540.  
  541.   if (msg->crypto_stamped_p)
  542.     {
  543.       /* This doesn't actually write the stamp, just prepares for it; the
  544.          stamp itself can't be written until the crypto object is fully
  545.          parsed, so that we know whether the sig checked out and so on. */
  546.       char *s = MimeHeaders_finish_open_crypto_stamp();
  547.       if (!s) return MK_OUT_OF_MEMORY;
  548.       status = MimeObject_write(obj, s, XP_STRLEN(s), FALSE);
  549.       XP_FREE(s);
  550.       if (status < 0) return status;
  551.     }
  552.   else
  553.     {
  554.       /* If we're not writing a crypto stamp, and this is the outermost
  555.          message, then now is the time to run the post_header_html_fn.
  556.          (Otherwise, it will be run when the crypto-stamp is finally
  557.          closed off, in MimeFilter_emit_buffered_child() or
  558.          MimeMultipartSigned_emit_child().)
  559.        */
  560.       if (obj->options &&
  561.           obj->options->state &&
  562.           obj->options->generate_post_header_html_fn &&
  563.           !obj->options->state->post_header_html_run_p)
  564.         {
  565.           char *html = 0;
  566.           XP_ASSERT(obj->options->state->first_data_written_p);
  567.           html = obj->options->generate_post_header_html_fn(NULL,
  568.                                                     obj->options->html_closure,
  569.                                                             msg->hdrs);
  570.           obj->options->state->post_header_html_run_p = TRUE;
  571.           if (html)
  572.             {
  573.               status = MimeObject_write(obj, html, XP_STRLEN(html), FALSE);
  574.               XP_FREE(html);
  575.               if (status < 0) return status;
  576.             }
  577.         }
  578.  
  579.       /* Write out a paragraph break between the headers and body. */
  580.       {
  581.         char s[] = "<P>";
  582.         status = MimeObject_write(obj, s, XP_STRLEN(s), FALSE);
  583.         if (status < 0) return status;
  584.       }
  585.     }
  586.  
  587.   return 0;
  588. }
  589.  
  590.  
  591. #if defined(DEBUG) && defined(XP_UNIX)
  592. static int
  593. MimeMessage_debug_print (MimeObject *obj, FILE *stream, int32 depth)
  594. {
  595.   MimeMessage *msg = (MimeMessage *) obj;
  596.   char *addr = mime_part_address(obj);
  597.   int i;
  598.   for (i=0; i < depth; i++)
  599.     fprintf(stream, "  ");
  600.   fprintf(stream, "<%s %s%s 0x%08X>\n",
  601.           obj->class->class_name,
  602.           addr ? addr : "???",
  603.           (msg->container.nchildren == 0 ? " (no body)" : ""),
  604.           (uint32) msg);
  605.   FREEIF(addr);
  606.  
  607. #if 0
  608.   if (msg->hdrs)
  609.     {
  610.       char *s;
  611.  
  612.       depth++;
  613.  
  614. # define DUMP(HEADER) \
  615.       for (i=0; i < depth; i++)                                                \
  616.         fprintf(stream, "  ");                                                \
  617.       s = MimeHeaders_get (msg->hdrs, HEADER, FALSE, TRUE);                    \
  618.       fprintf(stream, HEADER ": %s\n", s ? s : "");                            \
  619.       FREEIF(s)
  620.  
  621.       DUMP(HEADER_SUBJECT);
  622.       DUMP(HEADER_DATE);
  623.       DUMP(HEADER_FROM);
  624.       DUMP(HEADER_TO);
  625.       /* DUMP(HEADER_CC); */
  626.       DUMP(HEADER_NEWSGROUPS);
  627.       DUMP(HEADER_MESSAGE_ID);
  628. # undef DUMP
  629.  
  630.       fprintf(stream, "\n");
  631.     }
  632. #endif
  633.  
  634.   XP_ASSERT(msg->container.nchildren <= 1);
  635.   if (msg->container.nchildren == 1)
  636.     {
  637.       MimeObject *kid = msg->container.children[0];
  638.       int status = kid->class->debug_print (kid, stream, depth+1);
  639.       if (status < 0) return status;
  640.     }
  641.   return 0;
  642. }
  643. #endif
  644.