Back to index

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

#include <nsImapMailFolder.h>

Collaboration diagram for nsMsgIMAPFolderACL:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMsgIMAPFolderACL (nsImapMailFolder *folder)
 ~nsMsgIMAPFolderACL ()
PRBool SetFolderRightsForUser (const char *userName, const char *rights)
PRBool GetCanUserLookupFolder (const char *userName)
PRBool GetCanUserReadFolder (const char *userName)
PRBool GetCanUserStoreSeenInFolder (const char *userName)
PRBool GetCanUserWriteFolder (const char *userName)
PRBool GetCanUserInsertInFolder (const char *userName)
PRBool GetCanUserPostToFolder (const char *userName)
PRBool GetCanUserCreateSubfolder (const char *userName)
PRBool GetCanUserDeleteInFolder (const char *userName)
PRBool GetCanUserAdministerFolder (const char *userName)
PRBool GetCanILookupFolder ()
PRBool GetCanIReadFolder ()
PRBool GetCanIStoreSeenInFolder ()
PRBool GetCanIWriteFolder ()
PRBool GetCanIInsertInFolder ()
PRBool GetCanIPostToFolder ()
PRBool GetCanICreateSubfolder ()
PRBool GetCanIDeleteInFolder ()
PRBool GetCanIAdministerFolder ()
PRBool GetDoIHaveFullRightsForFolder ()
PRBool GetIsFolderShared ()
nsresult CreateACLRightsString (PRUnichar **rightsString)

Protected Member Functions

const char * GetRightsStringForUser (const char *userName)
PRBool GetFlagSetInRightsForUser (const char *userName, char flag, PRBool defaultIfNotFound)
void BuildInitialACLFromCache ()
void UpdateACLCache ()

Static Protected Member Functions

static PRBool PR_CALLBACK FreeHashRights (nsHashKey *aKey, void *aData, void *closure)

Protected Attributes

nsHashtable * m_rightsHash
nsImapMailFolderm_folder
PRInt32 m_aclCount

Detailed Description

Definition at line 133 of file nsImapMailFolder.h.


Constructor & Destructor Documentation

Definition at line 5760 of file nsImapMailFolder.cpp.

{
  NS_ASSERTION(folder, "need folder");
  m_folder = folder;
  m_rightsHash = new nsHashtable(24);
  m_aclCount = 0;
  BuildInitialACLFromCache();
}

Definition at line 5769 of file nsImapMailFolder.cpp.


Member Function Documentation

Definition at line 5776 of file nsImapMailFolder.cpp.

{
  nsCAutoString myrights;
  
  PRUint32 startingFlags;
  m_folder->GetAclFlags(&startingFlags);
  
  if (startingFlags & IMAP_ACL_READ_FLAG)
    myrights += "r";
  if (startingFlags & IMAP_ACL_STORE_SEEN_FLAG)
    myrights += "s";
  if (startingFlags & IMAP_ACL_WRITE_FLAG)
    myrights += "w";
  if (startingFlags & IMAP_ACL_INSERT_FLAG)
    myrights += "i";
  if (startingFlags & IMAP_ACL_POST_FLAG)
    myrights += "p";
  if (startingFlags & IMAP_ACL_CREATE_SUBFOLDER_FLAG)
    myrights +="c";
  if (startingFlags & IMAP_ACL_DELETE_FLAG)
    myrights += "dt";
  if (startingFlags & IMAP_ACL_ADMINISTER_FLAG)
    myrights += "a";
  
  if (!myrights.IsEmpty())
    SetFolderRightsForUser(nsnull, myrights.get());
}

Here is the call graph for this function:

Definition at line 6064 of file nsImapMailFolder.cpp.

{
  nsAutoString rights;
  nsXPIDLString curRight;
  nsCOMPtr<nsIStringBundle> bundle;
  nsresult rv = IMAPGetStringBundle(getter_AddRefs(bundle));
  NS_ENSURE_SUCCESS(rv, rv);

  if (GetDoIHaveFullRightsForFolder())
  {
    return bundle->GetStringFromID(IMAP_ACL_FULL_RIGHTS, rightsString);
  }
  else
  {
    if (GetCanIReadFolder())
    {
      bundle->GetStringFromID(IMAP_ACL_READ_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanIWriteFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_WRITE_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanIInsertInFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_INSERT_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanILookupFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_LOOKUP_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanIStoreSeenInFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_SEEN_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanIDeleteInFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_DELETE_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanICreateSubfolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_CREATE_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanIPostToFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_POST_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
    if (GetCanIAdministerFolder())
    {
      if (!rights.IsEmpty()) rights.AppendLiteral(", ");
      bundle->GetStringFromID(IMAP_ACL_ADMINISTER_RIGHT, getter_Copies(curRight));
      rights.Append(curRight);
    }
  }
  *rightsString = ToNewUnicode(rights);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsMsgIMAPFolderACL::FreeHashRights ( nsHashKey *  aKey,
void aData,
void closure 
) [static, protected]

Definition at line 5753 of file nsImapMailFolder.cpp.

{
  PR_FREEIF(aData);
  return PR_TRUE;
}

Definition at line 6027 of file nsImapMailFolder.cpp.

Definition at line 6016 of file nsImapMailFolder.cpp.

Definition at line 6021 of file nsImapMailFolder.cpp.

Here is the caller graph for this function:

Definition at line 6006 of file nsImapMailFolder.cpp.

Here is the caller graph for this function:

Definition at line 5986 of file nsImapMailFolder.cpp.

Definition at line 6011 of file nsImapMailFolder.cpp.

Definition at line 5991 of file nsImapMailFolder.cpp.

Definition at line 5996 of file nsImapMailFolder.cpp.

Definition at line 6001 of file nsImapMailFolder.cpp.

Definition at line 5981 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'a', PR_FALSE);
}

Definition at line 5970 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'c', PR_FALSE);
}

Definition at line 5975 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'd', PR_FALSE)
    || GetFlagSetInRightsForUser(userName, 't', PR_FALSE);
}

Definition at line 5960 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'i', PR_FALSE);
}

Definition at line 5940 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'l', PR_FALSE);
}

Definition at line 5965 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'p', PR_FALSE);
}

Definition at line 5945 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'r', PR_FALSE);
}

Definition at line 5950 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 's', PR_FALSE);
}

Definition at line 5955 of file nsImapMailFolder.cpp.

{
  return GetFlagSetInRightsForUser(userName, 'w', PR_FALSE);
}
PRBool nsMsgIMAPFolderACL::GetFlagSetInRightsForUser ( const char *  userName,
char  flag,
PRBool  defaultIfNotFound 
) [protected]

Definition at line 5925 of file nsImapMailFolder.cpp.

{
  const char *flags = GetRightsStringForUser(userName);
  if (!flags)
  {
    const char *anyoneFlags = GetRightsStringForUser(IMAP_ACL_ANYONE_STRING);
    if (!anyoneFlags)
      return defaultIfNotFound;
    else
      return (strchr(anyoneFlags, flag) != nsnull);
  }
  else
    return (strchr(flags, flag) != nsnull);
}

Here is the call graph for this function:

Definition at line 6036 of file nsImapMailFolder.cpp.

{
  // If we have more than one ACL count for this folder, which means that someone
  // other than ourself has rights on it, then it is "shared."
  if (m_aclCount > 1)
    return PR_TRUE;
  
  // Or, if "anyone" has rights to it, it is shared.
  nsCStringKey hashKey(IMAP_ACL_ANYONE_STRING);
  const char *anyonesRights = (const char *)m_rightsHash->Get(&hashKey);
  
  return (anyonesRights != nsnull);
}

Here is the call graph for this function:

const char * nsMsgIMAPFolderACL::GetRightsStringForUser ( const char *  userName) [protected]

Definition at line 5902 of file nsImapMailFolder.cpp.

{
  nsXPIDLCString userName;
  userName.Assign(inUserName);
  if (userName.IsEmpty())
  {
    nsCOMPtr <nsIMsgIncomingServer> server;

    nsresult rv = m_folder->GetServer(getter_AddRefs(server));
    NS_ASSERTION(NS_SUCCEEDED(rv), "error getting server");
    if (NS_FAILED(rv)) return nsnull;
    // we need the real user name to match with what the imap server returns
    // in the acl response.
    server->GetRealUsername(getter_Copies(userName));
  }
  ToLowerCase(userName);
  nsCStringKey userKey(userName.get());
  
  return (const char *)m_rightsHash->Get(&userKey);
}

Here is the call graph for this function:

PRBool nsMsgIMAPFolderACL::SetFolderRightsForUser ( const char *  userName,
const char *  rights 
)

Definition at line 5852 of file nsImapMailFolder.cpp.

{
  PRBool ret = PR_FALSE;
  nsXPIDLCString myUserName;
  nsCOMPtr <nsIMsgIncomingServer> server;

  nsresult rv = m_folder->GetServer(getter_AddRefs(server));
  NS_ASSERTION(NS_SUCCEEDED(rv), "error getting server");
  if (NS_FAILED(rv)) 
    return PR_FALSE;
  // we need the real user name to match with what the imap server returns
  // in the acl response.
  server->GetRealUsername(getter_Copies(myUserName));

  nsCAutoString ourUserName;
  
  if (!userName)
    ourUserName.Assign(myUserName);
  else
    ourUserName.Assign(userName);

  if(ourUserName.IsEmpty())
    return ret;

  ToLowerCase(ourUserName);
  char *rightsWeOwn = PL_strdup(rights);
  nsCStringKey hashKey(ourUserName);
  if (rightsWeOwn)
  {
    char *oldValue = (char *) m_rightsHash->Get(&hashKey);
    if (oldValue)
    {
      PR_Free(oldValue);
      m_rightsHash->Remove(&hashKey);
      m_aclCount--;
      NS_ASSERTION(m_aclCount >= 0, "acl count can't go negative");
    }
    m_aclCount++;
    ret = (m_rightsHash->Put(&hashKey, rightsWeOwn) == 0);
  }
  
  if (myUserName.Equals(ourUserName) || ourUserName.EqualsLiteral(IMAP_ACL_ANYONE_STRING))
  {
    // if this is setting an ACL for me, cache it in the folder pref flags
    UpdateACLCache();
  }
  
  return ret;
}

Here is the call graph for this function:

Definition at line 5804 of file nsImapMailFolder.cpp.

{
  PRUint32 startingFlags = 0;
  m_folder->GetAclFlags(&startingFlags);
  
  if (GetCanIReadFolder())
    startingFlags |= IMAP_ACL_READ_FLAG;
  else
    startingFlags &= ~IMAP_ACL_READ_FLAG;
  
  if (GetCanIStoreSeenInFolder())
    startingFlags |= IMAP_ACL_STORE_SEEN_FLAG;
  else
    startingFlags &= ~IMAP_ACL_STORE_SEEN_FLAG;
  
  if (GetCanIWriteFolder())
    startingFlags |= IMAP_ACL_WRITE_FLAG;
  else
    startingFlags &= ~IMAP_ACL_WRITE_FLAG;
  
  if (GetCanIInsertInFolder())
    startingFlags |= IMAP_ACL_INSERT_FLAG;
  else
    startingFlags &= ~IMAP_ACL_INSERT_FLAG;
  
  if (GetCanIPostToFolder())
    startingFlags |= IMAP_ACL_POST_FLAG;
  else
    startingFlags &= ~IMAP_ACL_POST_FLAG;
  
  if (GetCanICreateSubfolder())
    startingFlags |= IMAP_ACL_CREATE_SUBFOLDER_FLAG;
  else
    startingFlags &= ~IMAP_ACL_CREATE_SUBFOLDER_FLAG;
  
  if (GetCanIDeleteInFolder())
    startingFlags |= IMAP_ACL_DELETE_FLAG;
  else
    startingFlags &= ~IMAP_ACL_DELETE_FLAG;
  
  if (GetCanIAdministerFolder())
    startingFlags |= IMAP_ACL_ADMINISTER_FLAG;
  else
    startingFlags &= ~IMAP_ACL_ADMINISTER_FLAG;
  
  m_folder->SetAclFlags(startingFlags);
}

Member Data Documentation

Definition at line 189 of file nsImapMailFolder.h.

Definition at line 188 of file nsImapMailFolder.h.

nsHashtable* nsMsgIMAPFolderACL::m_rightsHash [protected]

Definition at line 187 of file nsImapMailFolder.h.


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