From 56a02adde881bbcd0d0c88ee54ce08ce1341c466 Mon Sep 17 00:00:00 2001 From: "jefft%netscape.com" Date: Fri, 6 Aug 1999 13:43:49 +0000 Subject: [PATCH] enabled Compact This Folder command; implemented MoveFolder(), RenameLeaf() methods --- mailnews/imap/public/nsIImapService.h | 11 ++- mailnews/imap/src/nsImapMailFolder.cpp | 11 +++ mailnews/imap/src/nsImapMailFolder.h | 1 + mailnews/imap/src/nsImapService.cpp | 97 ++++++++++++++++++++++++++ mailnews/imap/src/nsImapService.h | 10 +++ 5 files changed, 129 insertions(+), 1 deletion(-) diff --git a/mailnews/imap/public/nsIImapService.h b/mailnews/imap/public/nsIImapService.h index acf8a0a4589e..e3f3c1857a5b 100644 --- a/mailnews/imap/public/nsIImapService.h +++ b/mailnews/imap/public/nsIImapService.h @@ -153,7 +153,16 @@ public: nsIUrlListener* aUrlListener, nsIURI** aURL, nsISupports* copyState) = 0; - + NS_IMETHOD MoveFolder(nsIEventQueue* aClientEventQ, + nsIMsgFolder* srcFolder, + nsIMsgFolder* dstFolder, + nsIUrlListener* urlListener, + nsIURI** aUrl) = 0; + NS_IMETHOD RenameLeaf(nsIEventQueue* aClientEventQ, + nsIMsgFolder* srcFolder, + const char* leafName, + nsIUrlListener* urlListener, + nsIURI** url) = 0; }; diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index baae0e02bc4c..c66f356cfbb7 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -550,6 +550,17 @@ NS_IMETHODIMP nsImapMailFolder::RemoveSubFolder (nsIMsgFolder *which) return rv; } +NS_IMETHODIMP nsImapMailFolder::Compact() +{ + nsresult rv; + NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv); + if (NS_SUCCEEDED(rv) && imapService) + { + rv = imapService->Expunge(m_eventQueue, this, nsnull, nsnull); + } + return rv; +} + NS_IMETHODIMP nsImapMailFolder::Delete () { nsresult rv = NS_ERROR_FAILURE; diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index e6690a0ae676..6ced1639ad7e 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -111,6 +111,7 @@ public: NS_IMETHOD CreateSubfolder(const char *folderName); NS_IMETHOD RemoveSubFolder (nsIMsgFolder *which); + NS_IMETHOD Compact(); NS_IMETHOD Delete (); NS_IMETHOD Rename (const char *newName); NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos); diff --git a/mailnews/imap/src/nsImapService.cpp b/mailnews/imap/src/nsImapService.cpp index 44e1ac46927e..5e2204b07657 100644 --- a/mailnews/imap/src/nsImapService.cpp +++ b/mailnews/imap/src/nsImapService.cpp @@ -144,6 +144,8 @@ nsImapService::SelectFolder(nsIEventQueue * aClientEventQueue, if (NS_SUCCEEDED(rv) && imapUrl) { + // nsImapUrl::SetSpec() will set the imap action properly + // rv = imapUrl->SetImapAction(nsIImapUrl::nsImapSelectFolder); rv = imapUrl->SetImapAction(nsIImapUrl::nsImapSelectFolder); nsCOMPtr mailNewsUrl = do_QueryInterface(imapUrl); @@ -1321,6 +1323,101 @@ nsImapService::GetImapConnectionAndLoadUrl(nsIEventQueue* aClientEventQueue, return rv; } +NS_IMETHODIMP +nsImapService::MoveFolder(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, + nsIMsgFolder* dstFolder, + nsIUrlListener* urlListener, nsIURI** url) +{ + NS_ASSERTION(eventQueue && srcFolder && dstFolder, + "Oops ... null pointer"); + if (!eventQueue || !srcFolder || !dstFolder) + return NS_ERROR_NULL_POINTER; + + nsIImapUrl* imapUrl; + nsString2 urlSpec(eOneByte); + nsresult rv; + + rv = CreateStartOfImapUrl(imapUrl, dstFolder, urlSpec); + if (NS_SUCCEEDED(rv) && imapUrl) + { + rv = SetImapUrlSink(dstFolder, imapUrl); + if (NS_SUCCEEDED(rv)) + { + char hierarchySeparator = kOnlineHierarchySeparatorUnknown; + nsString2 folderName(eOneByte); + GetFolderName(srcFolder, folderName); + urlSpec.Append("/movefolderhierarchy>"); + urlSpec.Append(hierarchySeparator); + urlSpec.Append(folderName.GetBuffer()); + urlSpec.Append('>'); + folderName.SetLength(0); + GetFolderName(dstFolder, folderName); + urlSpec.Append(hierarchySeparator); + urlSpec.Append(folderName.GetBuffer()); + nsCOMPtr uri = do_QueryInterface(imapUrl, &rv); + if (NS_SUCCEEDED(rv) && uri) + { + rv = uri->SetSpec((char*) urlSpec.GetBuffer()); + if (NS_SUCCEEDED(rv)) + rv = GetImapConnectionAndLoadUrl(eventQueue, imapUrl, + urlListener, nsnull, + url); + } + } + NS_RELEASE(imapUrl); + } + return rv; +} + +NS_IMETHODIMP +nsImapService::RenameLeaf(nsIEventQueue* eventQueue, nsIMsgFolder* srcFolder, + const char* newLeafName, nsIUrlListener* urlListener, + nsIURI** url) +{ + NS_ASSERTION(eventQueue && srcFolder && newLeafName && *newLeafName, + "Oops ... [RenameLeaf] null pointers"); + if (!eventQueue || !srcFolder || !newLeafName || !*newLeafName) + return NS_ERROR_NULL_POINTER; + + nsIImapUrl* imapUrl; + nsString2 urlSpec(eOneByte); + nsresult rv; + + rv = CreateStartOfImapUrl(imapUrl, srcFolder, urlSpec); + if (NS_SUCCEEDED(rv) && imapUrl) + { + rv = SetImapUrlSink(srcFolder, imapUrl); + if (NS_SUCCEEDED(rv)) + { + char hierarchySeparator = '/'; + nsString2 folderName(eOneByte); + GetFolderName(srcFolder, folderName); + urlSpec.Append("/rename>"); + urlSpec.Append(hierarchySeparator); + urlSpec.Append(folderName.GetBuffer()); + urlSpec.Append('>'); + PRInt32 leafNameStart = + folderName.RFindChar('/'); // ** troublesome hierarchyseparator + if (leafNameStart != -1) + folderName.SetLength(leafNameStart+1); + urlSpec.Append(hierarchySeparator); + urlSpec.Append(folderName.GetBuffer()); + urlSpec.Append(newLeafName); + nsCOMPtr uri = do_QueryInterface(imapUrl, &rv); + if (NS_SUCCEEDED(rv) && uri) + { + rv = uri->SetSpec((char*) urlSpec.GetBuffer()); + if (NS_SUCCEEDED(rv)) + rv = GetImapConnectionAndLoadUrl(eventQueue, imapUrl, + urlListener, nsnull, + url); + } // if (NS_SUCCEEDED(rv) && uri) + } // if (NS_SUCCEEDED(rv)) + NS_RELEASE(imapUrl); + } // if (NS_SUCCEEDED(rv) && imapUrl) + return rv; +} + #ifdef HAVE_PORT /* fetching the headers of RFC822 messages */ diff --git a/mailnews/imap/src/nsImapService.h b/mailnews/imap/src/nsImapService.h index a66cc50a6453..12ad52798a1a 100644 --- a/mailnews/imap/src/nsImapService.h +++ b/mailnews/imap/src/nsImapService.h @@ -149,6 +149,16 @@ public: nsIUrlListener* aUrlListener, nsIURI** aURL, nsISupports* copyState); + NS_IMETHOD MoveFolder(nsIEventQueue* eventQueue, + nsIMsgFolder* srcFolder, + nsIMsgFolder* dstFolder, + nsIUrlListener* urlListener, + nsIURI** url); + NS_IMETHOD RenameLeaf(nsIEventQueue* eventQueue, + nsIMsgFolder* srcFolder, + const char* leafName, + nsIUrlListener* urlListener, + nsIURI** url); //////////////////////////////////////////////////////////////////////////////////////// // End support of nsIImapService interface ////////////////////////////////////////////////////////////////////////////////////////