Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions
modlmime.h File Reference
#include "prtypes.h"
#include "nsString.h"
#include "nsMailHeaders.h"
#include "nsIMimeStreamConverter.h"
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "nsIPrefBranch.h"
#include "mozITXTToHTMLConv.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MimeHeaders
class  MimeDisplayOptions

Defines

#define MIME_DRAFTS

Typedefs

typedef struct MimeHeaders MimeHeaders
typedef struct MSG_AttachmentData
typedef char *(* MimeHTMLGeneratorFunction )(const char *data, void *closure, MimeHeaders *headers)

Enumerations

enum  MimeHeadersState {
  MimeHeadersAll, MimeHeadersSome, MimeHeadersSomeNoRef, MimeHeadersMicro,
  MimeHeadersMicroPlus, MimeHeadersCitation, MimeHeadersOnly, MimeHeadersNone
}

Functions

char * MimeHeaders_get (MimeHeaders *hdrs, const char *header_name, PRBool strip_p, PRBool all_p)
char * MimeHeaders_get_parameter (const char *header_value, const char *parm_name, char **charset, char **language)
MimeHeadersMimeHeaders_copy (MimeHeaders *srcHeaders)
void MimeHeaders_free (MimeHeaders *hdrs)

Class Documentation

struct MimeHeaders

Definition at line 60 of file modlmime.h.

Class Members
char * all_headers
PRInt32 all_headers_fp
PRInt32 all_headers_size
PRBool done_p
char ** heads
PRInt32 heads_size
char * munged_subject
char * obuffer
PRInt32 obuffer_fp
PRInt32 obuffer_size

Define Documentation

Definition at line 54 of file modlmime.h.


Typedef Documentation

typedef struct MimeHeaders MimeHeaders

Definition at line 160 of file modlmime.h.

typedef struct MSG_AttachmentData

Definition at line 94 of file modlmime.h.


Enumeration Type Documentation

Enumerator:
MimeHeadersAll 
MimeHeadersSome 
MimeHeadersSomeNoRef 
MimeHeadersMicro 
MimeHeadersMicroPlus 
MimeHeadersCitation 
MimeHeadersOnly 
MimeHeadersNone 

Definition at line 143 of file modlmime.h.

             {
  MimeHeadersAll,                           /* Show all headers */
  MimeHeadersSome,                        /* Show all "interesting" headers */
  MimeHeadersSomeNoRef,            /* Same, but suppress the `References' header
                                                                     (for when we're printing this message.) */
  MimeHeadersMicro,                       /* Show a one-line header summary */
  MimeHeadersMicroPlus,            /* Same, but show the full recipient list as
                                                                     well (To, CC, etc.) */
  MimeHeadersCitation,             /* A one-line summary geared toward use in a
                                                                     reply citation ("So-and-so wrote:") */
  MimeHeadersOnly,        /* Just parse and output headers...nothing else! */
  MimeHeadersNone         /* Skip showing any headers */
} MimeHeadersState;

Function Documentation

Definition at line 163 of file mimehdrs.cpp.

{
  MimeHeaders *hdrs2;
  if (!hdrs) return 0;

  hdrs2 = (MimeHeaders *) PR_MALLOC(sizeof(*hdrs));
  if (!hdrs2) return 0;
  memset(hdrs2, 0, sizeof(*hdrs2));

  if (hdrs->all_headers)
       {
         hdrs2->all_headers = (char *) PR_MALLOC(hdrs->all_headers_fp);
         if (!hdrs2->all_headers)
              {
                PR_Free(hdrs2);
                return 0;
              }
         memcpy(hdrs2->all_headers, hdrs->all_headers, hdrs->all_headers_fp);

         hdrs2->all_headers_fp   = hdrs->all_headers_fp;
         hdrs2->all_headers_size = hdrs->all_headers_fp;
       }

  hdrs2->done_p = hdrs->done_p;

  if (hdrs->heads)
       {
         int i;
         hdrs2->heads = (char **) PR_MALLOC(hdrs->heads_size
                                                                      * sizeof(*hdrs->heads));
         if (!hdrs2->heads)
              {
                PR_FREEIF(hdrs2->all_headers);
                PR_Free(hdrs2);
                return 0;
              }
         hdrs2->heads_size = hdrs->heads_size;
         for (i = 0; i < hdrs->heads_size; i++)
              {
                hdrs2->heads[i] = (hdrs2->all_headers +
                                                  (hdrs->heads[i] - hdrs->all_headers));
              }
       }
  return hdrs2;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 104 of file mimehdrs.cpp.

{
  if (!hdrs) return;
  PR_FREEIF(hdrs->all_headers);
  PR_FREEIF(hdrs->heads);
  PR_FREEIF(hdrs->obuffer);
  PR_FREEIF(hdrs->munged_subject);
  hdrs->obuffer_fp = 0;
  hdrs->obuffer_size = 0;

# ifdef DEBUG__
  {
       int i, size = sizeof(*hdrs);
       PRUint32 *array = (PRUint32*) hdrs;
       for (i = 0; i < (size / sizeof(*array)); i++)
         array[i] = (PRUint32) 0xDEADBEEF;
  }
# endif /* DEBUG */

  PR_Free(hdrs);
}

Here is the caller graph for this function:

char* MimeHeaders_get ( MimeHeaders hdrs,
const char *  header_name,
PRBool  strip_p,
PRBool  all_p 
)

Definition at line 319 of file mimehdrs.cpp.

{
  int i;
  int name_length;
  char *result = 0;

/*  PR_ASSERT(hdrs); cause delete message problem in WinFE */
  if (!hdrs) return 0;
  NS_ASSERTION(header_name, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
  if (!header_name) return 0;

  /* Specifying strip_p and all_p at the same time doesn't make sense... */
  NS_ASSERTION(!(strip_p && all_p), "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");

  /* One shouldn't be trying to read headers when one hasn't finished
        parsing them yet... but this can happen if the message ended
        prematurely, and has no body at all (as opposed to a null body,
        which is more normal.)   So, if we try to read from the headers,
        let's assume that the headers are now finished.  If they aren't
        in fact finished, then a later attempt to write to them will assert.
   */
  if (!hdrs->done_p)
       {
         int status;
         hdrs->done_p = PR_TRUE;
         status = MimeHeaders_build_heads_list(hdrs);
         if (status < 0) return 0;
       }

  if (!hdrs->heads)    /* Must not have been any headers. */
       {
         NS_ASSERTION(hdrs->all_headers_fp == 0, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
         return 0;
       }

  name_length = strlen(header_name);

  for (i = 0; i < hdrs->heads_size; i++)
       {
         char *head = hdrs->heads[i];
         char *end = (i == hdrs->heads_size-1
                               ? hdrs->all_headers + hdrs->all_headers_fp
                               : hdrs->heads[i+1]);
         char *colon, *ocolon;

         NS_ASSERTION(head, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
         if (!head) continue;

         /* Quick hack to skip over BSD Mailbox delimiter. */
         if (i == 0 && head[0] == 'F' && !strncmp(head, "From ", 5))
              continue;

         /* Find the colon. */
         for (colon = head; colon < end; colon++)
              if (*colon == ':') break;

         if (colon >= end) continue;

         /* Back up over whitespace before the colon. */
         ocolon = colon;
         for (; colon > head && nsCRT::IsAsciiSpace(colon[-1]); colon--)
              ;

         /* If the strings aren't the same length, it doesn't match. */
         if (name_length != colon - head )
              continue;

         /* If the strings differ, it doesn't match. */
         if (nsCRT::strncasecmp(header_name, head, name_length))
              continue;

         /* Otherwise, we've got a match. */
         {
              char *contents = ocolon + 1;
              char *s;

              /* Skip over whitespace after colon. */
              while (contents <= end && nsCRT::IsAsciiSpace(*contents))
                contents++;

              /* If we're supposed to strip at the frist token, pull `end' back to
                 the first whitespace or ';' after the first token.
               */
              if (strip_p)
                {
                     for (s = contents;
                             s <= end && *s != ';' && *s != ',' && !nsCRT::IsAsciiSpace(*s);
                             s++)
                       ;
                     end = s;
                }

              /* Now allocate some storage.
                 If `result' already has a value, enlarge it.
                 Otherwise, just allocate a block.
                 `s' gets set to the place where the new data goes.
               */
              if (!result)
                {
                     result = (char *) PR_MALLOC(end - contents + 1);
                     if (!result)
                       return 0;
                     s = result;
                }
              else
                {
                     PRInt32 L = strlen(result);
                     s = (char *) PR_Realloc(result, (L + (end - contents + 10)));
                     if (!s)
                       {
                            PR_Free(result);
                            return 0;
                       }
                     result = s;
                     s = result + L;

                     /* Since we are tacking more data onto the end of the header
                        field, we must make it be a well-formed continuation line,
                          by separating the old and new data with CR-LF-TAB.
                      */
                     *s++ = ',';                        /* #### only do this for addr headers? */
                     *s++ = MSG_LINEBREAK[0];
# if (MSG_LINEBREAK_LEN == 2)
                     *s++ = MSG_LINEBREAK[1];
# endif
                     *s++ = '\t';
                }

              /* Take off trailing whitespace... */
              while (end > contents && nsCRT::IsAsciiSpace(end[-1]))
                end--;

              if (end > contents)
                {
                  /* Now copy the header's contents in...
                   */
                  memcpy(s, contents, end - contents);
                  s[end - contents] = 0;
                }
              else
                {
                  s[0] = 0;
                }

              /* If we only wanted the first occurence of this header, we're done. */
              if (!all_p) break;
         }
       }

  if (result && !*result)  /* empty string */
       {
         PR_Free(result);
         return 0;
       }

  return result;
}

Here is the call graph for this function:

char* MimeHeaders_get_parameter ( const char *  header_value,
const char *  parm_name,
char **  charset,
char **  language 
)

Definition at line 479 of file mimehdrs.cpp.

{
  if (!header_value || !parm_name || !*header_value || !*parm_name)
    return nsnull;

  nsresult rv;
  nsCOMPtr <nsIMIMEHeaderParam> mimehdrpar = 
    do_GetService(NS_MIMEHEADERPARAM_CONTRACTID, &rv);

  if (NS_FAILED(rv))
    return nsnull;

  nsXPIDLCString result;
  rv = mimehdrpar->GetParameterInternal(header_value, parm_name, charset, 
                                        language, getter_Copies(result));
  return NS_SUCCEEDED(rv) ? PL_strdup(result.get()) : nsnull; 
}

Here is the call graph for this function:

Here is the caller graph for this function: