!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Alec Flett <alecf@netscape.com>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38 // The gReturnmycall is used as a global variable that is set during a callback.
39 var gReturnmycall=false;
40 var accountManagerContractID = "@mozilla.org/messenger/account-manager;1";
41 var gAnyValidIdentity = false; //If there are no valid identities for any account
42 // returns the first account with an invalid server or identity
43
44 var gNewAccountToLoad = null; // used to load new messages if we come from the mail3pane
45
getInvalidAccounts
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
46 function getInvalidAccounts(accounts)
47 {
48 var numAccounts = accounts.Count();
49 var invalidAccounts = new Array;
50 var numIdentities = 0;
51 for (var i=0; i<numAccounts; i++) {
52 var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
53 try {
54 if (!account.incomingServer.valid) {
55 invalidAccounts[invalidAccounts.length] = account;
56 // skip to the next account
57 continue;
58 }
59 } catch (ex) {
60 // this account is busted, just keep going
61 continue;
62 }
63
64 var identities = account.identities;
65 numIdentities = identities.Count();
66
67 for (var j=0; j<numIdentities; j++) {
68 var identity = identities.QueryElementAt(j, Components.interfaces.nsIMsgIdentity);
69 if (identity.valid) {
70 gAnyValidIdentity = true;
71 }
72 else {
73 invalidAccounts[invalidAccounts.length] = account;
74 }
75 }
76 }
77 return invalidAccounts;
78 }
79
80 // This function gets called from verifyAccounts.
81 // We do not have to do anything on
82 // unix and mac but on windows we have to bring up a
83 // dialog based on the settings the user has.
84 // This will bring up the dialog only once per session and only if we
85 // are not the default mail client.
showMailIntegrationDialog
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
86 function showMailIntegrationDialog() {
87 var mapiRegistry = null;
88 try {
89 var mapiRegistryProgID = "@mozilla.org/mapiregistry;1"
90 if (mapiRegistryProgID in Components.classes) {
91 mapiRegistry = Components.classes[mapiRegistryProgID].getService(Components.interfaces.nsIMapiRegistry);
92 }
93 }
94 catch (ex) {
95 }
96
97 // showDialog is TRUE only if we did not bring up this dialog already
98 // and we are not the default mail client
99 var prefLocked = false;
100 if (mapiRegistry && mapiRegistry.showDialog) {
101 const prefbase = "system.windows.lock_ui.";
102 try {
103 var prefService = Components.classes["@mozilla.org/preferences-service;1"]
104 .getService()
105 .QueryInterface(Components.interfaces.nsIPrefService);
106 var prefBranch = prefService.getBranch(prefbase);
107
108 if (prefBranch && prefBranch.prefIsLocked("defaultMailClient")) {
109 prefLocked = true;
110 mapiRegistry.isDefaultMailClient = prefBranch.getBoolPref("defaultMailClient") ;
111 }
112 }
113 catch (ex) {}
114 try {
115 if (!prefLocked)
116 mapiRegistry.showMailIntegrationDialog(window /* parent window */);
117 }
118 catch (ex) {
119 dump("mapi code failed: " + ex + "\n");
120 }
121 }
122 }
123
verifyAccounts
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
124 function verifyAccounts(wizardcallback)
125 {
126 //check to see if the function is called with the callback and if so set the global variable gReturnmycall to true
127 if(wizardcallback)
128 gReturnmycall = true;
129 var openWizard = false;
130 var prefillAccount;
131 var state=true;
132 var ret = true;
133
134 try {
135 var am = Components.classes[accountManagerContractID].getService(Components.interfaces.nsIMsgAccountManager);
136
137 // migrate quoting preferences from global to per account. This function returns
138 // true if it had to migrate, which we will use to mean this is a just migrated
139 // or new profile
140 var newProfile = migrateGlobalQuotingPrefs(am.allIdentities);
141
142 var accounts = am.accounts;
143
144 // as long as we have some accounts, we're fine.
145 var accountCount = accounts.Count();
146 var invalidAccounts = getInvalidAccounts(accounts);
147 if (invalidAccounts.length > 0) {
148 prefillAccount = invalidAccounts[0];
149 } else {
150 }
151
152 // if there are no accounts, or all accounts are "invalid"
153 // then kick off the account migration. Or if this is a new (to Mozilla) profile.
154 // MCD can set up accounts without the profile being used yet
155 if (newProfile) {
156 // check if MCD is configured. If not, say this is not a new profile
157 // so that we don't accidentally remigrate non MCD profiles.
158 var adminUrl;
159 var pref = Components.classes["@mozilla.org/preferences-service;1"]
160 .getService(Components.interfaces.nsIPrefBranch);
161 try {
162 adminUrl = pref.getCharPref("autoadmin.global_config_url");
163 }
164 catch (ex) {}
165 if (!adminUrl)
166 newProfile = false;
167 }
168 if ((newProfile && !accountCount) || accountCount == invalidAccounts.length)
169 openWizard = true;
170
171 //We are doing openWizard if MessengerMigration returns some kind of error
172 //(including those cases where there is nothing to migrate).
173 //prefillAccount is valid, if there is an invalid account already
174 //gAnyValidIdentity is true when you've got at least one *valid* identity,
175 //Since local folders is an identity-less account, if you only have
176 //local folders, it will be false.
177 //wizardcallback is true only when verifyaccounts is called from compose window.
178 //the last condition in the if is so that we call account wizard only when the user
179 //has only a local folder and tries to compose mail.
180
181 if (openWizard || prefillAccount || ((!gAnyValidIdentity) && wizardcallback)) {
182 MsgAccountWizard();
183 ret = false;
184 }
185 else
186 {
187 var localFoldersExists;
188 try
189 {
190 localFoldersExists = am.localFoldersServer;
191 }
192 catch (ex)
193 {
194 localFoldersExists = false;
195 }
196
197 // we didn't create the MsgAccountWizard - we need to verify that local folders exists.
198 if (!localFoldersExists)
199 am.createLocalMailAccount();
200 }
201
202 // This will only succeed on SeaMonkey windows builds
203 var mapiRegistryProgID = "@mozilla.org/mapiregistry;1"
204 if (mapiRegistryProgID in Components.classes)
205 {
206 // hack, set a time out to do this, so that the window can load first
207 setTimeout(showMailIntegrationDialog, 0);
208 }
209
210 return ret;
211 }
212 catch (ex) {
213 dump("error verifying accounts " + ex + "\n");
214 return false;
215 }
216 }
217
218 // we do this from a timer because if this is called from the onload=
219 // handler, then the parent window doesn't appear until after the wizard
220 // has closed, and this is confusing to the user
MsgAccountWizard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
221 function MsgAccountWizard()
222 {
223 setTimeout("msgOpenAccountWizard();", 0);
224 }
225
msgOpenAccountWizard
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
226 function msgOpenAccountWizard()
227 {
228 gNewAccountToLoad = null;
229
230 // Check to see if the verify accounts function
231 // was called with callback or not.
232 if (gReturnmycall)
233 window.openDialog("chrome://messenger/content/AccountWizard.xul",
234 "AccountWizard", "chrome,modal,titlebar,centerscreen", {okCallback:WizCallback});
235 else
236 window.openDialog("chrome://messenger/content/AccountWizard.xul",
237 "AccountWizard", "chrome,modal,titlebar,centerscreen");
238
239 loadInboxForNewAccount();
240
241 // For the first account we need to reset the default smtp server in the
242 // panel, by accessing smtpServers we are actually ensuring the smtp server
243 // list is loaded.
244 var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"].getService(Components.interfaces.nsISmtpService);
245 var servers = smtpService.smtpServers;
246 try{ReloadSmtpPanel();}
247 catch(ex){}
248 }
249
250 // selectPage: the xul file name for the viewing page,
251 // null for the account main page, other pages are
252 // 'am-server.xul', 'am-copies.xul', 'am-offline.xul',
253 // 'am-addressing.xul', 'am-smtp.xul'
MsgAccountManager
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
254 function MsgAccountManager(selectPage)
255 {
256 var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].
257 getService(Components.interfaces.nsIWindowMediator);
258
259 var existingAccountManager = windowManager.getMostRecentWindow("mailnews:accountmanager");
260
261 if (existingAccountManager)
262 existingAccountManager.focus();
263 else {
264 var server;
265 try {
266 var folderURI = GetSelectedFolderURI();
267 server = GetServer(folderURI);
268 } catch (ex) { /* functions might not be defined */}
269
270 window.openDialog("chrome://messenger/content/AccountManager.xul",
271 "AccountManager", "chrome,centerscreen,modal,titlebar",
272 { server: server, selectPage: selectPage });
273 }
274 }
275
loadInboxForNewAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
276 function loadInboxForNewAccount()
277 {
278 // gNewAccountToLoad is set in the final screen of the Account Wizard if a POP account
279 // was created, the download messages box is checked, and the wizard was opened from the 3pane
280 if (gNewAccountToLoad) {
281 var rootMsgFolder = gNewAccountToLoad.incomingServer.rootMsgFolder;
282 var outNumFolders = new Object();
283 var inboxFolder = rootMsgFolder.getFoldersWithFlag(0x1000, 1, outNumFolders);
284 SelectFolder(inboxFolder.URI);
285 window.focus();
286 setTimeout(MsgGetMessage, 0);
287 gNewAccountToLoad = null;
288 }
289 }
290
291 // returns true if we migrated - it knows this because 4.x did not have the
292 // pref mailnews.quotingPrefs.version, so if it's not set, we're either
293 // migrating from 4.x, or a much older version of Mozilla.
migrateGlobalQuotingPrefs
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
294 function migrateGlobalQuotingPrefs(allIdentities)
295 {
296 // if reply_on_top and auto_quote exist then, if non-default
297 // migrate and delete, if default just delete.
298 var reply_on_top = 0;
299 var auto_quote = true;
300 var quotingPrefs = 0;
301 var migrated = false;
302 try {
303 var prefService = Components.classes["@mozilla.org/preferences-service;1"]
304 .getService(Components.interfaces.nsIPrefService);
305 var pref = prefService.getBranch(null);
306 quotingPrefs = pref.getIntPref("mailnews.quotingPrefs.version");
307 } catch (ex) {}
308
309 // If the quotingPrefs version is 0 then we need to migrate our preferences
310 if (quotingPrefs == 0) {
311 migrated = true;
312 try {
313 reply_on_top = pref.getIntPref("mailnews.reply_on_top");
314 auto_quote = pref.getBoolPref("mail.auto_quote");
315 } catch (ex) {}
316
317 if (!auto_quote || reply_on_top) {
318 var numIdentities = allIdentities.Count();
319 var identity = null;
320 for (var j = 0; j < numIdentities; j++) {
321 identity = allIdentities.QueryElementAt(j, Components.interfaces.nsIMsgIdentity);
322 if (identity.valid) {
323 identity.autoQuote = auto_quote;
324 identity.replyOnTop = reply_on_top;
325 }
326 }
327 }
328 pref.setIntPref("mailnews.quotingPrefs.version", 1);
329 }
330 return migrated;
331 }