Back to index

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

Go to the source code of this file.

Defines

#define MIME_SUPERCLASS   mimeInlineTextPlainClass

Functions

 MimeDefClass (MimeInlineTextHTMLAsPlaintext, MimeInlineTextHTMLAsPlaintextClass, mimeInlineTextHTMLAsPlaintextClass,&MIME_SUPERCLASS)
static int MimeInlineTextHTMLAsPlaintext_parse_line (char *, PRInt32, MimeObject *)
static int MimeInlineTextHTMLAsPlaintext_parse_begin (MimeObject *obj)
static int MimeInlineTextHTMLAsPlaintext_parse_eof (MimeObject *, PRBool)
static void MimeInlineTextHTMLAsPlaintext_finalize (MimeObject *obj)
static int MimeInlineTextHTMLAsPlaintextClassInitialize (MimeInlineTextHTMLAsPlaintextClass *clazz)

Define Documentation

Definition at line 53 of file mimethpl.cpp.


Function Documentation

Definition at line 146 of file mimethpl.cpp.

{
  MimeInlineTextHTMLAsPlaintext *textHTMLPlain =
                                        (MimeInlineTextHTMLAsPlaintext *) obj;
  if (textHTMLPlain && textHTMLPlain->complete_buffer)
  {
    // If there's content in the buffer, make sure that we output it.
    // don't care about return codes
    obj->clazz->parse_eof(obj, PR_FALSE);

    delete textHTMLPlain->complete_buffer;
    textHTMLPlain->complete_buffer = NULL;
      /* It is important to zero the pointer, so we can reliably check for
         the validity of it in the other functions. See above. */
  }
  ((MimeObjectClass*)&MIME_SUPERCLASS)->finalize (obj);
}

Here is the caller graph for this function:

Definition at line 83 of file mimethpl.cpp.

{
  MimeInlineTextHTMLAsPlaintext *textHTMLPlain =
                                       (MimeInlineTextHTMLAsPlaintext *) obj;
  textHTMLPlain->complete_buffer = new nsString();
     // Let's just hope that libmime won't have the idea to call begin twice...
  return ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_begin(obj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 93 of file mimethpl.cpp.

{
  if (obj->closed_p)
    return 0;

  // This is a hack. We need to call parse_eof() of the super class to flush out any buffered data.
  // We can't call it yet for our direct super class, because it would "close" the output 
  // (write tags such as </pre> and </div>). We'll do that after parsing the buffer.
  int status = ((MimeObjectClass*)&MIME_SUPERCLASS)->superclass->parse_eof(obj, abort_p);
  if (status < 0)
    return status;
  
  MimeInlineTextHTMLAsPlaintext *textHTMLPlain =
                                       (MimeInlineTextHTMLAsPlaintext *) obj;

  if (!textHTMLPlain || !textHTMLPlain->complete_buffer)
  {
    return 0;
  }
  nsString& cb = *(textHTMLPlain->complete_buffer);
  nsString asPlaintext;
  PRUint32 flags = nsIDocumentEncoder::OutputFormatted
    | nsIDocumentEncoder::OutputWrap
    | nsIDocumentEncoder::OutputFormatFlowed
    | nsIDocumentEncoder::OutputLFLineBreak
    | nsIDocumentEncoder::OutputNoScriptContent
    | nsIDocumentEncoder::OutputNoFramesContent
    | nsIDocumentEncoder::OutputBodyOnly;
  HTML2Plaintext(cb, asPlaintext, flags, 80);

  NS_ConvertUTF16toUTF8 resultCStr(asPlaintext);
  // TODO parse each line independently
  status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_line(
                             resultCStr.BeginWriting(),
                             resultCStr.Length(),
                             obj);

  cb.Truncate();

  if (status < 0)
    return status;

  // Second part of the flush hack. Pretend obj wasn't closed yet, so that our super class 
  // gets a chance to write the closing.
  PRBool save_closed_p = obj->closed_p;
  obj->closed_p = PR_FALSE;
  status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_eof(obj, abort_p);
  // Restore closed_p.
  obj->closed_p = save_closed_p;
  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 165 of file mimethpl.cpp.

{
  MimeInlineTextHTMLAsPlaintext *textHTMLPlain =
                                       (MimeInlineTextHTMLAsPlaintext *) obj;

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

  /*
    To convert HTML->TXT syncronously, I need the full source at once,
    not line by line (how do you convert "<li>foo\n" to plaintext?).
    parse_decoded_buffer claims to give me that, but in fact also gives
    me single lines.
    It might be theoretically possible to drive this asyncronously, but
    I don't know, which odd circumstances might arise and how libmime
    will behave then. It's not worth the trouble for me to figure this all out.
   */
  nsCString linestr(line, length);
  NS_ConvertUTF8toUCS2 line_ucs2(linestr.get());
  if (length && line_ucs2.IsEmpty())
    line_ucs2.AssignWithConversion(linestr.get());
  (textHTMLPlain->complete_buffer)->Append(line_ucs2);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file mimethpl.cpp.

Here is the call graph for this function: