Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
C2047Translator Class Reference

#include <nsImportTranslator.h>

Inheritance diagram for C2047Translator:
Inheritance graph
[legend]
Collaboration diagram for C2047Translator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~C2047Translator ()
 C2047Translator (const char *pCharset, PRUint32 headerLen)
void SetUseQuotedPrintable (void)
virtual PRBool ConvertToFile (const PRUint8 *pIn, PRUint32 inLen, ImportOutFile *pOutFile, PRUint32 *pProcessed=nsnull)
PRBool ConvertToFileQ (const PRUint8 *pIn, PRUint32 inLen, ImportOutFile *pOutFile, PRUint32 *pProcessed)
virtual PRBool Supports8bitEncoding (void)
virtual PRUint32 GetMaxBufferSize (PRUint32 inLen)
virtual void ConvertBuffer (const PRUint8 *pIn, PRUint32 inLen, PRUint8 *pOut)
virtual PRBool FinishConvertToFile (ImportOutFile *)
virtual void GetCharset (nsCString &charSet)
virtual void GetLanguage (nsCString &lang)
virtual void GetEncoding (nsCString &encoding)

Protected Attributes

PRBool m_useQuotedPrintable
nsCString m_charset
PRUint32 m_startLen

Detailed Description

Definition at line 79 of file nsImportTranslator.h.


Constructor & Destructor Documentation

virtual C2047Translator::~C2047Translator ( ) [inline, virtual]

Definition at line 81 of file nsImportTranslator.h.

{}
C2047Translator::C2047Translator ( const char *  pCharset,
PRUint32  headerLen 
) [inline]

Definition at line 83 of file nsImportTranslator.h.

{ m_charset = pCharset; m_startLen = headerLen; m_useQuotedPrintable = PR_FALSE;}

Member Function Documentation

virtual void nsImportTranslator::ConvertBuffer ( const PRUint8 pIn,
PRUint32  inLen,
PRUint8 pOut 
) [inline, virtual, inherited]

Reimplemented in CMHTranslator.

Definition at line 59 of file nsImportTranslator.h.

{ memcpy( pOut, pIn, inLen); pOut[inLen] = 0;}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool C2047Translator::ConvertToFile ( const PRUint8 pIn,
PRUint32  inLen,
ImportOutFile pOutFile,
PRUint32 pProcessed = nsnull 
) [virtual]

Reimplemented from nsImportTranslator.

Definition at line 162 of file nsImportTranslator.cpp.

{
       if (m_useQuotedPrintable)
              return( ConvertToFileQ( pIn, inLen, pOutFile, pProcessed));

       if (!inLen)
              return( PR_TRUE);

       int                  maxLineLen = 64;
       int                  curLineLen = m_startLen;
       PRBool        startLine = PR_TRUE;
       int                  encodeMax;
       PRUint8 *     pEncoded = new PRUint8[maxLineLen * 2];

       while (inLen) {
              if (startLine) {
                     if (!pOutFile->WriteStr( " =?")) {
                            delete [] pEncoded;
                            return( PR_FALSE);
                     }
                     if (!pOutFile->WriteStr( m_charset.get())) {
                            delete [] pEncoded;
                            return( PR_FALSE);
                     }
                     if (!pOutFile->WriteStr( "?b?")) {
                            delete [] pEncoded;
                            return( PR_FALSE);
                     }
                     curLineLen += (6 + m_charset.Length());
                     startLine = PR_FALSE;
              }
              encodeMax = maxLineLen - curLineLen;
              encodeMax *= 3;
              encodeMax /= 4;
              if ((PRUint32)encodeMax > inLen)
                     encodeMax = (int)inLen;

              // encode the line, end the line
              // then continue. Update curLineLen, pIn, startLine, and inLen
              UMimeEncode::ConvertBuffer( pIn, encodeMax, pEncoded, maxLineLen, maxLineLen, "\x0D\x0A");

              if (!pOutFile->WriteStr( (const char *)pEncoded)) {
                     delete [] pEncoded;
                     return( PR_FALSE);
              }

              pIn += encodeMax;
              inLen -= encodeMax;
              startLine = PR_TRUE;
              curLineLen = 0;
              if (!pOutFile->WriteStr( "?=")) {
                     delete [] pEncoded;
                     return( PR_FALSE);
              }
              if (inLen) {
                     if (!pOutFile->WriteStr( "\x0D\x0A ")) {
                            delete [] pEncoded;
                            return( PR_FALSE);
                     }
              }
       }

       delete [] pEncoded;

       if (pProcessed)
              *pProcessed = inLen;

       return( PR_TRUE);
}

Here is the call graph for this function:

PRBool C2047Translator::ConvertToFileQ ( const PRUint8 pIn,
PRUint32  inLen,
ImportOutFile pOutFile,
PRUint32 pProcessed 
)

Definition at line 99 of file nsImportTranslator.cpp.

{
       if (!inLen)
              return( PR_TRUE);

       int           maxLineLen = 64;
       int           curLineLen = m_startLen;
       PRBool startLine = PR_TRUE;

       PRUint8       hex[2];
       while (inLen) {
              if (startLine) {
                     if (!pOutFile->WriteStr( " =?"))
                            return( PR_FALSE);
                     if (!pOutFile->WriteStr( m_charset.get()))
                            return( PR_FALSE);
                     if (!pOutFile->WriteStr( "?q?"))
                            return( PR_FALSE);
                     curLineLen += (6 + m_charset.Length());
                     startLine = PR_FALSE;
              }

              if (!ImportCharSet::IsUSAscii( *pIn) || ImportCharSet::Is822SpecialChar( *pIn) || ImportCharSet::Is822CtlChar( *pIn) ||
                     (*pIn == ImportCharSet::cSpaceChar) || (*pIn == '?') || (*pIn == '=')) {
                     // needs to be encode as =hex val
                     if (!pOutFile->WriteByte( '='))
                            return( PR_FALSE);
                     ImportCharSet::ByteToHex( *pIn, hex);
                     if (!pOutFile->WriteData( hex, 2))
                            return( PR_FALSE);
                     curLineLen += 3;
              }
              else {
                     if (!pOutFile->WriteByte( *pIn))
                            return( PR_FALSE);
                     curLineLen++;
              }
              pIn++; inLen--;
              if (curLineLen > maxLineLen) {
                     if (!pOutFile->WriteStr( "?="))
                            return( PR_FALSE);
                     if (inLen) {
                            if (!pOutFile->WriteStr( "\x0D\x0A "))
                                   return( PR_FALSE);
                     }

                     startLine = PR_TRUE;
                     curLineLen = 0;
              }
       }

       if (!startLine) {
              // end the encoding!
              if (!pOutFile->WriteStr( "?="))
                     return( PR_FALSE);
       }

       if (pProcessed)
              *pProcessed = inLen;

       return( PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual PRBool nsImportTranslator::FinishConvertToFile ( ImportOutFile ) [inline, virtual, inherited]

Definition at line 61 of file nsImportTranslator.h.

{ return( PR_TRUE);}

Here is the caller graph for this function:

virtual void nsImportTranslator::GetCharset ( nsCString charSet) [inline, virtual, inherited]

Definition at line 63 of file nsImportTranslator.h.

{ charSet = "us-ascii";}

Here is the caller graph for this function:

virtual void nsImportTranslator::GetEncoding ( nsCString encoding) [inline, virtual, inherited]

Definition at line 65 of file nsImportTranslator.h.

{ encoding.Truncate();}

Here is the caller graph for this function:

virtual void nsImportTranslator::GetLanguage ( nsCString lang) [inline, virtual, inherited]

Definition at line 64 of file nsImportTranslator.h.

{ lang = "en";}

Here is the caller graph for this function:

virtual PRUint32 nsImportTranslator::GetMaxBufferSize ( PRUint32  inLen) [inline, virtual, inherited]

Reimplemented in CMHTranslator.

Definition at line 58 of file nsImportTranslator.h.

{ return( inLen + 1);}

Here is the caller graph for this function:

Definition at line 85 of file nsImportTranslator.h.

virtual PRBool nsImportTranslator::Supports8bitEncoding ( void  ) [inline, virtual, inherited]

Definition at line 57 of file nsImportTranslator.h.

{ return( PR_FALSE);}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 92 of file nsImportTranslator.h.

Definition at line 93 of file nsImportTranslator.h.

Definition at line 91 of file nsImportTranslator.h.


The documentation for this class was generated from the following files: