Back to index

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

#include <nsMimePlainEmitter.h>

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

List of all members.

Public Member Functions

 nsMimePlainEmitter ()
virtual ~nsMimePlainEmitter (void)
NS_IMETHOD StartHeader (PRBool rootMailHeader, PRBool headerOnly, const char *msgID, const char *outCharset)
NS_IMETHOD AddHeaderField (const char *field, const char *value)
NS_IMETHOD EndHeader ()
NS_IMETHOD WriteBody (const char *buf, PRUint32 size, PRUint32 *amountWritten)
NS_DECL_ISUPPORTS
NS_DECL_NSIMIMEEMITTER
NS_DECL_NSIINTERFACEREQUESTOR
NS_IMETHOD 
UtilityWriteCRLF (const char *buf)
char * MimeGetStringByName (const char *aHeaderName)
char * MimeGetStringByID (PRInt32 aID)
char * LocalizeHeaderName (const char *aHeaderName, const char *aDefaultName)
const char * GetHeaderValue (const char *aHeaderName)
virtual nsresult WriteHeaderFieldHTMLPrefix ()
virtual nsresult WriteHeaderFieldHTML (const char *field, const char *value)
virtual nsresult WriteHeaderFieldHTMLPostfix ()
void Initialize (in nsIURI url, in nsIChannel aChannel, in long aFormat)
void Complete ()
void SetPipe (in nsIInputStream inputStream, in nsIOutputStream outStream)
void SetOutputListener (in nsIStreamListener listener)
nsIStreamListener GetOutputListener ()
void StartHeader (in PRBool rootMailHeader, in PRBool headerOnly,[const ] in string msgID,[const ] in string outCharset)
void AddHeaderField ([const ] in string field,[const ] in string value)
void addAllHeaders ([const ] in string allheaders,[const ] in long allheadersize)
void WriteHTMLHeaders ()
void UpdateCharacterSet ([const ] in string aCharset)
void StartAttachment ([const ] in string name,[const ] in string contentType,[const ] in string url, in PRBool aNotDownloaded)
void AddAttachmentField ([const ] in string field,[const ] in string value)
void EndAttachment ()
void EndAllAttachments ()
void StartBody (in PRBool bodyOnly,[const ] in string msgID,[const ] in string outCharset)
void WriteBody ([const ] in string buf, in PRUint32 size, out PRUint32 amountWritten)
void EndBody ()
void Write ([const ] in string buf, in PRUint32 size, out PRUint32 amountWritten)
void UtilityWrite ([const ] in string buf)
void getInterface (in nsIIDRef uuid,[iid_is(uuid), retval] out nsQIResult result)
 Retrieves the specified interface pointer.

Protected Member Functions

void CleanupHeaderArray (nsVoidArray *aArray)
nsresult DumpSubjectFromDate ()
nsresult DumpToCC ()
nsresult DumpRestOfHeaders ()
nsresult OutputGenericHeader (const char *aHeaderVal)
nsresult WriteHelper (const char *buf, PRUint32 count, PRUint32 *countWritten)

Protected Attributes

nsCOMPtr< nsIStringBundlem_stringBundle
nsCOMPtr< nsIStringBundlem_headerStringBundle
MimeRebuffermBufferMgr
nsIOutputStreammOutStream
nsIInputStreammInputStream
nsIStreamListenermOutListener
nsIChannelmChannel
PRUint32 mTotalWritten
PRUint32 mTotalRead
PRBool mDocHeader
nsIURImURL
PRInt32 mHeaderDisplayType
nsCString mHTMLHeaders
PRInt32 mAttachCount
nsVoidArraymAttachArray
attachmentInfoTypemCurrentAttachment
nsVoidArraymHeaderArray
nsVoidArraymEmbeddedHeaderArray
nsCOMPtr< nsIMsgHeaderParsermHeaderParser
PRBool mBodyStarted
nsCString mBody
PRBool mFirstHeaders
PRInt32 mFormat
nsCOMPtr< nsIMimeConvertermUnicodeConverter
nsString mCharset

Detailed Description

Definition at line 49 of file nsMimePlainEmitter.h.


Constructor & Destructor Documentation

Definition at line 54 of file nsMimePlainEmitter.cpp.

{
}

Definition at line 59 of file nsMimePlainEmitter.cpp.

{
}

Member Function Documentation

void nsIMimeEmitter::addAllHeaders ( [const ] in string  allheaders,
[const ] in long  allheadersize 
) [inherited]
void nsIMimeEmitter::AddAttachmentField ( [const ] in string  field,
[const ] in string  value 
) [inherited]

Here is the caller graph for this function:

nsresult nsMimePlainEmitter::AddHeaderField ( const char *  field,
const char *  value 
)

Definition at line 74 of file nsMimePlainEmitter.cpp.

{
  if ( (!field) || (!value) )
    return NS_OK;

  UtilityWrite(field);
  UtilityWrite(":\t");
  UtilityWriteCRLF(value);
  return NS_OK;
}

Here is the call graph for this function:

void nsIMimeEmitter::AddHeaderField ( [const ] in string  field,
[const ] in string  value 
) [inherited]

Here is the caller graph for this function:

void nsMimeBaseEmitter::CleanupHeaderArray ( nsVoidArray aArray) [protected, inherited]

Definition at line 177 of file nsMimeBaseEmitter.cpp.

{
  if (!aArray)
    return;

  for (PRInt32 i=0; i<aArray->Count(); i++)
  {
    headerInfoType *headerInfo = (headerInfoType *)aArray->ElementAt(i);
    if (!headerInfo)
      continue;
    
    PR_FREEIF(headerInfo->name);
    PR_FREEIF(headerInfo->value);
    PR_FREEIF(headerInfo);
  }

  delete aArray;
}

Here is the caller graph for this function:

void nsIMimeEmitter::Complete ( ) [inherited]

Implemented in nsMimeXmlEmitter.

nsresult nsMimeBaseEmitter::DumpRestOfHeaders ( ) [protected, inherited]

Definition at line 877 of file nsMimeBaseEmitter.cpp.

{
  PRInt32     i;
  nsVoidArray *array = mDocHeader? mHeaderArray : mEmbeddedHeaderArray;

  mHTMLHeaders.Append("<table border=0 cellspacing=0 cellpadding=0 width=\"100%\" class=\"header-part3\">");
  
  for (i = 0; i < array->Count(); i++)
  {
    headerInfoType *headerInfo = (headerInfoType *)array->ElementAt(i);
    if ( (!headerInfo) || (!headerInfo->name) || (!(*headerInfo->name)) ||
      (!headerInfo->value) || (!(*headerInfo->value)))
      continue;
    
    if ( (!nsCRT::strcasecmp(HEADER_SUBJECT, headerInfo->name)) ||
      (!nsCRT::strcasecmp(HEADER_DATE, headerInfo->name)) ||
      (!nsCRT::strcasecmp(HEADER_FROM, headerInfo->name)) ||
      (!nsCRT::strcasecmp(HEADER_TO, headerInfo->name)) ||
      (!nsCRT::strcasecmp(HEADER_CC, headerInfo->name)) )
      continue;
    
    WriteHeaderFieldHTML(headerInfo->name, headerInfo->value);
  }
  
  mHTMLHeaders.Append("</table>");
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 827 of file nsMimeBaseEmitter.cpp.

{
  mHTMLHeaders.Append("<table border=0 cellspacing=0 cellpadding=0 width=\"100%\" class=\"header-part1\">");

    // This is the envelope information
    OutputGenericHeader(HEADER_SUBJECT);
    OutputGenericHeader(HEADER_FROM);
    OutputGenericHeader(HEADER_DATE);

    // If we are Quoting a message, then we should dump the To: also
    if ( ( mFormat == nsMimeOutput::nsMimeMessageQuoting ) ||
         ( mFormat == nsMimeOutput::nsMimeMessageBodyQuoting ) )
      OutputGenericHeader(HEADER_TO);

  mHTMLHeaders.Append("</table>");
 
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsMimeBaseEmitter::DumpToCC ( ) [protected, inherited]

Definition at line 847 of file nsMimeBaseEmitter.cpp.

{
  const char * toField = GetHeaderValue(HEADER_TO);
  const char * ccField = GetHeaderValue(HEADER_CC);
  const char * bccField = GetHeaderValue(HEADER_BCC);
  const char * newsgroupField = GetHeaderValue(HEADER_NEWSGROUPS);

  // only dump these fields if we have at least one of them! When displaying news
  // messages that didn't have a To or Cc field, we'd always get an empty box
  // which looked weird.
  if (toField || ccField || bccField || newsgroupField)
  {
    mHTMLHeaders.Append("<table border=0 cellspacing=0 cellpadding=0 width=\"100%\" class=\"header-part2\">");

    if (toField)
      WriteHeaderFieldHTML(HEADER_TO, toField);
    if (ccField)
      WriteHeaderFieldHTML(HEADER_CC, ccField);
    if (bccField)
      WriteHeaderFieldHTML(HEADER_BCC, bccField);
    if (newsgroupField)
      WriteHeaderFieldHTML(HEADER_NEWSGROUPS, newsgroupField);

    mHTMLHeaders.Append("</table>");
  }

  return NS_OK;
}

Here is the call graph for this function:

Implemented in nsMimeHtmlDisplayEmitter.

Here is the caller graph for this function:

Implemented in nsMimeHtmlDisplayEmitter, and nsMimeXmlEmitter.

Here is the caller graph for this function:

void nsIMimeEmitter::EndBody ( ) [inherited]

Implemented in nsMimeHtmlDisplayEmitter.

Here is the caller graph for this function:

Implements nsIMimeEmitter.

Definition at line 86 of file nsMimePlainEmitter.cpp.

{
  UtilityWriteCRLF("");
  return NS_OK; 
}

Here is the call graph for this function:

const char * nsMimeBaseEmitter::GetHeaderValue ( const char *  aHeaderName) [inherited]

Definition at line 536 of file nsMimeBaseEmitter.cpp.

{
  PRInt32     i;
  char        *retVal = nsnull;
  nsVoidArray *array = mDocHeader? mHeaderArray : mEmbeddedHeaderArray;

  if (!array)
    return nsnull;

  for (i = 0; i < array->Count(); i++)
  {
    headerInfoType *headerInfo = (headerInfoType *)array->ElementAt(i);
    if ( (!headerInfo) || (!headerInfo->name) || (!(*headerInfo->name)) )
      continue;
    
    if (!nsCRT::strcasecmp(aHeaderName, headerInfo->name))
    {
      retVal = headerInfo->value;
      break;
    }
  }

  return retVal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIInterfaceRequestor::getInterface ( in nsIIDRef  uuid,
[iid_is(uuid), retval] out nsQIResult  result 
) [inherited]

Retrieves the specified interface pointer.

Parameters:
uuidThe IID of the interface being requested.
result[out] The interface pointer to be filled in if the interface is accessible.
Returns:
NS_OK - interface was successfully returned. NS_NOINTERFACE - interface not accessible. NS_ERROR* - method failure.
void nsIMimeEmitter::Initialize ( in nsIURI  url,
in nsIChannel  aChannel,
in long  aFormat 
) [inherited]
char * nsMimeBaseEmitter::LocalizeHeaderName ( const char *  aHeaderName,
const char *  aDefaultName 
) [inherited]

Definition at line 313 of file nsMimeBaseEmitter.cpp.

{
  char *retVal = nsnull;

  // prefer to use translated strings if not for quoting
  if (mFormat != nsMimeOutput::nsMimeMessageQuoting &&
      mFormat != nsMimeOutput::nsMimeMessageBodyQuoting)
  {
    // map name to id and get the translated string
    PRInt32 id = MapHeaderNameToID(aHeaderName);
    if (id > 0)
      retVal = MimeGetStringByID(id);
  }
  
  // get the string from the other bundle (usually not translated)
  if (!retVal)
    retVal = MimeGetStringByName(aHeaderName);

  if (retVal)
    return retVal;
  else
    return nsCRT::strdup(aDefaultName);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsMimeBaseEmitter::MimeGetStringByID ( PRInt32  aID) [inherited]

Definition at line 277 of file nsMimeBaseEmitter.cpp.

{
  nsresult res = NS_OK;

  if (!m_stringBundle)
  {
    static const char propertyURL[] = MIME_URL;

    nsCOMPtr<nsIStringBundleService> sBundleService = 
                            do_GetService(NS_STRINGBUNDLE_CONTRACTID, &res); 
    if (NS_SUCCEEDED(res)) 
      res = sBundleService->CreateBundle(propertyURL, getter_AddRefs(m_stringBundle));
  }

  if (m_stringBundle)
  {
    nsXPIDLString val;

    res = m_stringBundle->GetStringFromID(aID, getter_Copies(val));

    if (NS_FAILED(res)) 
      return nsnull;

    return ToNewUTF8String(val);
  }
  else
    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsMimeBaseEmitter::MimeGetStringByName ( const char *  aHeaderName) [inherited]

Definition at line 238 of file nsMimeBaseEmitter.cpp.

{
       nsresult res = NS_OK;

       if (!m_headerStringBundle)
       {
              static const char propertyURL[] = MIME_HEADER_URL;

              nsCOMPtr<nsIStringBundleService> sBundleService = 
                       do_GetService(NS_STRINGBUNDLE_CONTRACTID, &res); 
              if (NS_SUCCEEDED(res) && (nsnull != sBundleService)) 
              {
                     res = sBundleService->CreateBundle(propertyURL, getter_AddRefs(m_headerStringBundle));
              }
       }

       if (m_headerStringBundle)
       {
    nsXPIDLString val;

    res = m_headerStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(aHeaderName).get(), 
                                                  getter_Copies(val));

    if (NS_FAILED(res)) 
      return nsnull;
    
    // Here we need to return a new copy of the string
    // This returns a UTF-8 string so the caller needs to perform a conversion 
    // if this is used as UCS-2 (e.g. cannot do nsString(utfStr);
    //
    return ToNewUTF8String(val);
       }
       else
       {
    return nsnull;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMimeBaseEmitter::OutputGenericHeader ( const char *  aHeaderVal) [protected, inherited]

Definition at line 906 of file nsMimeBaseEmitter.cpp.

{
  const char *val = GetHeaderValue(aHeaderVal);

  if (val)
    return WriteHeaderFieldHTML(aHeaderVal, val);

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMimeEmitter::SetPipe ( in nsIInputStream  inputStream,
in nsIOutputStream  outStream 
) [inherited]
void nsIMimeEmitter::StartAttachment ( [const ] in string  name,
[const ] in string  contentType,
[const ] in string  url,
in PRBool  aNotDownloaded 
) [inherited]

Here is the caller graph for this function:

void nsIMimeEmitter::StartBody ( in PRBool  bodyOnly,
[const ] in string  msgID,
[const ] in string  outCharset 
) [inherited]

Here is the caller graph for this function:

nsresult nsMimePlainEmitter::StartHeader ( PRBool  rootMailHeader,
PRBool  headerOnly,
const char *  msgID,
const char *  outCharset 
)

Definition at line 66 of file nsMimePlainEmitter.cpp.

{
  mDocHeader = rootMailHeader;
  return NS_OK; 
}
void nsIMimeEmitter::StartHeader ( in PRBool  rootMailHeader,
in PRBool  headerOnly,
[const ] in string  msgID,
[const ] in string  outCharset 
) [inherited]

Here is the caller graph for this function:

void nsIMimeEmitter::UpdateCharacterSet ( [const ] in string  aCharset) [inherited]

Here is the caller graph for this function:

void nsIMimeEmitter::UtilityWrite ( [const ] in string  buf) [inherited]

Here is the caller graph for this function:

Definition at line 449 of file nsMimeBaseEmitter.cpp.

{
  PRInt32     tmpLen = strlen(buf);
  PRUint32    written;

  Write(buf, tmpLen, &written);
  Write(CRLF, 2, &written);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMimeEmitter::Write ( [const ] in string  buf,
in PRUint32  size,
out PRUint32  amountWritten 
) [inherited]

Here is the caller graph for this function:

NS_IMETHODIMP nsMimePlainEmitter::WriteBody ( const char *  buf,
PRUint32  size,
PRUint32 amountWritten 
)

Definition at line 93 of file nsMimePlainEmitter.cpp.

{
  Write(buf, size, amountWritten);
  return NS_OK;
}

Here is the call graph for this function:

void nsIMimeEmitter::WriteBody ( [const ] in string  buf,
in PRUint32  size,
out PRUint32  amountWritten 
) [inherited]

Here is the caller graph for this function:

nsresult nsMimeBaseEmitter::WriteHeaderFieldHTML ( const char *  field,
const char *  value 
) [virtual, inherited]

Reimplemented in nsMimeHtmlDisplayEmitter.

Definition at line 697 of file nsMimeBaseEmitter.cpp.

{
  char  *newValue = nsnull;

  if ( (!field) || (!value) )
    return NS_OK;

  //
  // This is a check to see what the pref is for header display. If
  // We should only output stuff that corresponds with that setting.
  //
  if (!EmitThisHeaderForPrefSetting(mHeaderDisplayType, field))
    return NS_OK;

  if ( (mUnicodeConverter) && (mFormat != nsMimeOutput::nsMimeMessageSaveAs) )
  {
    nsXPIDLCString tValue;

    // we're going to need a converter to convert
    nsresult rv = mUnicodeConverter->DecodeMimeHeader(value, getter_Copies(tValue));
    if (NS_SUCCEEDED(rv) && tValue)
    {
      newValue = nsEscapeHTML(tValue);
    }
    else
    {
      newValue = nsEscapeHTML(value);
    }
  }
  else
  {
    newValue = nsCRT::strdup(value);
  }

  if (!newValue)
    return NS_OK;

  mHTMLHeaders.Append("<tr>");
  mHTMLHeaders.Append("<td>");

  if (mFormat == nsMimeOutput::nsMimeMessageSaveAs)
    mHTMLHeaders.Append("<b>");
  else
    mHTMLHeaders.Append("<div class=\"headerdisplayname\" style=\"display:inline;\">");

  // Here is where we are going to try to L10N the tagName so we will always
  // get a field name next to an emitted header value. Note: Default will always
  // be the name of the header itself.
  //
  nsCAutoString  newTagName(field);
  newTagName.CompressWhitespace(PR_TRUE, PR_TRUE);
  ToUpperCase(newTagName);

  char *l10nTagName = LocalizeHeaderName(newTagName.get(), field);
  if ( (!l10nTagName) || (!*l10nTagName) )
    mHTMLHeaders.Append(field);
  else
  {
    mHTMLHeaders.Append(l10nTagName);
    PR_FREEIF(l10nTagName);
  }

  mHTMLHeaders.Append(": ");
  if (mFormat == nsMimeOutput::nsMimeMessageSaveAs)
    mHTMLHeaders.Append("</b>");
  else
    mHTMLHeaders.Append("</div>");

  // Now write out the actual value itself and move on!
  //
  mHTMLHeaders.Append(newValue);
  mHTMLHeaders.Append("</td>");

  mHTMLHeaders.Append("</tr>");

  PR_FREEIF(newValue);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in nsMimeHtmlDisplayEmitter.

Definition at line 793 of file nsMimeBaseEmitter.cpp.

{
  mHTMLHeaders.Append("<br>");
  return NS_OK;
}

Reimplemented in nsMimeHtmlDisplayEmitter.

Definition at line 777 of file nsMimeBaseEmitter.cpp.

{
  if ( 
      ( (mFormat == nsMimeOutput::nsMimeMessageSaveAs) && (mFirstHeaders) ) ||
      ( (mFormat == nsMimeOutput::nsMimeMessagePrintOutput) && (mFirstHeaders) )
     )
     /* DO NOTHING */ ;   // rhp: Do nothing...leaving the conditional like this so its 
                          //      easier to see the logic of what is going on. 
  else
    mHTMLHeaders.Append("<br><hr width=\"90%\" size=4><br>");

  mFirstHeaders = PR_FALSE;
  return NS_OK;
}
nsresult nsMimeBaseEmitter::WriteHelper ( const char *  buf,
PRUint32  count,
PRUint32 countWritten 
) [protected, inherited]

Definition at line 513 of file nsMimeBaseEmitter.cpp.

{
  nsresult rv;

  rv = mOutStream->Write(buf, count, countWritten);
  if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
    // pipe is full, push contents of pipe to listener...
    PRUint32 avail;
    rv = mInputStream->Available(&avail);
    if (NS_SUCCEEDED(rv) && avail) {
      mOutListener->OnDataAvailable(mChannel, mURL, mInputStream, 0, avail);

      // try writing again...
      rv = mOutStream->Write(buf, count, countWritten);
    }
  }
  return rv;
}

Implemented in nsMimeHtmlDisplayEmitter.


Member Data Documentation

Definition at line 130 of file nsMimeBaseEmitter.h.

Definition at line 129 of file nsMimeBaseEmitter.h.

Definition at line 156 of file nsMimeBaseEmitter.h.

PRInt32 nsMimeBaseEmitter::mAttachCount [protected, inherited]

Reimplemented in nsMimeXmlEmitter.

Definition at line 155 of file nsMimeBaseEmitter.h.

nsCString nsMimeBaseEmitter::mBody [protected, inherited]

Definition at line 166 of file nsMimeBaseEmitter.h.

PRBool nsMimeBaseEmitter::mBodyStarted [protected, inherited]

Definition at line 165 of file nsMimeBaseEmitter.h.

Definition at line 133 of file nsMimeBaseEmitter.h.

nsIChannel* nsMimeBaseEmitter::mChannel [protected, inherited]

Definition at line 142 of file nsMimeBaseEmitter.h.

nsString nsMimeBaseEmitter::mCharset [protected, inherited]

Definition at line 174 of file nsMimeBaseEmitter.h.

Definition at line 157 of file nsMimeBaseEmitter.h.

PRBool nsMimeBaseEmitter::mDocHeader [protected, inherited]

Definition at line 149 of file nsMimeBaseEmitter.h.

Definition at line 161 of file nsMimeBaseEmitter.h.

PRBool nsMimeBaseEmitter::mFirstHeaders [protected, inherited]

Definition at line 167 of file nsMimeBaseEmitter.h.

PRInt32 nsMimeBaseEmitter::mFormat [protected, inherited]

Definition at line 170 of file nsMimeBaseEmitter.h.

Definition at line 160 of file nsMimeBaseEmitter.h.

Definition at line 151 of file nsMimeBaseEmitter.h.

Definition at line 162 of file nsMimeBaseEmitter.h.

Definition at line 152 of file nsMimeBaseEmitter.h.

Definition at line 140 of file nsMimeBaseEmitter.h.

Definition at line 141 of file nsMimeBaseEmitter.h.

Definition at line 139 of file nsMimeBaseEmitter.h.

PRUint32 nsMimeBaseEmitter::mTotalRead [protected, inherited]

Definition at line 146 of file nsMimeBaseEmitter.h.

Definition at line 145 of file nsMimeBaseEmitter.h.

Definition at line 173 of file nsMimeBaseEmitter.h.

nsIURI* nsMimeBaseEmitter::mURL [protected, inherited]

Definition at line 150 of file nsMimeBaseEmitter.h.


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