Bug 462045: make server.isSecure work for POP/IMAP. r=neil, sr=bienvenu
authorMagnus Melin <mkmelin@iki.fi>
Tue, 04 Nov 2008 07:30:36 +0200
changeset 812 e689f497950d6224c02818935d5799990ac31960
parent 811 17945ea26634fd56e1004b39f7f1f9a878820751
child 813 a9219080b2f2b91dfd0ff4aeb2cdf27e99c88efa
push id737
push usermkmelin@iki.fi
push dateTue, 04 Nov 2008 05:30:52 +0000
treeherdercomm-central@e689f497950d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil, bienvenu
bugs462045
Bug 462045: make server.isSecure work for POP/IMAP. r=neil, sr=bienvenu
mailnews/base/resources/content/folderWidgets.xml
mailnews/base/src/nsMsgFolderDataSource.cpp
mailnews/base/util/nsMsgIncomingServer.cpp
mailnews/news/src/nsNntpIncomingServer.cpp
mailnews/news/src/nsNntpIncomingServer.h
--- a/mailnews/base/resources/content/folderWidgets.xml
+++ b/mailnews/base/resources/content/folderWidgets.xml
@@ -624,32 +624,18 @@
           var biffStates = ["NewMail", "NoMail", "UnknownMail"];
           for each (var state in biffStates) {
             if (aFolder.biffState == Ci.nsIMsgFolder["nsMsgBiffState_" + state]) {
               aMenuNode.setAttribute("BiffState", state);
               break;
             }
           }
 
-          // IsServer is simple
           aMenuNode.setAttribute("IsServer", aFolder.isServer);
-
-          // We have to work a bit for IsSecure.  This sucks
-          var server = aFolder.server;
-          if (server instanceof Ci.nsINntpIncomingServer) {
-            aMenuNode.setAttribute("IsSecure", server.isSecure);
-          } else {
-            // If it's not a news-server, apparently we look at the socket type
-            var sock = server.socketType;
-            var isSecure = (sock == Ci.nsIMsgIncomingServer.alwaysUseTLS ||
-                            sock == Ci.nsIMsgIncomingServer.useSSL);
-            aMenuNode.setAttribute("IsSecure", isSecure);
-          }
-
-          // the ServerType attribute
+          aMenuNode.setAttribute("IsSecure", aFolder.server.isSecure);
           aMenuNode.setAttribute("ServerType", aFolder.server.type);
         ]]></body>
       </method>
 
       <!--
          - Makes a given folder selected.
          -
          - @param aFolder  the folder to select
--- a/mailnews/base/src/nsMsgFolderDataSource.cpp
+++ b/mailnews/base/src/nsMsgFolderDataSource.cpp
@@ -1378,27 +1378,18 @@ nsMsgFolderDataSource::createFolderIsSec
 {
   nsresult rv;
   PRBool isSecure = PR_FALSE;
 
   nsCOMPtr<nsIMsgIncomingServer> server;
   rv = folder->GetServer(getter_AddRefs(server));
 
   if (NS_SUCCEEDED(rv) && server) {
-    nsCOMPtr<nsINntpIncomingServer> nntpIncomingServer = do_QueryInterface(server);
-
-    if(nntpIncomingServer)
-      rv = server->GetIsSecure(&isSecure);
-    else {
-      PRInt32 socketType;
-      rv = server->GetSocketType(&socketType);
-      if (NS_SUCCEEDED(rv) && (socketType == nsIMsgIncomingServer::alwaysUseTLS ||
-                              socketType == nsIMsgIncomingServer::useSSL))
-        isSecure = PR_TRUE;
-    }
+    rv = server->GetIsSecure(&isSecure);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   *target = (isSecure) ? kTrueLiteral : kFalseLiteral;
   NS_IF_ADDREF(*target);
   return NS_OK;
 }
 
 
--- a/mailnews/base/util/nsMsgIncomingServer.cpp
+++ b/mailnews/base/util/nsMsgIncomingServer.cpp
@@ -1521,26 +1521,32 @@ NS_IMETHODIMP
 nsMsgIncomingServer::GetSearchScope(nsMsgSearchScopeValue *searchScope)
 {
   NS_ENSURE_ARG_POINTER(searchScope);
   *searchScope = nsMsgSearchScope::offlineMail;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMsgIncomingServer::GetIsSecure(PRBool* aIsSecure)
+nsMsgIncomingServer::GetIsSecure(PRBool *aIsSecure)
 {
-  return GetBoolValue("isSecure", aIsSecure);
+  NS_ENSURE_ARG_POINTER(aIsSecure);
+  PRInt32 socketType;
+  nsresult rv = GetSocketType(&socketType);
+  NS_ENSURE_SUCCESS(rv,rv);
+  *aIsSecure = (socketType == nsIMsgIncomingServer::alwaysUseTLS ||
+                socketType == nsIMsgIncomingServer::useSSL);
 }
 
 NS_IMETHODIMP
 nsMsgIncomingServer::SetIsSecure(PRBool aIsSecure)
 {
   PRBool isSecure;
-  GetBoolValue("isSecure", &isSecure);
+  nsresult rv = GetIsSecure(&isSecure);
+  NS_ENSURE_SUCCESS(rv,rv);
   if (isSecure != aIsSecure) {
     SetBoolValue("isSecure", aIsSecure);
     if (m_rootFolder)
       m_rootFolder->NotifyBoolPropertyChanged(NS_NewAtom("isSecure"), isSecure, aIsSecure);
   }
   return NS_OK;
 }
 
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -2053,16 +2053,22 @@ nsNntpIncomingServer::GetSearchScope(nsM
    }
    else {
      *searchScope = nsMsgSearchScope::news;
    }
    return NS_OK;
 }
 
 NS_IMETHODIMP
+nsNntpIncomingServer::GetIsSecure(PRBool* aIsSecure)
+{
+  return GetBoolValue("isSecure", aIsSecure);
+}
+
+NS_IMETHODIMP
 nsNntpIncomingServer::OnUserOrHostNameChanged(const nsACString& oldName, const nsACString& newName)
 {
   nsresult rv;
   // 1. Do common things in the base class.
   rv = nsMsgIncomingServer::OnUserOrHostNameChanged(oldName, newName);
   NS_ENSURE_SUCCESS(rv,rv);
 
   // 2. Remove file hostinfo.dat so that the new subscribe
--- a/mailnews/news/src/nsNntpIncomingServer.h
+++ b/mailnews/news/src/nsNntpIncomingServer.h
@@ -72,17 +72,17 @@ public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSINNTPINCOMINGSERVER
     NS_DECL_NSIURLLISTENER
     NS_DECL_NSISUBSCRIBABLESERVER
     NS_DECL_NSITREEVIEW
 
     nsNntpIncomingServer();
     virtual ~nsNntpIncomingServer();
-    
+
     NS_IMETHOD GetLocalStoreType(nsACString& type);
     NS_IMETHOD CloseCachedConnections();
     NS_IMETHOD PerformBiff(nsIMsgWindow *aMsgWindow);
     NS_IMETHOD PerformExpand(nsIMsgWindow *aMsgWindow);
     NS_IMETHOD OnUserOrHostNameChanged(const nsACString& oldName, const nsACString& newName);
 
     // for nsMsgLineBuffer
     virtual PRInt32 HandleLine(const char *line, PRUint32 line_size);
@@ -92,16 +92,18 @@ public:
     NS_IMETHOD GetCanSearchMessages(PRBool *canSearchMessages);
     NS_IMETHOD GetOfflineSupportLevel(PRInt32 *aSupportLevel);
     NS_IMETHOD GetDefaultCopiesAndFoldersPrefsToServer(PRBool *aCopiesAndFoldersOnServer);
     NS_IMETHOD GetCanCreateFoldersOnServer(PRBool *aCanCreateFoldersOnServer);
     NS_IMETHOD GetCanFileMessagesOnServer(PRBool *aCanFileMessagesOnServer);
     NS_IMETHOD GetFilterScope(nsMsgSearchScopeValue *filterScope);
     NS_IMETHOD GetSearchScope(nsMsgSearchScopeValue *searchScope);
 
+    NS_IMETHOD GetIsSecure(PRBool *aIsSecure); // override nsMsgIncomingServer impl
+
     nsresult AppendIfSearchMatch(nsCString& newsgroupName);
 
 protected:
    virtual nsresult CreateRootFolderFromUri(const nsCString &serverUri,
                                             nsIMsgFolder **rootFolder);
     nsresult CreateProtocolInstance(nsINNTPProtocol ** aNntpConnection, nsIURI *url,
                                              nsIMsgWindow *window);
     PRBool ConnectionTimeOut(nsINNTPProtocol* aNntpConnection);