Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsLocalUtils.h File Reference
#include "nsFileSpec.h"
#include "nsString.h"
#include "nsIMsgIncomingServer.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

nsresult nsLocalURI2Path (const char *rootURI, const char *uriStr, nsFileSpec &pathResult)
nsresult nsParseLocalMessageURI (const char *uri, nsCString &folderURI, PRUint32 *key)
nsresult nsBuildLocalMessageURI (const char *baseURI, PRUint32 key, nsCString &uri)
nsresult nsCreateLocalBaseMessageURI (const char *baseURI, char **baseMessageURI)

Variables

static const char kMailboxRootURI [] = "mailbox:/"
static const char kMailboxMessageRootURI [] = "mailbox-message:/"

Function Documentation

nsresult nsBuildLocalMessageURI ( const char *  baseURI,
PRUint32  key,
nsCString uri 
)

Definition at line 254 of file nsLocalUtils.cpp.

{
  
  // need to convert mailbox://hostname/.. to mailbox-message://hostname/..

  uri.Append(baseURI);
  uri.Append('#');
  uri.AppendInt(key);
  return NS_OK;
}
nsresult nsCreateLocalBaseMessageURI ( const char *  baseURI,
char **  baseMessageURI 
)

Definition at line 265 of file nsLocalUtils.cpp.

{
  if(!baseMessageURI)
    return NS_ERROR_NULL_POINTER;

  nsCAutoString tailURI(baseURI);

  // chop off mailbox:/
  if (tailURI.Find(kMailboxRootURI) == 0)
    tailURI.Cut(0, PL_strlen(kMailboxRootURI));
  
  nsCAutoString baseURIStr(kMailboxMessageRootURI);
  baseURIStr += tailURI;

  *baseMessageURI = ToNewCString(baseURIStr);
  if(!*baseMessageURI)
    return NS_ERROR_OUT_OF_MEMORY;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsLocalURI2Path ( const char *  rootURI,
const char *  uriStr,
nsFileSpec pathResult 
)

Definition at line 155 of file nsLocalUtils.cpp.

{
  nsresult rv;
  
  // verify that rootURI starts with "mailbox:/" or "mailbox-message:/"
  if ((PL_strcmp(rootURI, kMailboxRootURI) != 0) && 
      (PL_strcmp(rootURI, kMailboxMessageRootURI) != 0)) {
    pathResult = nsnull;
    return NS_ERROR_FAILURE;
  }

  // verify that uristr starts with rooturi
  nsCAutoString uri(uriStr);
  if (uri.Find(rootURI) != 0)
    return NS_ERROR_FAILURE;


  nsCOMPtr<nsIMsgIncomingServer> server;
  rv = nsLocalURI2Server(uriStr, getter_AddRefs(server));

  if (NS_FAILED(rv))
    return rv;
  
  // now ask the server what it's root is
  // and begin pathResult with the mailbox root
  nsCOMPtr<nsIFileSpec> localPath;
  rv = server->GetLocalPath(getter_AddRefs(localPath));
  if (NS_SUCCEEDED(rv)) 
    localPath->GetFileSpec(&pathResult);

  const char *curPos = uriStr + PL_strlen(rootURI);
  if (curPos) {
    
    // advance past hostname
    while ((*curPos)=='/') curPos++;
    while (*curPos && (*curPos)!='/') curPos++;

    // get the separator
    nsAutoString sbdSep;
    rv = nsGetMailFolderSeparator(sbdSep);
    
       
    nsCAutoString newPath("");
    char *unescaped = nsCRT::strdup(curPos);  
    // Unescape folder name
    if (unescaped) {
      nsUnescape(unescaped);
      NS_MsgCreatePathStringFromFolderURI(unescaped, newPath);
      PR_Free(unescaped);
    }
    else
      NS_MsgCreatePathStringFromFolderURI(curPos, newPath);

    pathResult+=newPath.get();
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsParseLocalMessageURI ( const char *  uri,
nsCString folderURI,
PRUint32 key 
)

Definition at line 222 of file nsLocalUtils.cpp.

{
  if(!key)
    return NS_ERROR_NULL_POINTER;

  nsCAutoString uriStr(uri);
  PRInt32 keySeparator = uriStr.FindChar('#');
  if(keySeparator != -1)
  {
    PRInt32 keyEndSeparator = uriStr.FindCharInSet("?&", 
                                                   keySeparator); 
    nsAutoString folderPath;
    uriStr.Left(folderURI, keySeparator);
        folderURI.Cut(7, 8);    // cut out the -message part of mailbox-message:

    nsCAutoString keyStr;
    if (keyEndSeparator != -1)
        uriStr.Mid(keyStr, keySeparator+1, 
                   keyEndSeparator-(keySeparator+1));
    else
        uriStr.Right(keyStr, uriStr.Length() - (keySeparator + 1));
    PRInt32 errorCode;
    *key = keyStr.ToInteger(&errorCode);

    return errorCode;
  }
  return NS_ERROR_FAILURE;

}

Here is the caller graph for this function:


Variable Documentation

const char kMailboxMessageRootURI[] = "mailbox-message:/" [static]

Definition at line 46 of file nsLocalUtils.h.

const char kMailboxRootURI[] = "mailbox:/" [static]

Definition at line 45 of file nsLocalUtils.h.