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): |
---|
23 | * ***** END LICENSE BLOCK ***** */ |
---|
24 | |
---|
25 | var EXPORTED_SYMBOLS = ["identityCollection", "identityData", "identityDataExtras", "DEFAULT_SMTP_TAG", "NO_SMTP_TAG"] |
---|
26 | |
---|
27 | const DEFAULT_SMTP_TAG = "vI_useDefaultSMTP" |
---|
28 | const NO_SMTP_TAG = "vI_noStoredSMTP" |
---|
29 | |
---|
30 | Components.utils.import("resource://v_identity/vI_log.js"); |
---|
31 | let Log = setupLogging("virtualIdentity.identityData"); |
---|
32 | Components.utils.import("resource://v_identity/vI_prefs.js"); |
---|
33 | Components.utils.import("resource://v_identity/vI_accountUtils.js"); |
---|
34 | |
---|
35 | Components.utils.import("resource://v_identity/vI_identityDataExtras.js"); |
---|
36 | Components.utils.import("resource://v_identity/identityDataExtras/returnReceipt.js"); |
---|
37 | Components.utils.import("resource://v_identity/identityDataExtras/fccSwitch.js"); |
---|
38 | Components.utils.import("resource://v_identity/identityDataExtras/messageFormat.js"); |
---|
39 | Components.utils.import("resource://v_identity/identityDataExtras/characterEncoding.js"); |
---|
40 | Components.utils.import("resource://v_identity/identityDataExtras/sMimeEncryption.js"); |
---|
41 | Components.utils.import("resource://v_identity/identityDataExtras/sMimeSignature.js"); |
---|
42 | Components.utils.import("resource://v_identity/identityDataExtras/PGPEncryption.js"); |
---|
43 | Components.utils.import("resource://v_identity/identityDataExtras/PGPSignature.js"); |
---|
44 | Components.utils.import("resource://v_identity/identityDataExtras/PGPMIME.js"); |
---|
45 | |
---|
46 | function identityData(currentWindow, email, fullName, id, smtp, extras, sideDescription, existingID) { |
---|
47 | this._currentWindow = currentWindow; |
---|
48 | this._email = email ? email : ""; |
---|
49 | this._emailParsed = false; |
---|
50 | this._fullName = fullName ? fullName : ""; |
---|
51 | this.id = new idObj(id); |
---|
52 | this.smtp = new smtpObj(smtp); |
---|
53 | if (extras) this.extras = extras; |
---|
54 | else this.extras = new identityDataExtras(currentWindow); |
---|
55 | this.comp = { // holds the results of the last comparison for later creation of a compareMatrix |
---|
56 | compareID: null, |
---|
57 | equals: { |
---|
58 | fullName: {}, |
---|
59 | email: {}, |
---|
60 | smtp: {}, |
---|
61 | id: {}, |
---|
62 | extras: {} |
---|
63 | } |
---|
64 | } |
---|
65 | if (sideDescription) this.sideDescription = sideDescription; |
---|
66 | if (existingID) this.existingID = existingID; |
---|
67 | else if (this.id.value) this.sideDescription = " - " + this.id.value; |
---|
68 | this.stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"] |
---|
69 | .getService(Components.interfaces.nsIStringBundleService) |
---|
70 | .createBundle("chrome://v_identity/locale/v_identity.properties"); |
---|
71 | } |
---|
72 | identityData.prototype = { |
---|
73 | _email: null, // internal email-field might contain combinedName (until first queried via email) |
---|
74 | _fullName: null, |
---|
75 | _emailParsed: null, |
---|
76 | _currentWindow: null, |
---|
77 | id: null, |
---|
78 | smtp: null, |
---|
79 | extras: null, |
---|
80 | sideDescription: null, |
---|
81 | existingID: null, // indicates that this is a pre-defined Identity, which might handled slightly differently |
---|
82 | |
---|
83 | stringBundle: null, |
---|
84 | comp: null, |
---|
85 | |
---|
86 | parseEmail: function () { |
---|
87 | if (this._emailParsed) return; |
---|
88 | // parse email and move any additional parts to fullName |
---|
89 | if (this._email.match(/<\s*[^>\s]*@[^>\s]*\s*>/) || this._email.match(/<?\s*[^>\s]*@[^>\s]*\s*>?/) || this._email.match(/$/)) { |
---|
90 | this._fullName += RegExp.leftContext + RegExp.rightContext; |
---|
91 | this._email = RegExp.lastMatch; |
---|
92 | // Log.debug("parseEmail _fullName = '" + this._fullName + "'"); |
---|
93 | // Log.debug("parseEmail _email = '" + this._email + "'"); |
---|
94 | } |
---|
95 | this._emailParsed = true; |
---|
96 | }, |
---|
97 | get email() { |
---|
98 | this.parseEmail(); |
---|
99 | return (this._email ? this._email.replace(/\s+|<|>/g, "") : ""); |
---|
100 | }, |
---|
101 | set email(email) { |
---|
102 | this._email = email; |
---|
103 | this._emailParsed = false; |
---|
104 | }, |
---|
105 | |
---|
106 | cleanName: function (fullName) { |
---|
107 | // Log.debug("cleanName init '" + fullName + "'"); |
---|
108 | var _fullName = fullName.replace(/^\s+|\s+$/g, ""); |
---|
109 | if (_fullName.search(/^\".+\"$|^'.+'$/g) != -1) { |
---|
110 | _fullName = this.cleanName(_fullName.replace(/^\"(.+)\"$|^'(.+)'$/g, "$1$2")); |
---|
111 | } |
---|
112 | // Log.debug("cleanName done '" + _fullName + "'"); |
---|
113 | return _fullName; |
---|
114 | }, |
---|
115 | |
---|
116 | get fullName() { |
---|
117 | this.parseEmail(); |
---|
118 | return (this._fullName ? this.cleanName(this._fullName) : "") |
---|
119 | }, |
---|
120 | set fullName(fullName) { |
---|
121 | this._fullName = fullName; |
---|
122 | }, |
---|
123 | |
---|
124 | get combinedName() { |
---|
125 | var fullName = this.fullName; |
---|
126 | var email = this.email; |
---|
127 | return fullName ? fullName + (email ? " <" + email + ">" : "") : email |
---|
128 | }, |
---|
129 | set combinedName(combinedName) { |
---|
130 | this._email = combinedName; |
---|
131 | this._fullName = ""; |
---|
132 | this._emailParsed = false; |
---|
133 | }, |
---|
134 | |
---|
135 | __makeHtml: function (string) { |
---|
136 | return string ? string.replace(/>/g, ">").replace(/</g, "<") : "" |
---|
137 | }, |
---|
138 | get idHtml() { |
---|
139 | return this.__makeHtml(this.id.value); |
---|
140 | }, |
---|
141 | get smtpHtml() { |
---|
142 | return this.__makeHtml(this.smtp.value); |
---|
143 | }, |
---|
144 | get fullNameHtml() { |
---|
145 | return this.__makeHtml(this.fullName); |
---|
146 | }, |
---|
147 | get emailHtml() { |
---|
148 | return this.__makeHtml(this.email); |
---|
149 | }, |
---|
150 | get combinedNameHtml() { |
---|
151 | return this.__makeHtml(this.combinedName); |
---|
152 | }, |
---|
153 | |
---|
154 | get idLabel() { |
---|
155 | return this.stringBundle.GetStringFromName("vident.identityData.baseID") |
---|
156 | }, |
---|
157 | get smtpLabel() { |
---|
158 | return this.stringBundle.GetStringFromName("vident.identityData.SMTP") |
---|
159 | }, |
---|
160 | get fullNameLabel() { |
---|
161 | return this.stringBundle.GetStringFromName("vident.identityData.Name") |
---|
162 | }, |
---|
163 | get emailLabel() { |
---|
164 | return this.stringBundle.GetStringFromName("vident.identityData.Address") |
---|
165 | }, |
---|
166 | |
---|
167 | // creates an Duplicate of the current IdentityData, cause usually we are working with a pointer |
---|
168 | getDuplicate: function () { |
---|
169 | return new identityData(this._currentWindow, this.email, this.fullName, this.id.key, this.smtp.key, this.extras ? this.extras.getDuplicate() : null, |
---|
170 | this.sideDescription, this.existingID); |
---|
171 | }, |
---|
172 | |
---|
173 | takeOverAvailableData: function(identityData) { |
---|
174 | if (identityData.email) |
---|
175 | this.email = identityData.email; |
---|
176 | if (identityData.fullName) |
---|
177 | this.fullName = identityData.fullName; |
---|
178 | if (identityData.id.key) |
---|
179 | this.id.key = identityData.id.key; |
---|
180 | if (identityData.smtp.key) |
---|
181 | this.smtp.key = identityData.smtp.key; |
---|
182 | if (identityData.sideDescription) |
---|
183 | this.sideDescription = identityData.sideDescription; |
---|
184 | if (identityData.extras) |
---|
185 | this.extras.copy(identityData.extras); |
---|
186 | }, |
---|
187 | |
---|
188 | // copys all values of an identity. This way we can create a new object with a different document-context |
---|
189 | copy: function (identityData) { |
---|
190 | this.email = identityData.email; |
---|
191 | this.fullName = identityData.fullName; |
---|
192 | this.id.key = identityData.id.key; |
---|
193 | this.smtp.key = identityData.smtp.key; |
---|
194 | this.sideDescription = identityData.sideDescription; |
---|
195 | if (this.extras) this.extras.copy(identityData.extras); |
---|
196 | // don't copy the currentWindow value |
---|
197 | }, |
---|
198 | |
---|
199 | // dependent on MsgComposeCommands, should/will only be called in ComposeDialog |
---|
200 | isExistingIdentity: function (ignoreFullNameWhileComparing) { |
---|
201 | Log.debug("isExistingIdentity: ignoreFullNameWhileComparing='" + ignoreFullNameWhileComparing + "'"); |
---|
202 | // Log.debug("base: fullName.toLowerCase()='" + this.fullName + "' email.toLowerCase()='" + this.email + "' smtp='" + this.smtp.key + "'"); |
---|
203 | |
---|
204 | var ignoreFullNameMatchKey = null; |
---|
205 | var accounts = getAccountsArray(); |
---|
206 | for (let acc = 0; acc < accounts.length; acc++) { |
---|
207 | let account = accounts[acc]; |
---|
208 | try { |
---|
209 | prefroot.getBoolPref("mail.account." + account.key + ".vIdentity"); |
---|
210 | continue; |
---|
211 | } catch (e) {}; |
---|
212 | let identities = getIdentitiesArray(account); |
---|
213 | for (let i = 0; i < identities.length; i++) { |
---|
214 | let identity = identities[i]; |
---|
215 | // Log.debug("comp: fullName.toLowerCase()='" + identity.fullName.toLowerCase() + "' email.toLowerCase()='" + identity.email.toLowerCase() + "' smtp='" + identity.smtpServerKey + "'"); |
---|
216 | var email = this.email ? this.email : ""; // might be null if no identity is set |
---|
217 | var idEmail = identity.email ? identity.email : ""; // might be null if no identity is set |
---|
218 | if ((email.toLowerCase() == idEmail.toLowerCase()) && |
---|
219 | this.smtp.equal(new smtpObj(identity.smtpServerKey))) { |
---|
220 | // if fullName matches, than this is a final match |
---|
221 | if (this.fullName.toLowerCase() == identity.fullName.toLowerCase()) { |
---|
222 | Log.debug("isExistingIdentity: " + this.combinedName + " found, id='" + identity.key + "'"); |
---|
223 | return identity.key; // return key and stop searching |
---|
224 | } |
---|
225 | // if fullNames don't match, remember the key but continue to search for full match |
---|
226 | else if (!ignoreFullNameMatchKey) ignoreFullNameMatchKey = identity.key; |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | if (ignoreFullNameWhileComparing && ignoreFullNameMatchKey) { |
---|
232 | Log.debug("isExistingIdentity: " + this.combinedName + " found, id='" + ignoreFullNameMatchKey + "'"); |
---|
233 | return ignoreFullNameMatchKey; |
---|
234 | } |
---|
235 | |
---|
236 | Log.debug("isExistingIdentity: " + this.combinedName + " not found"); |
---|
237 | return null; |
---|
238 | }, |
---|
239 | |
---|
240 | // dependent on MsgComposeCommands, should/will only be called in ComposeDialog |
---|
241 | hasMatchingDomainIdentity: function () { |
---|
242 | Log.debug("hasMatchingDomainIdentity"); |
---|
243 | |
---|
244 | var domainArray = this.email.match(/@[^@]+$/); |
---|
245 | if (!domainArray) { |
---|
246 | Log.debug("hasMatchingDomainIdentity found no domain for email " + this.email); |
---|
247 | return; |
---|
248 | } |
---|
249 | Log.debug("hasMatchingDomainIdentity searching for domain " + domainArray[0]); |
---|
250 | |
---|
251 | var accounts = getAccountsArray(); |
---|
252 | for (let acc = 0; acc < accounts.length; acc++) { |
---|
253 | let account = accounts[acc]; |
---|
254 | try { |
---|
255 | prefroot.getBoolPref("mail.account." + account.key + ".vIdentity"); |
---|
256 | continue; |
---|
257 | } catch (e) {}; |
---|
258 | let identities = getIdentitiesArray(account); |
---|
259 | for (let i = 0; i < identities.length; i++) { |
---|
260 | let identity = identities[i]; |
---|
261 | var idDomainArray = identity.email.match(/@[^@]+$/); |
---|
262 | if (!idDomainArray) continue; |
---|
263 | // Log.debug("comp: domain.toLowerCase()='" + domainArray[0].toLowerCase() + "' idDomain.toLowerCase()='" + idDomainArray[0].toLowerCase() + "'"); |
---|
264 | if (domainArray[0].toLowerCase() == idDomainArray[0].toLowerCase()) { |
---|
265 | // if domain matches, everything is perfect! |
---|
266 | Log.debug("hasMatchingDomainIdentity: found matching id for domain '" + domainArray[0] + "'"); |
---|
267 | return identity.key; // return key and stop searching |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | Log.debug("hasMatchingDomainIdentity: '" + domainArray[0] + "' not found"); |
---|
272 | return null; |
---|
273 | }, |
---|
274 | |
---|
275 | equals: function (compareIdentityData) { |
---|
276 | if (!compareIdentityData) |
---|
277 | return false; |
---|
278 | |
---|
279 | this.comp.compareID = compareIdentityData; |
---|
280 | |
---|
281 | this.comp.equals.fullName = (((this.fullName) ? this.fullName.toLowerCase() : null) == ((compareIdentityData.fullName) ? compareIdentityData.fullName.toLowerCase() : null)); |
---|
282 | if (!this.comp.equals.fullName) { |
---|
283 | // Log.debug("fullName not equal ('" + ((this.fullName)?this.fullName.toLowerCase():null) + "' != '" + ((compareIdentityData.fullName)?compareIdentityData.fullName.toLowerCase():null) + "')"); |
---|
284 | } |
---|
285 | this.comp.equals.email = (((this.email) ? this.email.toLowerCase() : null) == ((compareIdentityData.email) ? compareIdentityData.email.toLowerCase() : null)); |
---|
286 | if (!this.comp.equals.email) { |
---|
287 | // Log.debug("email not equal ('" + ((this.email)?this.email.toLowerCase():null) + "' != '" + ((compareIdentityData.email)?compareIdentityData.email.toLowerCase():null) + "')"); |
---|
288 | } |
---|
289 | |
---|
290 | this.comp.equals.smtp = this.smtp.equal(compareIdentityData.smtp); |
---|
291 | this.comp.equals.id = this.id.equal(compareIdentityData.id); |
---|
292 | this.comp.equals.extras = this.extras ? this.extras.equal(compareIdentityData.extras) : true; |
---|
293 | |
---|
294 | return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals.smtp && this.comp.equals.id && this.comp.equals.extras); |
---|
295 | }, |
---|
296 | |
---|
297 | equalsIdentity: function (compareIdentityData, getCompareMatrix) { |
---|
298 | var equal = this.equals(compareIdentityData); |
---|
299 | var compareMatrix = null; |
---|
300 | // generate CompareMatrix only if asked and non-equal |
---|
301 | if (getCompareMatrix && !equal) compareMatrix = this.getCompareMatrix(); |
---|
302 | return { |
---|
303 | equal: equal, |
---|
304 | compareMatrix: compareMatrix |
---|
305 | }; |
---|
306 | }, |
---|
307 | |
---|
308 | getCompareMatrix: function () { |
---|
309 | const Items = Array("fullName", "email", "smtp", "id"); |
---|
310 | var string = ""; |
---|
311 | var saveBaseId = vIprefs.get("storage_store_base_id"); |
---|
312 | var saveSMTP = vIprefs.get("storage_store_SMTP"); |
---|
313 | for (let item of Items) { |
---|
314 | var classEqual = (this.comp.equals[item]) ? "equal" : "unequal"; |
---|
315 | var classIgnore = (((!saveBaseId) && (item == "id")) || ((!saveSMTP) && (item == "smtp"))) ? " ignoreValues" : "" |
---|
316 | string += "<tr>" + |
---|
317 | "<td class='col1 " + classEqual + "'>" + this[item + "Label"] + "</td>" + |
---|
318 | "<td class='col2 " + classEqual + classIgnore + "'>" + this.comp.compareID[item + "Html"] + "</td>" + |
---|
319 | "<td class='col3 " + classEqual + classIgnore + "'>" + this[item + "Html"] + "</td>" + |
---|
320 | "</tr>" |
---|
321 | } |
---|
322 | string += this.extras ? this.extras.getCompareMatrix() : ""; |
---|
323 | return string; |
---|
324 | }, |
---|
325 | |
---|
326 | getMatrix: function () { |
---|
327 | const Items = Array("smtp", "id"); |
---|
328 | var string = ""; |
---|
329 | for (var item of Items) if (this[item + "Html"]) |
---|
330 | string += "<tr><td class='col1'>" + this[item + "Label"] + ":</td>" + |
---|
331 | "<td class='col2'>" + this[item + "Html"] + "</td></tr>" |
---|
332 | string += this.extras ? this.extras.getMatrix() : ""; |
---|
333 | return string; |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | function identityCollection() { |
---|
338 | this.number = 0; |
---|
339 | this.identityDataCollection = {}; |
---|
340 | this.menuItems = {}; |
---|
341 | } |
---|
342 | identityCollection.prototype = { |
---|
343 | number: null, |
---|
344 | identityDataCollection: null, |
---|
345 | menuItems: null, |
---|
346 | |
---|
347 | mergeWithoutDuplicates: function (addIdentityCollection) { |
---|
348 | for (var index = 0; index < addIdentityCollection.number; index++) |
---|
349 | this.addWithoutDuplicates(addIdentityCollection.identityDataCollection[index]) |
---|
350 | }, |
---|
351 | |
---|
352 | dropIdentity: function (index) { |
---|
353 | Log.debug("dropping address from inputList: " + this.identityDataCollection[index].combinedName); |
---|
354 | while (index < (this.number - 1)) { |
---|
355 | this.identityDataCollection[index] = this.identityDataCollection[++index]; |
---|
356 | }; |
---|
357 | this.identityDataCollection[--this.number] = null; |
---|
358 | }, |
---|
359 | |
---|
360 | addWithoutDuplicates: function (identityData) { |
---|
361 | if (!identityData) return; |
---|
362 | for (var index = 0; index < this.number; index++) { |
---|
363 | if (this.identityDataCollection[index].email == identityData.email && |
---|
364 | (!this.identityDataCollection[index].id.key || !identityData.id.key || |
---|
365 | (this.identityDataCollection[index].id.key == identityData.id.key && |
---|
366 | this.identityDataCollection[index].smtp.key == identityData.smtp.key))) { |
---|
367 | // found, so check if we can use the Name of the new field |
---|
368 | if (this.identityDataCollection[index].fullName == "" && identityData.fullName != "") { |
---|
369 | this.identityDataCollection[index].fullName = identityData.fullName; |
---|
370 | Log.debug("added fullName '" + identityData.fullName + "' to stored email '" + this.identityDataCollection[index].email + "'") |
---|
371 | } |
---|
372 | // check if id_key, smtp_key or extras can be used |
---|
373 | // only try this once, for the first Identity where id is set) |
---|
374 | if (!this.identityDataCollection[index].id.key && identityData.id.key) { |
---|
375 | this.identityDataCollection[index].id.key = identityData.id.key; |
---|
376 | this.identityDataCollection[index].smtp.key = identityData.smtp.key; |
---|
377 | this.identityDataCollection[index].extras = identityData.extras; |
---|
378 | Log.debug("added id '" + identityData.id.value + "' smtp '" + identityData.smtp.value + "' (+extras) to stored email '" + this.identityDataCollection[index].email + "'") |
---|
379 | } |
---|
380 | return; |
---|
381 | } |
---|
382 | } |
---|
383 | Log.debug("add new address to result: " + identityData.combinedName) |
---|
384 | this.identityDataCollection[index] = identityData; |
---|
385 | this.number = index + 1; |
---|
386 | }, |
---|
387 | |
---|
388 | // this is used to completely use the conten of another identityCollection, but without changing all pointers |
---|
389 | // see for instance vI.smartIdentity.__filterAddresses |
---|
390 | takeOver: function (newIdentityCollection) { |
---|
391 | this.number = newIdentityCollection.number |
---|
392 | this.identityDataCollection = newIdentityCollection.identityDataCollection |
---|
393 | } |
---|
394 | }; |
---|
395 | |
---|
396 | function smtpObj(key) { |
---|
397 | this._key = key; |
---|
398 | this.DEFAULT_TAG = Components.classes["@mozilla.org/intl/stringbundle;1"] |
---|
399 | .getService(Components.interfaces.nsIStringBundleService) |
---|
400 | .createBundle("chrome://messenger/locale/messenger.properties"). |
---|
401 | GetStringFromName("defaultServerTag"); |
---|
402 | } |
---|
403 | smtpObj.prototype = { |
---|
404 | DEFAULT_TAG: null, |
---|
405 | _key: null, |
---|
406 | _value: null, |
---|
407 | |
---|
408 | set key(key) { |
---|
409 | this._key = key; |
---|
410 | this._value = null; |
---|
411 | }, |
---|
412 | get key() { |
---|
413 | var dummy = this.value; // just to be sure key is adapted if SMTP is not available |
---|
414 | return this._key |
---|
415 | }, |
---|
416 | get keyNice() { // the same as key but with "" for DEFAULT_SMTP_TAG |
---|
417 | if (this.key == DEFAULT_SMTP_TAG) return ""; // this is the key used for default server |
---|
418 | return this.key |
---|
419 | }, |
---|
420 | get value() { |
---|
421 | if (this._value == null) { |
---|
422 | this._value = ""; |
---|
423 | if (this._key == null || this._key == "") this._key = DEFAULT_SMTP_TAG; |
---|
424 | if (this._key == DEFAULT_SMTP_TAG) this._value = this.DEFAULT_TAG; |
---|
425 | else if (!this._key) this._value = null; |
---|
426 | else if (this._key) { |
---|
427 | var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"] |
---|
428 | .getService(Components.interfaces.nsISmtpService); |
---|
429 | // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService |
---|
430 | if (typeof (smtpService.servers) == "object") servers = smtpService.servers; |
---|
431 | else servers = smtpService.smtpServers; |
---|
432 | |
---|
433 | while (servers && servers.hasMoreElements()) { |
---|
434 | var server = servers.getNext(); |
---|
435 | if (server instanceof Components.interfaces.nsISmtpServer && |
---|
436 | !server.redirectorType && this._key == server.key) { |
---|
437 | this._value = server.description ? server.description : server.hostname; |
---|
438 | break; |
---|
439 | } |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | if (!this._value) this._key = NO_SMTP_TAG; // if non-existant SMTP handle like non available |
---|
444 | return this._value; |
---|
445 | }, |
---|
446 | equal: function (compareSmtpObj) { |
---|
447 | if (this.key == NO_SMTP_TAG || compareSmtpObj.key == NO_SMTP_TAG) return true; |
---|
448 | if (this.keyNice != compareSmtpObj.keyNice) { |
---|
449 | // Log.debug("smtp not equal ('" + this.keyNice + "' != '" + compareSmtpObj.keyNice + "')"); |
---|
450 | } |
---|
451 | return (this.keyNice == compareSmtpObj.keyNice); |
---|
452 | }, |
---|
453 | hasNoDefinedSMTP: function () { |
---|
454 | return (this.key == NO_SMTP_TAG); |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | function idObj(key) { |
---|
459 | this._key = key; |
---|
460 | } |
---|
461 | idObj.prototype = { |
---|
462 | _key: null, |
---|
463 | _value: null, |
---|
464 | _accountkey: null, |
---|
465 | |
---|
466 | set key(key) { |
---|
467 | this._key = key; |
---|
468 | this._value = null; |
---|
469 | }, |
---|
470 | get key() { |
---|
471 | if (this._value == null) var dummy = this.value; |
---|
472 | return this._key |
---|
473 | }, |
---|
474 | get accountkey() { |
---|
475 | if (this._value == null) var dummy = this.value; |
---|
476 | return this._accountkey |
---|
477 | }, |
---|
478 | get value() { |
---|
479 | if (this._value == null) { |
---|
480 | this._value = ""; |
---|
481 | // if this worked we are having at least seamonkey 1.17 |
---|
482 | let accounts = getAccountsArray(); |
---|
483 | for (let acc = 0; acc < accounts.length; acc++) { |
---|
484 | let account = accounts[acc]; |
---|
485 | let identities = getIdentitiesArray(account); |
---|
486 | if (identities.length == 0) |
---|
487 | continue; |
---|
488 | for (let i = 0; i < identities.length; i++) { |
---|
489 | let identity = identities[i]; |
---|
490 | if (this._key == identity.key) { |
---|
491 | this._value = identity.identityName; |
---|
492 | this._accountkey = account.key; |
---|
493 | break; |
---|
494 | } |
---|
495 | } |
---|
496 | } |
---|
497 | if (!this._value) { |
---|
498 | this._key = null; |
---|
499 | this._accountkey = null; |
---|
500 | } |
---|
501 | } |
---|
502 | return this._value; |
---|
503 | }, |
---|
504 | equal: function (compareIdObj) { |
---|
505 | if (!this.key || !compareIdObj.key) return true; |
---|
506 | if (this.key != compareIdObj.key) { |
---|
507 | // Log.debug("id not equal ('" + this.key + "' != '" + compareIdObj.key + "')"); |
---|
508 | } |
---|
509 | return (this.key == compareIdObj.key); |
---|
510 | } |
---|
511 | } |
---|