Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Enumerations | Functions
nsMessenger.cpp File Reference
#include "prsystem.h"
#include "nsMessenger.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsFileStream.h"
#include "nsIStringStream.h"
#include "nsEscape.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIFileSpec.h"
#include "nsILocalFile.h"
#include "nsISupportsObsolete.h"
#include "nsSpecialSystemDirectory.h"
#include "nsQuickSort.h"
#include "nsNativeCharsetUtils.h"
#include "nsMimeTypes.h"
#include "nsIURL.h"
#include "nsIPrompt.h"
#include "nsIStreamListener.h"
#include "nsIStreamConverterService.h"
#include "nsNetUtil.h"
#include "nsIFileURL.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFResource.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsLayoutCID.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsIWebBrowserPrint.h"
#include "nsIDOMWindowInternal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsIDocShellLoadInfo.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h"
#include "nsIWebNavigation.h"
#include "nsIMsgMailNewsUrl.h"
#include "nsMsgUtils.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgAccountManager.h"
#include "nsIMsgMailSession.h"
#include "nsIMailboxUrl.h"
#include "nsIMsgFolder.h"
#include "nsMsgFolderFlags.h"
#include "nsIMsgIncomingServer.h"
#include "nsIMsgMessageService.h"
#include "nsIMsgStatusFeedback.h"
#include "nsMsgRDFUtils.h"
#include "nsIMsgHdr.h"
#include "nsIMimeMiscStatus.h"
#include "nsMsgCompCID.h"
#include "nsMsgI18N.h"
#include "nsIMsgCopyService.h"
#include "nsIMsgCopyServiceListener.h"
#include "nsIMsgSendLater.h"
#include "nsIMsgSendLaterListener.h"
#include "nsIUrlListener.h"
#include "nsITransaction.h"
#include "nsMsgTxn.h"
#include "nsMsgMimeCID.h"
#include "nsIMimeConverter.h"
#include "nsMsgPrintEngine.h"
#include "nsIFilePicker.h"
#include "nsIStringBundle.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsCExternalHandlerService.h"
#include "nsIExternalProtocolService.h"
#include "nsIMIMEService.h"
#include "nsITransfer.h"
#include "nsILinkHandler.h"
#include "nsIParser.h"
#include "nsParserCIID.h"
#include "nsICharsetConverterManager.h"
#include "nsIContentSink.h"
#include "nsIHTMLToTextSink.h"

Go to the source code of this file.

Classes

class  nsSaveMsgListener
class  nsSaveAllAttachmentsState
class  SendLaterListener
struct  msgAttachment
class  nsAttachmentState
class  nsDelAttachListener

Defines

#define FOUR_K   4096
#define MESSENGER_SAVE_DIR_PREF_NAME   "messenger.save.dir"
#define MAILNEWS_ALLOW_PLUGINS_PREF_NAME   "mailnews.message_display.allow.plugins"
#define MIMETYPE_DELETED   "text/x-moz-deleted"
#define HTML_FILE_EXTENSION   ".htm"
#define HTML_FILE_EXTENSION2   ".html"
#define TEXT_FILE_EXTENSION   ".txt"
#define EML_FILE_EXTENSION   ".eml"
#define MESSENGER_STRING_URL   "chrome://messenger/locale/messenger.properties"

Enumerations

enum  MESSENGER_SAVEAS_FILE_TYPE { EML_FILE_TYPE = 0, HTML_FILE_TYPE = 1, TEXT_FILE_TYPE = 2, ANY_FILE_TYPE = 3 }

Functions

static NS_DEFINE_CID (kRDFServiceCID, NS_RDFSERVICE_CID)
static NS_DEFINE_CID (kMsgSendLaterCID, NS_MSGSENDLATER_CID)
static NS_DEFINE_CID (kCParserCID, NS_PARSER_CID)
static nsresult ConvertBufToPlainText (nsString &aConBuf)
nsresult ConvertAndSanitizeFileName (const char *displayName, PRUnichar **unicodeResult, char **result)
static char * GetAttachmentPartId (const char *aAttachmentUrl)
static int CompareAttachmentPartId (const char *aAttachUrlLeft, const char *aAttachUrlRight)

Define Documentation

#define EML_FILE_EXTENSION   ".eml"

Definition at line 1047 of file nsMessenger.cpp.

#define FOUR_K   4096

Definition at line 156 of file nsMessenger.cpp.

Definition at line 1044 of file nsMessenger.cpp.

Definition at line 1045 of file nsMessenger.cpp.

#define MAILNEWS_ALLOW_PLUGINS_PREF_NAME   "mailnews.message_display.allow.plugins"

Definition at line 158 of file nsMessenger.cpp.

#define MESSENGER_SAVE_DIR_PREF_NAME   "messenger.save.dir"

Definition at line 157 of file nsMessenger.cpp.

#define MESSENGER_STRING_URL   "chrome://messenger/locale/messenger.properties"

Definition at line 2212 of file nsMessenger.cpp.

#define MIMETYPE_DELETED   "text/x-moz-deleted"

Definition at line 160 of file nsMessenger.cpp.

Definition at line 1046 of file nsMessenger.cpp.


Enumeration Type Documentation

Enumerator:
EML_FILE_TYPE 
HTML_FILE_TYPE 
TEXT_FILE_TYPE 
ANY_FILE_TYPE 

Definition at line 1037 of file nsMessenger.cpp.


Function Documentation

static int CompareAttachmentPartId ( const char *  aAttachUrlLeft,
const char *  aAttachUrlRight 
) [static]

Definition at line 2501 of file nsMessenger.cpp.

{
  // part ids are numbers separated by periods, like "1.2.3.4".
  // we sort by doing a numerical comparison on each item in turn. e.g. "1.4" < "1.25"
  // shorter entries come before longer entries. e.g. "1.4" < "1.4.1.2"
  // return values:
  //  -2  left is a parent of right
  //  -1  left is less than right
  //   0  left == right
  //   1  right is greater than left
  //   2  right is a parent of left

  char * partIdLeft  = GetAttachmentPartId(aAttachUrlLeft);
  char * partIdRight = GetAttachmentPartId(aAttachUrlRight);

  // for detached attachments the URL does not contain any "part=xx"
  if(!partIdLeft)
    partIdLeft = "0";

  if(!partIdRight)
    partIdRight = "0";

  long idLeft, idRight;
  do
  {
    NS_ABORT_IF_FALSE(partIdLeft && NS_IS_DIGIT(*partIdLeft), "Invalid character in part id string");
    NS_ABORT_IF_FALSE(partIdRight && NS_IS_DIGIT(*partIdRight), "Invalid character in part id string");

    // if the part numbers are different then the numerically smaller one is first
    idLeft  = strtol(partIdLeft, &partIdLeft, 10);
    idRight = strtol(partIdRight, &partIdRight, 10);
    if (idLeft != idRight)
      return idLeft < idRight ? -1 : 1;
    
    // if one part id is complete but the other isn't, then the shortest one 
    // is first (parents before children)
    if (*partIdLeft != *partIdRight)
      return *partIdRight ? -2 : 2;

    // if both part ids are complete (*partIdLeft == *partIdRight now) then
    // they are equal
    if (!*partIdLeft)
      return 0;

    NS_ABORT_IF_FALSE(*partIdLeft == '.', "Invalid character in part id string");
    NS_ABORT_IF_FALSE(*partIdRight == '.', "Invalid character in part id string");

    ++partIdLeft;
    ++partIdRight;
  }
  while (PR_TRUE);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult ConvertAndSanitizeFileName ( const char *  displayName,
PRUnichar **  unicodeResult,
char **  result 
)

Definition at line 211 of file nsMessenger.cpp.

{
  nsCAutoString unescapedName(displayName);

  /* we need to convert the UTF-8 fileName to platform specific character set.
     The display name is in UTF-8 because it has been escaped from JS
  */ 
  NS_UnescapeURL(unescapedName);
  NS_ConvertUTF8toUCS2 ucs2Str(unescapedName);

  nsresult rv = NS_OK;
#if defined(XP_MAC)  /* reviewed for 1.4, XP_MACOSX not needed */
  /* We need to truncate the name to 31 characters, this even on MacOS X until the file API
     correctly support long file name. Using a nsILocalFile will do the trick...
  */
  nsCOMPtr<nsILocalFile> aLocalFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
  if (NS_SUCCEEDED(aLocalFile->SetLeafName(ucs2Str)))
  {
    aLocalFile->GetLeafName(ucs2Str);
  }
#endif

  // replace platform specific path separator and illegale characters to avoid any confusion
  ucs2Str.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '-');

  if (result) {
    nsCAutoString nativeStr;
    rv =  NS_CopyUnicodeToNative(ucs2Str, nativeStr);
    *result = ToNewCString(nativeStr);
  }

  if (unicodeResult)
    *unicodeResult = ToNewUnicode(ucs2Str);

 return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ConvertBufToPlainText ( nsString aConBuf) [static]

Definition at line 174 of file nsMessenger.cpp.

{
  if (aConBuf.IsEmpty())
    return NS_OK;

  nsresult rv;
  nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
  if (NS_SUCCEEDED(rv) && parser)
  {
    nsCOMPtr<nsIContentSink> sink;

    sink = do_CreateInstance(NS_PLAINTEXTSINK_CONTRACTID);
    NS_ENSURE_TRUE(sink, NS_ERROR_FAILURE);

    nsCOMPtr<nsIHTMLToTextSink> textSink(do_QueryInterface(sink));
    NS_ENSURE_TRUE(textSink, NS_ERROR_FAILURE);

    nsAutoString convertedText;
    textSink->Initialize(&convertedText, 0, 72);

    parser->SetContentSink(sink);

    parser->Parse(aConBuf, 0, NS_LITERAL_CSTRING("text/html"), PR_FALSE, PR_TRUE);

    //
    // Now if we get here, we need to get from ASCII text to 
    // UTF-8 format or there is a problem downstream...
    //
    if (NS_SUCCEEDED(rv))
    {
      aConBuf = convertedText;
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* GetAttachmentPartId ( const char *  aAttachmentUrl) [static]

Definition at line 2494 of file nsMessenger.cpp.

{
  static const char partIdPrefix[] = "part=";
  char * partId = PL_strstr(aAttachmentUrl, partIdPrefix);
  return partId ? (partId + sizeof(partIdPrefix) - 1) : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kRDFServiceCID  ,
NS_RDFSERVICE_CID   
) [static]
static NS_DEFINE_CID ( kMsgSendLaterCID  ,
NS_MSGSENDLATER_CID   
) [static]
static NS_DEFINE_CID ( kCParserCID  ,
NS_PARSER_CID   
) [static]