Back to index

lightning-sunbird  0.9+nobinonly
nsMovemailIncomingServer.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  *   Adam D. Moss <adam@gimp.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsMsgLocalCID.h"
00040 #include "nsMsgFolderFlags.h"
00041 #include "nsIFileSpec.h"
00042 #include "nsIMsgLocalMailFolder.h"
00043 #include "nsIMovemailService.h"
00044 #include "msgCore.h" // pre-compiled headers
00045 #include "nsMovemailIncomingServer.h"
00046 
00047 
00048 static NS_DEFINE_CID(kCMovemailServiceCID, NS_MOVEMAILSERVICE_CID);
00049 
00050 
00051 NS_IMPL_ISUPPORTS_INHERITED2(nsMovemailIncomingServer,
00052                              nsMsgIncomingServer,
00053                              nsIMovemailIncomingServer,
00054                              nsILocalMailIncomingServer)
00055 
00056                             
00057 
00058 nsMovemailIncomingServer::nsMovemailIncomingServer()
00059 {    
00060     m_canHaveFilters = PR_TRUE;
00061 }
00062 
00063 nsMovemailIncomingServer::~nsMovemailIncomingServer()
00064 {
00065 }
00066 
00067 NS_IMETHODIMP
00068 nsMovemailIncomingServer::GetIsSecureServer(PRBool *aIsSecureServer)
00069 {
00070     NS_ENSURE_ARG_POINTER(aIsSecureServer);
00071     *aIsSecureServer = PR_FALSE;
00072     return NS_OK;
00073 }
00074 
00075 nsresult
00076 nsMovemailIncomingServer::GetLocalStoreType(char **type)
00077 {
00078     NS_ENSURE_ARG_POINTER(type);
00079     *type = strdup("mailbox");
00080     return NS_OK;
00081 }
00082 
00083 NS_IMETHODIMP 
00084 nsMovemailIncomingServer::PerformBiff(nsIMsgWindow *aMsgWindow)
00085 {
00086     nsresult rv;
00087     nsCOMPtr<nsIMovemailService> movemailService(do_GetService(
00088                                                  kCMovemailServiceCID, &rv));
00089     if (NS_FAILED(rv)) return rv;
00090     nsCOMPtr<nsIMsgFolder> inbox;
00091     nsCOMPtr<nsIMsgFolder> rootMsgFolder;
00092     nsCOMPtr<nsIUrlListener> urlListener;
00093     rv = GetRootMsgFolder(getter_AddRefs(rootMsgFolder));
00094     if(NS_SUCCEEDED(rv) && rootMsgFolder)
00095     {
00096          PRUint32 numFolders;
00097          rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1,
00098                                                 &numFolders,
00099                                                 getter_AddRefs(inbox));
00100          if (NS_FAILED(rv) || numFolders != 1) return rv;
00101     }
00102 
00103     SetPerformingBiff(PR_TRUE);
00104     urlListener = do_QueryInterface(inbox);
00105 
00106     PRBool downloadOnBiff = PR_FALSE;
00107     rv = GetDownloadOnBiff(&downloadOnBiff);
00108     if (downloadOnBiff)
00109     {
00110        nsCOMPtr <nsIMsgLocalMailFolder> localInbox = do_QueryInterface(inbox,
00111                                                                        &rv);
00112        if (localInbox && NS_SUCCEEDED(rv))
00113        {
00114            PRBool valid = PR_FALSE;
00115            nsCOMPtr <nsIMsgDatabase> db;
00116            rv = inbox->GetMsgDatabase(aMsgWindow, getter_AddRefs(db));
00117            if (NS_SUCCEEDED(rv) && db)
00118            {
00119                rv = db->GetSummaryValid(&valid);
00120            }
00121            if (NS_SUCCEEDED(rv) && valid)
00122            {
00123                rv = movemailService->GetNewMail(aMsgWindow, urlListener, inbox,
00124                                                 this, nsnull);
00125            }
00126            else
00127            {
00128               PRBool isLocked;
00129               inbox->GetLocked(&isLocked);
00130               if (!isLocked)
00131               {
00132                  rv = localInbox->ParseFolder(aMsgWindow, urlListener);
00133               }
00134               if (NS_SUCCEEDED(rv))
00135               {
00136                  rv = localInbox->SetCheckForNewMessagesAfterParsing(PR_TRUE);
00137               }
00138            }
00139        }
00140     }
00141     else
00142     {
00143         movemailService->CheckForNewMail(urlListener, inbox, this, nsnull); 
00144     }
00145 
00146     return NS_OK;
00147 }
00148 
00149 NS_IMETHODIMP
00150 nsMovemailIncomingServer::SetFlagsOnDefaultMailboxes()
00151 {
00152     nsCOMPtr<nsIMsgFolder> rootFolder;
00153     nsresult rv = GetRootFolder(getter_AddRefs(rootFolder));
00154     NS_ENSURE_SUCCESS(rv, rv);
00155 
00156     nsCOMPtr<nsIMsgLocalMailFolder> localFolder =
00157         do_QueryInterface(rootFolder, &rv);
00158     NS_ENSURE_SUCCESS(rv, rv);
00159 
00160     localFolder->SetFlagsOnDefaultMailboxes(MSG_FOLDER_FLAG_INBOX |
00161                                             MSG_FOLDER_FLAG_SENTMAIL |
00162                                             MSG_FOLDER_FLAG_DRAFTS |
00163                                             MSG_FOLDER_FLAG_TEMPLATES |
00164                                             MSG_FOLDER_FLAG_TRASH |
00165                                             MSG_FOLDER_FLAG_JUNK |
00166                                             // hmm?
00167                                             MSG_FOLDER_FLAG_QUEUE);
00168     return NS_OK;
00169 }
00170 
00171 NS_IMETHODIMP nsMovemailIncomingServer::CreateDefaultMailboxes(nsIFileSpec *path)
00172 {
00173     NS_ENSURE_ARG_POINTER(path);
00174 
00175     nsresult rv = path->AppendRelativeUnixPath("Inbox");
00176     if (NS_FAILED(rv)) return rv;
00177     PRBool exists;
00178     rv = path->Exists(&exists);
00179     if (NS_FAILED(rv)) return rv;
00180     if (!exists) {
00181         rv = path->Touch();
00182         if (NS_FAILED(rv)) return rv;
00183     }
00184 
00185     rv = path->SetLeafName("Trash");
00186     if (NS_FAILED(rv)) return rv;
00187     rv = path->Exists(&exists);
00188     if (NS_FAILED(rv)) return rv;
00189     if (!exists) {
00190         rv = path->Touch();
00191         if (NS_FAILED(rv)) return rv;
00192     }
00193 
00194     rv = path->SetLeafName("Sent");
00195     if (NS_FAILED(rv)) return rv;
00196     rv = path->Exists(&exists);
00197     if (NS_FAILED(rv)) return rv;
00198     if (!exists) {
00199         rv = path->Touch();
00200         if (NS_FAILED(rv)) return rv;
00201     }
00202 
00203     rv = path->SetLeafName("Drafts");
00204     if (NS_FAILED(rv)) return rv;
00205     rv = path->Exists(&exists);
00206     if (NS_FAILED(rv)) return rv;
00207     if (!exists) {
00208         rv = path->Touch();
00209         if (NS_FAILED(rv)) return rv;
00210     }
00211 
00212     rv = path->SetLeafName("Templates");
00213     if (NS_FAILED(rv)) return rv;
00214     rv = path->Exists(&exists);
00215     if (NS_FAILED(rv)) return rv;
00216     if (!exists) {
00217         rv = path->Touch();
00218         if (NS_FAILED(rv)) return rv;
00219     }
00220 
00221     rv = path->SetLeafName("Unsent Messages");
00222     if (NS_FAILED(rv)) return rv;
00223     rv = path->Exists(&exists);
00224     if (NS_FAILED(rv)) return rv;
00225     if (!exists) {
00226         rv = path->Touch();
00227         if (NS_FAILED(rv)) return rv;
00228     }
00229     return rv;
00230 }
00231 
00232 
00233 NS_IMETHODIMP
00234 nsMovemailIncomingServer::GetNewMail(nsIMsgWindow *aMsgWindow,
00235                                      nsIUrlListener *aUrlListener,
00236                                      nsIMsgFolder *aMsgFolder,
00237                                      nsIURI **aResult)
00238 {
00239     nsresult rv;
00240     
00241     nsCOMPtr<nsIMovemailService> movemailService = 
00242              do_GetService(kCMovemailServiceCID, &rv);
00243     
00244     if (NS_FAILED(rv)) return rv;
00245     
00246     rv = movemailService->GetNewMail(aMsgWindow, aUrlListener,
00247                                      aMsgFolder, this, aResult);
00248 
00249     return rv;
00250 }        
00251 
00252 NS_IMETHODIMP
00253 nsMovemailIncomingServer::GetDownloadMessagesAtStartup(PRBool *getMessagesAtStartup)
00254 {
00255     NS_ENSURE_ARG_POINTER(getMessagesAtStartup);
00256     *getMessagesAtStartup = PR_TRUE;
00257     return NS_OK;
00258 }
00259 
00260 NS_IMETHODIMP
00261 nsMovemailIncomingServer::GetCanSearchMessages(PRBool *canSearchMessages)
00262 {
00263     NS_ENSURE_ARG_POINTER(canSearchMessages);
00264     *canSearchMessages = PR_TRUE;
00265     return NS_OK;
00266 }
00267 
00268 NS_IMETHODIMP 
00269 nsMovemailIncomingServer::GetServerRequiresPasswordForBiff(PRBool *aServerRequiresPasswordForBiff)
00270 {
00271     NS_ENSURE_ARG_POINTER(aServerRequiresPasswordForBiff);
00272     *aServerRequiresPasswordForBiff = PR_FALSE;
00273     return NS_OK;
00274 }
00275 
00276 NS_IMETHODIMP 
00277 nsMovemailIncomingServer::GetAccountManagerChrome(nsAString& aResult)
00278 {
00279     aResult.AssignLiteral("am-main.xul");
00280     return NS_OK;
00281 }