!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 Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Manuel Reimer <Manuel.Reimer@gmx.de>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 /* the okCallback is used for sending a callback for the parent window */
41 var okCallback = null;
42 /* The account wizard creates new accounts */
43
44 /*
45 data flow into the account wizard like this:
46
47 For new accounts:
48 * pageData -> Array -> createAccount -> finishAccount
49
50 For accounts coming from the ISP setup:
51 * RDF -> Array -> pageData -> Array -> createAccount -> finishAccount
52
53 for "unfinished accounts"
54 * account -> Array -> pageData -> Array -> finishAccount
55
56 Where:
57 pageData - the actual pages coming out of the Widget State Manager
58 RDF - the ISP datasource
59 Array - associative array of attributes, that very closely
60 resembles the nsIMsgAccount/nsIMsgIncomingServer/nsIMsgIdentity
61 structure
62 createAccount() - creates an account from the above Array
63 finishAccount() - fills an existing account with data from the above Array
64
65 */
66
67 /*
68 the account wizard path is something like:
69
70 accounttype -> identity -> server -> login -> accname -> done
71 \-> newsserver ----/
72
73 where the accounttype determines which path to take
74 (server vs. newsserver)
75 */
76
77 var contentWindow;
78
79 var gPageData;
80 var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"].getService(Components.interfaces.nsISmtpService);
81 var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
82 var gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
83 var gMailSession = Components.classes["@mozilla.org/messenger/services/session;1"].getService(Components.interfaces.nsIMsgMailSession);
84 var accounts = am.accounts;
85
86 //accountCount indicates presence or absense of accounts
87 var accountCount = accounts.Count();
88
89 var nsIMsgIdentity = Components.interfaces.nsIMsgIdentity;
90 var nsIMsgIncomingServer = Components.interfaces.nsIMsgIncomingServer;
91 var gPrefsBundle, gMessengerBundle;
92 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
93 promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
94
95 // the current nsIMsgAccount
96 var gCurrentAccount;
97
98 // default account
99 var gDefaultAccount;
100
101 // the current associative array that
102 // will eventually be dumped into the account
103 var gCurrentAccountData;
104
105 // default picker mode for copies and folders
106 const gDefaultSpecialFolderPickerMode = "0";
107
108 // event handlers
onAccountWizardLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
109 function onAccountWizardLoad() {
110 gPrefsBundle = document.getElementById("bundle_prefs");
111 gMessengerBundle = document.getElementById("bundle_messenger");
112
113 if ("testingIspServices" in this) {
114 if ("SetCustomizedWizardDimensions" in this && testingIspServices()) {
115 SetCustomizedWizardDimensions();
116 }
117 }
118
119 /* We are checking here for the callback argument */
120 if (window.arguments && window.arguments[0]) {
121 if(window.arguments[0].okCallback )
122 {
123 //dump("There is okCallback");
124 top.okCallback = window.arguments[0].okCallback;
125 }
126 }
127
128 checkForInvalidAccounts();
129
130 try {
131 gDefaultAccount = am.defaultAccount;
132 }
133 catch (ex) {
134 // no default account, this is expected the first time you launch mail
135 // on a new profile
136 gDefaultAccount = null;
137 }
138
139 // Set default value for global inbox checkbox
140 var checkGlobalInbox = document.getElementById("deferStorage");
141 try {
142 checkGlobalInbox.checked = gPrefs.getBoolPref("mail.accountwizard.deferstorage");
143 } catch(e) {}
144 }
145
onCancel
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
146 function onCancel()
147 {
148 if ("ActivationOnCancel" in this && ActivationOnCancel())
149 return false;
150 var firstInvalidAccount = getFirstInvalidAccount();
151 var closeWizard = true;
152
153 // if the user cancels the the wizard when it pops up because of
154 // an invalid account (example, a webmail account that activation started)
155 // we just force create it by setting some values and calling the FinishAccount()
156 // see bug #47521 for the full discussion
157 if (firstInvalidAccount) {
158 var pageData = GetPageData();
159 // set the fullName if it doesn't exist
160 if (!pageData.identity.fullName || !pageData.identity.fullName.value) {
161 setPageData(pageData, "identity", "fullName", "");
162 }
163
164 // set the email if it doesn't exist
165 if (!pageData.identity.email || !pageData.identity.email.value) {
166 setPageData(pageData, "identity", "email", "user@domain.invalid");
167 }
168
169 // call FinishAccount() and not onFinish(), since the "finish"
170 // button may be disabled
171 FinishAccount();
172 }
173 else {
174 // since this is not an invalid account
175 // really cancel if the user hits the "cancel" button
176 if (accountCount < 1) {
177 var confirmMsg = gPrefsBundle.getString("cancelWizard");
178 var confirmTitle = gPrefsBundle.getString("accountWizard");
179 var result = promptService.confirmEx(window, confirmTitle, confirmMsg,
180 (promptService.BUTTON_TITLE_IS_STRING*promptService.BUTTON_POS_0)+
181 (promptService.BUTTON_TITLE_IS_STRING*promptService.BUTTON_POS_1),
182 gPrefsBundle.getString('WizardExit'),
183 gPrefsBundle.getString('WizardContinue'),
184 null, null, {value:0});
185
186 if (result == 1)
187 closeWizard = false;
188 }
189
190 if(top.okCallback && closeWizard) {
191 var state = false;
192 top.okCallback(state);
193 }
194 }
195 return closeWizard;
196 }
197
FinishAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
198 function FinishAccount()
199 {
200 try {
201 var pageData = GetPageData();
202
203 var accountData= gCurrentAccountData;
204
205 if (!accountData)
206 {
207 accountData = new Object;
208 // Time to set the smtpRequiresUsername attribute
209 if (!serverIsNntp(pageData))
210 accountData.smtpRequiresUsername = true;
211 }
212
213 // we may need local folders before account is "Finished"
214 // if it's a pop3 account which defers to Local Folders.
215 verifyLocalFoldersAccount();
216
217 PageDataToAccountData(pageData, accountData);
218
219 FixupAccountDataForIsp(accountData);
220
221 // we might be simply finishing another account
222 if (!gCurrentAccount)
223 gCurrentAccount = createAccount(accountData);
224
225 // transfer all attributes from the accountdata
226 finishAccount(gCurrentAccount, accountData);
227
228 setupCopiesAndFoldersServer(gCurrentAccount, getCurrentServerIsDeferred(pageData), accountData);
229
230 if (!serverIsNntp(pageData))
231 EnableCheckMailAtStartUpIfNeeded(gCurrentAccount);
232
233 if (!document.getElementById("downloadMsgs").hidden) {
234 // skip the default biff, we will load messages manually if needed
235 window.opener.gLoadStartFolder = false;
236 if (document.getElementById("downloadMsgs").checked) {
237 window.opener.gNewAccountToLoad = gCurrentAccount; // load messages for new POP account
238 }
239 }
240
241 // in case we crash, force us a save of the prefs file NOW
242 try {
243 am.saveAccountInfo();
244 }
245 catch (ex) {
246 dump("Error saving account info: " + ex + "\n");
247 }
248 window.close();
249 if(top.okCallback)
250 {
251 var state = true;
252 //dump("finish callback");
253 top.okCallback(state);
254 }
255 }
256 catch(ex) {
257 dump("FinishAccount failed, " + ex +"\n");
258 }
259 }
260
261 // prepopulate pageData with stuff from accountData
262 // use: to prepopulate the wizard with account information
AccountDataToPageData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
263 function AccountDataToPageData(accountData, pageData)
264 {
265 if (!accountData) {
266 dump("null account data! clearing..\n");
267 // handle null accountData as if it were an empty object
268 // so that we clear-out any old pagedata from a
269 // previous accountdata. The trick is that
270 // with an empty object, accountData.identity.slot is undefined,
271 // so this will clear out the prefill data in setPageData
272
273 accountData = new Object;
274 accountData.incomingServer = new Object;
275 accountData.identity = new Object;
276 accountData.smtp = new Object;
277 }
278
279 var server = accountData.incomingServer;
280
281 if (server.type == undefined) {
282 // clear out the old server data
283 //setPageData(pageData, "accounttype", "mailaccount", undefined);
284 // setPageData(pageData, "accounttype", "newsaccount", undefined);
285 setPageData(pageData, "server", "servertype", undefined);
286 setPageData(pageData, "server", "hostname", undefined);
287
288 } else {
289
290 if (server.type == "nntp") {
291 setPageData(pageData, "accounttype", "newsaccount", true);
292 setPageData(pageData, "accounttype", "mailaccount", false);
293 setPageData(pageData, "newsserver", "hostname", server.hostName);
294 }
295
296 else {
297 setPageData(pageData, "accounttype", "mailaccount", true);
298 setPageData(pageData, "accounttype", "newsaccount", false);
299 setPageData(pageData, "server", "servertype", server.type);
300 setPageData(pageData, "server", "hostname", server.hostName);
301 }
302 setPageData(pageData, "accounttype", "otheraccount", false);
303 }
304
305 setPageData(pageData, "login", "username", server.username);
306 setPageData(pageData, "login", "password", server.password);
307 setPageData(pageData, "login", "rememberPassword", server.rememberPassword);
308 setPageData(pageData, "accname", "prettyName", server.prettyName);
309 setPageData(pageData, "accname", "userset", false);
310 setPageData(pageData, "ispdata", "supplied", false);
311
312 var identity;
313
314 if (accountData.identity) {
315 dump("This is an accountdata\n");
316 identity = accountData.identity;
317 }
318 else if (accountData.identities) {
319 identity = accountData.identities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity);
320 dump("this is an account, id= " + identity + "\n");
321 }
322
323 setPageData(pageData, "identity", "email", identity.email);
324 setPageData(pageData, "identity", "fullName", identity.fullName);
325
326 var smtp;
327
328 if (accountData.smtp) {
329 smtp = accountData.smtp;
330 setPageData(pageData, "server", "smtphostname", smtp.hostname);
331 setPageData(pageData, "login", "smtpusername", smtp.username);
332 }
333 }
334
335 // take data from each page of pageData and dump it into accountData
336 // use: to put results of wizard into a account-oriented object
PageDataToAccountData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
337 function PageDataToAccountData(pageData, accountData)
338 {
339 if (!accountData.identity)
340 accountData.identity = new Object;
341 if (!accountData.incomingServer)
342 accountData.incomingServer = new Object;
343 if (!accountData.smtp)
344 accountData.smtp = new Object;
345 if (!accountData.pop3)
346 accountData.pop3 = new Object;
347
348 var identity = accountData.identity;
349 var server = accountData.incomingServer;
350 var smtp = accountData.smtp;
351
352 if (pageData.identity.email)
353 identity.email = pageData.identity.email.value;
354 if (pageData.identity.fullName)
355 identity.fullName = pageData.identity.fullName.value;
356
357 server.type = getCurrentServerType(pageData);
358 server.hostName = getCurrentHostname(pageData);
359 if (getCurrentServerIsDeferred(pageData))
360 {
361 try
362 {
363 var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
364 var localFoldersServer = accountManager.localFoldersServer;
365 var localFoldersAccount = accountManager.FindAccountForServer(localFoldersServer);
366 accountData.pop3.deferredToAccount = localFoldersAccount.key;
367 accountData.pop3.deferGetNewMail = true;
368 server["ServerType-pop3"] = accountData.pop3;
369 }
370 catch (ex) {dump ("exception setting up deferred account" + ex);}
371 }
372 if (serverIsNntp(pageData)) {
373 // this stuff probably not relevant
374 dump("not setting username/password/rememberpassword/etc\n");
375 } else {
376 if (pageData.login) {
377 if (pageData.login.username)
378 server.username = pageData.login.username.value;
379 if (pageData.login.password)
380 server.password = pageData.login.password.value;
381 if (pageData.login.rememberPassword)
382 server.rememberPassword = pageData.login.rememberPassword.value;
383 if (pageData.login.smtpusername)
384 smtp.username = pageData.login.smtpusername.value;
385 }
386
387 dump("pageData.server = " + pageData.server + "\n");
388 if (pageData.server) {
389 dump("pageData.server.smtphostname.value = " + pageData.server.smtphostname + "\n");
390 if (pageData.server.smtphostname &&
391 pageData.server.smtphostname.value)
392 smtp.hostname = pageData.server.smtphostname.value;
393 }
394 if (pageData.identity.smtpServerKey)
395 identity.smtpServerKey = pageData.identity.smtpServerKey.value;
396 }
397
398 if (pageData.accname) {
399 if (pageData.accname.prettyName)
400 server.prettyName = pageData.accname.prettyName.value;
401 }
402
403 }
404
405 // given an accountData structure, create an account
406 // (but don't fill in any fields, that's for finishAccount()
createAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
407 function createAccount(accountData)
408 {
409 var server = accountData.incomingServer;
410
411 // for news, username is always null
412 var username = (server.type == "nntp") ? null : server.username;
413
414 dump("am.createIncomingServer(" + username + "," +
415 server.hostName + "," +
416 server.type + ")\n");
417
418 var server = am.createIncomingServer(username,
419 server.hostName,
420 server.type);
421
422 dump("am.createAccount()\n");
423 var account = am.createAccount();
424
425 if (accountData.identity.email) // only create an identity for this account if we really have one (use the email address as a check)
426 {
427 dump("am.createIdentity()\n");
428 var identity = am.createIdentity();
429
430 /* new nntp identities should use plain text by default
431 * we want that GNKSA (The Good Net-Keeping Seal of Approval) */
432 if (server.type == "nntp") {
433 identity.composeHtml = false;
434 }
435
436 account.addIdentity(identity);
437 }
438
439 // we mark the server as invalid so that the account manager won't
440 // tell RDF about the new server - it's not quite finished getting
441 // set up yet, in particular, the deferred storage pref hasn't been set.
442 server.valid = false;
443 account.incomingServer = server;
444 server.valid = true;
445 return account;
446 }
447
448 // given an accountData structure, copy the data into the
449 // given account, incoming server, and so forth
finishAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
450 function finishAccount(account, accountData)
451 {
452 if (accountData.incomingServer) {
453
454 var destServer = account.incomingServer;
455 var srcServer = accountData.incomingServer;
456 copyObjectToInterface(destServer, srcServer, true);
457
458 // see if there are any protocol-specific attributes
459 // if so, we use the type to get the IID, QueryInterface
460 // as appropriate, then copy the data over
461 dump("srcServer.ServerType-" + srcServer.type + " = " +
462 srcServer["ServerType-" + srcServer.type] + "\n");
463 if (srcServer["ServerType-" + srcServer.type]) {
464 // handle server-specific stuff
465 var IID = getInterfaceForType(srcServer.type);
466 if (IID) {
467 destProtocolServer = destServer.QueryInterface(IID);
468 srcProtocolServer = srcServer["ServerType-" + srcServer.type];
469
470 dump("Copying over " + srcServer.type + "-specific data\n");
471 copyObjectToInterface(destProtocolServer, srcProtocolServer, false);
472 }
473 }
474
475 account.incomingServer.valid=true;
476 // hack to cause an account loaded notification now the server is valid
477 account.incomingServer = account.incomingServer;
478 }
479
480 // copy identity info
481 var destIdentity = account.identities.Count() ? account.identities.QueryElementAt(0, nsIMsgIdentity) : null;
482
483 if (destIdentity) // does this account have an identity?
484 {
485 if (accountData.identity && accountData.identity.email) {
486 // fixup the email address if we have a default domain
487 var emailArray = accountData.identity.email.split('@');
488 if (emailArray.length < 2 && accountData.domain) {
489 accountData.identity.email += '@' + accountData.domain;
490 }
491
492 copyObjectToInterface(destIdentity, accountData.identity, true);
493 destIdentity.valid=true;
494 }
495
496 /**
497 * If signature file need to be set, get the path to the signature file.
498 * Signature files, if exist, are placed under default location. Get
499 * default files location for messenger using directory service. Signature
500 * file name should be extracted from the account data to build the complete
501 * path for signature file. Once the path is built, set the identity's signature pref.
502 */
503 if (destIdentity.attachSignature)
504 {
505 var sigFileName = accountData.signatureFileName;
506
507 var sigFile = gMailSession.getDataFilesDir("messenger");
508 sigFile.append(sigFileName);
509 destIdentity.signature = sigFile;
510 }
511
512 // don't try to create an smtp server if we already have one.
513 if (!destIdentity.smtpServerKey)
514 {
515 var smtpServer;
516
517 /**
518 * Create a new smtp server if needed. If smtpCreateNewServer pref
519 * is set then createSmtpServer routine() will create one. Otherwise,
520 * default server is returned which is also set to create a new smtp server
521 * (via GetDefaultServer()) if no default server is found.
522 */
523 if (accountData.smtp.hostname != null)
524 smtpServer = smtpService.createSmtpServer();
525 else
526 smtpServer = smtpService.defaultServer;
527
528 // may not have a smtp server, see bug #138076
529 if (smtpServer) {
530 dump("Copying smtpServer (" + smtpServer + ") to accountData\n");
531 if (smtpService.defaultServer.hostname == null)
532 smtpService.defaultServer = smtpServer;
533
534 copyObjectToInterface(smtpServer, accountData.smtp, false);
535
536 // refer bug#141314
537 // since we clone the default smtpserver with the new account's username
538 // force every account to use the smtp server that was created or assigned to it in the
539 // case of isps using rdf files
540 try{
541 destIdentity.smtpServerKey = smtpServer.key;
542 }
543 catch(ex)
544 {
545 dump("There is no smtp server assigned to this account: Exception= "+ex+"\n");
546 }
547 }
548 }
549 } // if the account has an identity...
550
551 if (this.FinishAccountHook != undefined) {
552 FinishAccountHook(accountData.domain);
553 }
554 }
555
556 // Helper method used by copyObjectToInterface which attempts to set dest[attribute] as a generic
557 // attribute on the xpconnect object, src.
558 // This routine skips any attribute that begins with ServerType-
setGenericAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
559 function setGenericAttribute(dest, src, attribute)
560 {
561 if (!(/^ServerType-/i.test(attribute)))
562 {
563 switch (typeof src[attribute])
564 {
565 case "string":
566 dest.setUnicharAttribute(attribute, src[attribute]);
567 break;
568 case "boolean":
569 dest.setBoolAttribute(attribute, src[attribute]);
570 break;
571 case "number":
572 dest.setIntAttribute(attribute, src[attribute]);
573 break;
574 default:
575 dump('Error: No Generic attribute found for: ' + typeof src[attribute] + '\n');
576 break;
577 }
578 }
579 }
580
581 // copy over all attributes from dest into src that already exist in src
582 // the assumption is that src is an XPConnect interface full of attributes
583 // @param useGenericFallback if we can't set an attribute directly on src, then fall back
584 // and try setting it generically. This assumes that src supports setIntAttribute, setUnicharAttribute
585 // and setBoolAttribute.
copyObjectToInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
586 function copyObjectToInterface(dest, src, useGenericFallback)
587 {
588 if (!dest) return;
589 if (!src) return;
590
591 var attribute;
592 for (attribute in src)
593 {
594 if (dest.__lookupSetter__(attribute))
595 {
596 if (dest[attribute] != src[attribute])
597 dest[attribute] = src[attribute];
598 }
599 else if (useGenericFallback) // fall back to setting the attribute generically
600 setGenericAttribute(dest, src, attribute);
601 } // for each attribute in src we want to copy
602 }
603
604 // check if there already is a "Local Folders"
605 // if not, create it.
verifyLocalFoldersAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
606 function verifyLocalFoldersAccount()
607 {
608 var localMailServer = null;
609 try {
610 localMailServer = am.localFoldersServer;
611 }
612 catch (ex) {
613 // dump("exception in findserver: " + ex + "\n");
614 localMailServer = null;
615 }
616
617 try {
618 if (!localMailServer)
619 {
620 // dump("Creating local mail account\n");
621 // creates a copy of the identity you pass in
622 am.createLocalMailAccount();
623 try {
624 localMailServer = am.localFoldersServer;
625 }
626 catch (ex) {
627 dump("error! we should have found the local mail server after we created it.\n");
628 localMailServer = null;
629 }
630 }
631 }
632 catch (ex) {dump("Error in verifyLocalFoldersAccount" + ex + "\n"); }
633
634 }
635
setupCopiesAndFoldersServer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
636 function setupCopiesAndFoldersServer(account, accountIsDeferred, accountData)
637 {
638 try {
639 var server = account.incomingServer;
640 if (server.type == "rss")
641 return false;
642 var identity = account.identities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity);
643 // For this server, do we default the folder prefs to this server, or to the "Local Folders" server
644 // If it's deferred, we use the local folders account.
645 var defaultCopiesAndFoldersPrefsToServer = !accountIsDeferred && server.defaultCopiesAndFoldersPrefsToServer;
646
647 var copiesAndFoldersServer = null;
648 if (defaultCopiesAndFoldersPrefsToServer)
649 {
650 copiesAndFoldersServer = server;
651 }
652 else
653 {
654 if (!am.localFoldersServer)
655 {
656 dump("error! we should have a local mail server at this point\n");
657 return false;
658 }
659 copiesAndFoldersServer = am.localFoldersServer;
660 }
661
662 setDefaultCopiesAndFoldersPrefs(identity, copiesAndFoldersServer, accountData);
663
664 } catch (ex) {
665 // return false (meaning we did not setupCopiesAndFoldersServer)
666 // on any error
667 dump("Error setupCopiesAndFoldersServer" + ex + "\n");
668 return false;
669 }
670 return true;
671 }
672
setDefaultCopiesAndFoldersPrefs
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
673 function setDefaultCopiesAndFoldersPrefs(identity, server, accountData)
674 {
675 var rootFolder = server.rootFolder;
676
677 // we need to do this or it is possible that the server's draft,
678 // stationery fcc folder will not be in rdf
679 //
680 // this can happen in a couple cases
681 // 1) the first account we create, creates the local mail. since
682 // local mail was just created, it obviously hasn't been opened,
683 // or in rdf..
684 // 2) the account we created is of a type where
685 // defaultCopiesAndFoldersPrefsToServer is true
686 // this since we are creating the server, it obviously hasn't been
687 // opened, or in rdf.
688 //
689 // this makes the assumption that the server's draft, stationery fcc folder
690 // are at the top level (ie subfolders of the root folder.) this works
691 // because we happen to be doing things that way, and if the user changes
692 // that, it will work because to change the folder, it must be in rdf,
693 // coming from the folder cache, in the worst case.
694 var folders = rootFolder.GetSubFolders();
695 var msgFolder = rootFolder.QueryInterface(Components.interfaces.nsIMsgFolder);
696
697 /**
698 * When a new account is created, folders 'Sent', 'Drafts'
699 * and 'Templates' are not created then, but created on demand at runtime.
700 * But we do need to present them as possible choices in the Copies and Folders
701 * UI. To do that, folder URIs have to be created and stored in the prefs file.
702 * So, if there is a need to build special folders, append the special folder
703 * names and create right URIs.
704 */
705 var folderDelim = "/";
706
707 /* we use internal names known to everyone like Sent, Templates and Drafts */
708 /* if folder names were already given in isp rdf, we use them,
709 otherwise we use internal names known to everyone like Sent, Templates and Drafts */
710
711 var draftFolder = (accountData.identity && accountData.identity.draftFolder ? accountData.identity.draftFolder : "Drafts");
712 var stationeryFolder = (accountData.identity && accountData.identity.stationeryFolder ? accountData.identity.stationeryFolder : "Templates");
713 var fccFolder = (accountData.identity && accountData.identity.fccFolder ? accountData.identity.fccFolder : "Sent");
714
715 identity.draftFolder = msgFolder.server.serverURI+ folderDelim + draftFolder;
716 identity.stationeryFolder = msgFolder.server.serverURI+ folderDelim + stationeryFolder;
717 identity.fccFolder = msgFolder.server.serverURI+ folderDelim + fccFolder;
718
719
720 identity.fccFolderPickerMode = (accountData.identity && accountData.identity.fccFolder ? 1 : gDefaultSpecialFolderPickerMode);
721 identity.draftsFolderPickerMode = (accountData.identity && accountData.identity.draftFolder ? 1 : gDefaultSpecialFolderPickerMode);
722 identity.tmplFolderPickerMode = (accountData.identity && accountData.identity.stationeryFolder ? 1 : gDefaultSpecialFolderPickerMode);
723 }
724
AccountExists
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
725 function AccountExists(userName,hostName,serverType)
726 {
727 var accountExists = false;
728 var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
729 try {
730 var server = accountManager.findRealServer(userName,hostName,serverType,0);
731 if (server) {
732 accountExists = true;
733 }
734 }
735 catch (ex) {
736 accountExists = false;
737 }
738 return accountExists;
739 }
740
getFirstInvalidAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
741 function getFirstInvalidAccount()
742 {
743 am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
744
745 var invalidAccounts = getInvalidAccounts(am.accounts);
746
747 if (invalidAccounts.length > 0)
748 return invalidAccounts[0];
749 else
750 return null;
751 }
752
checkForInvalidAccounts
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
753 function checkForInvalidAccounts()
754 {
755 var firstInvalidAccount = getFirstInvalidAccount();
756
757 if (firstInvalidAccount) {
758 var pageData = GetPageData();
759 dump("We have an invalid account, " + firstInvalidAccount + ", let's use that!\n");
760 gCurrentAccount = firstInvalidAccount;
761
762 // there's a possibility that the invalid account has ISP defaults
763 // as well.. so first pre-fill accountData with ISP info, then
764 // overwrite it with the account data
765
766
767 var identity =
768 firstInvalidAccount.identities.QueryElementAt(0, nsIMsgIdentity);
769
770 var accountData = null;
771 // If there is a email address already provided, try to get to other ISP defaults.
772 // If not, get pre-configured data, if any.
773 if (identity.email) {
774 dump("Invalid account: trying to get ISP data for " + identity.email + "\n");
775 accountData = getIspDefaultsForEmail(identity.email);
776 dump("Invalid account: Got " + accountData + "\n");
777
778 // account -> accountData -> pageData
779 accountData = AccountToAccountData(firstInvalidAccount, accountData);
780 }
781 else {
782 accountData = getPreConfigDataForAccount(firstInvalidAccount);
783 }
784
785 AccountDataToPageData(accountData, pageData);
786
787 gCurrentAccountData = accountData;
788
789 setupWizardPanels();
790 // Set the page index to identity page.
791 document.documentElement.pageIndex = 1;
792 }
793 }
794
795 // Transfer all invalid account information to AccountData. Also, get those special
796 // preferences (not associated with any interfaces but preconfigurable via prefs or rdf files)
797 // like whether not the smtp server associated with this account requires
798 // a user name (mail.identity.<id_key>.smtpRequiresUsername) and the choice of skipping
799 // panels (mail.identity.<id_key>.wizardSkipPanels).
getPreConfigDataForAccount
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
800 function getPreConfigDataForAccount(account)
801 {
802 var accountData = new Object;
803 accountData = new Object;
804 accountData.incomingServer = new Object;
805 accountData.identity = new Object;
806 accountData.smtp = new Object;
807
808 accountData = AccountToAccountData(account, null);
809
810 var identity = account.identities.QueryElementAt(0, nsIMsgIdentity);
811
812 try {
813 var skipPanelsPrefStr = "mail.identity." + identity.key + ".wizardSkipPanels";
814 accountData.wizardSkipPanels = gPrefs.getCharPref(skipPanelsPrefStr);
815
816 if (identity.smtpServerKey) {
817 var smtpServer = smtpService.getServerByKey(identity.smtpServerKey);
818 accountData.smtp = smtpServer;
819
820 var smtpRequiresUsername = false;
821 var smtpRequiresPrefStr = "mail.identity." + identity.key + ".smtpRequiresUsername";
822 smtpRequiresUsername = gPrefs.getBoolPref(smtpRequiresPrefStr);
823 accountData.smtpRequiresUsername = smtpRequiresUsername;
824 }
825 }
826 catch(ex) {
827 // reached here as special identity pre-configuration prefs
828 // (wizardSkipPanels, smtpRequiresUsername) are not defined.
829 }
830
831 return accountData;
832 }
833
AccountToAccountData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
834 function AccountToAccountData(account, defaultAccountData)
835 {
836 dump("AccountToAccountData(" + account + ", " +
837 defaultAccountData + ")\n");
838 var accountData = defaultAccountData;
839 if (!accountData)
840 accountData = new Object;
841
842 accountData.incomingServer = account.incomingServer;
843 accountData.identity = account.identities.QueryElementAt(0, nsIMsgIdentity);
844 accountData.smtp = smtpService.defaultServer;
845
846 return accountData;
847 }
848
849 // sets the page data, automatically creating the arrays as necessary
setPageData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
850 function setPageData(pageData, tag, slot, value) {
851 if (!pageData[tag]) pageData[tag] = [];
852
853 if (value == undefined) {
854 // clear out this slot
855 if (pageData[tag][slot]) delete pageData[tag][slot];
856 } else {
857 // pre-fill this slot
858 if (!pageData[tag][slot]) pageData[tag][slot] = [];
859 pageData[tag][slot].id = slot;
860 pageData[tag][slot].value = value;
861 }
862 }
863
864 // value of checkbox on the first page
serverIsNntp
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
865 function serverIsNntp(pageData) {
866 if (pageData.accounttype.newsaccount)
867 return pageData.accounttype.newsaccount.value;
868 return false;
869 }
870
getUsernameFromEmail
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
871 function getUsernameFromEmail(aEmail, aEnsureDomain)
872 {
873 var username = aEmail.split("@")[0];
874 if (aEnsureDomain && gCurrentAccountData && gCurrentAccountData.domain)
875 username += '@' + gCurrentAccountData.domain;
876 return username;
877 }
878
getCurrentUserName
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
879 function getCurrentUserName(pageData)
880 {
881 var userName = "";
882
883 if (pageData.login) {
884 if (pageData.login.username) {
885 userName = pageData.login.username.value;
886 }
887 }
888 if (userName == "") {
889 var email = pageData.identity.email.value;
890 userName = getUsernameFromEmail(email, false);
891 }
892 return userName;
893 }
894
getCurrentServerType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
895 function getCurrentServerType(pageData) {
896 var servertype = "pop3"; // hopefully don't resort to default!
897 if (serverIsNntp(pageData))
898 servertype = "nntp";
899 else if (pageData.server && pageData.server.servertype)
900 servertype = pageData.server.servertype.value;
901 return servertype;
902 }
903
getCurrentServerIsDeferred
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
904 function getCurrentServerIsDeferred(pageData) {
905 var serverDeferred = false;
906 if (getCurrentServerType(pageData) == "pop3" && pageData.server && pageData.server.deferStorage)
907 serverDeferred = pageData.server.deferStorage.value;
908
909 return serverDeferred;
910 }
911
getCurrentHostname
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
912 function getCurrentHostname(pageData) {
913 if (serverIsNntp(pageData))
914 return pageData.newsserver.hostname.value;
915 else
916 return pageData.server.hostname.value;
917 }
918
GetPageData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
919 function GetPageData()
920 {
921 if (!gPageData)
922 gPageData = new Object;
923
924 return gPageData;
925 }
926
PrefillAccountForIsp
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
927 function PrefillAccountForIsp(ispName)
928 {
929 dump("AccountWizard.prefillAccountForIsp(" + ispName + ")\n");
930
931 var ispData = getIspDefaultsForUri(ispName);
932
933 var pageData = GetPageData();
934
935 if (!ispData) {
936 SetCurrentAccountData(null);
937 return;
938 }
939
940 // prefill the rest of the wizard
941 dump("PrefillAccountForISP: filling with " + ispData + "\n");
942 SetCurrentAccountData(ispData);
943 AccountDataToPageData(ispData, pageData);
944
945 setPageData(pageData, "ispdata", "supplied", true);
946 }
947
948 // does any cleanup work for the the account data
949 // - sets the username from the email address if it's not already set
950 // - anything else?
FixupAccountDataForIsp
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
951 function FixupAccountDataForIsp(accountData)
952 {
953 // no fixup for news
954 // setting the username does bad things
955 // see bugs #42105 and #154213
956 if (accountData.incomingServer.type == "nntp")
957 return;
958
959 var email = accountData.identity.email;
960
961 // fix up the username
962 if (!accountData.incomingServer.username)
963 accountData.incomingServer.username = getUsernameFromEmail(email, accountData.incomingServerUserNameRequiresDomain);
964
965 if (!accountData.smtp.username &&
966 accountData.smtpRequiresUsername) {
967 // fix for bug #107953
968 // if incoming hostname is same as smtp hostname
969 // use the server username (instead of the email username)
970 if (accountData.smtp.hostname == accountData.incomingServer.hostName)
971 accountData.smtp.username = accountData.incomingServer.username;
972 else
973 accountData.smtp.username = getUsernameFromEmail(email, accountData.smtpUserNameRequiresDomain);
974 }
975 }
976
SetCurrentAccountData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
977 function SetCurrentAccountData(accountData)
978 {
979 // dump("Setting current account data (" + gCurrentAccountData + ") to " + accountData + "\n");
980 gCurrentAccountData = accountData;
981 }
982
getInterfaceForType
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
983 function getInterfaceForType(type) {
984 try {
985 var protocolInfoContractIDPrefix = "@mozilla.org/messenger/protocol/info;1?type=";
986
987 var thisContractID = protocolInfoContractIDPrefix + type;
988
989 var protoInfo = Components.classes[thisContractID].getService(Components.interfaces.nsIMsgProtocolInfo);
990
991 return protoInfo.serverIID;
992 } catch (ex) {
993 dump("could not get IID for " + type + ": " + ex + "\n");
994 return undefined;
995 }
996 }
997
998 // flush the XUL cache - just for debugging purposes - not called
onFlush
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
999 function onFlush() {
1000 gPrefs.setBoolPref("nglayout.debug.disable_xul_cache", true);
1001 gPrefs.setBoolPref("nglayout.debug.disable_xul_cache", false);
1002
1003 }
1004
1005 /** If there are no default accounts..
1006 * this is will be the new default, so enable
1007 * check for mail at startup
1008 */
EnableCheckMailAtStartUpIfNeeded
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1009 function EnableCheckMailAtStartUpIfNeeded(newAccount)
1010 {
1011 // Check if default account exists and if that account is alllowed to be
1012 // a default account. If no such account, make this one as the default account
1013 // and turn on the new mail check at startup for the current account
1014 if (!(gDefaultAccount && gDefaultAccount.incomingServer.canBeDefaultServer)) {
1015 am.defaultAccount = newAccount;
1016 newAccount.incomingServer.loginAtStartUp = true;
1017 newAccount.incomingServer.downloadOnBiff = true;
1018 }
1019 }
1020
SetSmtpRequiresUsernameAttribute
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1021 function SetSmtpRequiresUsernameAttribute(accountData)
1022 {
1023 // If this is the default server, time to set the smtp user name
1024 // Set the generic attribute for requiring user name for smtp to true.
1025 // ISPs can override the pref via rdf files.
1026 if (!(gDefaultAccount && gDefaultAccount.incomingServer.canBeDefaultServer)) {
1027 accountData.smtpRequiresUsername = true;
1028 }
1029 }
1030
setNextPage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1031 function setNextPage(currentPageId, nextPageId) {
1032 var currentPage = document.getElementById(currentPageId);
1033 currentPage.next = nextPageId;
1034 }