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) 2007 |
---|
20 | the Initial Developer. All Rights Reserved. |
---|
21 | |
---|
22 | Contributor(s): chuonthis |
---|
23 | * ***** END LICENSE BLOCK ***** */ |
---|
24 | |
---|
25 | /** |
---|
26 | * some code copied and adapted from 'Show SMTP Username' |
---|
27 | * thanks to chuonthis |
---|
28 | */ |
---|
29 | |
---|
30 | vI_smtpSelector = { |
---|
31 | smtpService : Components.classes["@mozilla.org/messengercompose/smtp;1"] |
---|
32 | .getService(Components.interfaces.nsISmtpService), |
---|
33 | |
---|
34 | elements : { |
---|
35 | Area_SMTPServerList : null, |
---|
36 | Obj_SMTPServerList : null, |
---|
37 | Obj_SMTPServerListPopup : null |
---|
38 | }, |
---|
39 | |
---|
40 | init : function() { |
---|
41 | vI_smtpSelector.elements.Area_SMTPServerList = document.getElementById("smtpServerListHbox"); |
---|
42 | vI_smtpSelector.elements.Obj_SMTPServerList = document.getElementById("smtp_server_list"); |
---|
43 | vI_smtpSelector.elements.Obj_SMTPServerListPopup = document.getElementById("smtp_server_list_popup"); |
---|
44 | vI_smtpSelector.loadSMTP_server_list(); |
---|
45 | if (vI.preferences.getBoolPref("show_smtp") && |
---|
46 | (vI_smtpSelector.elements.Obj_SMTPServerListPopup.childNodes.length > 1)) |
---|
47 | vI_smtpSelector.elements.Area_SMTPServerList.setAttribute("hidden", "false"); |
---|
48 | }, |
---|
49 | |
---|
50 | loadSMTP : function() |
---|
51 | { |
---|
52 | vI_msgIdentityClone.inputEvent(); |
---|
53 | }, |
---|
54 | |
---|
55 | resetMenuToMsgIdentity : function(identitykey) { |
---|
56 | var smtpKey = gAccountManager.getIdentity(identitykey).smtpServerKey |
---|
57 | if (!smtpKey) for (var i in gAccountManager.accounts) { |
---|
58 | for (var j in gAccountManager.accounts[i].identities) { |
---|
59 | if (identitykey == gAccountManager.accounts[i].identities[j].key) |
---|
60 | smtpKey = gAccountManager.accounts[i].defaultIdentity.smtpServerKey; |
---|
61 | } |
---|
62 | } |
---|
63 | if (!smtpKey) smtpKey = vI_smtpSelector.smtpService.defaultServer.key; |
---|
64 | |
---|
65 | MenuItems = vI_smtpSelector.elements.Obj_SMTPServerListPopup.childNodes |
---|
66 | for (index = 0; index < MenuItems.length; index++) { |
---|
67 | if (MenuItems[index].getAttribute("key") == smtpKey) { |
---|
68 | vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem = |
---|
69 | MenuItems[index]; |
---|
70 | break; |
---|
71 | } |
---|
72 | } |
---|
73 | }, |
---|
74 | |
---|
75 | loadSMTP_server_list : function() |
---|
76 | { |
---|
77 | var idserver; |
---|
78 | if (vI.helper.getBaseIdentity().smtpServerKey) |
---|
79 | idserver = vI_smtpSelector.smtpService.getServerByKey(vI.helper.getBaseIdentity().smtpServerKey); |
---|
80 | else { |
---|
81 | // find the account related to the identity, to get the account-related default smtp, if it exists. |
---|
82 | var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount); |
---|
83 | accounts.sort(compareAccountSortOrder); |
---|
84 | |
---|
85 | for (var x in accounts) { |
---|
86 | if (idserver) break; |
---|
87 | var server = accounts[x].incomingServer; |
---|
88 | |
---|
89 | // ignore (other) virtualIdentity Accounts |
---|
90 | if (!server || server.hostName == "virtualIdentity") continue; |
---|
91 | |
---|
92 | var identities = queryISupportsArray(accounts[x].identities, Components.interfaces.nsIMsgIdentity); |
---|
93 | for (var j in identities) { |
---|
94 | var identity = identities[j]; |
---|
95 | if (identity.key == vI.helper.getBaseIdentity().key) { |
---|
96 | if (accounts[x].defaultIdentity.smtpServerKey) |
---|
97 | idserver = vI_smtpSelector.smtpService.getServerByKey(accounts[x].defaultIdentity.smtpServerKey); |
---|
98 | break; |
---|
99 | } |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | if (!idserver) idserver = vI_smtpSelector.smtpService.defaultServer; |
---|
104 | |
---|
105 | var defaultServer = vI_smtpSelector.smtpService.defaultServer; |
---|
106 | var servers = vI_smtpSelector.smtpService.smtpServers; |
---|
107 | |
---|
108 | var serverCount = servers.Count(); |
---|
109 | |
---|
110 | for (var i=0 ; i<serverCount; i++) { |
---|
111 | var server = servers.QueryElementAt(i, Components.interfaces.nsISmtpServer); |
---|
112 | if (!server.redirectorType) |
---|
113 | { |
---|
114 | var listitem = vI_smtpSelector.createSmtpListItemx(server); |
---|
115 | vI_smtpSelector.elements.Obj_SMTPServerListPopup.appendChild(listitem); |
---|
116 | // set choosen default server |
---|
117 | if (idserver == server) vI_smtpSelector.elements.Obj_SMTPServerList.selectedItem = listitem; |
---|
118 | } |
---|
119 | } |
---|
120 | vI_smtpSelector.elements.Obj_SMTPServerList.setAttribute("label", vI_smtpSelector.getNewHostnamex(idserver)); |
---|
121 | }, |
---|
122 | |
---|
123 | createSmtpListItemx : function (server) { |
---|
124 | var listitem = document.createElement("menuitem"); |
---|
125 | |
---|
126 | var hostname = vI_smtpSelector.getNewHostnamex(server); |
---|
127 | |
---|
128 | listitem.setAttribute("label", hostname); |
---|
129 | listitem.setAttribute("key", server.key); |
---|
130 | // give it some unique id |
---|
131 | listitem.id = "smtpServer." + server.key; |
---|
132 | |
---|
133 | return listitem; |
---|
134 | }, |
---|
135 | |
---|
136 | getNewHostnamex : function (server) |
---|
137 | { |
---|
138 | var showAlias = true; |
---|
139 | var showUsername = true; |
---|
140 | var hideUsername = true; |
---|
141 | |
---|
142 | |
---|
143 | // reuse Preferences from ssun |
---|
144 | try { showAlias = vI.preferences.getBoolPref("ssun.showalias"); } catch (ex) {} |
---|
145 | try { showUsername = vI.preferences.getBoolPref("ssun.showusername"); } catch (ex) {} |
---|
146 | try { hideUsername = vI.preferences.getBoolPref("ssun.hideusername"); } catch (ex) {} |
---|
147 | |
---|
148 | var hostname = server.hostname; |
---|
149 | var port = ""; |
---|
150 | |
---|
151 | if (server.port) |
---|
152 | port = ":" + server.port; |
---|
153 | |
---|
154 | // SSUN: Get server alias |
---|
155 | var alias = ""; |
---|
156 | if (showAlias) { |
---|
157 | try { alias = vI.preferences.getCharPref("ssun." + server.key + ".alias"); } catch (ex) {} |
---|
158 | if (alias) { |
---|
159 | hostname = alias; |
---|
160 | } else { |
---|
161 | hostname += port; |
---|
162 | } |
---|
163 | } else { |
---|
164 | hostname += port; |
---|
165 | } |
---|
166 | |
---|
167 | // SSUN: Add username |
---|
168 | if (showUsername && (!showAlias || (showAlias && (!alias || !hideUsername))) && server.authMethod && server.username) |
---|
169 | hostname += " (" + server.username + ")"; |
---|
170 | |
---|
171 | return hostname |
---|
172 | } |
---|
173 | } |
---|