Bug 470907 Thunderbird always uses port 119 for NNTP, ignoring port configured in server settings. r/sr=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Thu, 19 Mar 2009 19:49:57 +0000
changeset 2248 1d0fcdefa375a657e3a81816fb6ac9117c67e123
parent 2247 a4dcc4160c3fdc0d693ff65760695d9afa446695
child 2249 1e7ea699bf3f21a9f85c3ea234def941a0ae5aeb
push id1819
push userbugzilla@standard8.plus.com
push dateThu, 19 Mar 2009 19:51:59 +0000
treeherdercomm-central@1e7ea699bf3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs470907
Bug 470907 Thunderbird always uses port 119 for NNTP, ignoring port configured in server settings. r/sr=bienvenu
mailnews/news/src/nsNNTPNewsgroupList.cpp
mailnews/news/src/nsNntpService.cpp
mailnews/news/test/unit/head_server_setup.js
mailnews/news/test/unit/test_getNewsMessage.js
--- a/mailnews/news/src/nsNNTPNewsgroupList.cpp
+++ b/mailnews/news/src/nsNNTPNewsgroupList.cpp
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -165,17 +165,17 @@ nsNNTPNewsgroupList::Initialize(nsINntpU
 nsresult
 nsNNTPNewsgroupList::CleanUp()
 {
   // here we make sure that there aren't missing articles in the unread set
   // So if an article is the unread set, and the known arts set, but isn't in the
   // db, then we should mark it read in the unread set.
   if (m_newsDB)
   {
-    if (m_knownArts.set)
+    if (m_knownArts.set && m_knownArts.set->getLength() && m_set->getLength())
     {
       nsCOMPtr <nsIDBFolderInfo> folderInfo;
       m_newsDB->GetDBFolderInfo(getter_AddRefs(folderInfo));
       PRInt32 firstKnown = m_knownArts.set->GetFirstMember();
       PRInt32 lastKnown =  m_knownArts.set->GetLastMember();
       if (folderInfo)
       {
         PRUint32 lastMissingCheck;
--- a/mailnews/news/src/nsNntpService.cpp
+++ b/mailnews/news/src/nsNntpService.cpp
@@ -292,21 +292,34 @@ nsNntpService::DisplayMessage(const char
     nsCOMPtr<nsIMsgIncomingServer> server;
     // We need to set the port on the url, just like 
     // nsNNTPProtocol::Initialize does, so the specs will be the same.
     // we can ignore errors here - worst case, we'll display the
     // "message not available" message.
     rv = folder->GetServer(getter_AddRefs(server));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    PRInt32 socketType;
-    nsresult rv = server->GetSocketType(&socketType);
-    NS_ENSURE_SUCCESS(rv, rv);
-    url->SetPort((socketType == nsIMsgIncomingServer::useSSL) ?
-                 nsINntpUrl::DEFAULT_NNTPS_PORT : nsINntpUrl::DEFAULT_NNTP_PORT);
+    PRInt32 port = 0;
+    rv = url->GetPort(&port);
+    if (NS_FAILED(rv) || (port <= 0))
+    {
+      rv = server->GetPort(&port);
+      if (NS_FAILED(rv) || (port <= 0))
+      {
+        PRInt32 socketType;
+        rv = server->GetSocketType(&socketType);
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        port = (socketType == nsIMsgIncomingServer::useSSL) ?
+               nsINntpUrl::DEFAULT_NNTPS_PORT : nsINntpUrl::DEFAULT_NNTP_PORT;
+      }
+
+      rv = url->SetPort(port);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
 
     folder->ShouldStoreMsgOffline(key, &shouldStoreMsgOffline);
 
     // Look for the message in the offline cache
     PRBool hasMsgOffline = PR_FALSE;
     folder->HasMsgOffline(key, &hasMsgOffline);
 
     // Now look in the memory cache
--- a/mailnews/news/test/unit/head_server_setup.js
+++ b/mailnews/news/test/unit/head_server_setup.js
@@ -1,15 +1,24 @@
 // Import the servers
 do_import_script("../mailnews/test/fakeserver/maild.js");
 do_import_script("../mailnews/test/fakeserver/nntpd.js");
 
 // Generic mailnews resource scripts
 do_import_script("../mailnews/test/resources/mailDirService.js");
 
+const kSimpleNewsArticle =
+  "From: John Doe <john.doe@example.com>\n"+
+  "Date: Sat, 24 Mar 1990 10:59:24 -0500\n"+
+  "Newsgroups: test.subscribe.simple\n"+
+  "Subject: H2G2 -- What does it mean?\n"+
+  "Message-ID: <TSS1@nntp.test>\n"+
+  "\n"+
+  "What does the acronym H2G2 stand for? I've seen it before...\n";
+
 // The groups to set up on the fake server.
 // It is an array of tuples, where the first element is the group name and the
 // second element is whether or not we should subscribe to it.
 var groups = [
   ["test.empty", false],
   ["test.subscribe.empty", true],
   ["test.subscribe.simple", true],
   ["test.filter", true]
@@ -46,23 +55,17 @@ function setupNNTPDaemon() {
         post += part;
         part = sstream.read(4096);
       }
       sstream.close();
       fstream.close();
       daemon.addArticle(new newsArticle(post));
   });
 
-  var article = new newsArticle("From: John Doe <john.doe@example.com>\n"+
-      "Date: Sat, 24 Mar 1990 10:59:24 -0500\n"+
-      "Newsgroups: test.subscribe.simple\n"+
-      "Subject: H2G2 -- What does it mean?\n"+
-      "Message-ID: <TSS1@nntp.test>\n"+
-      "\n"+
-      "What does the acronym H2G2 stand for? I've seen it before...\n");
+  var article = new newsArticle(kSimpleNewsArticle);
   daemon.addArticleToGroup(article, "test.subscribe.simple", 1);
 
   return daemon;
 }
 
 // Enable strict threading
 var prefs = Cc["@mozilla.org/preferences-service;1"]
               .getService(Ci.nsIPrefBranch);
new file mode 100644
--- /dev/null
+++ b/mailnews/news/test/unit/test_getNewsMessage.js
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Tests:
+ * - getNewMessages for a newsgroup folder (single message).
+ * - DisplayMessage for a newsgroup message
+ *   - Downloading a single message and checking content in stream is correct.
+ */
+
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+// The basic daemon to use for testing nntpd.js implementations
+var daemon = setupNNTPDaemon();
+
+// Define these up here for checking with the transaction
+var type = null;
+var test = null;
+
+var server;
+var localserver;
+
+var streamListener =
+{
+  _data: "",
+
+  QueryInterface:
+    XPCOMUtils.generateQI([Ci.nsIStreamListener, Ci.nsIRequestObserver]),
+
+  // nsIRequestObserver
+  onStartRequest: function(aRequest, aContext) {
+  },
+  onStopRequest: function(aRequest, aContext, aStatusCode) {
+    localserver.closeCachedConnections();
+
+    server.stop();
+
+    var thread = gThreadManager.currentThread;
+    while (thread.hasPendingEvents())
+      thread.processNextEvent(true);
+
+    do_check_eq(aStatusCode, 0);
+
+    // Reduce any \r\n to just \n so we can do a good comparison on any
+    // platform.
+    var reduced = this._data.replace(/\r\n/g, "\n");
+    do_check_eq(reduced, kSimpleNewsArticle);
+    do_test_finished();
+  },
+
+  // nsIStreamListener
+  onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
+    let scriptStream = Cc["@mozilla.org/scriptableinputstream;1"]
+                         .createInstance(Ci.nsIScriptableInputStream);
+
+    scriptStream.init(aInputStream);
+
+    this._data += scriptStream.read(aCount);
+  }
+};
+
+function run_test() {
+  type = "RFC 977";
+  var handler = new NNTP_RFC977_handler(daemon);
+  localserver = setupLocalServer(NNTP_PORT);
+  server = new nsMailServer(handler);
+  server.start(NNTP_PORT);
+
+  try {
+    // Get the folder and new mail
+    var folder = localserver.rootFolder.getChildNamed("test.subscribe.simple");
+    folder.clearFlag(Ci.nsMsgFolderFlags.Offline);
+    folder.getNewMessages(null, {
+      OnStopRunningUrl: function () { localserver.closeCachedConnections(); }});
+    server.performTest();
+
+    do_check_eq(folder.getTotalMessages(false), 1);
+    do_check_true(folder.hasNewMessages);
+ 
+    server.resetTest();
+
+    var message = folder.firstNewMessage;
+
+    var messageUri = folder.getUriForMsg(message);
+
+    var nntpService = Cc["@mozilla.org/messenger/nntpservice;1"]
+      .getService(Ci.nsIMsgMessageService);
+
+    do_test_pending();
+
+    nntpService.DisplayMessage(messageUri, streamListener, null, null, null, {});
+  } catch (e) {
+    server.stop();
+    do_throw(e);
+  }
+};