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 vI_smartIdentity = { |
---|
26 | messenger : Components.classes["@mozilla.org/messenger;1"].createInstance() |
---|
27 | .QueryInterface(Components.interfaces.nsIMessenger), |
---|
28 | |
---|
29 | smartIdentity_BaseIdentity : null, |
---|
30 | |
---|
31 | clean : function() { |
---|
32 | vI_smartIdentity.smartIdentity_BaseIdentity = null; |
---|
33 | }, |
---|
34 | |
---|
35 | // After Loading the MessageComposeDialog, check if smartIdentity is needed |
---|
36 | init : function() { |
---|
37 | var type = gMsgCompose.type; |
---|
38 | var msgComposeType = Components.interfaces.nsIMsgCompType; |
---|
39 | vI_notificationBar.dump("## vI_smartIdentity: msgComposeType = " + type + "\n"); |
---|
40 | |
---|
41 | switch (type) { |
---|
42 | case msgComposeType.ForwardAsAttachment: |
---|
43 | case msgComposeType.ForwardInline: |
---|
44 | case msgComposeType.Reply: |
---|
45 | case msgComposeType.ReplyAll: |
---|
46 | case msgComposeType.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later |
---|
47 | case msgComposeType.ReplyToSender: |
---|
48 | case msgComposeType.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later |
---|
49 | case msgComposeType.ReplyWithTemplate: |
---|
50 | vI_smartIdentity.Reply(); break; |
---|
51 | case msgComposeType.Draft: |
---|
52 | case msgComposeType.Template: |
---|
53 | vI_smartIdentity.Draft(); break; |
---|
54 | case msgComposeType.New: |
---|
55 | case msgComposeType.NewsPost: |
---|
56 | case msgComposeType.MailToUrl: |
---|
57 | vI_smartIdentity.NewMail(); break; |
---|
58 | } |
---|
59 | }, |
---|
60 | |
---|
61 | // this function adds a timestamp to the current sender |
---|
62 | __autoTimestamp : function() { |
---|
63 | vI_notificationBar.dump("## vI_smartIdentity: __autoTimestamp()\n"); |
---|
64 | if (document.getElementById("msgIdentity_clone").vid) { |
---|
65 | vI_notificationBar.dump("## vI_smartIdentity: Virtual Identity in use, aborting\n"); |
---|
66 | return; |
---|
67 | } |
---|
68 | |
---|
69 | var current_email = getCurrentIdentity().email; |
---|
70 | vI_notificationBar.dump("## vI_smartIdentity: current email: " + current_email + "\n"); |
---|
71 | |
---|
72 | var dateobj = new Date(); |
---|
73 | var new_email = current_email.replace(/@/g, parseInt(dateobj.getTime()/1000)+"@"); |
---|
74 | vI_notificationBar.dump("## vI_smartIdentity: new email: " + new_email + "\n"); |
---|
75 | |
---|
76 | vI_notificationBar.setNote(vI.elements.strings.getString("vident.smartIdentity.vIUsage") + ".", |
---|
77 | "smart_reply_notification"); |
---|
78 | |
---|
79 | document.getElementById("msgIdentity_clone").email = new_email; |
---|
80 | }, |
---|
81 | |
---|
82 | NewMail : function() { |
---|
83 | var storageIdentities = new identityCollection(); |
---|
84 | vI_storage.getVIdentityFromAllRecipients(storageIdentities); |
---|
85 | |
---|
86 | if (storageIdentities.number > 0) vI_smartIdentity.__smartIdentitySelection(storageIdentities, false) |
---|
87 | else if (vI.preferences.getBoolPref("autoTimestamp")) vI_smartIdentity.__autoTimestamp(); |
---|
88 | }, |
---|
89 | |
---|
90 | ReplyOnSent : function(hdr) { |
---|
91 | vI_notificationBar.dump("## vI_smartIdentity: ReplyOnSent() (rules like SmartDraft)\n"); |
---|
92 | |
---|
93 | var allIdentities = new identityCollection(); |
---|
94 | |
---|
95 | vI_smartIdentity.__SmartDraftOrReplyOnSent(hdr, allIdentities); |
---|
96 | var storageIdentities = new identityCollection(); |
---|
97 | vI_storage.getVIdentityFromAllRecipients(storageIdentities); |
---|
98 | |
---|
99 | allIdentities.mergeWithoutDuplicates(storageIdentities); |
---|
100 | |
---|
101 | if (allIdentities.number > 0) vI_smartIdentity.__smartIdentitySelection(allIdentities, true); |
---|
102 | |
---|
103 | }, |
---|
104 | |
---|
105 | Draft : function() { |
---|
106 | vI_notificationBar.dump("## vI_smartIdentity: Draft()\n"); |
---|
107 | |
---|
108 | var allIdentities = new identityCollection(); |
---|
109 | |
---|
110 | var draftHdr = vI_smartIdentity.messenger. |
---|
111 | messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI); |
---|
112 | // fails with seamonkey 1.1.11, so just try to read to draft id |
---|
113 | try { draftHdr = vI_smartIdentity.messenger. |
---|
114 | messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId); |
---|
115 | } catch (ex) { }; |
---|
116 | |
---|
117 | vI_smartIdentity.__SmartDraftOrReplyOnSent(draftHdr, allIdentities); |
---|
118 | var storageIdentities = new identityCollection(); |
---|
119 | vI_storage.getVIdentityFromAllRecipients(storageIdentities); |
---|
120 | |
---|
121 | allIdentities.mergeWithoutDuplicates(storageIdentities); |
---|
122 | |
---|
123 | if (allIdentities.number > 0) vI_smartIdentity.__smartIdentitySelection(allIdentities, true); |
---|
124 | }, |
---|
125 | |
---|
126 | __parseHeadersWithArray: function(hdr, allIdentities) { |
---|
127 | var emails = {}; var fullNames = {}; var combinedNames = {}; |
---|
128 | var number = vI.headerParser.parseHeadersWithArray(hdr, emails, fullNames, combinedNames); |
---|
129 | for (var index = 0; index < number; index++) { |
---|
130 | var newIdentity = new identityData(emails.value[index], fullNames.value[index], |
---|
131 | null, NO_SMTP_TAG, null, null); |
---|
132 | allIdentities.addWithoutDuplicates(newIdentity); |
---|
133 | } |
---|
134 | }, |
---|
135 | |
---|
136 | // this function checks if we have a draft-case and Smart-Draft should replace the Identity |
---|
137 | __SmartDraftOrReplyOnSent : function(hdr, allIdentities) { |
---|
138 | if (!vI.preferences.getBoolPref("smart_draft")) |
---|
139 | { vI_notificationBar.dump("## vI_smartIdentity: SmartDraft deactivated\n"); return; } |
---|
140 | |
---|
141 | vI_notificationBar.dump("## vI_smartIdentity: __SmartDraftOrReplyOnSent()\n"); |
---|
142 | |
---|
143 | if (hdr) { |
---|
144 | vI_smartIdentity.__parseHeadersWithArray(hdr.author, allIdentities) |
---|
145 | vI_notificationBar.dump("## vI_smartIdentity: sender '" + allIdentities.identityDataCollection[0].combinedName + "'\n"); |
---|
146 | } |
---|
147 | else vI_notificationBar.dump("## vI_smartIdentity: __SmartDraftOrReplyOnSent: No Header found, shouldn't happen\n"); |
---|
148 | }, |
---|
149 | |
---|
150 | __filterAddresses : function(smartIdentities) { |
---|
151 | var returnIdentities = new identityCollection(); |
---|
152 | |
---|
153 | var filterList = |
---|
154 | vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_filter")).split(/\n/) |
---|
155 | if (filterList.length == 0) filterList[0] == "" |
---|
156 | |
---|
157 | for (var i = 0; i < filterList.length; i++) { |
---|
158 | const filterType = { None : 0, RegExp : 1, StrCmp : 2 } |
---|
159 | var recentfilterType; var skipRegExp = false; |
---|
160 | if (filterList.length <= 1 && filterList[0] == "") |
---|
161 | { vI_notificationBar.dump("## vI_smartIdentity: no filters configured\n"); recentfilterType = filterType.None; } |
---|
162 | else if (/^[+-]?\/(.*)\/$/.exec(filterList[i])) |
---|
163 | { vI_notificationBar.dump("## vI_smartIdentity: filter emails with RegExp '" |
---|
164 | + filterList[i].replace(/\\/g,"\\\\") + "'\n"); recentfilterType = filterType.RegExp; } |
---|
165 | else { vI_notificationBar.dump("## vI_smartIdentity: filter emails, compare with '" |
---|
166 | + filterList[i] + "'\n"); recentfilterType = filterType.StrCmp; } |
---|
167 | for (var j = 0; j < smartIdentities.number; j++) { // check if recent email-address (pre-choosen identity) is found in |
---|
168 | // copied and adapted from correctIdentity, thank you for the RegExp-idea! |
---|
169 | var add_addr = false; |
---|
170 | switch (recentfilterType) { |
---|
171 | case filterType.None: |
---|
172 | add_addr = true; break; |
---|
173 | case filterType.RegExp: |
---|
174 | if (skipRegExp) break; |
---|
175 | try { /^[+-]?\/(.*)\/$/.exec(filterList[i]); |
---|
176 | if ( filterList[i][0] == "-" ) { |
---|
177 | if (smartIdentities.identityDataCollection[j].email.match(new RegExp(RegExp.$1,"i"))) |
---|
178 | smartIdentities.dropIdentity(j--); |
---|
179 | } else |
---|
180 | add_addr = (smartIdentities.identityDataCollection[j].email.match(new RegExp(RegExp.$1,"i"))); |
---|
181 | } |
---|
182 | catch(vErr) { |
---|
183 | vI_notificationBar.addNote( |
---|
184 | vI.elements.strings.getString("vident.smartIdentity.ignoreRegExp") + |
---|
185 | +filterList[i].replace(/\\/g,"\\\\") + " .", |
---|
186 | "smart_reply_notification"); |
---|
187 | skipRegExp = true; } |
---|
188 | break; |
---|
189 | case filterType.StrCmp: |
---|
190 | add_addr = ( smartIdentities.identityDataCollection[j].email.toLowerCase().indexOf(filterList[i].toLowerCase()) != -1) |
---|
191 | break; |
---|
192 | } |
---|
193 | if (add_addr) returnIdentities.addWithoutDuplicates(smartIdentities.identityDataCollection[j]) |
---|
194 | } |
---|
195 | } |
---|
196 | smartIdentities.takeOver(returnIdentities); |
---|
197 | }, |
---|
198 | |
---|
199 | __smartReplyCollectAddresses : function(hdr, allIdentities) { |
---|
200 | // add emails from selected headers (stored by vI_getHeader.xul/js) |
---|
201 | var reply_headers = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_headers")).split(/\n/) |
---|
202 | |
---|
203 | for (var index = 0; index < reply_headers.length; index++) { |
---|
204 | // ------------- prepare fields to read the stored header ---------------- |
---|
205 | var replyHeader_splitted = reply_headers[index].split(/:/) |
---|
206 | // use first part (all before ':') as the header name |
---|
207 | var replyHeaderName = replyHeader_splitted[0].toLowerCase() |
---|
208 | // check second or third part for any number |
---|
209 | var replyHeaderNumber = parseInt(replyHeader_splitted[1]) |
---|
210 | if (isNaN(replyHeaderNumber)) replyHeaderNumber = parseInt(replyHeader_splitted[2]) |
---|
211 | // check if Fullnames should be erased |
---|
212 | var replyHeaderEmptyFullNames = ((replyHeader_splitted[1] && replyHeader_splitted[1].match(/@/)) || |
---|
213 | (replyHeader_splitted[2] && replyHeader_splitted[2].match(/@/))) |
---|
214 | |
---|
215 | // create header name to find the value |
---|
216 | var replyHeaderNameToRead = replyHeaderName |
---|
217 | if (!isNaN(replyHeaderNumber)) replyHeaderNameToRead += ":" + replyHeaderNumber |
---|
218 | |
---|
219 | // if mailing-list ignore to-header (usually the mailing list address) |
---|
220 | if (replyHeaderNameToRead == "to" && hdr.getStringProperty("vI_list-id")) { |
---|
221 | vI_notificationBar.dump("## vI_smartIdentity: header 'list-id' found (mailinglist), skipping header 'to'\n"); |
---|
222 | continue; |
---|
223 | } |
---|
224 | |
---|
225 | // ------------- read the stored header ------------------------------- |
---|
226 | var value = vI.unicodeConverter.ConvertToUnicode(hdr.getStringProperty("vI_" + replyHeaderNameToRead)) |
---|
227 | vI_notificationBar.dump("## vI_smartIdentity: reading header '" + |
---|
228 | replyHeaderNameToRead + "': '" + value + "'\n"); |
---|
229 | |
---|
230 | // ------------- parse address-string to get a field of single email-addresses |
---|
231 | var splitted = new identityCollection(); |
---|
232 | vI_smartIdentity.__parseHeadersWithArray(value, splitted); |
---|
233 | |
---|
234 | // move found addresses step by step to allIdentities, and change values if requested |
---|
235 | for (var i = 0; i < splitted.number; i++) { |
---|
236 | // if there is no email than it makes no sense to use it as a sender |
---|
237 | if (!splitted.identityDataCollection[i].email.match(/^.*@.*$/)) { |
---|
238 | vI_notificationBar.dump("## vI_smartIdentity: skipping '" + |
---|
239 | splitted.identityDataCollection[i].email + "', no email\n") |
---|
240 | continue; |
---|
241 | } |
---|
242 | |
---|
243 | if (replyHeaderEmptyFullNames) splitted.identityDataCollection[i].fullName = "" |
---|
244 | |
---|
245 | allIdentities.addWithoutDuplicates(splitted.identityDataCollection[i]); |
---|
246 | |
---|
247 | vI_notificationBar.dump("## vI_smartIdentity: found '" + |
---|
248 | splitted.identityDataCollection[i].combinedName + "'\n") |
---|
249 | } |
---|
250 | } |
---|
251 | }, |
---|
252 | |
---|
253 | Reply : function() { |
---|
254 | var hdr = vI_smartIdentity.messenger. |
---|
255 | messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI); |
---|
256 | |
---|
257 | vI_notificationBar.dump("## vI_smartIdentity: Reply()\n"); |
---|
258 | |
---|
259 | if (hdr && !gMsgCompose.compFields.newsgroups) { |
---|
260 | // RFC 2821 (http://www.ietf.org/rfc/rfc2821.txt) says: |
---|
261 | // "4.4 Trace Information |
---|
262 | // When an SMTP server receives a message for delivery or further |
---|
263 | // processing, it MUST insert trace ("time stamp" or "Received") |
---|
264 | // information at the beginning of the message content, as discussed in |
---|
265 | // section 4.1.1.4." |
---|
266 | // so it should be always possible to decide if Reply or Draft based on received headers |
---|
267 | // hidden option smart_detectByReceivedHeader will act as a switch for not RFC-compliant servers |
---|
268 | // RFC-compliant |
---|
269 | if (vI.preferences.getBoolPref("smart_detectByReceivedHeader")) { |
---|
270 | if (!hdr.getStringProperty("vI_received")) { // mail was not received |
---|
271 | vI_notificationBar.dump("## vI_smartIdentity: reply on non-received (sent?) mail. Using SmartDraft. \n"); |
---|
272 | vI_smartIdentity.ReplyOnSent(hdr); |
---|
273 | return; |
---|
274 | } |
---|
275 | } |
---|
276 | // not RFC-compliant |
---|
277 | else { |
---|
278 | const MSG_FOLDER_FLAG_INBOX = 0x1000 |
---|
279 | const MSG_FOLDER_FLAG_SENTMAIL = 0x0200; |
---|
280 | |
---|
281 | if (hdr && (hdr.folder.flags & MSG_FOLDER_FLAG_SENTMAIL)) { |
---|
282 | vI_notificationBar.dump("## vI_smartIdentity: reply from Sent folder."); |
---|
283 | if (hdr.folder.flags & MSG_FOLDER_FLAG_INBOX) |
---|
284 | vI_notificationBar.dump(" Folder is INBOX, assuming Reply-Case. \n"); |
---|
285 | else { |
---|
286 | vI_notificationBar.dump(" Using SmartDraft. \n"); |
---|
287 | vI_smartIdentity.ReplyOnSent(hdr); |
---|
288 | return; |
---|
289 | } |
---|
290 | } |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | var storageIdentities = new identityCollection(); |
---|
295 | vI_storage.getVIdentityFromAllRecipients(storageIdentities); |
---|
296 | |
---|
297 | var smartIdentities = new identityCollection(); |
---|
298 | if (storageIdentities.number == 0 || !vI.preferences.getBoolPref("idSelection_storage_ignore_smart_reply")) |
---|
299 | vI_smartIdentity.__SmartReply(hdr, smartIdentities); |
---|
300 | else vI_notificationBar.dump("## vI_smartIdentity: SmartReply skipped, Identities in Storage found.\n"); |
---|
301 | |
---|
302 | // merge SmartReply-Identities and Storage-Identites |
---|
303 | if (vI.preferences.getBoolPref("idSelection_storage_prefer_smart_reply")) |
---|
304 | { smartIdentities.mergeWithoutDuplicates(storageIdentities); var allIdentities = smartIdentities; } |
---|
305 | else |
---|
306 | { storageIdentities.mergeWithoutDuplicates(smartIdentities); var allIdentities = storageIdentities; } |
---|
307 | |
---|
308 | vI_notificationBar.dump("## vI_smartIdentity: merged SmartReply & Storage, " + allIdentities.number + " address(es) left\n") |
---|
309 | |
---|
310 | if (allIdentities.number > 0) vI_smartIdentity.__smartIdentitySelection(allIdentities, false); |
---|
311 | }, |
---|
312 | |
---|
313 | // this function checks if we have a reply-case and Smart-Reply should replace the Identity |
---|
314 | __SmartReply : function(hdr, smartIdentities) { |
---|
315 | if (!vI.preferences.getBoolPref("smart_reply")) |
---|
316 | { vI_notificationBar.dump("## vI_smartIdentity: SmartReply deactivated\n"); return; } |
---|
317 | if (gMsgCompose.compFields.newsgroups && !vI.preferences.getBoolPref("smart_reply_for_newsgroups")) { |
---|
318 | vI_notificationBar.dump("## vI_smartIdentity: SmartReply, answering to a newsgroup, aborting\n"); |
---|
319 | return; |
---|
320 | } |
---|
321 | |
---|
322 | vI_notificationBar.dump("## vI_smartIdentity: __SmartReply()\n"); |
---|
323 | vI_notificationBar.dump("## vI_smartIdentity: ----------------------------------------------------------\n") |
---|
324 | if (hdr) { |
---|
325 | /* first step: collect addresses */ |
---|
326 | vI_smartIdentity.__smartReplyCollectAddresses(hdr, smartIdentities); |
---|
327 | vI_notificationBar.dump("## vI_smartIdentity: " + smartIdentities.number + " address(es) after parsing, before filtering\n") |
---|
328 | |
---|
329 | /* second step: filter (and sort) addresses */ |
---|
330 | vI_smartIdentity.__filterAddresses(smartIdentities); |
---|
331 | |
---|
332 | vI_notificationBar.dump("## vI_smartIdentity: filtering done, " + smartIdentities.number + " address(es) left\n") |
---|
333 | |
---|
334 | /* set default FullName */ |
---|
335 | var smart_reply_defaultFullName = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_defaultFullName")) |
---|
336 | if (smart_reply_defaultFullName != "") { |
---|
337 | for (var index = 0; index < smartIdentities.number; index++) { |
---|
338 | if (smartIdentities.identityDataCollection[index].fullName == "") { |
---|
339 | smartIdentities.identityDataCollection[index].fullName = smart_reply_defaultFullName |
---|
340 | vI_notificationBar.dump("## vI_smartIdentity: added default FullName '" + |
---|
341 | smart_reply_defaultFullName + "' to '" + smartIdentities.identityDataCollection[index].email + "'\n") |
---|
342 | } |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | /* smart_reply_ignoreFullName: compare email with other Identities */ |
---|
347 | /* if match replace FullName with existing one, keep identity in list by now */ |
---|
348 | /* will not be added to the menu but probably choosen with __smartIdentitySelection */ |
---|
349 | if (vI.preferences.getBoolPref("smart_reply_ignoreFullName")) { |
---|
350 | vI_notificationBar.dump("## vI_smartIdentity: compare with existing Identities (ignoring FullNames).\n") |
---|
351 | |
---|
352 | for (var index = 0; index < smartIdentities.number; index++) { |
---|
353 | var idKey = smartIdentities.identityDataCollection[index].isExistingIdentity(true); |
---|
354 | if (idKey) { |
---|
355 | var newFullName = gAccountManager.getIdentity(idKey).fullName; |
---|
356 | smartIdentities.identityDataCollection[index].fullName = newFullName; |
---|
357 | vI_notificationBar.dump("## vI_smartIdentity: replaced Fullname of '" + smartIdentities.identityDataCollection[index].email + "' with '" + newFullName + "' \n"); |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | } |
---|
362 | else vI_notificationBar.dump("## vI_smartIdentity: SmartReply skipped. No Header-information found.\n"); |
---|
363 | |
---|
364 | vI_notificationBar.dump("## vI_smartIdentity: ----------------------------------------------------------\n") |
---|
365 | }, |
---|
366 | |
---|
367 | __smartIdentitySelection : function(allIdentities, autocreate) { |
---|
368 | document.getElementById("msgIdentity_clone").addIdentitiesToCloneMenu(allIdentities); |
---|
369 | |
---|
370 | /* compare with existing Identities */ |
---|
371 | for (var index = 0; index < allIdentities.number; index++) { |
---|
372 | var existingID = allIdentities.identityDataCollection[index].isExistingIdentity(true); |
---|
373 | if (existingID) { |
---|
374 | allIdentities.identityDataCollection[index].id.key = existingID; // set found identity |
---|
375 | // if 'preferExisting' than select it and return |
---|
376 | if (vI.preferences.getBoolPref("idSelection_preferExisting")) { |
---|
377 | vI_notificationBar.dump("## vI_smartIdentity: found existing Identity, use without interaction.\n"); |
---|
378 | vI_smartIdentity.changeIdentityToSmartIdentity(allIdentities, index); |
---|
379 | return; |
---|
380 | } |
---|
381 | // else reorder list of Identities to prefer it on autoselect |
---|
382 | vI_notificationBar.dump("## vI_smartIdentity: found existing Identity, prefer this one.\n"); |
---|
383 | var firstIdentity = allIdentities.identityDataCollection[index]; |
---|
384 | for (var i = index; index > 0; index--) { |
---|
385 | allIdentities.identityDataCollection[index] = allIdentities.identityDataCollection[index-1]; |
---|
386 | } |
---|
387 | allIdentities.identityDataCollection[0] = firstIdentity; |
---|
388 | break; |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | if (!autocreate && vI.preferences.getBoolPref("idSelection_ask") && |
---|
393 | ((allIdentities.number == 1 && vI.preferences.getBoolPref("idSelection_ask_always")) |
---|
394 | || allIdentities.number > 1)) { |
---|
395 | for (var index = 0; index < allIdentities.number; index++) { |
---|
396 | vI_notificationBar.dump("## vI_smartIdentityReplyDialog index=" + index + ": '" + allIdentities.identityDataCollection[index].combinedName + "' " |
---|
397 | + "(" + allIdentities.identityDataCollection[index].id.value + "," + allIdentities.identityDataCollection[index].smtp.value + ")\n"); |
---|
398 | } |
---|
399 | window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0, |
---|
400 | "chrome, dialog, modal, alwaysRaised, resizable=yes", |
---|
401 | allIdentities, |
---|
402 | /* callback: */ vI_smartIdentity.changeIdentityToSmartIdentity).focus(); |
---|
403 | } |
---|
404 | else if (autocreate || vI.preferences.getBoolPref("idSelection_autocreate")) { |
---|
405 | vI_smartIdentity.changeIdentityToSmartIdentity(allIdentities, 0); |
---|
406 | } |
---|
407 | }, |
---|
408 | |
---|
409 | changeIdentityToSmartIdentity : function(allIdentities, selectedValue) { |
---|
410 | vI_notificationBar.dump("## changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' " |
---|
411 | + "(" + allIdentities.identityDataCollection[selectedValue].id.value + "," + allIdentities.identityDataCollection[selectedValue].smtp.value + ")\n"); |
---|
412 | document.getElementById("msgIdentity_clone").selectedMenuItem = allIdentities.menuItems[selectedValue]; |
---|
413 | if (document.getElementById("msgIdentity_clone").vid) { |
---|
414 | var label=vI.elements.strings.getString("vident.smartIdentity.vIUsage"); |
---|
415 | if (allIdentities.number > 1) label += " " |
---|
416 | + vI.elements.strings.getString("vident.smartIdentity.moreThanOne"); |
---|
417 | vI_notificationBar.addNote(label + ".", "smart_reply_notification"); |
---|
418 | } |
---|
419 | vI_smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue); |
---|
420 | }, |
---|
421 | |
---|
422 | __removeSmartIdentityFromRecipients : function(allIdentities, index) { |
---|
423 | if (!vI.preferences.getBoolPref("idSelection_removeSmartIdentityFromRecipients")) return; |
---|
424 | |
---|
425 | // check if selected email is defined as doBcc address. If so, it should not be removed. |
---|
426 | var skip_bcc = false; |
---|
427 | if (getCurrentIdentity().doBcc) { |
---|
428 | var bcc_addresses = new identityCollection(); |
---|
429 | vI_smartIdentity.__parseHeadersWithArray(getCurrentIdentity().doBccList, bcc_addresses); |
---|
430 | |
---|
431 | for (var i = 0; i < bcc_addresses.number; i++) { |
---|
432 | if (allIdentities.identityDataCollection[index].email == bcc_addresses.identityDataCollection[i].email) { |
---|
433 | skip_bcc = true; break; |
---|
434 | } |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | // check if there is more than one recipient for this mail. If not, preserve the only one existing. |
---|
439 | var recipientCount = 0; |
---|
440 | for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { |
---|
441 | var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); |
---|
442 | if (recipientType == "addr_to" || recipientType == "addr_cc") recipientCount++; |
---|
443 | } |
---|
444 | if (recipientCount < 2) return; |
---|
445 | |
---|
446 | |
---|
447 | for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { |
---|
448 | var popup = awGetPopupElement(row); |
---|
449 | var input = awGetInputElement(row); |
---|
450 | var recipientType = popup.selectedItem.getAttribute("value"); |
---|
451 | // if the entry is not a recipient, just continue |
---|
452 | if (recipientType == "addr_reply" || recipientType == "addr_followup") continue; |
---|
453 | // check if the entry is used as a BCC selected in account settings |
---|
454 | if (recipientType == "addr_bcc" && skip_bcc) continue; |
---|
455 | // check if entry is matching senders address, if so, remove it |
---|
456 | if (input.value == allIdentities.identityDataCollection[index].email || |
---|
457 | input.value == allIdentities.identityDataCollection[index].combinedName) { |
---|
458 | awSetInputAndPopupValue(input, "", popup, "addr_to", -1); |
---|
459 | awCleanupRows() |
---|
460 | vI_notificationBar.addNote(" " + |
---|
461 | vI.elements.strings.getString("vident.smartIdentity.remRecipient"), |
---|
462 | "smart_reply_notification"); |
---|
463 | break; |
---|
464 | } |
---|
465 | } |
---|
466 | } |
---|
467 | } |
---|