Back to index

lightning-sunbird  0.9+nobinonly
Functions
mimehdrs.h File Reference
#include "modlmime.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

MimeHeadersMimeHeaders_new (void)
int MimeHeaders_parse_line (const char *buffer, PRInt32 size, MimeHeaders *hdrs)
int MimeHeaders_write_headers_html (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBool attachment)
int MimeHeaders_write_all_headers (MimeHeaders *, MimeDisplayOptions *, PRBool)
int MimeHeaders_write_raw_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt, PRBool dont_write_content_type)
char * MimeHeaders_open_crypto_stamp (void)
char * MimeHeaders_finish_open_crypto_stamp (void)
char * MimeHeaders_close_crypto_stamp (void)
char * MimeHeaders_make_crypto_stamp (PRBool encrypted_p, PRBool signed_p, PRBool good_p, PRBool unverified_p, PRBool close_parent_stamp_p, const char *stamp_url)
char * MimeHeaders_get_name (MimeHeaders *hdrs, MimeDisplayOptions *opt)
char * mime_decode_filename (char *name, const char *charset, MimeDisplayOptions *opt)
char * MIME_StripContinuations (char *original)

Function Documentation

char* mime_decode_filename ( char *  name,
const char *  charset,
MimeDisplayOptions opt 
)

Definition at line 660 of file mimehdrs.cpp.

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

  if (NS_FAILED(rv))
    return nsnull;
  nsCAutoString result;
  rv = mimehdrpar->DecodeParameter(nsDependentCString(name), charset,
                                   opt->default_charset,
                                   opt->override_charset, 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:

char* MIME_StripContinuations ( char *  original)

Definition at line 630 of file mimehdrs.cpp.

{
       char *p1, *p2;

       /* If we were given a null string, return it as is */
       if (!original) return NULL;

       /* Start source and dest pointers at the beginning */
       p1 = p2 = original;

       while(*p2)
       {
              /* p2 runs ahead at (CR and/or LF) */
              if ((p2[0] == nsCRT::CR) || (p2[0] == nsCRT::LF))
              {
            p2++;
              } else {
            *p1++ = *p2++;
        }
       }
       *p1 = '\0';

       return original;
}

Definition at line 865 of file mimehdrs.cpp.

{
  return nsnull;
}

Definition at line 859 of file mimehdrs.cpp.

{
  return nsnull;
}
char* MimeHeaders_get_name ( MimeHeaders hdrs,
MimeDisplayOptions opt 
)

Definition at line 683 of file mimehdrs.cpp.

{
  char *s = 0, *name = 0, *cvt = 0;
  char *charset = nsnull; // for RFC2231 support

  s = MimeHeaders_get(hdrs, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);
  if (s)
  {
    name = MimeHeaders_get_parameter(s, HEADER_PARM_FILENAME, &charset, NULL);
    PR_Free(s);
  }

  if (! name)
  {
    s = MimeHeaders_get(hdrs, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);
    if (s)
    {
      nsMemory::Free(charset);

      name = MimeHeaders_get_parameter(s, HEADER_PARM_NAME, &charset, NULL);
      PR_Free(s);
    }
  }

  if (! name)
    name = MimeHeaders_get (hdrs, HEADER_CONTENT_NAME, PR_FALSE, PR_FALSE);
  
  if (! name)
    name = MimeHeaders_get (hdrs, HEADER_X_SUN_DATA_NAME, PR_FALSE, PR_FALSE);

  if (name)
  {
    /* First remove continuation delimiters (CR+LF+space), then
       remove escape ('\\') characters, then attempt to decode
       mime-2 encoded-words. The latter two are done in 
       mime_decode_filename. 
    */
    MIME_StripContinuations(name);

    /* Argh. What we should do if we want to be robust is to decode qtext
       in all appropriate headers. Unfortunately, that would be too scary
       at this juncture. So just decode qtext/mime2 here. */
    cvt = mime_decode_filename(name, charset, opt);

    nsMemory::Free(charset);

    if (cvt && cvt != name)
    {
      PR_Free(name);
      name = cvt;
    }
  }

  return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* MimeHeaders_make_crypto_stamp ( PRBool  encrypted_p,
PRBool  signed_p,
PRBool  good_p,
PRBool  unverified_p,
PRBool  close_parent_stamp_p,
const char *  stamp_url 
)

Definition at line 871 of file mimehdrs.cpp.

{
  return nsnull;
}

Definition at line 92 of file mimehdrs.cpp.

{
  MimeHeaders *hdrs = (MimeHeaders *) PR_MALLOC(sizeof(MimeHeaders));
  if (!hdrs) return 0;

  memset(hdrs, 0, sizeof(*hdrs));
  hdrs->done_p = PR_FALSE;

  return hdrs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 853 of file mimehdrs.cpp.

{
  return nsnull;
}
int MimeHeaders_parse_line ( const char *  buffer,
PRInt32  size,
MimeHeaders hdrs 
)

Definition at line 127 of file mimehdrs.cpp.

{
  int status = 0;
  int desired_size;

  NS_ASSERTION(hdrs, "1.22 <rhp@netscape.com> 22 Aug 1999 08:48");
  if (!hdrs) return -1;

  /* Don't try and feed me more data after having fed me a blank line... */
  NS_ASSERTION(!hdrs->done_p, "1.22 <rhp@netscape.com> 22 Aug 1999 08:48");
  if (hdrs->done_p) return -1;

  if (!buffer || size == 0 || *buffer == nsCRT::CR || *buffer == nsCRT::LF)
       {
         /* If this is a blank line, we're done.
          */
         hdrs->done_p = PR_TRUE;
         return MimeHeaders_build_heads_list(hdrs);
       }

  /* Tack this data on to the end of our copy.
   */
  desired_size = hdrs->all_headers_fp + size + 1;
  if (desired_size >= hdrs->all_headers_size)
       {
         status = mime_GrowBuffer (desired_size, sizeof(char), 255,
                                                    &hdrs->all_headers, &hdrs->all_headers_size);
         if (status < 0) return status;
       }
  memcpy(hdrs->all_headers+hdrs->all_headers_fp, buffer, size);
  hdrs->all_headers_fp += size;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 509 of file mimehdrs.cpp.

{
  int status = 0;
  int i;
  PRBool wrote_any_p = PR_FALSE;

  NS_ASSERTION(hdrs, "1.1 <rhp@netscape.com> 19 Mar 1999 12:00");
  if (!hdrs) 
    return -1;

  /* 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)
  {
    hdrs->done_p = PR_TRUE;
    status = MimeHeaders_build_heads_list(hdrs);
    if (status < 0) return 0;
  }

  char *charset = nsnull;
  if (opt->format_out == nsMimeOutput::nsMimeMessageSaveAs)
  {
    if (opt->override_charset)
      charset = PL_strdup(opt->default_charset);
    else
    {
      char *contentType = MimeHeaders_get(hdrs, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);
      if (contentType)
        charset = MimeHeaders_get_parameter(contentType, HEADER_PARM_CHARSET, nsnull, nsnull);
      PR_FREEIF(contentType);
    }
  }

  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;
    char *contents = end;
    
    /* Hack for BSD Mailbox delimiter. */
    if (i == 0 && head[0] == 'F' && !strncmp(head, "From ", 5))
    {
      /* For now, we don't really want this header to be output so
         we are going to just continue */
      continue;
      /* colon = head + 4; contents = colon + 1; */
    }
    else
    {
      /* Find the colon. */
      for (colon = head; colon < end && *colon != ':'; colon++)
        ;
        
        /* Back up over whitespace before the colon. */
        ocolon = colon;
        for (; colon > head && nsCRT::IsAsciiSpace(colon[-1]); colon--)
          ;
        
        contents = ocolon + 1;
    }
    
    /* Skip over whitespace after colon. */
    while (contents < end && nsCRT::IsAsciiSpace(*contents))
      contents++;
    
    /* Take off trailing whitespace... */
    while (end > contents && nsCRT::IsAsciiSpace(end[-1]))
      end--;
    
    nsCAutoString name(Substring(head, colon));
    nsCAutoString hdr_value;

    if ( (end - contents) > 0 )
    {
      hdr_value = Substring(contents, end);
    }
    
    MimeHeaders_convert_header_value(opt, hdr_value);
    // if we're saving as html, we need to convert headers from utf8 to message charset, if any
    if (opt->format_out == nsMimeOutput::nsMimeMessageSaveAs && charset)
    {
      nsCAutoString convertedStr;
      if (NS_SUCCEEDED(ConvertFromUnicode(charset, NS_ConvertUTF8toUTF16(hdr_value),
                       convertedStr)))
      {
        hdr_value = convertedStr;
      }
    }

    if (attachment)
      status = mimeEmitterAddAttachmentField(opt, name.get(), hdr_value.get());
    else
      status = mimeEmitterAddHeaderField(opt, name.get(), hdr_value.get());
    
    if (status < 0) return status;
    if (!wrote_any_p) 
      wrote_any_p = (status > 0);
  }
  mimeEmitterAddAllHeaders(opt, hdrs->all_headers, hdrs->all_headers_fp);
  PR_FREEIF(charset);

  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int MimeHeaders_write_raw_headers ( MimeHeaders hdrs,
MimeDisplayOptions opt,
PRBool  dont_write_content_type 
)

Definition at line 798 of file mimehdrs.cpp.

{
  int status;

  if (hdrs && !hdrs->done_p)
       {
         hdrs->done_p = PR_TRUE;
         status = MimeHeaders_build_heads_list(hdrs);
         if (status < 0) return 0;
       }

  if (!dont_write_content_type)
       {
         char nl[] = MSG_LINEBREAK;
         if (hdrs)
              {
                status = MimeHeaders_write(opt, hdrs->all_headers,
                                                                hdrs->all_headers_fp);
                if (status < 0) return status;
              }
         status = MimeHeaders_write(opt, nl, strlen(nl));
         if (status < 0) return status;
       }
  else if (hdrs)
       {
         PRInt32 i;
         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]);

                NS_ASSERTION(head, "1.22 <rhp@netscape.com> 22 Aug 1999 08:48");
                if (!head) continue;

                /* Don't write out any Content- header. */
                if (!nsCRT::strncasecmp(head, "Content-", 8))
                     continue;

                /* Write out this (possibly multi-line) header. */
                status = MimeHeaders_write(opt, head, end - head);
                if (status < 0) return status;
              }
       }

  if (hdrs)
       MimeHeaders_compact (hdrs);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: