Bug 748726 - Received messages contain parts of other messages with movemail account. r=Standard8
--- a/mailnews/local/src/nsMovemailService.cpp
+++ b/mailnews/local/src/nsMovemailService.cpp
@@ -390,24 +390,27 @@ nsMovemailService::GetNewMail(nsIMsgWind
nsCOMPtr<nsIMsgIncomingServer> in_server =
do_QueryInterface(movemailServer);
if (!in_server)
return NS_MSG_INVALID_OR_MISSING_SERVER;
mMsgWindow = aMsgWindow;
// Attempt to locate the mail spool file
nsCAutoString spoolPath;
- rv = LocateSpoolFile(spoolPath);
+ rv = in_server->GetCharValue("spoolDir", spoolPath);
+ if (spoolPath.IsEmpty())
+ rv = LocateSpoolFile(spoolPath);
if (NS_FAILED(rv) || spoolPath.IsEmpty()) {
Error(MOVEMAIL_SPOOL_FILE_NOT_FOUND, nsnull, 0);
return NS_ERROR_FAILURE;
}
// Create an input stream for the spool file
nsCOMPtr<nsILocalFile> spoolFile;
+ printf("spool path = %s\n", spoolPath.get());
rv = NS_NewNativeLocalFile(spoolPath, true, getter_AddRefs(spoolFile));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> spoolInputStream;
rv = NS_NewLocalFileInputStream(getter_AddRefs(spoolInputStream), spoolFile);
if (NS_FAILED(rv)) {
const PRUnichar *params[] = {
NS_ConvertUTF8toUTF16(spoolPath).get()
};
@@ -432,32 +435,24 @@ nsMovemailService::GetNewMail(nsIMsgWind
if (!rootMsgFolder)
return rv;
rv = rootMsgFolder->GetFolderWithFlags(nsMsgFolderFlags::Inbox,
getter_AddRefs(inbox));
NS_ENSURE_TRUE(inbox, NS_ERROR_FAILURE);
nsCOMPtr <nsIOutputStream> outputStream;
nsCOMPtr<nsIMsgPluggableStore> msgStore;
+ nsCOMPtr<nsIMsgDBHdr> newHdr;
rv = in_server->GetMsgStore(getter_AddRefs(msgStore));
NS_ENSURE_SUCCESS(rv, rv);
bool reusable;
- nsCOMPtr<nsIMsgDBHdr> newHdr;
- msgStore->GetNewMsgOutputStream(inbox, getter_AddRefs(newHdr),
- &reusable, getter_AddRefs(outputStream));
- NS_ENSURE_SUCCESS(rv, rv);
- nsCOMPtr <nsIInputStream> inputStream = do_QueryInterface(outputStream);
// create a new mail parser
nsRefPtr<nsParseNewMailState> newMailParser = new nsParseNewMailState;
NS_ENSURE_TRUE(newMailParser, NS_ERROR_OUT_OF_MEMORY);
- rv = newMailParser->Init(serverFolder, inbox,
- nsnull, newHdr, outputStream);
- NS_ENSURE_SUCCESS(rv, rv);
-
in_server->SetServerBusy(true);
// Try and obtain the lock for the spool file
bool usingLockFile;
if (!ObtainSpoolLock(spoolPath.get(), 5, &usingLockFile)) {
nsAutoString lockFile = NS_ConvertUTF8toUTF16(spoolPath);
lockFile.AppendLiteral(".lock");
const PRUnichar *params[] = {
@@ -479,34 +474,53 @@ nsMovemailService::GetNewMail(nsIMsgWind
// If first string is empty and we're now at EOF then abort parsing.
if (buffer.IsEmpty() && !isMore) {
LOG(("Empty spool file"));
break;
}
buffer += MSG_LINEBREAK;
+ if (isMore && !strncmp(buffer.get(), "From ", 5)) {
+ // finish prev header, if any.
+ if (newHdr) {
+ outputStream->Flush();
+ newMailParser->PublishMsgHeader(nsnull);
+ msgStore->FinishNewMessage(outputStream, newHdr);
+ newMailParser->Clear();
+ }
+ msgStore->GetNewMsgOutputStream(inbox, getter_AddRefs(newHdr),
+ &reusable, getter_AddRefs(outputStream));
+ NS_ENSURE_SUCCESS(rv, rv);
+ nsCOMPtr <nsIInputStream> inputStream = do_QueryInterface(outputStream);
+ rv = newMailParser->Init(serverFolder, inbox,
+ nsnull, newHdr, outputStream);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ }
newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length());
outputStream->Write(buffer.get(), buffer.Length(), &bytesWritten);
// 'From' lines delimit messages
if (isMore && !strncmp(buffer.get(), "From ", 5)) {
buffer.AssignLiteral("X-Mozilla-Status: 8000" MSG_LINEBREAK);
newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length());
outputStream->Write(buffer.get(), buffer.Length(), &bytesWritten);
buffer.AssignLiteral("X-Mozilla-Status2: 00000000" MSG_LINEBREAK);
newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length());
outputStream->Write(buffer.get(), buffer.Length(), &bytesWritten);
}
}
-
- outputStream->Flush();
- newMailParser->OnStopRequest(nsnull, nsnull, NS_OK);
- msgStore->FinishNewMessage(outputStream, newHdr);
- outputStream->Close();
+ if (outputStream) {
+ outputStream->Flush();
+ newMailParser->PublishMsgHeader(nsnull);
+ newMailParser->OnStopRequest(nsnull, nsnull, NS_OK);
+ msgStore->FinishNewMessage(outputStream, newHdr);
+ outputStream->Close();
+ }
// Truncate the spool file
rv = spoolFile->SetFileSize(0);
if (NS_FAILED(rv)) {
const PRUnichar *params[] = {
NS_ConvertUTF8toUTF16(spoolPath).get()
};
Error(MOVEMAIL_CANT_TRUNCATE_SPOOL_FILE, params, 1);
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/data/movemailspool
@@ -0,0 +1,169 @@
+From - Tue Oct 02 00:26:47 2007
+X-Account-Key: account2
+X-UIDL: UID18345-1161858178
+X-Mozilla-Status: 0001
+X-Mozilla-Status2: 00000000
+X-Mozilla-Keys: $label4
+Received: from caspiaco by host29.example.com with local-bsmtp (Exim 4.68)
+ (envelope-from <bugzilla-daemon@mozilla.org>)
+ id 1JtrbR-0001Kc-Nf
+ for kent@example.com; Wed, 07 May 2008 15:55:21 -0600
+X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on
+ host29.example.com
+X-Spam-Level:
+X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham
+ version=3.2.3
+Received: from webapp01.sj.mozilla.com ([63.245.208.146] helo=webapp-out.mozilla.org)
+ by host29.example.com with esmtps (TLSv1:AES256-SHA:256)
+ (Exim 4.68)
+ (envelope-from <bugzilla-daemon@mozilla.org>)
+ id 1JtrbR-0001KT-FP
+ for kent@example.com; Wed, 07 May 2008 15:55:09 -0600
+Received: from mrapp51.mozilla.org (mrapp51.mozilla.org [127.0.0.1])
+ by webapp-out.mozilla.org (8.13.8/8.13.8) with ESMTP id m47LtAFJ007547
+ for <kent@example.com>; Wed, 7 May 2008 14:55:10 -0700
+Received: (from root@localhost)
+ by mrapp51.mozilla.org (8.13.8/8.13.8/Submit) id m47LtAEf007542;
+ Wed, 7 May 2008 14:55:10 -0700
+Date: Wed, 7 May 2008 14:55:10 -0700
+Message-Id: <200805072155.m47LtAEf007542@mrapp51.mozilla.org>
+To: invalid@example.com
+From: PrimaryEmail1@test.invalid
+Cc: invalid@example.com
+Subject: [Bug 397009] A filter will let me tag, but not untag
+X-Bugzilla-Reason: None
+X-Bugzilla-Type: newchanged
+X-Bugzilla-Watch-Reason: QAcontact filters@mail.bugs
+X-Bugzilla-Product: Core
+X-Bugzilla-Component: MailNews: Filters
+X-Bugzilla-Keywords:
+X-Bugzilla-Severity: enhancement
+X-Bugzilla-Who: bugmail@example.org
+X-Bugzilla-Status: NEW
+X-Bugzilla-Priority: --
+X-Bugzilla-Assigned-To: nobody@mozilla.org
+X-Bugzilla-Target-Milestone: ---
+X-Bugzilla-Changed-Fields: Blocks
+In-Reply-To: <bug-397009-254728@https.bugzilla.mozilla.org/>
+References: <bug-397009-254728@https.bugzilla.mozilla.org/>
+Content-Type: text/plain; charset="UTF-8"
+MIME-Version: 1.0
+X-user: ::::63.245.208.146:host29.hostmonster.com::::::
+DomainKey-Status: no signature
+
+Do not reply to this email. You can add comments to this bug at
+https://bugzilla.mozilla.org/show_bug.cgi?id=397009
+
+
+Some User <bugmail@example.org> changed:
+
+ What |Removed |Added
+----------------------------------------------------------------------------
+ Blocks| |432710
+
+
+
+
+--
+Configure bugmail: https://bugzilla.mozilla.org/userprefs.cgi?tab=email
+------- You are receiving this mail because: -------
+You are watching the QA contact of the bug.
+
+
+From - Sat Jun 07 04:23:42 2008
+X-Mozilla-Status: 0000
+X-Mozilla-Status2: 00000000
+X-Mozilla-Keys:
+FCC: mailbox://nobody@Local%20Folders/Sent
+BCC: Some User <u1@example.com>, Another Person <u2@example.com>
+X-Identity-Key: id2
+Message-ID: <4849BF7B.2030800@example.com>
+Date: Sat, 07 Jun 2008 04:23:42 +0530
+From: Some User <example@example.com>
+X-Mozilla-Draft-Info: internal/draft; vcard=0; receipt=0; DSN=0; uuencode=0
+User-Agent: Thunderbird 3.0a2pre (Windows/2008060416)
+MIME-Version: 1.0
+To: bugmail@example.org
+Subject: Hello, did you receive my bugmail?
+Content-Type: text/html; charset=ISO-8859-1
+Content-Transfer-Encoding: 7bit
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="content-type"
+ content="text/html; charset=ISO-8859-1">
+</head>
+<body text="#000000" bgcolor="#ffffff">
+This is an HTML message. Did you receive my bugmail?<br>
+<br>
+Thanks, and goodbye.<br>
+<br>
+--<br>
+Some User<br>
+<br>
+</body>
+</html>
+
+
+From - Tue Oct 02 00:26:47 2007
+X-UIDL: UID18345-1161858178
+X-Mozilla-Status: 0001
+X-Mozilla-Status2: 00000000
+Received: (from root@localhost)
+ by mrapp51.mozilla.org (8.13.8/8.13.8/Submit) id m47LtAEf007542;
+ Wed, 7 May 2008 14:55:10 -0700
+Date: Wed, 7 May 2008 14:55:10 -0700
+Message-Id: <200805072155.m47LtAEf007542@mrapp51.mozilla.org>
+To: invalid@example.com
+From: PrimaryEmail1@test.invalid
+Cc: invalid@example.com
+Subject: [Bug 655578] list-id filter broken
+X-Bugzilla-Reason: None
+X-Bugzilla-Type: newchanged
+X-Bugzilla-Watch-Reason: QAcontact filters@mail.bugs
+X-Bugzilla-Product: Core
+X-Bugzilla-Component: MailNews: Filters
+X-Bugzilla-Keywords:
+X-Bugzilla-Severity: enhancement
+X-Bugzilla-Who: bugmail@example.org
+X-Bugzilla-Status: NEW
+X-Bugzilla-Priority: --
+X-Bugzilla-Assigned-To: nobody@mozilla.org
+X-Bugzilla-Target-Milestone: ---
+X-Bugzilla-Changed-Fields: Blocks
+In-Reply-To: <bug-397009-254728@https.bugzilla.mozilla.org/>
+References: <bug-397009-254728@https.bugzilla.mozilla.org/>
+ <4DC2493C.4060403@gmx.com>
+ <BANLkTin2w8LJxYGHV3_5NpFbsiBhrP96XA@mail.gmail.com>
+ <175221688.20110506234025@my_localhost>
+ <201105072315.25120@thufir.ingo-kloecker.de>
+ <BANLkTinacQCd+mZ7fL1THLK55X2+u9g5-w@mail.gmail.com>
+ <05433510.20110507224940@my_localhost>
+ <4DC5C015.7050800@sixdemonbag.org>
+ <BANLkTinv7NvPG9gE1Fha+X+6ZkHzdXdRdg@mail.gmail.com>
+ <BANLkTi=6zDTsYymc+bUTwPOM2AohJD2wfA@mail.gmail.com>
+Reply-To: FOO <bar@foo.com>
+List-Id: Help and discussion among users of GnuPG <gnupg-users.gnupg.org>
+Content-Type: text/plain; charset="UTF-8"
+MIME-Version: 1.0
+
+Do not reply to this email. You can add comments to this bug at
+https://bugzilla.mozilla.org/show_bug.cgi?id=397009
+
+
+Some User <bugmail@example.org> changed:
+
+ What |Removed |Added
+----------------------------------------------------------------------------
+ Blocks| |432710
+
+
+
+
+--
+Configure bugmail: https://bugzilla.mozilla.org/userprefs.cgi?tab=email
+------- You are receiving this mail because: -------
+You are watching the QA contact of the bug.
+
+
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/test_movemailDownload.js
@@ -0,0 +1,103 @@
+/**
+ * The intent of this file is to test that movemail download code
+ * works correctly.
+ */
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+var testSubjects = ["[Bug 397009] A filter will let me tag, but not untag",
+ "Hello, did you receive my bugmail?",
+ "[Bug 655578] list-id filter broken"];
+
+var gMsgHdrs = [];
+var gHdrIndex = 0;
+
+// the movemail spool dir file is these three files
+// concatenated together.
+
+let gFiles = ["../../../data/bugmail1",
+ "../../../data/draft1",
+ "../../../data/bugmail19"];
+
+var gMoveMailInbox;
+
+function run_test()
+{
+ // disable test on windows.
+ if ("@mozilla.org/windows-registry-key;1" in Cc) {
+ do_test_finished();
+ return;
+ }
+
+ loadLocalMailAccount();
+
+ let acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
+ .getService(Ci.nsIMsgAccountManager);
+ var incoming = acctMgr.createIncomingServer("", "", "movemail");
+ let workingDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
+ let workingDirFile = workingDir.clone();
+ let fullPath = workingDirFile.path + "/data/movemailspool";
+ workingDirFile.initWithPath(fullPath);
+ // movemail truncates spool file, so make a copy, and use that
+ workingDirFile.copyTo(null, "movemailspool-copy");
+ fullPath += "-copy";
+ dump("full path = " + fullPath + "\n");
+ incoming.setCharValue("spoolDir", fullPath);
+ incoming.QueryInterface(Ci.nsILocalMailIncomingServer);
+ incoming.getNewMail(null, null, null);
+ gMoveMailInbox = incoming.rootFolder.getChildNamed("INBOX");
+ // add 3 messages
+ do_test_pending();
+ continueTest();
+}
+
+function continueTest()
+{
+ // get message headers for the inbox folder
+ let enumerator = gMoveMailInbox.msgDatabase.EnumerateMessages();
+ var msgCount = 0;
+ let hdr;
+ while (enumerator.hasMoreElements())
+ {
+ let hdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
+ gMsgHdrs.push(hdr);
+ do_check_eq(hdr.subject, testSubjects[msgCount++]);
+ }
+ do_check_eq(msgCount, 3);
+ streamNextMessage();
+}
+
+function streamNextMessage()
+{
+ let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
+ let msghdr = gMsgHdrs[gHdrIndex];
+ let msgURI = msghdr.folder.getUriForMsg(msghdr);
+ dump("streaming msg " + msgURI + " store token = " + msghdr.getStringProperty("storeToken"));
+ let msgServ = messenger.messageServiceFromURI(msgURI);
+ msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", true);
+}
+
+gStreamListener = {
+ QueryInterface : XPCOMUtils.generateQI([Ci.nsIStreamListener]),
+ _stream : null,
+ _data : null,
+ onStartRequest : function (aRequest, aContext) {
+ this._stream = null;
+ this._data = "";
+ },
+ onStopRequest : function (aRequest, aContext, aStatusCode) {
+ // check that the streamed message starts with "From "
+ do_check_eq(this._data.indexOf("From "), 0);
+ if (++gHdrIndex == gFiles.length)
+ do_test_finished();
+ else
+ streamNextMessage();
+ },
+ onDataAvailable : function (aRequest, aContext, aInputStream, aOff, aCount) {
+ if (this._stream == null) {
+ this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
+ this._stream.init(aInputStream);
+ }
+ this._data += this._stream.read(aCount);
+ },
+};
+
--- a/mailnews/local/test/unit/xpcshell.ini
+++ b/mailnews/local/test/unit/xpcshell.ini
@@ -2,16 +2,17 @@
head = head_maillocal.js
tail = tail_local.js
[test_bug457168.js]
[test_fileName.js]
[test_nsIMsgLocalMailFolder.js]
[test_mailboxContentLength.js]
[test_mailboxProtocol.js]
+[test_movemailDownload.js]
[test_msgCopy.js]
[test_msgIDParsing.js]
[test_over2GBMailboxes.js]
[test_over4GBMailboxes.js]
[test_pop3AuthMethods.js]
[test_pop3Download.js]
[test_pop3DownloadTempFileHandling.js]
[test_pop3Duplicates.js]