Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
mimethsa.cpp File Reference
#include "mimethsa.h"
#include "prmem.h"
#include "prlog.h"
#include "msgCore.h"
#include "mimemoz2.h"
#include "nsIPrefBranch.h"
#include "nsString.h"
#include "nsReadableUtils.h"

Go to the source code of this file.

Defines

#define MIME_SUPERCLASS   mimeInlineTextHTMLClass

Functions

 MimeDefClass (MimeInlineTextHTMLSanitized, MimeInlineTextHTMLSanitizedClass, mimeInlineTextHTMLSanitizedClass,&MIME_SUPERCLASS)
static int MimeInlineTextHTMLSanitized_parse_line (char *, PRInt32, MimeObject *)
static int MimeInlineTextHTMLSanitized_parse_begin (MimeObject *obj)
static int MimeInlineTextHTMLSanitized_parse_eof (MimeObject *, PRBool)
static void MimeInlineTextHTMLSanitized_finalize (MimeObject *obj)
static int MimeInlineTextHTMLSanitizedClassInitialize (MimeInlineTextHTMLSanitizedClass *clazz)

Define Documentation

Definition at line 53 of file mimethsa.cpp.


Function Documentation

Definition at line 216 of file mimethsa.cpp.

{
#ifdef DEBUG_BenB
printf("finalize\n");
#endif
  MimeInlineTextHTMLSanitized *textHTMLSan =
                                        (MimeInlineTextHTMLSanitized *) obj;
#ifdef DEBUG_BenB
printf(" cbp: %d\n", textHTMLSan->complete_buffer);
printf(" F1\n");
#endif

  if (textHTMLSan && textHTMLSan->complete_buffer)
  {
    obj->clazz->parse_eof(obj, PR_FALSE);
#ifdef DEBUG_BenB
printf(" F2\n");
#endif
    delete textHTMLSan->complete_buffer;
#ifdef DEBUG_BenB
printf(" cbp: %d\n", textHTMLSan->complete_buffer);
printf(" F3\n");
#endif
    textHTMLSan->complete_buffer = NULL;
  }

#ifdef DEBUG_BenB
printf(" cbp: %d\n", textHTMLSan->complete_buffer);
printf(" F4\n");
#endif
  ((MimeObjectClass*)&MIME_SUPERCLASS)->finalize (obj);
#ifdef DEBUG_BenB
printf("/finalize\n");
#endif
}

Here is the caller graph for this function:

Definition at line 77 of file mimethsa.cpp.

{
#ifdef DEBUG_BenB
printf("parse_begin\n");
#endif
  MimeInlineTextHTMLSanitized *textHTMLSan =
                                       (MimeInlineTextHTMLSanitized *) obj;
  textHTMLSan->complete_buffer = new nsString();
#ifdef DEBUG_BenB
printf(" B1\n");
printf(" cbp: %d\n", textHTMLSan->complete_buffer);
#endif
  int status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_begin(obj);
  if (status < 0)
    return status;
#ifdef DEBUG_BenB
printf(" B2\n");
#endif

  // charset
  /* honestly, I don't know how that charset stuff works in libmime.
     The part in mimethtm doesn't make much sense to me either.
     I'll just dump the charset we get in the mime headers into a
     HTML meta http-equiv.
     XXX Not sure, if that is correct, though. */
  char *content_type =
    (obj->headers
     ? MimeHeaders_get(obj->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE)
     : 0);
  if (content_type)
  {
    char* charset = MimeHeaders_get_parameter(content_type,
                                              HEADER_PARM_CHARSET,
                                              NULL, NULL);
    PR_Free(content_type);
    if (charset)
    {
      nsCAutoString charsetline(
        "\n<meta http-equiv=\"Context-Type\" content=\"text/html; charset=");
      charsetline += charset;
      charsetline += "\">\n";
      int status = MimeObject_write(obj,
                                    charsetline.get(),
                                    charsetline.Length(),
                                    PR_TRUE);
      PR_Free(charset);
      if (status < 0)
        return status;
    }
  }
#ifdef DEBUG_BenB
printf("/parse_begin\n");
#endif
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 134 of file mimethsa.cpp.

{
#ifdef DEBUG_BenB
printf("parse_eof\n");
#endif

  if (obj->closed_p)
    return 0;
  int status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p);
  if (status < 0) 
    return status;
  MimeInlineTextHTMLSanitized *textHTMLSan =
                                       (MimeInlineTextHTMLSanitized *) obj;

#ifdef DEBUG_BenB
printf(" cbp: %d\n", textHTMLSan->complete_buffer);
printf(" closed_p: %s\n", obj->closed_p?"true":"false");
#endif
  if (!textHTMLSan || !textHTMLSan->complete_buffer)
  {
#ifdef DEBUG_BenB
printf("/parse_eof (early exit)\n");
#endif
    return 0;
  }
#ifdef DEBUG_BenB
printf(" E1\n");
printf("buffer: -%s-\n", NS_LossyConvertUCS2toASCII(*textHTMLSan->complete_buffer).get());
#endif

  char* allowedTags = 0;
  nsIPrefBranch *prefBranch = GetPrefBranch(obj->options);
  if (prefBranch)
    prefBranch->GetCharPref("mailnews.display.html_sanitizer.allowed_tags",
                            &allowedTags);

#ifdef DEBUG_BenB
printf(" E2\n");
#endif
  nsString& cb = *(textHTMLSan->complete_buffer);
#ifdef DEBUG_BenB
printf(" E3\n");
#endif
  nsString sanitized;
#ifdef DEBUG_BenB
printf(" E4\n");
#endif
  HTMLSanitize(cb, sanitized, 0, NS_ConvertASCIItoUCS2(allowedTags));
#ifdef DEBUG_BenB
printf(" E5\n");
#endif

  NS_ConvertUTF16toUTF8 resultCStr(sanitized);
#ifdef DEBUG_BenB
printf(" E6\n");
#endif
  // TODO parse each line independently
  /* That function doesn't work correctly, if the first META tag is no
     charset spec. (It assumes that it's on its own line.)
     Most likely not fatally wrong, however. */
  status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_line(
                             resultCStr.BeginWriting(),
                             resultCStr.Length(),
                             obj);
#ifdef DEBUG_BenB
printf(" E7\n");
#endif

#ifdef DEBUG_BenB
printf(" E8\n");
#endif

  cb.Truncate();

#ifdef DEBUG_BenB
printf("/parse_eof\n");
#endif

  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 253 of file mimethsa.cpp.

{
#ifdef DEBUG_BenB
printf("p");
#endif
  MimeInlineTextHTMLSanitized *textHTMLSan =
                                       (MimeInlineTextHTMLSanitized *) obj;
#ifdef DEBUG_BenB
printf("%d", textHTMLSan->complete_buffer);
#endif

  if (!textHTMLSan || !(textHTMLSan->complete_buffer))
  {
#ifdef DEBUG
printf("Can't output: %s\n", line);
#endif
    return -1;
  }

  nsCString linestr(line, length);
  NS_ConvertUTF8toUCS2 line_ucs2(linestr.get());
  if (length && line_ucs2.IsEmpty())
    line_ucs2.AssignWithConversion(linestr.get());
  (textHTMLSan->complete_buffer)->Append(line_ucs2);

#ifdef DEBUG_BenB
printf("l ");
#endif
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file mimethsa.cpp.

Here is the call graph for this function: