Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
mimethtm.cpp File Reference
#include "mimethtm.h"
#include "prmem.h"
#include "plstr.h"
#include "prlog.h"
#include "prprf.h"
#include "msgCore.h"
#include "nsMimeStringResources.h"
#include "mimemoz2.h"

Go to the source code of this file.

Defines

#define MIME_SUPERCLASS   mimeInlineTextClass

Functions

 MimeDefClass (MimeInlineTextHTML, MimeInlineTextHTMLClass, mimeInlineTextHTMLClass,&MIME_SUPERCLASS)
static int MimeInlineTextHTML_parse_line (char *, PRInt32, MimeObject *)
static int MimeInlineTextHTML_parse_eof (MimeObject *, PRBool)
static int MimeInlineTextHTML_parse_begin (MimeObject *obj)
static int MimeInlineTextHTMLClassInitialize (MimeInlineTextHTMLClass *clazz)

Define Documentation

Definition at line 46 of file mimethtm.cpp.


Function Documentation

static int MimeInlineTextHTML_parse_begin ( MimeObject obj) [static]

Definition at line 67 of file mimethtm.cpp.

{
  int status = ((MimeObjectClass*)&mimeLeafClass)->parse_begin(obj);
  if (status < 0) return status;
  
  if (!obj->output_p) return 0;

  // Set a default font (otherwise unicode font will be used since the data is UTF-8).
  if (nsMimeOutput::nsMimeMessageBodyDisplay == obj->options->format_out ||
      nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
  {
    char buf[256];            // local buffer for html tag
    PRInt32 fontSize;         // default font size
    PRInt32 fontSizePercentage;   // size percentage
    nsCAutoString fontLang;       // langgroup of the font. 
    if (NS_SUCCEEDED(GetMailNewsFont(obj, PR_FALSE, &fontSize, &fontSizePercentage,fontLang)))
    {
      PR_snprintf(buf, 256, "<div class=\"moz-text-html\"  lang=\"%s\">", 
                  fontLang.get());
      status = MimeObject_write(obj, buf, strlen(buf), PR_FALSE);
    }
    else
    {
      status = MimeObject_write(obj, "<div class=\"moz-text-html\">", 27, PR_FALSE);
    }
    if(status<0) return status;
  }

  MimeInlineTextHTML  *textHTML = (MimeInlineTextHTML *) obj;
  
  textHTML->charset = nsnull;
  
  /* If this HTML part has a Content-Base header, and if we're displaying
        to the screen (that is, not writing this part "raw") then translate
   that Content-Base header into a <BASE> tag in the HTML.
  */
  if (obj->options &&
    obj->options->write_html_p &&
    obj->options->output_fn)
  {
    char *base_hdr = MimeHeaders_get (obj->headers, HEADER_CONTENT_BASE,
      PR_FALSE, PR_FALSE);
    
    /* rhp - for MHTML Spec changes!!! */
    if (!base_hdr)
    {
      base_hdr = MimeHeaders_get (obj->headers, HEADER_CONTENT_LOCATION, PR_FALSE, PR_FALSE);
    }
    /* rhp - for MHTML Spec changes!!! */
    
    if (base_hdr)
    {
      PRUint32 buflen = strlen(base_hdr) + 20;
      char *buf = (char *) PR_MALLOC(buflen);
      const char *in;
      char *out;
      if (!buf)
        return MIME_OUT_OF_MEMORY;
      
        /* The value of the Content-Base header is a number of "words".
        Whitespace in this header is not significant -- it is assumed
        that any real whitespace in the URL has already been encoded,
        and whitespace has been inserted to allow the lines in the
        mail header to be wrapped reasonably.  Creators are supposed
        to insert whitespace every 40 characters or less.
      */
      PL_strncpyz(buf, "<BASE HREF=\"", buflen);
      out = buf + strlen(buf);
      
      for (in = base_hdr; *in; in++)
        /* ignore whitespace and quotes */
        if (!nsCRT::IsAsciiSpace(*in) && *in != '"')
          *out++ = *in;
        
        /* Close the tag and argument. */
        *out++ = '"';
        *out++ = '>';
        *out++ = 0;
        
        PR_Free(base_hdr);
        
        status = MimeObject_write(obj, buf, strlen(buf), PR_FALSE);
        PR_Free(buf);
        if (status < 0) return status;
    }
  }
  
  // rhp: For a change, we will write out a separator after formatted text
  //      bodies.
  status = MimeObject_write_separator(obj);
  if (status < 0) return status;
  
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int MimeInlineTextHTML_parse_eof ( MimeObject obj,
PRBool  abort_p 
) [static]

Definition at line 222 of file mimethtm.cpp.

{
  int status;
  MimeInlineTextHTML  *textHTML = (MimeInlineTextHTML *) obj;
  if (obj->closed_p) return 0;

  PR_FREEIF(textHTML->charset);

  /* Run parent method first, to flush out any buffered data. */
  status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p);
  if (status < 0) return status;

  if (nsMimeOutput::nsMimeMessageBodyDisplay == obj->options->format_out ||
      nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
    status = MimeObject_write(obj, "</div>", 6, PR_FALSE);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int MimeInlineTextHTML_parse_line ( char *  line,
PRInt32  length,
MimeObject obj 
) [static]

Definition at line 164 of file mimethtm.cpp.

{
  MimeInlineTextHTML  *textHTML = (MimeInlineTextHTML *) obj;

  if (!obj->output_p) 
    return 0;

  if (!obj->options || !obj->options->output_fn)
    return 0;

  if (!textHTML->charset)
  {
    char * cp;
    // First, try to detect a charset via a META tag!
    if ((cp = PL_strncasestr(line, "META", length)) && 
        (cp = PL_strncasestr(cp, "HTTP-EQUIV=", length - (int)(cp - line))) && 
        (cp = PL_strncasestr(cp, "CONTENT=", length - (int)(cp - line))) && 
        (cp = PL_strncasestr(cp, "CHARSET=", length - (int)(cp - line))) 
        ) 
    {
      char* cp1 = cp + 8;  //8 for the length of "CHARSET="
      char* cp2 = PL_strnpbrk(cp1, " \"\'", length - (int)(cp1 - line));
      if (cp2)
      {
        char* charset = PL_strndup(cp1, (int)(cp2 - cp1));
 
        // Fix bug 101434, in this case since this parsing is a char* 
        // operation, a real UTF-16 or UTF-32 document won't be parse 
        // correctly, if it got parse, it cannot be UTF-16 nor UTF-32
        // there fore, we ignore them if somehow we got that value
        // 6 == strlen("UTF-16") or strlen("UTF-32"), this will cover
        // UTF-16, UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE
        if ((charset != nsnull) &&
            nsCRT::strncasecmp(charset, "UTF-16", 6) &&
            nsCRT::strncasecmp(charset, "UTF-32", 6))
        {
          textHTML->charset = charset; 

          // write out the data without the charset part...
          if (textHTML->charset)
          {
            int err = MimeObject_write(obj, line, cp - line, PR_TRUE);
            if (err == 0)
              err = MimeObject_write(obj, cp2, length - (int)(cp2 - line), PR_TRUE);

            return err;
          }
        }
        PR_FREEIF(charset);
      }
    }
  }

  // Now, just write out the data...
  return MimeObject_write(obj, line, length, PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 55 of file mimethtm.cpp.

Here is the call graph for this function: