Back to index

lightning-sunbird  0.9+nobinonly
nsNoneService.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *   David Bienvenu <bienvenu@nventure.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "msgCore.h"    // precompiled header...
00041 
00042 #include "nsNoneService.h"
00043 #include "nsINoIncomingServer.h"
00044 #include "nsINoneService.h"
00045 #include "nsIMsgProtocolInfo.h"
00046 #include "nsIMsgMailSession.h"
00047 
00048 #include "nsMsgLocalCID.h"
00049 #include "nsMsgBaseCID.h"
00050 #include "nsXPIDLString.h"
00051 #include "nsCOMPtr.h"
00052 #include "nsIFileSpec.h"
00053 #include "nsMsgUtils.h"
00054 
00055 #include "nsIDirectoryService.h"
00056 #include "nsAppDirectoryServiceDefs.h"
00057 
00058 #define PREF_MAIL_ROOT_NONE "mail.root.none"        // old - for backward compatibility only
00059 #define PREF_MAIL_ROOT_NONE_REL "mail.root.none-rel"
00060 
00061 nsNoneService::nsNoneService()
00062 {
00063 }
00064 
00065 nsNoneService::~nsNoneService()
00066 {}
00067 
00068 NS_IMPL_ISUPPORTS2(nsNoneService, nsINoneService, nsIMsgProtocolInfo)
00069 
00070 NS_IMETHODIMP
00071 nsNoneService::SetDefaultLocalPath(nsIFileSpec *aPath)
00072 {
00073     NS_ENSURE_ARG(aPath);
00074     
00075     nsFileSpec spec;
00076     nsresult rv = aPath->GetFileSpec(&spec);
00077     if (NS_FAILED(rv)) return rv;
00078     nsCOMPtr<nsILocalFile> localFile;
00079     NS_FileSpecToIFile(&spec, getter_AddRefs(localFile));
00080     if (!localFile) return NS_ERROR_FAILURE;
00081     
00082     return NS_SetPersistentFile(PREF_MAIL_ROOT_NONE_REL, PREF_MAIL_ROOT_NONE, localFile);
00083 }     
00084 
00085 NS_IMETHODIMP
00086 nsNoneService::GetDefaultLocalPath(nsIFileSpec ** aResult)
00087 {
00088     NS_ENSURE_ARG_POINTER(aResult);
00089     *aResult = nsnull;
00090     
00091     PRBool havePref;
00092     nsCOMPtr<nsILocalFile> localFile;    
00093     nsresult rv = NS_GetPersistentFile(PREF_MAIL_ROOT_NONE_REL,
00094                               PREF_MAIL_ROOT_NONE,
00095                               NS_APP_MAIL_50_DIR,
00096                               havePref,
00097                               getter_AddRefs(localFile));
00098     if (NS_FAILED(rv)) return rv;
00099     
00100     PRBool exists;
00101     rv = localFile->Exists(&exists);
00102     if (NS_SUCCEEDED(rv) && !exists)
00103         rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
00104     if (NS_FAILED(rv)) return rv;
00105     
00106     // Make the resulting nsIFileSpec
00107     // TODO: Convert arg to nsILocalFile and avoid this
00108     nsCOMPtr<nsIFileSpec> outSpec;
00109     rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec));
00110     if (NS_FAILED(rv)) return rv;
00111     
00112     if (!havePref || !exists) 
00113     {
00114         rv = NS_SetPersistentFile(PREF_MAIL_ROOT_NONE_REL, PREF_MAIL_ROOT_NONE, localFile);
00115         NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to set root dir pref.");
00116     }
00117         
00118     NS_IF_ADDREF(*aResult = outSpec);
00119     return NS_OK;
00120 
00121 }
00122     
00123 
00124 NS_IMETHODIMP
00125 nsNoneService::GetServerIID(nsIID* *aServerIID)
00126 {
00127     *aServerIID = new nsIID(NS_GET_IID(nsINoIncomingServer));
00128     return NS_OK;
00129 }
00130 
00131 NS_IMETHODIMP
00132 nsNoneService::GetRequiresUsername(PRBool *aRequiresUsername)
00133 {
00134   NS_ENSURE_ARG_POINTER(aRequiresUsername);
00135   *aRequiresUsername = PR_TRUE;
00136   return NS_OK;
00137 }
00138 
00139 NS_IMETHODIMP
00140 nsNoneService::GetPreflightPrettyNameWithEmailAddress(PRBool *aPreflightPrettyNameWithEmailAddress)
00141 {
00142   NS_ENSURE_ARG_POINTER(aPreflightPrettyNameWithEmailAddress);
00143   *aPreflightPrettyNameWithEmailAddress = PR_TRUE;
00144   return NS_OK;
00145 }
00146 
00147 NS_IMETHODIMP
00148 nsNoneService::GetCanLoginAtStartUp(PRBool *aCanLoginAtStartUp)
00149 {
00150   NS_ENSURE_ARG_POINTER(aCanLoginAtStartUp);
00151   *aCanLoginAtStartUp = PR_FALSE;
00152   return NS_OK;
00153 }
00154 
00155 NS_IMETHODIMP
00156 nsNoneService::GetCanDelete(PRBool *aCanDelete)
00157 {
00158   NS_ENSURE_ARG_POINTER(aCanDelete);
00159   *aCanDelete = PR_FALSE;
00160   return NS_OK;
00161 }  
00162 
00163 NS_IMETHODIMP
00164 nsNoneService::GetCanDuplicate(PRBool *aCanDuplicate)
00165 {
00166   NS_ENSURE_ARG_POINTER(aCanDuplicate);
00167   *aCanDuplicate = PR_FALSE;
00168   return NS_OK;
00169 }  
00170 
00171 NS_IMETHODIMP
00172 nsNoneService::GetCanGetMessages(PRBool *aCanGetMessages)
00173 {
00174     NS_ENSURE_ARG_POINTER(aCanGetMessages);
00175     *aCanGetMessages = PR_FALSE;
00176     return NS_OK;
00177 }  
00178 
00179 NS_IMETHODIMP
00180 nsNoneService::GetCanGetIncomingMessages(PRBool *aCanGetIncomingMessages)
00181 {
00182     NS_ENSURE_ARG_POINTER(aCanGetIncomingMessages);
00183     *aCanGetIncomingMessages = PR_FALSE;
00184     return NS_OK;
00185 } 
00186 
00187 NS_IMETHODIMP 
00188 nsNoneService::GetDefaultDoBiff(PRBool *aDoBiff)
00189 {
00190     NS_ENSURE_ARG_POINTER(aDoBiff);
00191     // by default, don't do biff for "none" servers
00192     *aDoBiff = PR_FALSE;    
00193     return NS_OK;
00194 }
00195 
00196 NS_IMETHODIMP
00197 nsNoneService::GetDefaultServerPort(PRBool isSecure, PRInt32 *aDefaultPort)
00198 {
00199     NS_ASSERTION(0, "This should probably never be called!");
00200     NS_ENSURE_ARG_POINTER(aDefaultPort);
00201     *aDefaultPort = -1;
00202     return NS_OK;
00203 }
00204 
00205 NS_IMETHODIMP 
00206 nsNoneService::GetShowComposeMsgLink(PRBool *showComposeMsgLink)
00207 {
00208     NS_ENSURE_ARG_POINTER(showComposeMsgLink);
00209     *showComposeMsgLink = PR_FALSE;    
00210     return NS_OK;
00211 }
00212 
00213 NS_IMETHODIMP
00214 nsNoneService::GetNeedToBuildSpecialFolderURIs(PRBool *needToBuildSpecialFolderURIs)
00215 {
00216     NS_ENSURE_ARG_POINTER(needToBuildSpecialFolderURIs);
00217     *needToBuildSpecialFolderURIs = PR_FALSE;
00218     return NS_OK;
00219 }
00220 
00221 NS_IMETHODIMP
00222 nsNoneService::GetSpecialFoldersDeletionAllowed(PRBool *specialFoldersDeletionAllowed)
00223 {
00224     NS_ENSURE_ARG_POINTER(specialFoldersDeletionAllowed);
00225     *specialFoldersDeletionAllowed = PR_TRUE;
00226     return NS_OK;
00227 }
00228