| 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 | Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js"); |
|---|
| 26 | virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { |
|---|
| 27 | |
|---|
| 28 | let Log = vI.setupLogging("virtualIdentity.main"); |
|---|
| 29 | Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension); |
|---|
| 30 | Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension); |
|---|
| 31 | Components.utils.import("resource://v_identity/vI_replyToSelf.js", virtualIdentityExtension); |
|---|
| 32 | Components.utils.import("resource://v_identity/plugins/signatureSwitch.js", virtualIdentityExtension); |
|---|
| 33 | |
|---|
| 34 | var main = { |
|---|
| 35 | headerParser : Components.classes["@mozilla.org/messenger/headerparser;1"] |
|---|
| 36 | .getService(Components.interfaces.nsIMsgHeaderParser), |
|---|
| 37 | |
|---|
| 38 | unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] |
|---|
| 39 | .createInstance(Components.interfaces.nsIScriptableUnicodeConverter), |
|---|
| 40 | |
|---|
| 41 | accountManager : Components.classes["@mozilla.org/messenger/account-manager;1"] |
|---|
| 42 | .getService(Components.interfaces.nsIMsgAccountManager), |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | gMsgCompose : null, // to store the global gMsgCompose after MsgComposeDialog is closed |
|---|
| 46 | |
|---|
| 47 | // Those variables keep pointers to original functions which might get replaced later |
|---|
| 48 | original_functions : { |
|---|
| 49 | GenericSendMessage : null, |
|---|
| 50 | FillIdentityList : null |
|---|
| 51 | }, |
|---|
| 52 | |
|---|
| 53 | // some pointers to the layout-elements of the extension |
|---|
| 54 | elements : { |
|---|
| 55 | init_base : function() { |
|---|
| 56 | main.elements.Area_MsgIdentityHbox = document.getElementById("virtualIdentityExtension_msgIdentityHbox"); |
|---|
| 57 | main.elements.Obj_MsgIdentity = document.getElementById("msgIdentity"); |
|---|
| 58 | }, |
|---|
| 59 | init_rest : function() { |
|---|
| 60 | main.elements.Obj_MsgIdentityPopup = document.getElementById("msgIdentityPopup"); |
|---|
| 61 | main.elements.Obj_vILogo = document.getElementById("virtualIdentityExtension_Logo"); |
|---|
| 62 | }, |
|---|
| 63 | strings : null |
|---|
| 64 | }, |
|---|
| 65 | |
|---|
| 66 | ComposeStateListener : { |
|---|
| 67 | NotifyComposeBodyReady: function() { |
|---|
| 68 | Log.debug("NotifyComposeBodyReady\n"); |
|---|
| 69 | main.initSystemStage2(); |
|---|
| 70 | }, |
|---|
| 71 | NotifyComposeFieldsReady: function() { |
|---|
| 72 | Log.debug("NotifyComposeFieldsReady\n"); |
|---|
| 73 | }, |
|---|
| 74 | ComposeProcessDone: function(aResult) { |
|---|
| 75 | Log.debug("StateListener reports ComposeProcessDone\n"); |
|---|
| 76 | main.Cleanup(); // not really required, parallel handled by main.close |
|---|
| 77 | vI.storage.clean(); |
|---|
| 78 | }, |
|---|
| 79 | SaveInFolderDone: function(folderURI) { |
|---|
| 80 | Log.debug("SaveInFolderDone\n"); |
|---|
| 81 | main.Cleanup(); |
|---|
| 82 | vI.storage.clean(); |
|---|
| 83 | } |
|---|
| 84 | }, |
|---|
| 85 | |
|---|
| 86 | replacement_functions : { |
|---|
| 87 | FillIdentityList: function(menulist) { |
|---|
| 88 | Log.debug("mod. FillIdentityList\n"); |
|---|
| 89 | var accounts = queryISupportsArray(main.accountManager.accounts, |
|---|
| 90 | Components.interfaces.nsIMsgAccount); |
|---|
| 91 | |
|---|
| 92 | // Ugly hack to work around bug 41133. :-( |
|---|
| 93 | accounts = accounts.filter(function isNonSuckyAccount(a) { return !!a.incomingServer; }); |
|---|
| 94 | function sortAccounts(a, b) { |
|---|
| 95 | if (a.key == main.accountManager.defaultAccount.key) |
|---|
| 96 | return -1; |
|---|
| 97 | if (b.key == main.accountManager.defaultAccount.key) |
|---|
| 98 | return 1; |
|---|
| 99 | var aIsNews = a.incomingServer.type == "nntp"; |
|---|
| 100 | var bIsNews = b.incomingServer.type == "nntp"; |
|---|
| 101 | if (aIsNews && !bIsNews) |
|---|
| 102 | return 1; |
|---|
| 103 | if (bIsNews && !aIsNews) |
|---|
| 104 | return -1; |
|---|
| 105 | |
|---|
| 106 | var aIsLocal = a.incomingServer.type == "none"; |
|---|
| 107 | var bIsLocal = b.incomingServer.type == "none"; |
|---|
| 108 | if (aIsLocal && !bIsLocal) |
|---|
| 109 | return 1; |
|---|
| 110 | if (bIsLocal && !aIsLocal) |
|---|
| 111 | return -1; |
|---|
| 112 | return 0; |
|---|
| 113 | } |
|---|
| 114 | accounts.sort(sortAccounts); |
|---|
| 115 | |
|---|
| 116 | for (var i in accounts) { |
|---|
| 117 | var server = accounts[i].incomingServer; |
|---|
| 118 | if (!server) continue; |
|---|
| 119 | // check for VirtualIdentity Account |
|---|
| 120 | try { vI.prefroot.getBoolPref("mail.account." + accounts[i].key + ".vIdentity"); |
|---|
| 121 | continue; } catch (e) { }; |
|---|
| 122 | |
|---|
| 123 | var identities = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity); |
|---|
| 124 | for (var j in identities) { |
|---|
| 125 | var identity = identities[j]; |
|---|
| 126 | var item = menulist.appendItem(identity.identityName, identity.key, server.prettyName); |
|---|
| 127 | item.setAttribute("accountkey", accounts[i].key); |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | }, |
|---|
| 131 | |
|---|
| 132 | GenericSendMessageInProgress : false, |
|---|
| 133 | GenericSendMessage: function (msgType) { |
|---|
| 134 | if (main.replacement_functions.GenericSendMessageInProgress) return; |
|---|
| 135 | main.replacement_functions.GenericSendMessageInProgress = true; |
|---|
| 136 | |
|---|
| 137 | // if addressCol2 is focused while sending check storage for the entered address before continuing |
|---|
| 138 | vI.storage.awOnBlur(vI.storage.focusedElement); |
|---|
| 139 | |
|---|
| 140 | Log.debug("\nVIdentity_GenericSendMessage\n"); |
|---|
| 141 | |
|---|
| 142 | if (msgType == Components.interfaces.nsIMsgCompDeliverMode.Now) |
|---|
| 143 | vI.addReplyToSelf(); |
|---|
| 144 | |
|---|
| 145 | var vid = document.getElementById("virtualIdentityExtension_msgIdentityClone").vid |
|---|
| 146 | var virtualIdentityData = document.getElementById("virtualIdentityExtension_msgIdentityClone").identityData; |
|---|
| 147 | |
|---|
| 148 | let returnValue = vI.vIaccount_prepareSendMsg( vid, msgType, virtualIdentityData, |
|---|
| 149 | main.accountManager.getIdentity(main.elements.Obj_MsgIdentity.value), |
|---|
| 150 | main._getRecipients() ); |
|---|
| 151 | if (returnValue.update == "abort") { |
|---|
| 152 | main.replacement_functions.GenericSendMessageInProgress = false; |
|---|
| 153 | Log.debug("sending: -------------- aborted ---------------------------------\n") |
|---|
| 154 | return; |
|---|
| 155 | } |
|---|
| 156 | else if (returnValue.update == "takeover") { |
|---|
| 157 | var msgIdentityCloneElem = document.getElementById("virtualIdentityExtension_msgIdentityClone"); |
|---|
| 158 | msgIdentityCloneElem.selectedMenuItem = msgIdentityCloneElem.addIdentityToCloneMenu(returnValue.storedIdentity); |
|---|
| 159 | main.replacement_functions.GenericSendMessageInProgress = false; |
|---|
| 160 | Log.debug("sending: -------------- aborted ---------------------------------\n") |
|---|
| 161 | return; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | if (vid) main.addVirtualIdentityToMsgIdentityMenu(); |
|---|
| 165 | |
|---|
| 166 | // final check if eyerything is nice before we handover to the real sending... |
|---|
| 167 | if (vI.vIaccount_finalCheck(virtualIdentityData, getCurrentIdentity())) { |
|---|
| 168 | main.replacement_functions.GenericSendMessageInProgress = false; |
|---|
| 169 | main.original_functions.GenericSendMessage(msgType); |
|---|
| 170 | } |
|---|
| 171 | else main.Cleanup(); |
|---|
| 172 | main.replacement_functions.GenericSendMessageInProgress = false; |
|---|
| 173 | // Log.debug("original_functions.GenericSendMessage done\n"); |
|---|
| 174 | }, |
|---|
| 175 | |
|---|
| 176 | replace_FillIdentityList : function() { |
|---|
| 177 | //~ Log.debug("replace FillIdentityList \n"); |
|---|
| 178 | main.original_functions.FillIdentityList = FillIdentityList; |
|---|
| 179 | FillIdentityList = main.replacement_functions.FillIdentityList; |
|---|
| 180 | } |
|---|
| 181 | }, |
|---|
| 182 | |
|---|
| 183 | remove: function() { |
|---|
| 184 | window.removeEventListener('compose-window-reopen', main.reopen, true); |
|---|
| 185 | window.removeEventListener('compose-window-close', main.close, true); |
|---|
| 186 | Log.debug("end. remove Account if there.\n") |
|---|
| 187 | main.Cleanup(); |
|---|
| 188 | vI.storage.clean(); |
|---|
| 189 | }, |
|---|
| 190 | |
|---|
| 191 | _getRecipients : function(row) { |
|---|
| 192 | var recipients = []; |
|---|
| 193 | for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { |
|---|
| 194 | var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); |
|---|
| 195 | if (recipientType == "addr_reply" || recipientType == "addr_followup" || |
|---|
| 196 | main._recipientIsDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue; |
|---|
| 197 | recipients.push( { recipient: awGetInputElement(row).value, recipientType : recipientType } ); |
|---|
| 198 | } |
|---|
| 199 | return recipients; |
|---|
| 200 | }, |
|---|
| 201 | |
|---|
| 202 | _recipientIsDoBcc : function(row) { |
|---|
| 203 | var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); |
|---|
| 204 | if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false |
|---|
| 205 | |
|---|
| 206 | var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {}); |
|---|
| 207 | |
|---|
| 208 | for (var index = 0; index < doBccArray.count; index++ ) { |
|---|
| 209 | if (doBccArray.StringAt(index) == awGetInputElement(row).value) { |
|---|
| 210 | Log.debug("_recipientIsDoBcc: ignoring doBcc field '" + |
|---|
| 211 | doBccArray.StringAt(index) + "'.\n"); |
|---|
| 212 | return true; |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | return false |
|---|
| 216 | }, |
|---|
| 217 | |
|---|
| 218 | // initialization // |
|---|
| 219 | init: function() { |
|---|
| 220 | window.removeEventListener('load', main.init, false); |
|---|
| 221 | window.removeEventListener('compose-window-init', main.init, true); |
|---|
| 222 | if (main.elements.Area_MsgIdentityHbox) return; // init done before, (?reopen) |
|---|
| 223 | Log.debug("\ninit.\n") |
|---|
| 224 | main.unicodeConverter.charset="UTF-8"; |
|---|
| 225 | if (!main.adapt_genericSendMessage()) { Log.debug("\ninit failed.\n"); return; } |
|---|
| 226 | |
|---|
| 227 | main.adapt_interface(); |
|---|
| 228 | gMsgCompose.RegisterStateListener(main.ComposeStateListener); |
|---|
| 229 | document.getElementById("virtualIdentityExtension_tooltipPopupset") |
|---|
| 230 | .addTooltip(document.getElementById("virtualIdentityExtension_msgIdentityClone"), false); |
|---|
| 231 | window.addEventListener('compose-window-reopen', main.reopen, true); |
|---|
| 232 | window.addEventListener('compose-window-close', main.close, true); |
|---|
| 233 | |
|---|
| 234 | // append observer to virtualIdentityExtension_fccSwitch, because it does'n work with real identities (hidden by css) |
|---|
| 235 | document.getElementById("virtualIdentityExtension_fccSwitch").appendChild(document.getElementById("virtualIdentityExtension_msgIdentityClone_observer").cloneNode(false)); |
|---|
| 236 | |
|---|
| 237 | main.AccountManagerObserver.register(); |
|---|
| 238 | |
|---|
| 239 | main.initSystemStage1(); |
|---|
| 240 | Log.debug("init done.\n\n") |
|---|
| 241 | }, |
|---|
| 242 | |
|---|
| 243 | initSystemStage1 : function() { |
|---|
| 244 | Log.debug("initSystemStage1.\n") |
|---|
| 245 | main.gMsgCompose = gMsgCompose; |
|---|
| 246 | document.getElementById("virtualIdentityExtension_msgIdentityClone").init(); |
|---|
| 247 | vI.statusmenu.init(); |
|---|
| 248 | Log.debug("initSystemStage1 done.\n") |
|---|
| 249 | }, |
|---|
| 250 | |
|---|
| 251 | initSystemStage2 : function() { |
|---|
| 252 | Log.debug("initSystemStage2.\n") |
|---|
| 253 | vI.initReplyTo(); |
|---|
| 254 | vI.storage.init(); |
|---|
| 255 | vI.smartIdentity.init(); |
|---|
| 256 | Log.debug("initSystemStage2 done.\n") |
|---|
| 257 | }, |
|---|
| 258 | |
|---|
| 259 | close : function() { |
|---|
| 260 | main.Cleanup(); |
|---|
| 261 | vI.storage.clean(); |
|---|
| 262 | }, |
|---|
| 263 | |
|---|
| 264 | adapt_interface : function() { |
|---|
| 265 | if (main.elements.Obj_MsgIdentityPopup) return; // only rearrange the interface once |
|---|
| 266 | |
|---|
| 267 | // initialize the pointers to extension elements |
|---|
| 268 | main.elements.init_base() |
|---|
| 269 | |
|---|
| 270 | // rearrange the positions of some elements |
|---|
| 271 | var parent_hbox = main.elements.Obj_MsgIdentity.parentNode; |
|---|
| 272 | var storage_box = document.getElementById("addresses-box"); |
|---|
| 273 | var virtualIdentityExtension_autoReplyToSelfLabel = document.getElementById("virtualIdentityExtension_autoReplyToSelfLabelBox"); |
|---|
| 274 | |
|---|
| 275 | storage_box.removeChild(virtualIdentityExtension_autoReplyToSelfLabel); |
|---|
| 276 | parent_hbox.appendChild(virtualIdentityExtension_autoReplyToSelfLabel); |
|---|
| 277 | storage_box.removeChild(main.elements.Area_MsgIdentityHbox); |
|---|
| 278 | parent_hbox.appendChild(main.elements.Area_MsgIdentityHbox); |
|---|
| 279 | |
|---|
| 280 | main.elements.Obj_MsgIdentity.setAttribute("hidden", "true"); |
|---|
| 281 | main.elements.Obj_MsgIdentity.previousSibling.setAttribute("control", "virtualIdentityExtension_msgIdentityClone"); |
|---|
| 282 | |
|---|
| 283 | var access_label = parent_hbox.getElementsByAttribute( "control", "msgIdentity" )[0]; |
|---|
| 284 | if (access_label) access_label.setAttribute("control", "virtualIdentityExtension_msgIdentityClone"); |
|---|
| 285 | |
|---|
| 286 | // initialize the pointers to extension elements (initialize those earlier might brake the interface) |
|---|
| 287 | main.elements.init_rest(); |
|---|
| 288 | }, |
|---|
| 289 | |
|---|
| 290 | adapt_genericSendMessage : function() { |
|---|
| 291 | if (main.original_functions.GenericSendMessage) return true; // only initialize this once |
|---|
| 292 | Log.debug("adapt GenericSendMessage\n"); |
|---|
| 293 | main.original_functions.GenericSendMessage = GenericSendMessage; |
|---|
| 294 | GenericSendMessage = main.replacement_functions.GenericSendMessage; |
|---|
| 295 | return true; |
|---|
| 296 | }, |
|---|
| 297 | |
|---|
| 298 | reopen: function() { |
|---|
| 299 | vI.clearDebugOutput(); |
|---|
| 300 | Log.debug("composeDialog reopened. (msgType " + gMsgCompose.type + ")\n") |
|---|
| 301 | |
|---|
| 302 | // clean all elements |
|---|
| 303 | document.getElementById("virtualIdentityExtension_msgIdentityClone").clean(); |
|---|
| 304 | Log.debug("everything cleaned.\n") |
|---|
| 305 | |
|---|
| 306 | // now (re)init the elements |
|---|
| 307 | main.initSystemStage1(); |
|---|
| 308 | |
|---|
| 309 | // stateListener only works in reply-cases |
|---|
| 310 | // so activate stage2 in reply-cases trough StateListener |
|---|
| 311 | // in other cases directly |
|---|
| 312 | var msgComposeType = Components.interfaces.nsIMsgCompType; |
|---|
| 313 | switch (gMsgCompose.type) { |
|---|
| 314 | case msgComposeType.New: |
|---|
| 315 | case msgComposeType.NewsPost: |
|---|
| 316 | case msgComposeType.MailToUrl: |
|---|
| 317 | case msgComposeType.Draft: |
|---|
| 318 | case msgComposeType.Template: |
|---|
| 319 | case msgComposeType.ForwardAsAttachment: |
|---|
| 320 | case msgComposeType.ForwardInline: |
|---|
| 321 | main.initSystemStage2(); break; |
|---|
| 322 | case msgComposeType.Reply: |
|---|
| 323 | case msgComposeType.ReplyAll: |
|---|
| 324 | case msgComposeType.ReplyToGroup: |
|---|
| 325 | case msgComposeType.ReplyToSender: |
|---|
| 326 | case msgComposeType.ReplyToSenderAndGroup: |
|---|
| 327 | case msgComposeType.ReplyWithTemplate: |
|---|
| 328 | case msgComposeType.ReplyToList: |
|---|
| 329 | gMsgCompose.RegisterStateListener(main.ComposeStateListener); |
|---|
| 330 | } |
|---|
| 331 | Log.debug("reopen done.\n") |
|---|
| 332 | }, |
|---|
| 333 | |
|---|
| 334 | tempStorage: { BaseIdentity : null, NewIdentity : null }, |
|---|
| 335 | |
|---|
| 336 | __setSelectedIdentity : function(menuItem) { |
|---|
| 337 | main.elements.Obj_MsgIdentity.selectedItem = menuItem; |
|---|
| 338 | main.elements.Obj_MsgIdentity.setAttribute("label", menuItem.getAttribute("label")); |
|---|
| 339 | main.elements.Obj_MsgIdentity.setAttribute("accountname", menuItem.getAttribute("accountname")); |
|---|
| 340 | main.elements.Obj_MsgIdentity.setAttribute("value", menuItem.getAttribute("value")); |
|---|
| 341 | }, |
|---|
| 342 | |
|---|
| 343 | // sets the values of the dropdown-menu to the ones of the newly created account |
|---|
| 344 | addVirtualIdentityToMsgIdentityMenu : function() |
|---|
| 345 | { |
|---|
| 346 | main.tempStorage.BaseIdentity = main.elements.Obj_MsgIdentity.selectedItem; |
|---|
| 347 | main.tempStorage.NewIdentity = document.createElement("menuitem"); |
|---|
| 348 | main.tempStorage.NewIdentity.className = "identity-popup-item"; |
|---|
| 349 | |
|---|
| 350 | // set the account name in the choosen menu item |
|---|
| 351 | main.tempStorage.NewIdentity.setAttribute("label", vI.get_vIaccount().defaultIdentity.identityName); |
|---|
| 352 | main.tempStorage.NewIdentity.setAttribute("accountname", " - " + vI.get_vIaccount().incomingServer.prettyName); |
|---|
| 353 | main.tempStorage.NewIdentity.setAttribute("accountkey", vI.get_vIaccount().key); |
|---|
| 354 | main.tempStorage.NewIdentity.setAttribute("value", vI.get_vIaccount().defaultIdentity.key); |
|---|
| 355 | |
|---|
| 356 | main.elements.Obj_MsgIdentityPopup.appendChild(main.tempStorage.NewIdentity); |
|---|
| 357 | main.__setSelectedIdentity(main.tempStorage.NewIdentity); |
|---|
| 358 | }, |
|---|
| 359 | |
|---|
| 360 | removeVirtualIdentityFromMsgIdentityMenu : function() |
|---|
| 361 | { |
|---|
| 362 | if (!main.tempStorage.BaseIdentity) return; // don't try to remove Item twice |
|---|
| 363 | try { // might not exist anymore (window closed), so just try to remove it |
|---|
| 364 | document.getElementById("msgIdentity").firstChild.removeChild(main.tempStorage.NewIdentity); |
|---|
| 365 | main.__setSelectedIdentity(main.tempStorage.BaseIdentity); |
|---|
| 366 | } catch (e) { }; |
|---|
| 367 | main.tempStorage.NewIdentity = null; |
|---|
| 368 | main.tempStorage.BaseIdentity = null; |
|---|
| 369 | }, |
|---|
| 370 | |
|---|
| 371 | prepareAccount : function() { |
|---|
| 372 | main.Cleanup(); // just to be sure that nothing is left (maybe last time sending was irregularily stopped) |
|---|
| 373 | vI.vIaccount_createAccount(document.getElementById("virtualIdentityExtension_msgIdentityClone").identityData, |
|---|
| 374 | main.accountManager.getIdentity(main.elements.Obj_MsgIdentity.value)); |
|---|
| 375 | main.addVirtualIdentityToMsgIdentityMenu(); |
|---|
| 376 | }, |
|---|
| 377 | |
|---|
| 378 | Cleanup : function() { |
|---|
| 379 | main.removeVirtualIdentityFromMsgIdentityMenu(); |
|---|
| 380 | vI.vIaccount_removeUsedVIAccount(); |
|---|
| 381 | }, |
|---|
| 382 | |
|---|
| 383 | // code adapted from http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html |
|---|
| 384 | AccountManagerObserver : { |
|---|
| 385 | _uninstall : false, |
|---|
| 386 | observe : function(subject, topic, data) { |
|---|
| 387 | if (topic == "am-smtpChanges") { |
|---|
| 388 | Log.debug("smtp changes observed\n"); |
|---|
| 389 | var virtualIdentityExtension_msgIdentityClone = document.getElementById("virtualIdentityExtension_msgIdentityClone"); |
|---|
| 390 | document.getAnonymousElementByAttribute(virtualIdentityExtension_msgIdentityClone, "class", "smtpServerListHbox").refresh(); |
|---|
| 391 | } |
|---|
| 392 | if (topic == "am-acceptChanges") { |
|---|
| 393 | Log.debug("account changes observed\n"); |
|---|
| 394 | document.getElementById("virtualIdentityExtension_msgIdentityClone").clean(); |
|---|
| 395 | document.getElementById("virtualIdentityExtension_msgIdentityClone").init(); |
|---|
| 396 | } |
|---|
| 397 | }, |
|---|
| 398 | register : function() { |
|---|
| 399 | var obsService = Components.classes["@mozilla.org/observer-service;1"]. |
|---|
| 400 | getService(Components.interfaces.nsIObserverService) |
|---|
| 401 | obsService.addObserver(this, "am-smtpChanges", false); |
|---|
| 402 | obsService.addObserver(this, "am-acceptChanges", false); |
|---|
| 403 | }, |
|---|
| 404 | unregister : function() { |
|---|
| 405 | var obsService = Components.classes["@mozilla.org/observer-service;1"]. |
|---|
| 406 | getService(Components.interfaces.nsIObserverService) |
|---|
| 407 | obsService.removeObserver(this, "am-smtpChanges"); |
|---|
| 408 | obsService.removeObserver(this, "am-acceptChanges"); |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | main.replacement_functions.replace_FillIdentityList(); |
|---|
| 415 | window.addEventListener('compose-window-init', main.init, true); |
|---|
| 416 | |
|---|
| 417 | window.addEventListener("unload", function(e) { main.AccountManagerObserver.unregister(); try {vI.statusmenu.removeObserver();} catch (ex) { } }, false); |
|---|
| 418 | vI.main = main; |
|---|
| 419 | }}); |
|---|