From 3fdadcff7b7de65a1b10071dbfe586fe4a8970b8 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Thu, 28 Aug 2003 23:16:52 +0000 Subject: [PATCH] use myrights for personal folders to fix interoperability problem with fastmail.fm, r=sspitzer, sr=scott, a=sspitzer 217431 --- mailnews/imap/src/nsImapMailFolder.cpp | 63 ++++++++++++++++++++++++-- mailnews/imap/src/nsImapMailFolder.h | 5 ++ mailnews/imap/src/nsImapProtocol.cpp | 21 +++++---- 3 files changed, 75 insertions(+), 14 deletions(-) diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 0e73c11fe228..9836d1b1e294 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -227,6 +227,7 @@ nsImapMailFolder::nsImapMailFolder() : m_pathName = nsnull; m_folderACL = nsnull; m_aclFlags = 0; + m_supportedUserFlags = 0; m_namespace = nsnull; m_numFilterClassifyRequests = 0; } @@ -5050,6 +5051,51 @@ NS_IMETHODIMP nsImapMailFolder::GetAclFlags(PRUint32 *aclFlags) return rv; } + +nsresult nsImapMailFolder::SetSupportedUserFlags(PRUint32 userFlags) +{ + nsCOMPtr dbFolderInfo; + nsresult rv = GetDatabase(nsnull); + + m_supportedUserFlags = userFlags; + if (mDatabase) + { + rv = mDatabase->GetDBFolderInfo(getter_AddRefs(dbFolderInfo)); + if (NS_SUCCEEDED(rv) && dbFolderInfo) + dbFolderInfo->SetUint32Property("imapFlags", userFlags); + } + + + return rv; +} + +nsresult nsImapMailFolder::GetSupportedUserFlags(PRUint32 *userFlags) +{ + NS_ENSURE_ARG_POINTER(userFlags); + + nsresult rv = NS_OK; + + ReadDBFolderInfo(PR_FALSE); // update cache first. + if (m_supportedUserFlags == 0) // 0 means invalid value, so get it from db. + { + nsCOMPtr dbFolderInfo; + rv = GetDatabase(nsnull); + + if (mDatabase) + { + rv = mDatabase->GetDBFolderInfo(getter_AddRefs(dbFolderInfo)); + if (NS_SUCCEEDED(rv) && dbFolderInfo) + { + rv = dbFolderInfo->GetUint32Property("imapFlags", userFlags, 0); + m_supportedUserFlags = *userFlags; + } + } + } + else + *userFlags = m_supportedUserFlags; + return rv; +} + NS_IMETHODIMP nsImapMailFolder::GetCanIOpenThisFolder(PRBool *aBool) { NS_ENSURE_ARG_POINTER(aBool); @@ -5165,9 +5211,18 @@ void nsMsgIMAPFolderACL::UpdateACLCache() PRBool nsMsgIMAPFolderACL::SetFolderRightsForUser(const char *userName, const char *rights) { - PRBool rv = PR_FALSE; + PRBool ret = PR_FALSE; nsXPIDLCString myUserName; - m_folder->GetUsername(getter_Copies(myUserName)); + nsCOMPtr 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)); + char *ourUserName = nsnull; if (!userName) @@ -5188,7 +5243,7 @@ PRBool nsMsgIMAPFolderACL::SetFolderRightsForUser(const char *userName, const ch NS_ASSERTION(m_aclCount >= 0, "acl count can't go negative"); } m_aclCount++; - rv = (m_rightsHash->Put(&hashKey, rightsWeOwn) == 0); + ret = (m_rightsHash->Put(&hashKey, rightsWeOwn) == 0); } if (ourUserName && @@ -5198,7 +5253,7 @@ PRBool nsMsgIMAPFolderACL::SetFolderRightsForUser(const char *userName, const ch UpdateACLCache(); } - return rv; + return ret; } const char *nsMsgIMAPFolderACL::GetRightsStringForUser(const char *inUserName) diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index 03f04d2d1b7c..98a9fe32d0e7 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -341,6 +341,10 @@ public: virtual nsresult SpamFilterClassifyMessages(const char **aURIArray, PRUint32 aURICount, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin); static nsresult AllocateUidStringFromKeys(nsMsgKey *keys, PRUint32 numKeys, nsCString &msgIds); + + // these might end up as an nsIImapMailFolder attribute. + nsresult SetSupportedUserFlags(PRUint32 userFlags); + nsresult GetSupportedUserFlags(PRUint32 *userFlags); protected: // Helper methods @@ -474,6 +478,7 @@ protected: nsMsgIMAPFolderACL *m_folderACL; PRUint32 m_aclFlags; + PRUint32 m_supportedUserFlags; nsCOMPtr mSupportsToRelease; diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index b6f30e447234..627b6ad5765f 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -474,7 +474,7 @@ nsresult nsImapProtocol::Initialize(nsIImapHostSessionList * aHostSessionList, n m_flagState = new nsImapFlagAndUidState(kImapFlagAndUidStateSize, PR_FALSE); if (!m_flagState) - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(m_flagState); @@ -4779,7 +4779,7 @@ void nsImapProtocol::HandleCurrentUrlError() nsImapMailboxSpec *notSelectedSpec = new nsImapMailboxSpec; if (notSelectedSpec) { - NS_ADDREF(notSelectedSpec); + NS_ADDREF(notSelectedSpec); notSelectedSpec->allocatedPathName = fCurrentUrl->CreateCanonicalSourceFolderPathString(); notSelectedSpec->hostName = fCurrentUrl->GetUrlHost(); notSelectedSpec->folderSelected = PR_FALSE; @@ -5353,16 +5353,16 @@ void nsImapProtocol::OnUnsubscribe(const char * sourceMailbox) void nsImapProtocol::RefreshACLForFolderIfNecessary(const char *mailboxName) { - if (GetServerStateParser().ServerHasACLCapability()) + if (GetServerStateParser().ServerHasACLCapability()) + { + if (!m_folderNeedsACLRefreshed && m_imapMailFolderSink) + m_imapMailFolderSink->GetFolderNeedsACLListed(&m_folderNeedsACLRefreshed); + if (m_folderNeedsACLRefreshed) { - if (!m_folderNeedsACLRefreshed && m_imapMailFolderSink) - m_imapMailFolderSink->GetFolderNeedsACLListed(&m_folderNeedsACLRefreshed); - if (m_folderNeedsACLRefreshed) - { - RefreshACLForFolder(mailboxName); - m_folderNeedsACLRefreshed = PR_FALSE; - } + RefreshACLForFolder(mailboxName); + m_folderNeedsACLRefreshed = PR_FALSE; } + } } void nsImapProtocol::RefreshACLForFolder(const char *mailboxName) @@ -5383,6 +5383,7 @@ void nsImapProtocol::RefreshACLForFolder(const char *mailboxName) ClearAllFolderRights(mailboxName, ns); // Now, get the new one. GetACLForFolder(mailboxName); + GetMyRightsForFolder(mailboxName); // We're all done, refresh the icon/flags for this folder RefreshFolderACLView(mailboxName, ns); break;