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): Mike Krieger, Sebastian Apel |
---|
23 | * ***** END LICENSE BLOCK ***** */ |
---|
24 | |
---|
25 | /** |
---|
26 | * some code copied and adapted from 'addressContext' and from 'Birthday Reminder' |
---|
27 | * thanks to Mike Krieger and Sebastian Apel |
---|
28 | */ |
---|
29 | |
---|
30 | virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { |
---|
31 | var storage = { |
---|
32 | focusedElement : null, |
---|
33 | _pref : Components.classes["@mozilla.org/preferences-service;1"] |
---|
34 | .getService(Components.interfaces.nsIPrefService) |
---|
35 | .getBranch("extensions.virtualIdentity."), |
---|
36 | |
---|
37 | lastCheckedEmail : {}, // array of last checked emails per row, |
---|
38 | // to prevent ugly double dialogs and time-consuming double-checks |
---|
39 | |
---|
40 | _rdfDatasourceAccess : null, // local storage |
---|
41 | |
---|
42 | clean: function() { |
---|
43 | vI.notificationBar.dump("## storage: clean.\n"); |
---|
44 | storage.multipleRecipients = null; |
---|
45 | storage.lastCheckedEmail = {}; |
---|
46 | storage.firstUsedInputElement = null; |
---|
47 | awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue; |
---|
48 | if (storage._rdfDatasourceAccess) storage._rdfDatasourceAccess.clean(); |
---|
49 | }, |
---|
50 | |
---|
51 | original_functions : { |
---|
52 | awSetInputAndPopupValue : null |
---|
53 | }, |
---|
54 | |
---|
55 | replacement_functions : { |
---|
56 | awSetInputAndPopupValue : function (inputElem, inputValue, popupElem, popupValue, rowNumber) { |
---|
57 | vI.notificationBar.dump("## storage: awSetInputAndPopupValue '" + inputElem.id +"'\n"); |
---|
58 | storage.original_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber); |
---|
59 | storage.updateVIdentityFromStorage(inputElem); |
---|
60 | } |
---|
61 | }, |
---|
62 | |
---|
63 | awOnBlur : function (element) { |
---|
64 | // only react on events triggered by addressCol2 - textinput Elements |
---|
65 | if (!element || ! element.id.match(/^addressCol2*/)) return; |
---|
66 | vI.notificationBar.dump("\n## storage: awOnBlur '" + element.id +"'\n"); |
---|
67 | storage.updateVIdentityFromStorage(element); |
---|
68 | storage.focusedElement = null; |
---|
69 | }, |
---|
70 | |
---|
71 | awOnFocus : function (element) { |
---|
72 | if (!element || ! element.id.match(/^addressCol2*/)) return; |
---|
73 | storage.focusedElement = element; |
---|
74 | }, |
---|
75 | |
---|
76 | awPopupOnCommand : function (element) { |
---|
77 | vI.notificationBar.dump("\n## storage: awPopupOnCommand'" + element.id +"'\n"); |
---|
78 | storage.updateVIdentityFromStorage(document.getElementById(element.id.replace(/^addressCol1/,"addressCol2"))); |
---|
79 | if (element.selectedItem.getAttribute("value") == "addr_reply") // if reply-to is manually entered disable AutoReplyToSelf |
---|
80 | document.getElementById("autoReplyToSelfLabel").setAttribute("hidden", "true"); |
---|
81 | |
---|
82 | }, |
---|
83 | |
---|
84 | initialized : null, |
---|
85 | init: function() { |
---|
86 | if (!storage.initialized) { |
---|
87 | storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess(); |
---|
88 | |
---|
89 | // better approach would be to use te onchange event, but this one is not fired in any change case |
---|
90 | // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367 |
---|
91 | // same seems to happen with the ondragdrop event |
---|
92 | if (top.MAX_RECIPIENTS == 0) top.MAX_RECIPIENTS = 1; |
---|
93 | for (var row = 1; row <= top.MAX_RECIPIENTS ; row ++) { |
---|
94 | var input = awGetInputElement(row); |
---|
95 | if (input) { |
---|
96 | var oldBlur = input.getAttribute("onblur") |
---|
97 | input.setAttribute("onblur", (oldBlur?oldBlur+"; ":"") + |
---|
98 | "window.setTimeout(virtualIdentityExtension.storage.awOnBlur, 250, this.parentNode.parentNode.parentNode);") |
---|
99 | var oldFocus = input.getAttribute("onfocus") |
---|
100 | input.setAttribute("onfocus", (oldFocus?oldFocus+"; ":"") + |
---|
101 | "window.setTimeout(virtualIdentityExtension.storage.awOnFocus, 250, this.parentNode.parentNode.parentNode);") |
---|
102 | } |
---|
103 | var popup = awGetPopupElement(row); |
---|
104 | if (popup) { |
---|
105 | var oldCommand = popup.getAttribute("oncommand") |
---|
106 | popup.setAttribute("oncommand", (oldCommand?oldCommand+"; ":"") + |
---|
107 | "window.setTimeout(virtualIdentityExtension.storage.awPopupOnCommand, 250, this);") |
---|
108 | } |
---|
109 | } |
---|
110 | storage.initialized = true; |
---|
111 | } |
---|
112 | storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue; |
---|
113 | awSetInputAndPopupValue = function (inputElem, inputValue, popupElem, popupValue, rowNumber) { |
---|
114 | storage.replacement_functions.awSetInputAndPopupValue (inputElem, inputValue, popupElem, popupValue, rowNumber) } |
---|
115 | |
---|
116 | // reset unavailable storageExtras preferences |
---|
117 | const enigmail_ID="{847b3a00-7ab1-11d4-8f02-006008948af5}" |
---|
118 | if (!vI.helper.extensionActive(enigmail_ID)) { |
---|
119 | vI.main.preferences.setBoolPref("storageExtras_openPGP_messageEncryption", false) |
---|
120 | vI.main.preferences.setBoolPref("storageExtras_openPGP_messageSignature", false) |
---|
121 | vI.main.preferences.setBoolPref("storageExtras_openPGP_PGPMIME", false) |
---|
122 | } |
---|
123 | }, |
---|
124 | |
---|
125 | |
---|
126 | firstUsedInputElement : null, // this stores the first Element for which a Lookup in the Storage was successfull |
---|
127 | updateVIdentityFromStorage: function(inputElement) { |
---|
128 | if (!storage._pref.getBoolPref("storage")) |
---|
129 | { vI.notificationBar.dump("## storage: Storage deactivated\n"); return; } |
---|
130 | vI.notificationBar.dump("## storage: updateVIdentityFromStorage()\n"); |
---|
131 | |
---|
132 | var recipientType = document.getElementById(inputElement.id.replace(/^addressCol2/,"addressCol1")) |
---|
133 | .selectedItem.getAttribute("value"); |
---|
134 | var row = inputElement.id.replace(/^addressCol2#/,"") |
---|
135 | if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.__isDoBcc(row)) { |
---|
136 | // reset firstUsedInputElement if recipientType was changed (and don't care about doBcc fields) |
---|
137 | if (storage.firstUsedInputElement == inputElement) |
---|
138 | storage.firstUsedInputElement = null; |
---|
139 | vI.notificationBar.dump("## storage: field is a 'reply-to' or 'followup-to' or preconfigured 'doBcc'. not searched.\n") |
---|
140 | return; |
---|
141 | } |
---|
142 | |
---|
143 | if (inputElement.value == "") { |
---|
144 | vI.notificationBar.dump("## storage: no recipient found, not checked.\n"); return; |
---|
145 | } |
---|
146 | |
---|
147 | var row = inputElement.id.replace(/^addressCol2#/,"") |
---|
148 | if (storage.lastCheckedEmail[row] && storage.lastCheckedEmail[row] == inputElement.value) { |
---|
149 | vI.notificationBar.dump("## storage: same email than before, not checked again.\n"); return; |
---|
150 | } |
---|
151 | storage.lastCheckedEmail[row] = inputElement.value; |
---|
152 | |
---|
153 | // firstUsedInputElement was set before and we are not editing the same |
---|
154 | var isNotFirstInputElement = (storage.firstUsedInputElement && storage.firstUsedInputElement != inputElement) |
---|
155 | var currentIdentity = document.getElementById("msgIdentity_clone").identityData |
---|
156 | var storageResult = storage._rdfDatasourceAccess.updateVIdentityFromStorage(inputElement.value, recipientType, |
---|
157 | currentIdentity, document.getElementById("msgIdentity_clone").vid, isNotFirstInputElement); |
---|
158 | |
---|
159 | if (storageResult.identityCollection.number == 0) return; // return if there was no match |
---|
160 | vI.notificationBar.dump("## storage: updateVIdentityFromStorage result: " + storageResult.result + "\n"); |
---|
161 | // found storageData, so store InputElement |
---|
162 | if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement; |
---|
163 | |
---|
164 | var selectedMenuItem; |
---|
165 | if (storageResult.result != "equal") { |
---|
166 | for (var j = 0; j < storageResult.identityCollection.number; j++) { |
---|
167 | vI.notificationBar.dump("## storage: updateVIdentityFromStorage adding: " + storageResult.identityCollection.identityDataCollection[j].combinedName + "\n"); |
---|
168 | selectedMenuItem = document.getElementById("msgIdentity_clone").addIdentityToCloneMenu(storageResult.identityCollection.identityDataCollection[j]) |
---|
169 | } |
---|
170 | } |
---|
171 | if (storageResult.result == "accept") { |
---|
172 | vI.notificationBar.dump("## storage: updateVIdentityFromStorage selecting: " + storageResult.identityCollection.identityDataCollection[0].combinedName + "\n"); |
---|
173 | document.getElementById("msgIdentity_clone").selectedMenuItem = selectedMenuItem; |
---|
174 | if (document.getElementById("msgIdentity_clone").vid) |
---|
175 | vI.notificationBar.setNote(vI.main.elements.strings.getString("vident.smartIdentity.vIStorageUsage") + ".", |
---|
176 | "storage_notification"); |
---|
177 | } |
---|
178 | }, |
---|
179 | |
---|
180 | __isDoBcc : function(row) { |
---|
181 | var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); |
---|
182 | if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false |
---|
183 | |
---|
184 | var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {}); |
---|
185 | |
---|
186 | for (var index = 0; index < doBccArray.count; index++ ) { |
---|
187 | if (doBccArray.StringAt(index) == awGetInputElement(row).value) { |
---|
188 | vI.notificationBar.dump("## storage: ignoring doBcc field '" + |
---|
189 | doBccArray.StringAt(index) + "'.\n"); |
---|
190 | return true; |
---|
191 | } |
---|
192 | } |
---|
193 | return false |
---|
194 | } |
---|
195 | } |
---|
196 | vI.storage = storage; |
---|
197 | }}); |
---|