Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsLocalUtils.cpp File Reference
#include "msgCore.h"
#include "nsLocalUtils.h"
#include "nsIServiceManager.h"
#include "prsystem.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsEscape.h"
#include "nsIFileSpec.h"
#include "nsIMsgAccountManager.h"
#include "nsIMsgIncomingServer.h"
#include "nsIPop3IncomingServer.h"
#include "nsINoIncomingServer.h"
#include "nsMsgBaseCID.h"
#include "nsMsgUtils.h"
#include "nsNetCID.h"

Go to the source code of this file.

Functions

static nsresult nsGetMailboxServer (const char *uriStr, nsIMsgIncomingServer **aResult)
static nsresult nsLocalURI2Server (const char *uriStr, nsIMsgIncomingServer **aResult)
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)

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:

static nsresult nsGetMailboxServer ( const char *  uriStr,
nsIMsgIncomingServer **  aResult 
) [static]

Definition at line 62 of file nsLocalUtils.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsIURL> aUrl = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  rv = aUrl->SetSpec(nsDependentCString(uriStr));  
  if (NS_FAILED(rv)) return rv;

  // retrieve the AccountManager
  nsCOMPtr<nsIMsgAccountManager> accountManager = 
    do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;
  
  // find all local mail "no servers" matching the given hostname
  nsCOMPtr<nsIMsgIncomingServer> none_server;
  aUrl->SetScheme(NS_LITERAL_CSTRING("none"));
  // No unescaping of username or hostname done here.
  // The unescaping is done inside of FindServerByURI
  rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
                                  getter_AddRefs(none_server));
  if (NS_SUCCEEDED(rv)) {
    NS_ADDREF(*aResult = none_server);
    return rv;
  }
  
  // if that fails, look for the rss hosts matching the given hostname
  nsCOMPtr<nsIMsgIncomingServer> rss_server;
  aUrl->SetScheme(NS_LITERAL_CSTRING("rss"));
  rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
                                  getter_AddRefs(rss_server));
  if (NS_SUCCEEDED(rv))
  {
     NS_ADDREF(*aResult = rss_server);
     return rv;
  }
#ifdef HAVE_MOVEMAIL
  // find all movemail "servers" matching the given hostname
  nsCOMPtr<nsIMsgIncomingServer> movemail_server;
  aUrl->SetScheme(NS_LITERAL_CSTRING("movemail"));
  rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
                                  getter_AddRefs(movemail_server));
  if (NS_SUCCEEDED(rv)) {
    NS_ADDREF(*aResult = movemail_server);
    return rv;
  }
#endif /* HAVE_MOVEMAIL */

  // if that fails, look for the pop hosts matching the given hostname
  nsCOMPtr<nsIMsgIncomingServer> server;
  if (NS_FAILED(rv)) 
  {
    aUrl->SetScheme(NS_LITERAL_CSTRING("pop3"));
    rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
                                    getter_AddRefs(server));

    // if we can't find a pop server, maybe it's a local message 
    // in an imap hierarchy. look for an imap server.
    if (NS_FAILED(rv)) 
    {
      aUrl->SetScheme(NS_LITERAL_CSTRING("imap"));
      rv = accountManager->FindServerByURI(aUrl, PR_FALSE,
                                    getter_AddRefs(server));
    }
  }
  if (NS_SUCCEEDED(rv)) 
  {
    NS_ADDREF(*aResult = server);
    return rv;
  }

// if you fail after looking at all "pop3", "movemail" and "none" servers, you fail.
return rv;
}

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:

static nsresult nsLocalURI2Server ( const char *  uriStr,
nsIMsgIncomingServer **  aResult 
) [static]

Definition at line 139 of file nsLocalUtils.cpp.

{
  nsresult rv;


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

  NS_IF_ADDREF(*aResult = server);

  return rv;
}

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: