1 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
2 | This program is free software; you can redistribute it and/or modify |
---|
3 | it under the terms of the GNU General Public License as published by |
---|
4 | the Free Software Foundation; either version 2 of the License, or |
---|
5 | (at your option) any later version. |
---|
6 | |
---|
7 | This program is distributed in the hope that it will be useful, |
---|
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | GNU General Public License for more details. |
---|
11 | |
---|
12 | You should have received a copy of the GNU General Public License |
---|
13 | along with this program; if not, write to the Free Software |
---|
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
15 | |
---|
16 | The Original Code is the Virtual Identity Extension. |
---|
17 | |
---|
18 | The Initial Developer of the Original Code is Rene Ejury. |
---|
19 | Portions created by the Initial Developer are Copyright (C) 2011 |
---|
20 | the Initial Developer. All Rights Reserved. |
---|
21 | |
---|
22 | Contributor(s): |
---|
23 | * ***** END LICENSE BLOCK ***** */ |
---|
24 | |
---|
25 | var EXPORTED_SYMBOLS = ["getAccountsArray", "getIdentitiesArray"] |
---|
26 | |
---|
27 | const {classes: Cc, interfaces: Ci, utils: Cu, results : Cr} = Components; |
---|
28 | |
---|
29 | Cu.import("resource://v_identity/vI_log.js"); |
---|
30 | let Log = setupLogging("virtualIdentity.accountUtils"); |
---|
31 | |
---|
32 | let accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"] |
---|
33 | .getService(Components.interfaces.nsIMsgAccountManager); |
---|
34 | |
---|
35 | // copy/pasted from MsgComposeCommands.js |
---|
36 | function queryISupportsArray(supportsArray, iid) { |
---|
37 | let count = supportsArray.Count(); |
---|
38 | var result = new Array |
---|
39 | for (let i = 0; i < count; i++) |
---|
40 | result[i] = supportsArray.QueryElementAt(i, iid); |
---|
41 | return result; |
---|
42 | }; |
---|
43 | |
---|
44 | function getIdentitiesArray(account) { |
---|
45 | var identities; |
---|
46 | if (Components.utils.import("resource:///modules/folderUtils.jsm") && Components.utils.import("resource:///modules/iteratorUtils.jsm") |
---|
47 | && typeof(toArray)=='function' && typeof(fixIterator)=='function') { |
---|
48 | identities = toArray(fixIterator(account.identities,Components.interfaces.nsIMsgIdentity)); |
---|
49 | } else { |
---|
50 | identities = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity); |
---|
51 | } |
---|
52 | return identities; |
---|
53 | } |
---|
54 | |
---|
55 | function getAccountsArray() { |
---|
56 | var accounts; |
---|
57 | function sortAccounts(a, b) { |
---|
58 | if (a.key == accountManager.defaultAccount.key) |
---|
59 | return -1; |
---|
60 | if (b.key == accountManager.defaultAccount.key) |
---|
61 | return 1; |
---|
62 | var aIsNews = a.incomingServer.type == "nntp"; |
---|
63 | var bIsNews = b.incomingServer.type == "nntp"; |
---|
64 | if (aIsNews && !bIsNews) |
---|
65 | return 1; |
---|
66 | if (bIsNews && !aIsNews) |
---|
67 | return -1; |
---|
68 | |
---|
69 | var aIsLocal = a.incomingServer.type == "none"; |
---|
70 | var bIsLocal = b.incomingServer.type == "none"; |
---|
71 | if (aIsLocal && !bIsLocal) |
---|
72 | return 1; |
---|
73 | if (bIsLocal && !aIsLocal) |
---|
74 | return -1; |
---|
75 | return 0; |
---|
76 | } |
---|
77 | if (Components.utils.import("resource:///modules/folderUtils.jsm") && Components.utils.import("resource:///modules/iteratorUtils.jsm") |
---|
78 | && typeof(allAccountsSorted)=='function') { |
---|
79 | // if this worked we are having at least seamonkey 1.17 |
---|
80 | // Log.debug("getAccounts - new schema"); |
---|
81 | accounts = allAccountsSorted(true); |
---|
82 | } else { |
---|
83 | // still some older version |
---|
84 | // Log.debug("getAccounts - old schema"); |
---|
85 | var accounts = queryISupportsArray(accountManager.accounts, |
---|
86 | Components.interfaces.nsIMsgAccount); |
---|
87 | |
---|
88 | // Ugly hack to work around bug 41133. :-( |
---|
89 | accounts = accounts.filter(function isNonSuckyAccount(a) { return !!a.incomingServer; }); |
---|
90 | accounts.sort(sortAccounts); |
---|
91 | } |
---|
92 | return accounts |
---|
93 | }; |
---|