Back to index

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

#include <nsIMAPNamespace.h>

List of all members.

Public Member Functions

 ~nsIMAPNamespaceList ()
nsresult InitFromString (const char *nameSpaceString, EIMAPNamespaceType nstype)
nsresult OutputToString (nsCString &OutputString)
int UnserializeNamespaces (const char *str, char **prefixes, int len)
nsresult SerializeNamespaces (char **prefixes, int len, nsCString &serializedNamespace)
void ClearNamespaces (PRBool deleteFromPrefsNamespaces, PRBool deleteServerAdvertisedNamespaces, PRBool reallyDelete)
int GetNumberOfNamespaces ()
int GetNumberOfNamespaces (EIMAPNamespaceType)
nsIMAPNamespaceGetNamespaceNumber (int nodeIndex)
nsIMAPNamespaceGetNamespaceNumber (int nodeIndex, EIMAPNamespaceType)
nsIMAPNamespaceGetDefaultNamespaceOfType (EIMAPNamespaceType type)
int AddNewNamespace (nsIMAPNamespace *ns)
nsIMAPNamespaceGetNamespaceForMailbox (const char *boxname)

Static Public Member Functions

static nsIMAPNamespaceListCreatensIMAPNamespaceList ()
static nsIMAPNamespaceGetNamespaceForFolder (const char *hostName, const char *canonicalFolderName, char delimiter)
static PRBool GetFolderIsNamespace (const char *hostName, const char *canonicalFolderName, char delimiter, nsIMAPNamespace *namespaceForFolder)
static char * GetFolderNameWithoutNamespace (nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName)
static char * AllocateServerFolderName (const char *canonicalFolderName, char delimiter)
static char * GetFolderOwnerNameFromPath (nsIMAPNamespace *namespaceForFolder, const char *canonicalFolderName)
static char * AllocateCanonicalFolderName (const char *onlineFolderName, char delimiter)
static void SuggestHierarchySeparatorForNamespace (nsIMAPNamespace *namespaceForFolder, char delimiterFromFolder)
static char * GenerateFullFolderNameWithDefaultNamespace (const char *hostName, const char *canonicalFolderName, const char *owner, EIMAPNamespaceType nsType, nsIMAPNamespace **nsUsed)

Protected Member Functions

 nsIMAPNamespaceList ()

Protected Attributes

nsVoidArray m_NamespaceList

Detailed Description

Definition at line 71 of file nsIMAPNamespace.h.


Constructor & Destructor Documentation

Definition at line 221 of file nsIMAPNamespace.cpp.

Here is the call graph for this function:

Definition at line 99 of file nsIMAPNamespace.cpp.

{
}

Here is the caller graph for this function:


Member Function Documentation

Definition at line 159 of file nsIMAPNamespace.cpp.

{
       // If the namespace is from the NAMESPACE response, then we should see if there
       // are any namespaces previously set by the preferences, or the default namespace.  If so, remove these.

       if (!ns->GetIsNamespaceFromPrefs())
       {
              int nodeIndex;
        // iterate backwards because we delete elements
              for (nodeIndex=m_NamespaceList.Count()-1; nodeIndex >= 0; nodeIndex--)
              {
                     nsIMAPNamespace *nspace = (nsIMAPNamespace *) m_NamespaceList.ElementAt(nodeIndex);
                     // if we find existing namespace(s) that matches the 
                     // new one, we'll just remove the old ones and let the
                     // new one get added when we've finished checking for
                     // matching namespaces or namespaces that came from prefs.
                     if (nspace &&
                            (nspace->GetIsNamespaceFromPrefs() ||
                            (!PL_strcmp(ns->GetPrefix(), nspace->GetPrefix()) &&
                          ns->GetType() == nspace->GetType() &&
                          ns->GetDelimiter() == nspace->GetDelimiter())))
                     {
                            m_NamespaceList.RemoveElementAt(nodeIndex);
                            delete nspace; 
                     }
              }
       }

       // Add the new namespace to the list.  This must come after the removing code,
       // or else we could never add the initial kDefaultNamespace type to the list.
       m_NamespaceList.AppendElement(ns);

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsIMAPNamespaceList::AllocateCanonicalFolderName ( const char *  onlineFolderName,
char  delimiter 
) [static]

Definition at line 418 of file nsIMAPNamespace.cpp.

{
  char *canonicalPath = nsnull;
  if (delimiter)
    canonicalPath = nsImapUrl::ReplaceCharsInCopiedString(onlineFolderName, delimiter , '/');
  else
    canonicalPath = PL_strdup(onlineFolderName);
  
  // eat any escape characters for escaped dir separators
  if (canonicalPath)
  {
    char *currentEscapeSequence = strstr(canonicalPath, "\\/");
    while (currentEscapeSequence)
    {
      strcpy(currentEscapeSequence, currentEscapeSequence+1);
      currentEscapeSequence = strstr(currentEscapeSequence+1, "\\/");
    }
  }
  
  return canonicalPath;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsIMAPNamespaceList::AllocateServerFolderName ( const char *  canonicalFolderName,
char  delimiter 
) [static]

Definition at line 512 of file nsIMAPNamespace.cpp.

{
  if (delimiter)
    return nsImapUrl::ReplaceCharsInCopiedString(canonicalFolderName, '/', delimiter);
  else
    return nsCRT::strdup(canonicalFolderName);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMAPNamespaceList::ClearNamespaces ( PRBool  deleteFromPrefsNamespaces,
PRBool  deleteServerAdvertisedNamespaces,
PRBool  reallyDelete 
)

Definition at line 227 of file nsIMAPNamespace.cpp.

{
       int nodeIndex;
       
    // iterate backwards because we delete elements
       for (nodeIndex=m_NamespaceList.Count()-1; nodeIndex >= 0; nodeIndex--)
       {
              nsIMAPNamespace *ns = (nsIMAPNamespace *) m_NamespaceList.ElementAt(nodeIndex);
              if (ns->GetIsNamespaceFromPrefs())
              {
                     if (deleteFromPrefsNamespaces)
                     {
                            m_NamespaceList.RemoveElementAt(nodeIndex);
                            if (reallyDelete)
                                   delete ns;
                     }
              }
              else if (deleteServerAdvertisedNamespaces)
              {
                     m_NamespaceList.RemoveElementAt(nodeIndex);
                     if (reallyDelete)
                            delete ns;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 93 of file nsIMAPNamespace.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsIMAPNamespaceList::GenerateFullFolderNameWithDefaultNamespace ( const char *  hostName,
const char *  canonicalFolderName,
const char *  owner,
EIMAPNamespaceType  nsType,
nsIMAPNamespace **  nsUsed 
) [static]

Definition at line 636 of file nsIMAPNamespace.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr<nsIImapHostSessionList> hostSession = 
           do_GetService(kCImapHostSessionListCID, &rv);
  NS_ENSURE_SUCCESS(rv, nsnull);
  nsIMAPNamespace *ns;
  char *fullFolderName = nsnull;
  rv = hostSession->GetDefaultNamespaceOfTypeForHost(hostName, nsType, ns);
  NS_ENSURE_SUCCESS(rv, nsnull);
  if (ns)
  {
    if (nsUsed)
      *nsUsed = ns;
    const char *prefix = ns->GetPrefix();
    char *convertedFolderName = AllocateServerFolderName(canonicalFolderName, ns->GetDelimiter());
    if (convertedFolderName)
    {
      char *convertedReturnName = nsnull;
      if (owner)
      {
        convertedReturnName = PR_smprintf("%s%s%c%s", prefix, owner, ns->GetDelimiter(), convertedFolderName);
      }
      else
      {
        convertedReturnName = PR_smprintf("%s%s", prefix, convertedFolderName);
      }
      
      if (convertedReturnName)
      {
        fullFolderName = AllocateCanonicalFolderName(convertedReturnName, ns->GetDelimiter());
        PR_Free(convertedReturnName);
      }
      PR_Free(convertedFolderName);
    }
    else
    {
      NS_ASSERTION(PR_FALSE, "couldn't allocate server folder name");
    }
  }
  else
  {
    // Could not find other users namespace on the given host
    NS_ASSERTION(PR_FALSE, "couldn't find namespace for given host");
  }
  return (fullFolderName);
}

Here is the call graph for this function:

Definition at line 196 of file nsIMAPNamespace.cpp.

{
       nsIMAPNamespace *rv = 0, *firstOfType = 0;

       int nodeIndex, count = m_NamespaceList.Count();
       for (nodeIndex= 0; nodeIndex < count && !rv; nodeIndex++)
       {
              nsIMAPNamespace *ns = (nsIMAPNamespace *) m_NamespaceList.ElementAt(nodeIndex);
              if (ns->GetType() == type)
              {
                     if (!firstOfType)
                            firstOfType = ns;
                     if (!(*(ns->GetPrefix())))
                     {
                            // This namespace's prefix is ""
                            // Therefore it is the default
                            rv = ns;
                     }
              }
       }
       if (!rv)
              rv = firstOfType;
       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsIMAPNamespaceList::GetFolderIsNamespace ( const char *  hostName,
const char *  canonicalFolderName,
char  delimiter,
nsIMAPNamespace namespaceForFolder 
) [static]

Definition at line 572 of file nsIMAPNamespace.cpp.

{
  NS_ASSERTION(namespaceForFolder, "null namespace");
  
  PRBool rv = PR_FALSE;
  
  const char *prefix = namespaceForFolder->GetPrefix();
  NS_ASSERTION(prefix, "namespace has no prefix");
  if (!prefix || !*prefix)  // empty namespace prefix
    return PR_FALSE;
  
  char *convertedFolderName = AllocateServerFolderName(canonicalFolderName, delimiter);
  if (convertedFolderName)
  {
    PRBool lastCharIsDelimiter = (prefix[strlen(prefix) - 1] == delimiter);
    
    if (lastCharIsDelimiter)
    {
      rv = ((strncmp(convertedFolderName, prefix, strlen(convertedFolderName)) == 0) &&
        (strlen(convertedFolderName) == strlen(prefix) - 1));
    }
    else
    {
      rv = (strcmp(convertedFolderName, prefix) == 0);
    }
    
    PR_Free(convertedFolderName);
  }
  else
  {
    NS_ASSERTION(PR_FALSE, "couldn't allocate server folder name");
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsIMAPNamespaceList::GetFolderNameWithoutNamespace ( nsIMAPNamespace namespaceForFolder,
const char *  canonicalFolderName 
) [static]

Definition at line 451 of file nsIMAPNamespace.cpp.

{
  NS_ASSERTION(canonicalFolderName, "null folder name");
#ifdef DEBUG
  NS_ASSERTION(namespaceForFolder || !PL_strcasecmp(canonicalFolderName, "INBOX"), "need namespace or INBOX");
#endif
  
  char *retFolderName = nsnull;
  
  if (!PL_strcasecmp(canonicalFolderName, "INBOX"))
    return PL_strdup(canonicalFolderName);
  
  // convert the canonical path to the online path
  char *convertedFolderName = nsIMAPNamespaceList::AllocateServerFolderName(canonicalFolderName, namespaceForFolder->GetDelimiter());
  if (convertedFolderName)
  {
    char *beginFolderPath = nsnull;
    if (strlen(convertedFolderName) <= strlen(namespaceForFolder->GetPrefix()))
      beginFolderPath = convertedFolderName;
    else
      beginFolderPath = convertedFolderName + strlen(namespaceForFolder->GetPrefix());
    NS_ASSERTION(beginFolderPath, "empty folder path");
    retFolderName = nsIMAPNamespaceList::AllocateCanonicalFolderName(beginFolderPath, namespaceForFolder->GetDelimiter());
    PR_Free(convertedFolderName);
  }
  
  NS_ASSERTION(retFolderName, "returning null folder name");
  return retFolderName;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * nsIMAPNamespaceList::GetFolderOwnerNameFromPath ( nsIMAPNamespace namespaceForFolder,
const char *  canonicalFolderName 
) [static]

Definition at line 528 of file nsIMAPNamespace.cpp.

{
  if (!namespaceForFolder || !canonicalFolderName)
  {
    NS_ASSERTION(PR_FALSE,"null namespace or canonical folder name");
    return nsnull;
  }
  
  char *rv = nsnull;
  
  // convert the canonical path to the online path
  char *convertedFolderName = AllocateServerFolderName(canonicalFolderName, namespaceForFolder->GetDelimiter());
  if (convertedFolderName)
  {
#ifdef DEBUG
    NS_ASSERTION(strlen(convertedFolderName) > strlen(namespaceForFolder->GetPrefix()), "server folder name invalid");
#endif
    if (strlen(convertedFolderName) > strlen(namespaceForFolder->GetPrefix()))
    {
      char *owner = convertedFolderName + strlen(namespaceForFolder->GetPrefix());
      NS_ASSERTION(owner, "couldn't find folder owner");
      char *nextDelimiter = strchr(owner, namespaceForFolder->GetDelimiter());
      // if !nextDelimiter, then the path is of the form Shared/Users/chrisf   (no subfolder)
      if (nextDelimiter)
      {
        *nextDelimiter = 0;
      }
      rv = PL_strdup(owner);
    }
    PR_Free(convertedFolderName);
  }
  else
  {
    NS_ASSERTION(PR_FALSE, "couldn't allocate server folder name");
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIMAPNamespace * nsIMAPNamespaceList::GetNamespaceForFolder ( const char *  hostName,
const char *  canonicalFolderName,
char  delimiter 
) [static]

Definition at line 482 of file nsIMAPNamespace.cpp.

{
  if (!hostName || !canonicalFolderName)
    return nsnull;
  
  nsIMAPNamespace *resultNamespace = nsnull;
  nsresult rv;
  char *convertedFolderName = nsIMAPNamespaceList::AllocateServerFolderName(canonicalFolderName, delimiter);

  if (convertedFolderName)
  {

    nsCOMPtr<nsIImapHostSessionList> hostSessionList = 
             do_GetService(kCImapHostSessionListCID, &rv);
    if (NS_FAILED(rv)) 
      return nsnull;
    hostSessionList->GetNamespaceForMailboxForHost(hostName, convertedFolderName, resultNamespace);
    PR_Free(convertedFolderName);
  }
  else
  {
    NS_ASSERTION(PR_FALSE, "couldn't get converted folder name");
  }
  
  return resultNamespace;
}

Here is the call graph for this function:

Definition at line 278 of file nsIMAPNamespace.cpp.

{
  // We want to find the LONGEST substring that matches the beginning of this mailbox's path.
  // This accounts for nested namespaces  (i.e. "Public/" and "Public/Users/")
  
  // Also, we want to match the namespace's mailbox to that namespace also:
  // The Personal box will match the Personal/ namespace, etc.
  
  // these lists shouldn't be too long (99% chance there won't be more than 3 or 4)
  // so just do a linear search
  
  int lengthMatched = -1;
  int currentMatchedLength = -1;
  nsIMAPNamespace *rv = nsnull;
  int nodeIndex = 0;
  
  if (!PL_strcasecmp(boxname, "INBOX"))
    return GetDefaultNamespaceOfType(kPersonalNamespace);
  
  for (nodeIndex=m_NamespaceList.Count()-1; nodeIndex >= 0; nodeIndex--)
  {
    nsIMAPNamespace *nspace = (nsIMAPNamespace *) m_NamespaceList.ElementAt(nodeIndex);
    currentMatchedLength = nspace->MailboxMatchesNamespace(boxname);
    if (currentMatchedLength > lengthMatched)
    {
      rv = nspace;
      lengthMatched = currentMatchedLength;
    }
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 253 of file nsIMAPNamespace.cpp.

{
  NS_ASSERTION(nodeIndex >= 0 && nodeIndex < GetNumberOfNamespaces(), "invalid IMAP namespace node index");
  if (nodeIndex < 0) nodeIndex = 0;

  // XXX really could be just ElementAt; that's why we have the assertion
  return      (nsIMAPNamespace *) m_NamespaceList.SafeElementAt(nodeIndex);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 262 of file nsIMAPNamespace.cpp.

{
  int nodeCount, count = 0;
  for (nodeCount=m_NamespaceList.Count()-1; nodeCount >= 0; nodeCount--)
  {
    nsIMAPNamespace *nspace = (nsIMAPNamespace *) m_NamespaceList.ElementAt(nodeCount);
    if (nspace->GetType() == type)
    {
      count++;
      if (count == nodeIndex)
        return nspace;
    }
  }
  return nsnull;
}

Here is the call graph for this function:

Definition at line 103 of file nsIMAPNamespace.cpp.

{
       return m_NamespaceList.Count();
}

Here is the caller graph for this function:

Definition at line 145 of file nsIMAPNamespace.cpp.

{
       int nodeIndex = 0, count = 0;
       for (nodeIndex=m_NamespaceList.Count()-1; nodeIndex >= 0; nodeIndex--)
       {
              nsIMAPNamespace *nspace = (nsIMAPNamespace *) m_NamespaceList.ElementAt(nodeIndex);
              if (nspace->GetType() == type)
              {
                     count++;
              }
       }
       return count;
}

Here is the call graph for this function:

nsresult nsIMAPNamespaceList::InitFromString ( const char *  nameSpaceString,
EIMAPNamespaceType  nstype 
)

Definition at line 109 of file nsIMAPNamespace.cpp.

{
       nsresult rv = NS_OK;
       if (nameSpaceString)
       {
              int numNamespaces = UnserializeNamespaces(nameSpaceString, nsnull, 0);
              char **prefixes = (char**) PR_CALLOC(numNamespaces * sizeof(char*));
              if (prefixes)
              {
                     int len = UnserializeNamespaces(nameSpaceString, prefixes, numNamespaces);
                     for (int i = 0; i < len; i++)
                     {
                            char *thisns = prefixes[i];
                            char delimiter = '/';       // a guess
                            if (PL_strlen(thisns) >= 1)
                                   delimiter = thisns[PL_strlen(thisns)-1];
                            nsIMAPNamespace *ns = new nsIMAPNamespace(nstype, thisns, delimiter, PR_TRUE);
                            if (ns)
                                   AddNewNamespace(ns);
                            PR_FREEIF(thisns);
                     }
                     PR_Free(prefixes);
              }
       }

       return rv;
}

Here is the call graph for this function:

Definition at line 137 of file nsIMAPNamespace.cpp.

{
       nsresult rv = NS_OK;

       return rv;
}
nsresult nsIMAPNamespaceList::SerializeNamespaces ( char **  prefixes,
int  len,
nsCString serializedNamespace 
)

Definition at line 317 of file nsIMAPNamespace.cpp.

{
       nsresult rv = NS_OK;
       if (len <= 0)
              return rv;
       if (len == 1)
       {
              serializedNamespaces = prefixes[0];
              return rv;
       }
       else
       {
              for (int i = 0; i < len; i++)
              {
                     char *temp = nsnull;
                     if (i == 0)
                     {
                            serializedNamespaces += "\"";

                            temp = PR_smprintf("\"%s\"",prefixes[i]); /* quote the string */
                     }
                     else
                     {
                            serializedNamespaces += ',';
                     }
                     serializedNamespaces += prefixes[i];
                     serializedNamespaces += "\"";
              }
              return rv;
       }
}
void nsIMAPNamespaceList::SuggestHierarchySeparatorForNamespace ( nsIMAPNamespace namespaceForFolder,
char  delimiterFromFolder 
) [static]

Definition at line 617 of file nsIMAPNamespace.cpp.

{
  NS_ASSERTION(namespaceForFolder, "need namespace");
  if (namespaceForFolder && !namespaceForFolder->GetIsDelimiterFilledIn())
    namespaceForFolder->SetDelimiter(delimiterFromFolder, PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsIMAPNamespaceList::UnserializeNamespaces ( const char *  str,
char **  prefixes,
int  len 
)

Definition at line 354 of file nsIMAPNamespace.cpp.

{
  if (!str)
    return 0;
  if (!prefixes)
  {
    if (str[0] != '"')
      return 1;
    else
    {
      int count = 0;
      char *ourstr = PL_strdup(str);
      char *origOurStr = ourstr;
      if (ourstr)
      {
        char *token = nsCRT::strtok( ourstr, SERIALIZER_SEPARATORS, &ourstr );
        while (token != nsnull)
        {
          token = nsCRT::strtok( ourstr, SERIALIZER_SEPARATORS, &ourstr );
          count++;
        }
        PR_Free(origOurStr);
      }
      return count;
    }
  }
  else
  {
    if ((str[0] != '"') && (len >= 1))
    {
      prefixes[0] = PL_strdup(str);
      return 1;
    }
    else
    {
      int count = 0;
      char *ourstr = PL_strdup(str);
      char *origOurStr = ourstr;
      if (ourstr)
      {
        char *token = nsCRT::strtok( ourstr, SERIALIZER_SEPARATORS, &ourstr );
        while ((count < len) && (token != nsnull))
        {
          
          char *current = PL_strdup(token), *where = current;
          if (where[0] == '"')
            where++;
          if (where[PL_strlen(where)-1] == '"')
            where[PL_strlen(where)-1] = 0;
          prefixes[count] = PL_strdup(where);
          PR_FREEIF(current);
          token = nsCRT::strtok( ourstr, SERIALIZER_SEPARATORS, &ourstr );
          count++;
        }
        PR_Free(origOurStr);
      }
      return count;
    }
  }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 112 of file nsIMAPNamespace.h.


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