Back to index

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

#include <nsMimeHtmlEmitter.h>

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

List of all members.

Public Member Functions

 nsMimeHtmlDisplayEmitter ()
nsresult Init ()
virtual ~nsMimeHtmlDisplayEmitter (void)
NS_IMETHOD EndHeader ()
NS_IMETHOD StartAttachment (const char *name, const char *contentType, const char *url, PRBool aIsExternalAttachment)
NS_IMETHOD AddAttachmentField (const char *field, const char *value)
NS_IMETHOD EndAttachment ()
NS_IMETHOD EndAllAttachments ()
NS_IMETHOD WriteBody (const char *buf, PRUint32 size, PRUint32 *amountWritten)
NS_IMETHOD EndBody ()
NS_IMETHOD WriteHTMLHeaders ()
virtual nsresult WriteHeaderFieldHTMLPrefix ()
virtual nsresult WriteHeaderFieldHTML (const char *field, const char *value)
virtual nsresult WriteHeaderFieldHTMLPostfix ()
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)
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 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 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 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

nsresult GetHeaderSink (nsIMsgHeaderSink **aHeaderSink)
PRBool BroadCastHeadersAndAttachments ()
nsresult StartAttachmentInBody (const char *name, const char *contentType, const char *url)
nsresult GenerateDateString (const char *dateString, nsACString &formattedDate)
nsresult BroadcastHeaders (nsIMsgHeaderSink *aHeaderSink, PRInt32 aHeaderMode, PRBool aFromNewsgroup)
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

PRBool mFirst
PRBool mSkipAttachment
nsCOMPtr< nsIMsgHeaderSinkmHeaderSink
nsCOMPtr< nsIDateTimeFormatmDateFormater
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 53 of file nsMimeHtmlEmitter.h.


Constructor & Destructor Documentation

Definition at line 79 of file nsMimeHtmlEmitter.cpp.

{
}

Member Function Documentation

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

Definition at line 496 of file nsMimeHtmlEmitter.cpp.

{
  if (mSkipAttachment || BroadCastHeadersAndAttachments())
    return NS_OK;

  // Don't let bad things happen
  if ( !value || !*value )
    return NS_OK;

  // Don't output this ugly header...
  if (!strcmp(field, HEADER_X_MOZILLA_PART_URL))
    return NS_OK;

  char  *newValue = nsEscapeHTML(value);

  UtilityWrite("<tr>");

  UtilityWrite("<td>");
  UtilityWrite("<div align=right class=\"headerdisplayname\" style=\"display:inline;\">");

  UtilityWrite(field);
  UtilityWrite(":");
  UtilityWrite("</div>");
  UtilityWrite("</td>");
  UtilityWrite("<td>");

  UtilityWrite(newValue);

  UtilityWrite("</td>");
  UtilityWrite("</tr>");

  PR_Free(newValue);
  return NS_OK;
}

Here is the call graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

nsresult nsMimeHtmlDisplayEmitter::BroadcastHeaders ( nsIMsgHeaderSink aHeaderSink,
PRInt32  aHeaderMode,
PRBool  aFromNewsgroup 
) [protected]

Definition at line 156 of file nsMimeHtmlEmitter.cpp.

{
  // two string enumerators to pass out to the header sink
  nsCOMPtr<nsIUTF8StringEnumerator> headerNameEnumerator;
  nsCOMPtr<nsIUTF8StringEnumerator> headerValueEnumerator;

  // CStringArrays which we can pass into the enumerators
  nsCStringArray headerNameArray;
  nsCStringArray headerValueArray;
  nsXPIDLCString extraExpandedHeaders;
  nsCStringArray extraExpandedHeadersArray;
  nsCAutoString convertedDateString;

  PRBool displayOriginalDate = PR_FALSE;
  nsresult rv;
  nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  if (pPrefBranch)
  {
    pPrefBranch->GetBoolPref("mailnews.display.original_date", &displayOriginalDate);
    pPrefBranch->GetCharPref("mailnews.headers.extraExpandedHeaders", getter_Copies(extraExpandedHeaders));
    // todo - should make this upper case
    if (!extraExpandedHeaders.IsEmpty())
    {
      ToLowerCase(extraExpandedHeaders);
      extraExpandedHeadersArray.ParseString(extraExpandedHeaders, " ");
    }

  }

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

    const char * headerValue = headerInfo->value;

    // optimization: if we aren't in view all header view mode, we only show a small set of the total # of headers.
    // don't waste time sending those out to the UI since the UI is going to ignore them anyway. 
    if (aHeaderMode != VIEW_ALL_HEADERS && (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer)) 
    {
      nsDependentCString headerStr(headerInfo->name);
      if (nsCRT::strcasecmp("to", headerInfo->name) && nsCRT::strcasecmp("from", headerInfo->name) &&
          nsCRT::strcasecmp("cc", headerInfo->name) && nsCRT::strcasecmp("newsgroups", headerInfo->name) &&
          nsCRT::strcasecmp("bcc", headerInfo->name) && nsCRT::strcasecmp("followup-to", headerInfo->name) &&
          nsCRT::strcasecmp("reply-to", headerInfo->name) && nsCRT::strcasecmp("subject", headerInfo->name) &&
          nsCRT::strcasecmp("organization", headerInfo->name) && nsCRT::strcasecmp("user-agent", headerInfo->name) &&
          nsCRT::strcasecmp("content-base", headerInfo->name) && nsCRT::strcasecmp("sender", headerInfo->name) &&
          nsCRT::strcasecmp("date", headerInfo->name) && nsCRT::strcasecmp("x-mailer", headerInfo->name) &&
          nsCRT::strcasecmp("content-type", headerInfo->name) && nsCRT::strcasecmp("message-id", headerInfo->name) &&
          nsCRT::strcasecmp("x-newsreader", headerInfo->name) && nsCRT::strcasecmp("x-mimeole", headerInfo->name) &&
          // make headerStr lower case because IndexOf is case-sensitive
         (!extraExpandedHeadersArray.Count() || (ToLowerCase(headerStr),
            extraExpandedHeadersArray.IndexOf(headerStr) == kNotFound)))
            continue;
    }

    if (!nsCRT::strcasecmp("Date", headerInfo->name) && !displayOriginalDate) 
    {
      GenerateDateString(headerValue, convertedDateString); 
      headerValueArray.AppendCString(convertedDateString);
    }
    else // append the header value as is
      headerValueArray.AppendCString(nsCString(headerValue));

    // XXX: TODO If nsCStringArray were converted over to take nsACStrings instead of nsCStrings, we can just 
    // wrap these strings with a nsDependentCString which would avoid making a duplicate copy of the string
    // like we are doing here....
    headerNameArray.AppendCString(nsCString(headerInfo->name));
  }

  // turn our string arrays into enumerators
  NS_NewUTF8StringEnumerator(getter_AddRefs(headerNameEnumerator), &headerNameArray);
  NS_NewUTF8StringEnumerator(getter_AddRefs(headerValueEnumerator), &headerValueArray);

  aHeaderSink->ProcessHeaders(headerNameEnumerator, headerValueEnumerator, aFromNewsgroup);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file nsMimeHtmlEmitter.cpp.

{
  // try to get a header sink if there is one....
  nsCOMPtr<nsIMsgHeaderSink> headerSink; 
  nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
  if (NS_SUCCEEDED(rv) && headerSink && mDocHeader)
    return PR_TRUE;
  else
    return PR_FALSE;
}

Here is the call graph for this function:

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:

Implements nsIMimeEmitter.

Definition at line 555 of file nsMimeHtmlEmitter.cpp.

{
  nsresult rv = NS_OK;
  nsCOMPtr<nsIMsgHeaderSink> headerSink; 
  rv = GetHeaderSink(getter_AddRefs(headerSink));
  if (headerSink)
         headerSink->OnEndAllAttachments();
  return rv;
}

Here is the call graph for this function:

Implements nsIMimeEmitter.

Definition at line 532 of file nsMimeHtmlEmitter.cpp.

{
  if (mSkipAttachment)
    return NS_OK;

  mSkipAttachment = PR_FALSE; // reset it for next attachment round

  if (BroadCastHeadersAndAttachments())
    return NS_OK;

  if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput) {
    UtilityWrite("</table>");
    UtilityWrite("</td>");
    UtilityWrite("</tr>");

    UtilityWrite("</table>");
    UtilityWrite("</center>");
    UtilityWrite("<br>");
  }
  return NS_OK;
}

Here is the call graph for this function:

Implements nsIMimeEmitter.

Definition at line 573 of file nsMimeHtmlEmitter.cpp.

{
  if (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer)
  {
  UtilityWriteCRLF("</body>");
  UtilityWriteCRLF("</html>");
  }
  nsCOMPtr<nsIMsgHeaderSink> headerSink; 
  nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
  nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl (do_QueryInterface(mURL, &rv));
  if (headerSink)
    headerSink->OnEndMsgHeaders(mailnewsUrl);

  return NS_OK;
}

Here is the call graph for this function:

Implements nsIMimeEmitter.

Definition at line 349 of file nsMimeHtmlEmitter.cpp.

{
  if (mDocHeader && (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer))
  {
    UtilityWriteCRLF("<html>");
    UtilityWriteCRLF("<head>");

    const char * val = GetHeaderValue(HEADER_SUBJECT); // do not free this value
    if (val)
    {
      char * subject = nsEscapeHTML(val);
      if (subject)
      {
        PRInt32 bufLen = strlen(subject) + 16;
        char *buf = new char[bufLen];
        if (!buf)
          return NS_ERROR_OUT_OF_MEMORY;
        PR_snprintf(buf, bufLen, "<title>%s</title>", subject);
        UtilityWriteCRLF(buf);
        delete [] buf;
        nsMemory::Free(subject);
      }
    }

    // mscott --> we should refer to the style sheet used in msg display...this one is wrong i think.
    // Stylesheet info!
    UtilityWriteCRLF("<link rel=\"important stylesheet\" href=\"chrome://messenger/skin/messageBody.css\">");

    UtilityWriteCRLF("</head>");
    UtilityWriteCRLF("<body>");
  }

  WriteHTMLHeaders();
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsMimeHtmlDisplayEmitter::GenerateDateString ( const char *  dateString,
nsACString &  formattedDate 
) [protected]

Definition at line 286 of file nsMimeHtmlEmitter.cpp.

{
  nsAutoString formattedDateString;
  nsresult rv = NS_OK;

  if (!mDateFormater) {
    mDateFormater = do_CreateInstance(kDateTimeFormatCID, &rv);
    if (NS_FAILED(rv))
      return rv;
  }

  PRTime messageTime;
  PR_ParseTimeString(dateString, PR_FALSE, &messageTime);

  PRTime currentTime = PR_Now();
  PRExplodedTime explodedCurrentTime;
  PR_ExplodeTime(currentTime, PR_LocalTimeParameters, &explodedCurrentTime);
  PRExplodedTime explodedMsgTime;
  PR_ExplodeTime(messageTime, PR_LocalTimeParameters, &explodedMsgTime);

  // if the message is from today, don't show the date, only the time. (i.e. 3:15 pm)
  // if the message is from the last week, show the day of the week.   (i.e. Mon 3:15 pm)
  // in all other cases, show the full date (03/19/01 3:15 pm)
  nsDateFormatSelector dateFormat = kDateFormatShort;
  if (explodedCurrentTime.tm_year == explodedMsgTime.tm_year &&
      explodedCurrentTime.tm_month == explodedMsgTime.tm_month &&
      explodedCurrentTime.tm_mday == explodedMsgTime.tm_mday)
  {
    // same day...
    dateFormat = kDateFormatNone;
  } 
  // the following chunk of code causes us to show a day instead of a number if the message was received
  // within the last 7 days. i.e. Mon 5:10pm. We need to add a preference so folks to can enable this behavior
  // if they want it. 
/*
  else if (LL_CMP(currentTime, >, dateOfMsg))
  {
    PRInt64 microSecondsPerSecond, secondsInDays, microSecondsInDays;
         LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
    LL_UI2L(secondsInDays, 60 * 60 * 24 * 7); // how many seconds in 7 days.....
         LL_MUL(microSecondsInDays, secondsInDays, microSecondsPerSecond); // turn that into microseconds

    PRInt64 diff;
    LL_SUB(diff, currentTime, dateOfMsg);
    if (LL_CMP(diff, <=, microSecondsInDays)) // within the same week 
      dateFormat = kDateFormatWeekday;
  }
*/

  if (NS_SUCCEEDED(rv)) 
    rv = mDateFormater->FormatPRTime(nsnull /* nsILocale* locale */,
                                      dateFormat,
                                      kTimeFormatNoSeconds,
                                      messageTime,
                                      formattedDateString);

  if (NS_SUCCEEDED(rv))
    CopyUTF16toUTF8(formattedDateString, formattedDate);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 127 of file nsMimeHtmlEmitter.cpp.

{
  nsresult rv = NS_OK;
  if ( (mChannel) && (!mHeaderSink) )
  {
    nsCOMPtr<nsIURI> uri;
    mChannel->GetURI(getter_AddRefs(uri));
    if (uri)
    {
      nsCOMPtr<nsIMsgMailNewsUrl> msgurl (do_QueryInterface(uri));
      if (msgurl)
      {
        msgurl->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
        if (!mHeaderSink)  // if the url is not overriding the header sink, then just get the one from the msg window
        {
        nsCOMPtr<nsIMsgWindow> msgWindow;
        msgurl->GetMsgWindow(getter_AddRefs(msgWindow));
        if (msgWindow)
          msgWindow->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
      }
    }
  }
  }

  *aHeaderSink = mHeaderSink;
  NS_IF_ADDREF(*aHeaderSink);
  return rv;
}

Here is the call graph for this function:

Here is the caller 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.

Definition at line 83 of file nsMimeHtmlEmitter.cpp.

{
  return NS_OK;
}
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]
nsresult nsMimeHtmlDisplayEmitter::StartAttachment ( const char *  name,
const char *  contentType,
const char *  url,
PRBool  aIsExternalAttachment 
)

Definition at line 386 of file nsMimeHtmlEmitter.cpp.

{
  nsresult rv = NS_OK;
  nsCOMPtr<nsIMsgHeaderSink> headerSink; 
  rv = GetHeaderSink(getter_AddRefs(headerSink));
  
  if (NS_SUCCEEDED(rv) && headerSink)
  {    
    char * escapedUrl = nsEscape(url, url_Path);
    nsXPIDLCString uriString;

    nsCOMPtr<nsIMsgMessageUrl> msgurl (do_QueryInterface(mURL, &rv));
    if (NS_SUCCEEDED(rv))
    {
      // HACK: news urls require us to use the originalSpec. Everyone
      // else uses GetURI to get the RDF resource which describes the message.
      nsCOMPtr<nsINntpUrl> nntpUrl (do_QueryInterface(mURL, &rv));
      if (NS_SUCCEEDED(rv) && nntpUrl)
        rv = msgurl->GetOriginalSpec(getter_Copies(uriString));
      else
        rv = msgurl->GetUri(getter_Copies(uriString));
    }

    // we need to convert the attachment name from UTF-8 to unicode before
    // we emit it...
    nsXPIDLString unicodeHeaderValue;

    rv = NS_ERROR_FAILURE;  // use failure to mean that we couldn't decode
    if (mUnicodeConverter)
      rv = mUnicodeConverter->DecodeMimeHeader(name,
                                             getter_Copies(unicodeHeaderValue));

    if (NS_FAILED(rv))
    {
      CopyUTF8toUTF16(name, unicodeHeaderValue);

      // but it's not really a failure if we didn't have a converter
      // in the first place
      if ( !mUnicodeConverter )
        rv = NS_OK;
    }

    headerSink->HandleAttachment(contentType, url /* was escapedUrl */,
                                 unicodeHeaderValue, uriString,
                                 aIsExternalAttachment);

    nsCRT::free(escapedUrl);
    mSkipAttachment = PR_TRUE;
  }
  else if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
  {
    // then we need to deal with the attachments in the body by inserting
    // them into a table..
    rv = StartAttachmentInBody(name, contentType, url);
  }
  else
  {
    // If we don't need or cannot broadcast attachment info, just ignore it
    mSkipAttachment = PR_TRUE;
    rv = NS_OK;
  }

  return rv;
}

Here is the call graph for this function:

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:

nsresult nsMimeHtmlDisplayEmitter::StartAttachmentInBody ( const char *  name,
const char *  contentType,
const char *  url 
) [protected]

Definition at line 460 of file nsMimeHtmlEmitter.cpp.

{
  mSkipAttachment = PR_FALSE;

  if ( (contentType) &&
       ((!strcmp(contentType, APPLICATION_XPKCS7_MIME)) ||
        (!strcmp(contentType, APPLICATION_XPKCS7_SIGNATURE)) ||
        (!strcmp(contentType, TEXT_VCARD)))
     ) {
     mSkipAttachment = PR_TRUE;
     return NS_OK;
  }

  if (!mFirst)
    UtilityWrite("<hr width=\"90%\" size=4>");

  mFirst = PR_FALSE;

  UtilityWrite("<center>");
  UtilityWrite("<table border>");
  UtilityWrite("<tr>");
  UtilityWrite("<td>");

  UtilityWrite("<div align=right class=\"headerdisplayname\" style=\"display:inline;\">");

  UtilityWrite(name);

  UtilityWrite("</div>");

  UtilityWrite("</td>");
  UtilityWrite("<td>");
  UtilityWrite("<table border=0>");
  return NS_OK;
}

Here is the call graph for this function:

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:

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:

nsresult nsMimeHtmlDisplayEmitter::WriteBody ( const char *  buf,
PRUint32  size,
PRUint32 amountWritten 
)

Definition at line 566 of file nsMimeHtmlEmitter.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 nsMimeHtmlDisplayEmitter::WriteHeaderFieldHTML ( const char *  field,
const char *  value 
) [virtual]

Reimplemented from nsMimeBaseEmitter.

Definition at line 109 of file nsMimeHtmlEmitter.cpp.

Here is the call graph for this function:

Reimplemented from nsMimeBaseEmitter.

Definition at line 118 of file nsMimeHtmlEmitter.cpp.

Here is the call graph for this function:

Reimplemented from nsMimeBaseEmitter.

Definition at line 100 of file nsMimeHtmlEmitter.cpp.

Here is the call graph for this function:

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;
}

Implements nsIMimeEmitter.

Definition at line 235 of file nsMimeHtmlEmitter.cpp.

{
  // if we aren't broadcasting headers OR printing...just do whatever
  // our base class does...
  if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
  {
    return nsMimeBaseEmitter::WriteHTMLHeaders();
  }
  else if (!BroadCastHeadersAndAttachments() || !mDocHeader)
  {
    // This needs to be here to correct the output format if we are
    // not going to broadcast headers to the XUL document.
    if (mFormat == nsMimeOutput::nsMimeMessageBodyDisplay)
      mFormat = nsMimeOutput::nsMimeMessagePrintOutput;

    return nsMimeBaseEmitter::WriteHTMLHeaders();
  }
  else
    mFirstHeaders = PR_FALSE;
 
  PRBool bFromNewsgroups = PR_FALSE;
  for (PRInt32 j=0; j < mHeaderArray->Count(); j++)
  {
    headerInfoType *headerInfo = (headerInfoType *)mHeaderArray->ElementAt(j);
    if (!(headerInfo && headerInfo->name && *headerInfo->name))
      continue;

    if (!nsCRT::strcasecmp("Newsgroups", headerInfo->name))
    {
      bFromNewsgroups = PR_TRUE;
         break;
    }
  }

  // try to get a header sink if there is one....
  nsCOMPtr<nsIMsgHeaderSink> headerSink; 
  nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));

  if (headerSink)
  {
  PRInt32 viewMode = 0;
  nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  if (pPrefBranch)
    rv = pPrefBranch->GetIntPref("mail.show_headers", &viewMode);

    rv = BroadcastHeaders(headerSink, viewMode, bFromNewsgroups);
  } // if header Sink

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


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.

Definition at line 89 of file nsMimeHtmlEmitter.h.

PRBool nsMimeBaseEmitter::mDocHeader [protected, inherited]

Definition at line 149 of file nsMimeBaseEmitter.h.

Definition at line 161 of file nsMimeBaseEmitter.h.

Definition at line 80 of file nsMimeHtmlEmitter.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 83 of file nsMimeHtmlEmitter.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.

Definition at line 81 of file nsMimeHtmlEmitter.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: