Back to index

lightning-sunbird  0.9+nobinonly
nsMessengerMigrator.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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  *
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 "nscore.h"
00040 #include "nsIMessengerMigrator.h"
00041 #include "nsCOMPtr.h"
00042 #include "nsISmtpServer.h"
00043 #include "nsIPrefService.h"
00044 #include "nsIPrefBranch.h"
00045 #include "nsIMsgIdentity.h"
00046 #include "nsIMsgIncomingServer.h"
00047 #include "nsIObserver.h"
00048 
00049 /*
00050  * some platforms (like Windows and Mac) use a map file, because of
00051  * file name length limitations.
00052  */
00053 #if defined(XP_UNIX) || defined(XP_BEOS)
00054 /* in 4.x, the prefix was ".newsrc-" and ".snewsrc-"
00055  * in 5.0, the profile migrator code copies the newsrc files from
00056  * ~/.newsrc-* to ~/.mozilla/<profile>/News/newsrc-*
00057  * ~/.snewsrc-* to ~/.mozilla/<profile>/News/snewsrc-*
00058  */
00059 #define NEWSRC_FILE_PREFIX_IN_5x "newsrc-"
00060 #define SNEWSRC_FILE_PREFIX_IN_5x "snewsrc-"
00061 #else
00062 #define USE_NEWSRC_MAP_FILE
00063 
00064 // in the fat file, the hostname is prefix by one of these:
00065 #define PSUEDO_NAME_PREFIX "newsrc-"
00066 #define PSUEDO_SECURE_NAME_PREFIX "snewsrc-"
00067 
00068 #if defined(XP_WIN) || defined(XP_OS2)
00069 /* another case of mac vs. windows in 4.x
00070  * on mac, the default for news fcc, if you used imap, 
00071  * was "Sent on Local Mail"
00072  * on windows, the default for news fcc, 
00073  * if you used imap, was "Sent on <imap server>"
00074  */
00075 #define NEWS_FCC_DEFAULT_TO_IMAP_SENT
00076 #define NEWS_FAT_FILE_NAME "fat"
00077 /*
00078  * on the PC, the fat file stores absolute paths to the newsrc files
00079  * on the Mac, the fat file stores relative paths to the newsrc files
00080  */
00081 #define NEWS_FAT_STORES_ABSOLUTE_NEWSRC_FILE_PATHS 1
00082 #elif defined(XP_MAC) || defined(XP_MACOSX)
00083 #define NEWS_FAT_FILE_NAME "NewsFAT"
00084 #else
00085 #error dont_know_what_your_news_fat_file_is
00086 #endif /* XP_WIN, XP_OS2, XP_MAC */
00087 
00088 #endif /* XP_UNIX || XP_BEOS */
00089 
00090 class nsMessengerMigrator
00091        : public nsIMessengerMigrator, public nsIObserver
00092 {
00093 public:
00094 
00095   nsMessengerMigrator();
00096   virtual ~nsMessengerMigrator();
00097   
00098   NS_DECL_ISUPPORTS
00099   NS_DECL_NSIMESSENGERMIGRATOR
00100   NS_DECL_NSIOBSERVER  
00101 
00102   nsresult Init();
00103   nsresult Shutdown();
00104 
00105 private:
00106 
00107   nsresult MigrateIdentity(nsIMsgIdentity *identity);
00108   nsresult MigrateSmtpServer(nsISmtpServer *server);
00109   nsresult SetMailCopiesAndFolders(nsIMsgIdentity *identity, const char *username, const char *hostname);
00110   nsresult SetNewsCopiesAndFolders(nsIMsgIdentity *identity);
00111   nsresult SetUsernameIfNecessary();
00112 
00113   nsresult MigrateImapAccounts(nsIMsgIdentity *identity);
00114   nsresult MigrateImapAccount(nsIMsgIdentity *identity, const char *hostAndPort, PRBool isDefaultAccount);
00115   
00116   nsresult MigrateOldImapPrefs(nsIMsgIncomingServer *server, const char *hostAndPort);
00117   
00118   nsresult MigratePopAccount(nsIMsgIdentity *identity);
00119 
00120 #ifdef HAVE_MOVEMAIL
00121   nsresult MigrateMovemailAccount(nsIMsgIdentity *identity);
00122 #endif /* HAVE_MOVEMAIL */
00123   
00124   nsresult MigrateLocalMailAccount();
00125 
00126   nsresult MigrateOldMailPrefs(nsIMsgIncomingServer *server);
00127   
00128   nsresult MigrateNewsAccounts(nsIMsgIdentity *identity);
00129   nsresult MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostAndPort, nsFileSpec &newsrcfile, nsFileSpec &newsHostsDir, PRBool isSecure);
00130   nsresult MigrateOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostAndPort, nsFileSpec &newsrcfile);
00131 
00132   nsresult MigrateAddressBookPrefs();
00133   nsresult MigrateAddressBooks();
00134   void migrateAddressBookPrefEnum(const char *aPref);
00135         
00136   nsresult ProceedWithMigration();
00137   
00138   nsresult Convert4XUri(const char *old_uri, PRBool for_news, const char *aUsername, const char *aHostname, const char *default_folder_name, const char *default_pref_name, char **new_uri);
00139  
00140   nsresult SetSendLaterUriPref(nsIMsgIncomingServer *server);
00141 
00142   nsresult getPrefService();
00143   nsresult initializeStrings();
00144   
00145   nsresult ResetState();
00146 
00147   nsCOMPtr <nsIPrefBranch> m_prefs;
00148   PRBool m_haveShutdown;
00149   PRInt32 m_oldMailType;
00150   PRBool m_alreadySetNntpDefaultLocalPath;
00151   PRBool m_alreadySetImapDefaultLocalPath;
00152 
00153   nsCString mLocalFoldersHostname;
00154   nsString mLocalFoldersName;
00155     
00156 };
00157