fix pop3 move filters truncation of inbox, r=standard8, bug 715924

This commit is contained in:
David Bienvenu 2012-01-10 07:28:41 -08:00
Родитель 95ad7c0a93
Коммит 192a527f72
5 изменённых файлов: 171 добавлений и 12 удалений

Просмотреть файл

@ -769,17 +769,12 @@ nsMsgBrkMBoxStore::DiscardNewMessage(nsIOutputStream *aOutputStream,
PRUint64 hdrOffset;
aNewHdr->GetMessageOffset(&hdrOffset);
aOutputStream->Close();
if (hdrOffset != 0)
{
nsCOMPtr<nsILocalFile> mboxFile;
nsCOMPtr<nsIMsgFolder> folder;
nsresult rv = aNewHdr->GetFolder(getter_AddRefs(folder));
NS_ENSURE_SUCCESS(rv, rv);
folder->GetFilePath(getter_AddRefs(mboxFile));
rv = mboxFile->SetFileSize(hdrOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
nsCOMPtr<nsILocalFile> mboxFile;
nsCOMPtr<nsIMsgFolder> folder;
nsresult rv = aNewHdr->GetFolder(getter_AddRefs(folder));
NS_ENSURE_SUCCESS(rv, rv);
folder->GetFilePath(getter_AddRefs(mboxFile));
return mboxFile->SetFileSize(hdrOffset);
}
NS_IMETHODIMP

Просмотреть файл

@ -2594,6 +2594,10 @@ nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr,
if (destIFolder)
destIFolder->SetFlag(nsMsgFolderFlags::GotNew);
nsCOMPtr<nsIMsgPluggableStore> store;
rv = m_downloadFolder->GetMsgStore(getter_AddRefs(store));
if (store)
store->DiscardNewMessage(m_outputStream, mailHdr);
if (destMailDB)
{
// update the folder size so we won't reparse.

Просмотреть файл

@ -245,7 +245,8 @@ nsPop3Sink::CheckPartialMessages(nsIPop3Protocol *protocol)
protocol->CheckMessage(partialMsg->m_uidl.get(), &found);
if (!found && partialMsg->m_msgDBHdr)
{
m_newMailParser->m_mailDB->DeleteHeader(partialMsg->m_msgDBHdr, nsnull, false, true);
if (m_newMailParser)
m_newMailParser->m_mailDB->DeleteHeader(partialMsg->m_msgDBHdr, nsnull, false, true);
deleted = true;
}
delete partialMsg;

Просмотреть файл

@ -0,0 +1,158 @@
/*
* This file tests that a pop3 move filter doesn't leave the
* original message in the inbox.
*
* Original author: David Bienvenu <dbienvenu@mozilla.com>
*/
load("../../../resources/POP3pump.js");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://gre/modules/Services.jsm");
const gFiles = ["../../../data/bugmail1", "../../../data/bugmail2"];
var gMoveFolder;
var gFilter; // the test filter
var gFilterList;
var gCurTestNum = 1;
const gTestArray =
[
function createFilters() {
gFilterList = gPOP3Pump.fakeServer.getFilterList(null);
gFilter = gFilterList.createFilter("MoveAll");
let searchTerm = gFilter.createTerm();
searchTerm.matchAll = true;
gFilter.appendTerm(searchTerm);
let moveAction = gFilter.createAction();
moveAction.type = Ci.nsMsgFilterAction.MoveToFolder;
moveAction.targetFolderUri = gMoveFolder.URI;
gFilter.appendAction(moveAction);
gFilter.enabled = true;
gFilter.filterType = Ci.nsMsgFilterType.InboxRule;
gFilterList.insertFilterAt(0, gFilter);
++gCurTestNum;
doTest();
},
// just get a message into the local folder
function getLocalMessages1() {
gPOP3Pump.files = gFiles;
gPOP3Pump.onDone = doTest;
++gCurTestNum;
gPOP3Pump.run();
},
function verifyFolders2() {
do_check_eq(folderCount(gMoveFolder), 2);
// the local inbox folder should now be empty, since we moved incoming mail.
do_check_eq(folderCount(gLocalInboxFolder), 0);
// invalidate the inbox summary file, to be sure that we really moved
// the mail.
gLocalInboxFolder.msgDatabase.summaryValid = false;
gLocalInboxFolder.msgDatabase = null;
gLocalInboxFolder.ForceDBClosed();
try {
gLocalInboxFolder.getDatabaseWithReparse(ParseListener, null);
} catch (ex) {
do_check_true(ex.result == Cr.NS_ERROR_NOT_INITIALIZED);
}
}
];
var ParseListener =
{
OnStartRunningUrl: function (aUrl) {
},
OnStopRunningUrl: function (aUrl, aExitCode) {
do_check_eq(aExitCode, 0);
do_check_true(gLocalInboxFolder.msgDatabase.summaryValid);
do_check_eq(folderCount(gLocalInboxFolder), 0);
++gCurTestNum;
doTest();
}
};
function folderCount(folder)
{
let enumerator = folder.msgDatabase.EnumerateMessages();
let count = 0;
while (enumerator.hasMoreElements())
{
count++;
let hdr = enumerator.getNext();
}
return count;
}
function run_test()
{
// Make sure we're not quarantining messages
Services.prefs.setBoolPref("mailnews.downloadToTempFile", false);
if (!gLocalInboxFolder)
loadLocalMailAccount();
gMoveFolder = gLocalIncomingServer.rootFolder.createLocalSubfolder("MoveFolder");
MailServices.mailSession.AddFolderListener(FolderListener,
Ci.nsIFolderListener.event |
Ci.nsIFolderListener.added |
Ci.nsIFolderListener.removed);
// "Master" do_test_pending(), paired with a do_test_finished() at the end of
// all the operations.
do_test_pending();
//start first test
doTest();
}
function doTest()
{
var test = gCurTestNum;
if (test <= gTestArray.length)
{
var testFn = gTestArray[test-1];
dump("Doing test " + test + " " + testFn.name + "\n");
try {
testFn();
} catch(ex) {
do_throw ('TEST FAILED ' + ex);
}
}
else
do_timeout(1000, endTest);
}
// nsIFolderListener implementation
var FolderListener = {
OnItemAdded: function OnItemAdded(aParentItem, aItem) {
this._showEvent(aParentItem, "OnItemAdded");
},
OnItemRemoved: function OnItemRemoved(aParentItem, aItem) {
this._showEvent(aParentItem, "OnItemRemoved");
// continue test, as all tests remove a message during the move
do_timeout(0, doTest);
},
OnItemEvent: function OnItemEvent(aEventFolder, aEvent) {
this._showEvent(aEventFolder, aEvent.toString())
},
_showEvent: function showEvent(aFolder, aEventString) {
dump("received folder event " + aEventString +
" folder " + aFolder.name +
"\n");
}
};
function endTest()
{
// Cleanup, null out everything, close all cached connections and stop the
// server
dump("Exiting mail tests\n");
let thread = gThreadManager.currentThread;
while (thread.hasPendingEvents())
thread.processNextEvent(true);
gPOP3Pump = null;
do_test_finished(); // for the one in run_test()
}

Просмотреть файл

@ -16,6 +16,7 @@ tail = tail_local.js
[test_pop3Duplicates.js]
[test_pop3GSSAPIFail.js]
[test_pop3GetNewMail.js]
[test_pop3MoveFilter.js]
[test_pop3Password.js]
[test_pop3Password2.js]
[test_pop3Password3.js]