Changeset 9cedc0
- Timestamp:
- Sep 25, 2011, 9:23:06 PM (11 years ago)
- Branches:
- ng_0.9
- Children:
- 284956
- Parents:
- 7666cb
- Location:
- chrome/content/v_identity
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
chrome/content/v_identity/vI_Dialog.js
r7666cb r9cedc0 31 31 32 32 init : function(warning) { 33 dump("warning.class=" + warning.class + "warning.class=" + warning.title + "warning.warning=" + warning.warning + "\n") 33 34 document.getElementById("vI_Dialog").setAttribute("class", warning.class); 34 35 Dialog.setDescription(document.getElementById("vI_Dialog_title"), warning.title); -
chrome/content/v_identity/vI_account.js
r7666cb r9cedc0 24 24 25 25 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { 26 function prepareSendMsg(vid, msgType, identityData, baseIdentity, recipients) { 27 var stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties"); 28 29 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] 30 .getService(Components.interfaces.nsIPromptService); 31 32 var prefs = Components.classes["@mozilla.org/preferences-service;1"] 33 .getService(Components.interfaces.nsIPrefService) 34 .getBranch("extensions.virtualIdentity."); 35 36 var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"] 37 .getService(Components.interfaces.nsIMsgAccountManager); 38 39 if (vI.notificationBar) vI.notificationBar.dump("\n## prepareSendMsg " + msgType + " " + Components.interfaces.nsIMsgCompDeliverMode.Now + "\n"); 40 41 returnValue = {}; 42 43 if (msgType == Components.interfaces.nsIMsgCompDeliverMode.Now) { 44 if ( (vid && prefs.getBoolPref("warn_virtual") && 45 !(promptService.confirm(window,"Warning", 46 stringBundle.GetStringFromName("vident.sendVirtual.warning")))) || 47 (!vid && prefs.getBoolPref("warn_nonvirtual") && 48 !(promptService.confirm(window,"Warning", 49 stringBundle.GetStringFromName("vident.sendNonvirtual.warning")))) ) { 50 return { update : "abort", storedIdentity : null }; // completely abort sending 51 } 52 if (prefs.getBoolPref("storage") && 53 (!vI.statusmenu || vI.statusmenu.objStorageSaveMenuItem.getAttribute("checked") == "true")) { 54 var localeDatasourceAccess = new vI.rdfDatasourceAccess(); 55 var returnValue = localeDatasourceAccess.storeVIdentityToAllRecipients(identityData, recipients) 56 if ( returnValue.update == "abort" || returnValue.update == "takeover" ) { 57 if (vI.notificationBar) vI.notificationBar.dump("## prepareSendMsg: sending aborted\n"); 58 return returnValue; 59 } 60 } 61 else if (vI.notificationBar) vI.notificationBar.dump("## prepareSendMsg: storage deactivated\n"); 62 } 63 if (vid) { 64 vI.account.removeUsedVIAccount(); 65 vI.account.createAccount(identityData, baseIdentity); 66 } 67 return { update : "accept", storedIdentity : null }; 68 }; 69 70 function finalCheck(virtualIdentityData, currentIdentity) { 71 var stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties"); 72 73 // vI.identityData(email, fullName, id, smtp, extras, sideDescription, existingID) 74 var currentIdentityData = new vI.identityData(currentIdentity.email, currentIdentity.fullName, null, currentIdentity.smtpServerKey, null, null, null); 75 76 if (vI.notificationBar) vI.notificationBar.dump("\n## vI.identityData SendMessage Final Check\n"); 77 if (vI.notificationBar) vI.notificationBar.dump("## vI.identityData currentIdentity: fullName='" + currentIdentityData.fullName + "' email='" + currentIdentityData.email + "' smtp='" + currentIdentityData.smtp.key + "'\n"); 78 if (vI.notificationBar) vI.notificationBar.dump("## vI.identityData virtualIdentityData: fullName='" + virtualIdentityData.fullName + "' email='" + virtualIdentityData.email + "' smtp='" + virtualIdentityData.smtp.key + "'\n"); 79 80 if (currentIdentityData.fullName.toLowerCase() == virtualIdentityData.fullName.toLowerCase() && 81 currentIdentityData.email.toLowerCase() == virtualIdentityData.email.toLowerCase() && 82 virtualIdentityData.smtp.equal(currentIdentityData.smtp) ) { 83 return true 84 } 85 else { 86 if (!(currentIdentityData.fullName.toLowerCase() == virtualIdentityData.fullName.toLowerCase())) vI.notificationBar.dump("\n## vI.identityData failed check for fullName.\n"); 87 if (!(currentIdentityData.email.toLowerCase() == virtualIdentityData.email.toLowerCase())) vI.notificationBar.dump("\n## vI.identityData failed check for email.\n"); 88 if (!(virtualIdentityData.smtp.equal(currentIdentityData.smtp))) vI.notificationBar.dump("\n## vI.identityData failed check for SMTP.\n"); 89 alert(stringBundle.getStringFromName("vident.genericSendMessage.error")); 90 return false 91 } 92 }; 93 26 94 var account = { 27 95 _account : null, 28 96 97 _baseIdentity : null, 98 29 99 _AccountManager : Components.classes["@mozilla.org/messenger/account-manager;1"] 30 100 .getService(Components.interfaces.nsIMsgAccountManager), … … 34 104 .getBranch(null), 35 105 36 _getBaseIdentity : function () { 37 return account._AccountManager.getIdentity(vI.main.elements.Obj_MsgIdentity.value); 38 }, 39 106 _pref : Components.classes["@mozilla.org/preferences-service;1"] 107 .getService(Components.interfaces.nsIPrefService) 108 .getBranch("extensions.virtualIdentity."), 109 110 _unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] 111 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter), 112 40 113 _copyBoolAttribute : function(name) { 41 114 account._account.defaultIdentity.setBoolAttribute(name, 42 account._ getBaseIdentity().getBoolAttribute(name));115 account._baseIdentity.getBoolAttribute(name)); 43 116 }, 44 117 45 118 _copyIntAttribute : function(name) { 46 119 account._account.defaultIdentity.setIntAttribute(name, 47 account._ getBaseIdentity().getIntAttribute(name));120 account._baseIdentity.getIntAttribute(name)); 48 121 }, 49 122 50 123 _copyCharAttribute : function(name) { 51 124 account._account.defaultIdentity.setCharAttribute(name, 52 account._ getBaseIdentity().getCharAttribute(name));125 account._baseIdentity.getCharAttribute(name)); 53 126 }, 54 127 55 128 _copyUnicharAttribute : function(name) { 56 129 account._account.defaultIdentity.setUnicharAttribute(name, 57 account._ getBaseIdentity().getUnicharAttribute(name));58 }, 59 60 copyPreferences : function() {61 if ( vI.main.preferences.getBoolPref("copySMIMESettings")) {130 account._baseIdentity.getUnicharAttribute(name)); 131 }, 132 133 _copyPreferences : function() { 134 if (account._pref.getBoolPref("copySMIMESettings")) { 62 135 // SMIME settings 63 136 vI.notificationBar.dump("## account: copy S/MIME settings\n") … … 67 140 } 68 141 /* seems not required, encryption happens before Virtual Identity account is created 69 if ( vI.main.preferences.getBoolPref("copyEnigmailSettings")) {142 if (account._pref.getBoolPref("copyEnigmailSettings")) { 70 143 // pgp/enigmail settings 71 144 vI.notificationBar.dump("## account: copy PGP settings\n") … … 80 153 account._copyIntAttribute("defaultEncryptionPolicy"); 81 154 } */ 82 if ( vI.main.preferences.getBoolPref("copyAttachVCardSettings")) {155 if (account._pref.getBoolPref("copyAttachVCardSettings")) { 83 156 // attach vcard 84 157 vI.notificationBar.dump("## account: copy VCard settings\n") … … 203 276 }, 204 277 205 createAccount : function( )278 createAccount : function(identityData, baseIdentity) 206 279 { 207 280 if (account._account) { // if the Account is still created, then leave all like it is … … 209 282 return; 210 283 } 284 account._baseIdentity = baseIdentity; 211 285 /* 212 286 // the easiest way would be to get all requiered Attributes might be to duplicate the default account like this … … 220 294 account._account = account._AccountManager.createAccount(); 221 295 account._prefroot.setBoolPref("mail.account." + account._account.key + ".vIdentity", true) 222 223 296 account._account.addIdentity(account._AccountManager.createIdentity()); 224 225 297 // the new account uses the same incomingServer than the base one, 226 298 // it's especially required for NNTP cause incomingServer is used for sending newsposts. 227 299 // by pointing to the same incomingServer stored passwords can be reused 228 300 // the incomingServer has to be replaced before the account is removed, else it get removed ether 229 var servers = account._AccountManager.GetServersForIdentity( account._getBaseIdentity());301 var servers = account._AccountManager.GetServersForIdentity(baseIdentity); 230 302 var server = servers.QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer); 231 232 303 // we mark the server as invalid so that the account manager won't 233 304 // tell RDF about the new server - we don't need this server for long … … 236 307 account._account.incomingServer = server; 237 308 server.valid = true; 238 239 account.copyMsgIdentityClone(); 240 account.copyPreferences(); 241 account.setupFcc(); 242 account.setupDraft(); 243 account.setupTemplates(); 244 }, 245 246 copyMsgIdentityClone : function() { 247 var identityData = document.getElementById("msgIdentity_clone").identityData; 309 account._copyIdentityData(identityData, baseIdentity); 310 account._copyPreferences(); 311 account._unicodeConverter.charset = "UTF-8"; 312 account._setupFcc(); 313 account._setupDraft(); 314 account._setupTemplates(); 315 }, 316 317 _copyIdentityData : function(identityData, baseIdentity) { 248 318 account._account.defaultIdentity.setCharAttribute("useremail", identityData.email); 249 319 account._account.defaultIdentity.setUnicharAttribute("fullName", identityData.fullName); 250 320 251 321 account._account.defaultIdentity.smtpServerKey = identityData.smtp.keyNice; // key with "" for vI.DEFAULT_SMTP_TAG 322 if (account._account.defaultIdentity.smtpServerKey == virtualIdentityExtension.NO_SMTP_TAG) 323 account._account.defaultIdentity.smtpServerKey = baseIdentity.smtpServerKey; 252 324 253 325 vI.notificationBar.dump("## account: Stored virtualIdentity (name " … … 257 329 }, 258 330 259 setupFcc : function()331 _setupFcc : function() 260 332 { 261 if (document.getElementById("fcc_switch").getAttribute("checked")) { 262 switch (vI.main.preferences.getCharPref("fccFolderPickerMode")) 333 // fcc_switch is only available in modified ComposeDialog. 334 // XXXXX get rid of this Elem reference 335 var doFcc = true; 336 try { doFcc = document.getElementById("fcc_switch").getAttribute("checked") } catch(e) { } 337 if (doFcc) { 338 switch (account._pref.getCharPref("fccFolderPickerMode")) 263 339 { 264 340 case "2" : … … 271 347 case "3" : 272 348 vI.notificationBar.dump ("## account: preparing Fcc --- use Settings of Modified Account\n"); 273 account._account.defaultIdentity.doFcc = account._ getBaseIdentity().doFcc;274 account._account.defaultIdentity.fccFolder = account._ getBaseIdentity().fccFolder;275 account._account.defaultIdentity.fccFolderPickerMode = account._ getBaseIdentity().fccFolderPickerMode;276 account._account.defaultIdentity.fccReplyFollowsParent = account._ getBaseIdentity().fccReplyFollowsParent;349 account._account.defaultIdentity.doFcc = account._baseIdentity.doFcc; 350 account._account.defaultIdentity.fccFolder = account._baseIdentity.fccFolder; 351 account._account.defaultIdentity.fccFolderPickerMode = account._baseIdentity.fccFolderPickerMode; 352 account._account.defaultIdentity.fccReplyFollowsParent = account._baseIdentity.fccReplyFollowsParent; 277 353 break; 278 354 default : 279 355 vI.notificationBar.dump ("## account: preparing Fcc --- use Virtual Identity Settings\n"); 280 356 account._account.defaultIdentity.doFcc 281 = vI.main.preferences.getBoolPref("doFcc");357 = account._pref.getBoolPref("doFcc"); 282 358 account._account.defaultIdentity.fccFolder 283 = vI.main.unicodeConverter.ConvertToUnicode(vI.main.preferences.getCharPref("fccFolder"));359 = account._unicodeConverter.ConvertToUnicode(account._pref.getCharPref("fccFolder")); 284 360 account._account.defaultIdentity.fccFolderPickerMode 285 = vI.main.preferences.getCharPref("fccFolderPickerMode");286 account._account.defaultIdentity.fccReplyFollowsParent = vI.main.preferences.getBoolPref("fccReplyFollowsParent");361 = account._pref.getCharPref("fccFolderPickerMode"); 362 account._account.defaultIdentity.fccReplyFollowsParent = account._pref.getBoolPref("fccReplyFollowsParent"); 287 363 288 364 break; … … 296 372 account._account.defaultIdentity.fccFolder + " fccFolderPickerMode " + 297 373 account._account.defaultIdentity.fccFolderPickerMode + "(" + 298 vI.main.preferences.getCharPref("fccFolderPickerMode") + "))\n");299 }, 300 301 setupDraft : function() {302 switch ( vI.main.preferences.getCharPref("draftFolderPickerMode"))374 account._pref.getCharPref("fccFolderPickerMode") + "))\n"); 375 }, 376 377 _setupDraft : function() { 378 switch (account._pref.getCharPref("draftFolderPickerMode")) 303 379 { 304 380 case "2" : … … 309 385 case "3" : 310 386 vI.notificationBar.dump ("## account: preparing Draft --- use Settings of Modified Account\n"); 311 account._account.defaultIdentity.draftFolder = account._ getBaseIdentity().draftFolder;312 account._account.defaultIdentity.draftsFolderPickerMode = account._ getBaseIdentity().draftsFolderPickerMode;387 account._account.defaultIdentity.draftFolder = account._baseIdentity.draftFolder; 388 account._account.defaultIdentity.draftsFolderPickerMode = account._baseIdentity.draftsFolderPickerMode; 313 389 break; 314 390 default : 315 391 vI.notificationBar.dump ("## account: preparing Draft --- use Virtual Identity Settings\n"); 316 392 account._account.defaultIdentity.draftFolder 317 = vI.main.unicodeConverter.ConvertToUnicode(vI.main.preferences.getCharPref("draftFolder"));393 = account._unicodeConverter.ConvertToUnicode(account._pref.getCharPref("draftFolder")); 318 394 account._account.defaultIdentity.draftsFolderPickerMode 319 = vI.main.preferences.getCharPref("draftFolderPickerMode");395 = account._pref.getCharPref("draftFolderPickerMode"); 320 396 break; 321 397 } … … 323 399 account._account.defaultIdentity.draftFolder + " draftsFolderPickerMode " + 324 400 account._account.defaultIdentity.draftsFolderPickerMode + "(" + 325 vI.main.preferences.getCharPref("draftFolderPickerMode") + "))\n");326 }, 327 328 setupTemplates : function() {329 switch ( vI.main.preferences.getCharPref("stationeryFolderPickerMode"))401 account._pref.getCharPref("draftFolderPickerMode") + "))\n"); 402 }, 403 404 _setupTemplates : function() { 405 switch (account._pref.getCharPref("stationeryFolderPickerMode")) 330 406 { 331 407 case "2" : … … 336 412 case "3" : 337 413 vI.notificationBar.dump ("## account: preparing Templates --- use Settings of Modified Account\n"); 338 account._account.defaultIdentity.stationeryFolder = account._ getBaseIdentity().stationeryFolder;339 account._account.defaultIdentity.tmplFolderPickerMode = account._ getBaseIdentity().tmplFolderPickerMode;414 account._account.defaultIdentity.stationeryFolder = account._baseIdentity.stationeryFolder; 415 account._account.defaultIdentity.tmplFolderPickerMode = account._baseIdentity.tmplFolderPickerMode; 340 416 break; 341 417 default : 342 418 vI.notificationBar.dump ("## account: preparing Templates --- use Virtual Identity Settings\n"); 343 419 account._account.defaultIdentity.stationeryFolder 344 = vI.main.unicodeConverter.ConvertToUnicode(vI.main.preferences.getCharPref("stationeryFolder"));420 = account._unicodeConverter.ConvertToUnicode(account._pref.getCharPref("stationeryFolder")); 345 421 account._account.defaultIdentity.tmplFolderPickerMode 346 = vI.main.preferences.getCharPref("stationeryFolderPickerMode");422 = account._pref.getCharPref("stationeryFolderPickerMode"); 347 423 break; 348 424 } … … 350 426 account._account.defaultIdentity.stationeryFolder + " tmplFolderPickerMode " + 351 427 account._account.defaultIdentity.tmplFolderPickerMode + "(" + 352 vI.main.preferences.getCharPref("stationeryFolderPickerMode") + "))\n");428 account._pref.getCharPref("stationeryFolderPickerMode") + "))\n"); 353 429 } 354 430 } 355 431 vI.account = account; 432 vI.prepareSendMsg = prepareSendMsg; 433 vI.finalCheck = finalCheck; 356 434 }}); -
chrome/content/v_identity/vI_getHeader.js
r7666cb r9cedc0 40 40 41 41 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { 42 // var storedHeaders = { }; 42 43 var getHeader = { 43 44 messenger: null, … … 90 91 // create array to count the header 91 92 var currentHeadersCounter = []; 93 // storedHeaders = { }; 92 94 93 95 var listId = false; var received = false; var content_base = false; … … 99 101 if (!listId && headerName == "list-id") { 100 102 hdr.setStringProperty("vI_list-id","found"); listId = true; 103 // storedHeaders["vI_list-id"] = "found"; 101 104 vI.notificationBar.dump("## getHeader: found header: list-id ...stored to recognize mailing-list\n"); 102 105 // continue; … … 106 109 if (!received && headerName == "received") { 107 110 hdr.setStringProperty("vI_received","found"); received = true; 111 // storedHeaders["vI_received"] = "found"; 108 112 vI.notificationBar.dump("## getHeader: found header: received ...stored to recognize received mail\n"); 109 113 // continue; … … 113 117 if (!content_base && headerName == "content-base") { 114 118 hdr.setStringProperty("vI_content_base","found"); content_base = true; 119 // storedHeaders["vI_content_base"] = "found"; 115 120 vI.notificationBar.dump("## getHeader: found header: content-base ...stored to recognize blog/news-feed\n"); 116 121 // continue; … … 130 135 ", " + value; 131 136 hdr.setStringProperty(getHeader.headerToSearch[index].headerNameToStore,getHeader.unicodeConverter.ConvertFromUnicode(value) + getHeader.unicodeConverter.Finish()); 137 138 // storedHeaders[getHeader.headerToSearch[index].headerNameToStore] = getHeader.unicodeConverter.ConvertFromUnicode(value) + getHeader.unicodeConverter.Finish(); 132 139 133 140 var storedValue = hdr.getProperty(getHeader.headerToSearch[index].headerNameToStore) … … 136 143 "[:" + currentHeadersCounter[headerName] + "] - stored as '" + 137 144 storedConvValue + "'\n"); 145 /* vI.notificationBar.dump("## getHeader: additional stored header: " + getHeader.headerToSearch[index].headerNameToStore + 146 " '" + storedHeaders[getHeader.headerToSearch[index].headerNameToStore] + "'\n");*/ 138 147 if (!found) { 139 148 subtitle = getHeader.strings.getString("vident.getHeader.headerFound"); … … 376 385 window.addEventListener("load", function(e) { prepareHeader.init(); }, false); 377 386 window.addEventListener("unload", function(e) { prepareHeader.cleanup(); }, false); 387 // vI.storedHeaders = storedHeaders; 378 388 }}); -
chrome/content/v_identity/vI_identityData.js
r7666cb r9cedc0 30 30 this.id = new idObj(id); 31 31 this.smtp = new smtpObj(smtp); 32 this.extras = extras?extras:new vI.storageExtras(); 32 if (extras) this.extras = extras; 33 else if (typeof(vI.storageExtras)=='function') this.extras = new vI.storageExtras(); 33 34 this.comp = { // holds the results of the last comparison for later creation of a compareMatrix 34 35 compareID : null, … … 38 39 if (existingID) this.existingID = existingID; 39 40 else if (this.id.value) this.sideDescription = " - " + this.id.value; 40 this.stringBundle = document.getElementById("vIdentBundle"); 41 this.stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"] 42 .getService(Components.interfaces.nsIStringBundleService) 43 .createBundle("chrome://v_identity/locale/v_identity.properties"); 41 44 } 42 45 identityData.prototype = { 46 _prefroot : Components.classes["@mozilla.org/preferences-service;1"] 47 .getService(Components.interfaces.nsIPrefService) 48 .getBranch(null), 49 50 _pref : Components.classes["@mozilla.org/preferences-service;1"] 51 .getService(Components.interfaces.nsIPrefService) 52 .getBranch("extensions.virtualIdentity."), 53 43 54 _email : null, // internal email-field might contain combinedName (until first queried via email) 44 55 _fullName : null, … … 99 110 get combinedNameHtml() { return this.__makeHtml(this.combinedName); }, 100 111 101 get idLabel() { return this.stringBundle. getString("vident.identityData.baseID") },102 get smtpLabel() { return this.stringBundle. getString("vident.identityData.SMTP") },103 get fullNameLabel() { return this.stringBundle. getString("vident.identityData.Name") },104 get emailLabel() { return this.stringBundle. getString("vident.identityData.Address") },112 get idLabel() { return this.stringBundle.GetStringFromName("vident.identityData.baseID") }, 113 get smtpLabel() { return this.stringBundle.GetStringFromName("vident.identityData.SMTP") }, 114 get fullNameLabel() { return this.stringBundle.GetStringFromName("vident.identityData.Name") }, 115 get emailLabel() { return this.stringBundle.GetStringFromName("vident.identityData.Address") }, 105 116 106 117 // creates an Duplicate of the current IdentityData, cause usually we are working with a pointer 107 118 getDuplicate : function() { 108 return new identityData(this.email, this.fullName, this.id.key, this.smtp.key, this.extras .getDuplicate(), this.sideDescription, this.existingID);119 return new identityData(this.email, this.fullName, this.id.key, this.smtp.key, this.extras?this.extras.getDuplicate():null, this.sideDescription, this.existingID); 109 120 }, 110 121 … … 116 127 this.smtp.key = identityData.smtp.key; 117 128 this.sideDescription = identityData.sideDescription; 118 this.extras.copy(identityData.extras);129 if (this.extras) this.extras.copy(identityData.extras); 119 130 }, 120 131 … … 125 136 126 137 var ignoreFullNameMatchKey = null; 127 128 var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount); 129 for (var i in accounts) { 130 // skip possible active VirtualIdentity Accounts 131 try { vI.account._prefroot.getBoolPref("mail.account."+accounts[i].key+".vIdentity"); continue; } catch (e) { }; 132 133 var identities = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity); 134 for (var j in identities) { 135 // vI.notificationBar.dump("## identityData comp: fullName.toLowerCase()='" + identities[j].fullName.toLowerCase() + "' email.toLowerCase()='" + identities[j].email.toLowerCase() + "' smtp='" + identities[j].smtpServerKey + "'\n"); 138 var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"] 139 .getService(Components.interfaces.nsIMsgAccountManager); 140 for (let i = 0; i < AccountManager.accounts.Count(); i++) { 141 var account = AccountManager.accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount); 142 try { this._prefroot.getBoolPref("mail.account."+account.key+".vIdentity"); continue; } catch (e) { }; 143 for (let j = 0; j < account.identities.Count(); j++) { 144 var identity = account.identities.QueryElementAt(j, Components.interfaces.nsIMsgIdentity); 145 // vI.notificationBar.dump("## identityData comp: fullName.toLowerCase()='" + identity.fullName.toLowerCase() + "' email.toLowerCase()='" + identity.email.toLowerCase() + "' smtp='" + identity.smtpServerKey + "'\n"); 136 146 var email = this.email?this.email:""; // might be null if no identity is set 137 var idEmail = identit ies[j].email?identities[j].email:""; // might be null if no identity is set147 var idEmail = identity.email?identity.email:""; // might be null if no identity is set 138 148 if ( (email.toLowerCase() == idEmail.toLowerCase()) && 139 this.smtp.equal(new smtpObj(identit ies[j].smtpServerKey)) ) {149 this.smtp.equal(new smtpObj(identity.smtpServerKey)) ) { 140 150 // if fullName matches, than this is a final match 141 if ( this.fullName.toLowerCase() == identit ies[j].fullName.toLowerCase() ) {142 vI.notificationBar.dump("## identityData: isExistingIdentity: " + this.combinedName + " found, id='" + identit ies[j].key + "'\n");143 return identit ies[j].key; // return key and stop searching151 if ( this.fullName.toLowerCase() == identity.fullName.toLowerCase() ) { 152 vI.notificationBar.dump("## identityData: isExistingIdentity: " + this.combinedName + " found, id='" + identity.key + "'\n"); 153 return identity.key; // return key and stop searching 144 154 } 145 155 // if fullNames don't match, remember the key but continue to search for full match 146 else if (!ignoreFullNameMatchKey) ignoreFullNameMatchKey = identit ies[j].key;156 else if (!ignoreFullNameMatchKey) ignoreFullNameMatchKey = identity.key; 147 157 } 148 158 } … … 168 178 169 179 this.comp.equals.id = this.id.equal(compareIdentityData.id); 170 this.comp.equals.extras = this.extras .equal(compareIdentityData.extras);180 this.comp.equals.extras = this.extras?this.extras.equal(compareIdentityData.extras):true; 171 181 172 182 return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals.smtp && this.comp.equals.id && this.comp.equals.extras); 173 183 }, 174 184 175 equals CurrentIdentity : function(getCompareMatrix) {176 var equal = this.equals( document.getElementById("msgIdentity_clone").identityData);185 equalsIdentity : function(compareIdentityData, getCompareMatrix) { 186 var equal = this.equals(compareIdentityData); 177 187 var compareMatrix = null; 178 188 // generate CompareMatrix only if asked and non-equal … … 184 194 const Items = Array("fullName", "email", "smtp", "id"); 185 195 var string = ""; 186 var saveBaseId = (vI.statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true") 187 var saveSMTP = (vI.statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true") 196 var saveBaseId = (!vI.statusmenu && this._pref.getBoolPref("storage_store_base_id") 197 || vI.statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true") 198 var saveSMTP = (!vI.statusmenu && this._pref.getBoolPref("storage_store_SMTP") 199 || vI.statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true") 188 200 for each (let item in Items) { 189 201 var classEqual = (this.comp.equals[item])?"equal":"unequal"; … … 195 207 "</tr>" 196 208 } 197 string += this.extras .getCompareMatrix();209 string += this.extras?this.extras.getCompareMatrix():""; 198 210 return string; 199 211 }, … … 205 217 string += "<tr><td class='col1'>" + this[item+"Label"] + ":</td>" + 206 218 "<td class='col2'>" + this[item+"Html"] + "</td></tr>" 207 string += this.extras .getMatrix();219 string += this.extras?this.extras.getMatrix():""; 208 220 return string; 209 221 } … … 233 245 234 246 addWithoutDuplicates : function(identityData) { 247 if (!identityData) return; 235 248 for (var index = 0; index < this.number; index++) { 236 249 if (this.identityDataCollection[index].email == identityData.email && … … 274 287 function smtpObj(key) { 275 288 this._key = key; 276 this.DEFAULT_TAG = document.getElementById("bundle_messenger").getString("defaultServerTag"); 289 this.DEFAULT_TAG = Components.classes["@mozilla.org/intl/stringbundle;1"] 290 .getService(Components.interfaces.nsIStringBundleService) 291 .createBundle("chrome://messenger/locale/messenger.properties"). 292 GetStringFromName("defaultServerTag"); 277 293 } 278 294 smtpObj.prototype = { -
chrome/content/v_identity/vI_msgIdentityCloneTools.js
r7666cb r9cedc0 24 24 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { 25 25 var msgIdentityCloneTools = { 26 _pref : Components.classes["@mozilla.org/preferences-service;1"] 27 .getService(Components.interfaces.nsIPrefService) 28 .getBranch("extensions.virtualIdentity."), 29 26 30 copySelectedIdentity : function(id_key) { 27 31 vI.notificationBar.dump("## msgIdentityCloneTools: copySelectedIdentity\n"); … … 46 50 vI.notificationBar.dump("## msgIdentityCloneTools: signatureSwitch hide/remove signatures\n"); 47 51 // code to hide the text signature 48 try { if ( vI.main.preferences.getBoolPref("hide_signature") && ss_signature.length == 0) {52 try { if (msgIdentityCloneTools._pref.getBoolPref("hide_signature") && ss_signature.length == 0) { 49 53 vI.notificationBar.dump("## msgIdentityCloneTools: hide text/html signature"); 50 54 ss_main.signatureSwitch() … … 52 56 } } catch(vErr) { vI.notificationBar.dump(" -- missing signatureSwitch extension?\n"); }; 53 57 // code to hide the sMime signature 54 try { if ( vI.main.preferences.getBoolPref("hide_sMime_messageSignature")) {58 try { if (msgIdentityCloneTools._pref.getBoolPref("hide_sMime_messageSignature")) { 55 59 var element = document.getElementById("menu_securitySign1"); 56 60 if (element.getAttribute("checked") == "true") { … … 62 66 } catch(vErr) { }; 63 67 // code to hide the openGPG signature 64 try { if ( vI.main.preferences.getBoolPref("hide_openPGP_messageSignature")) {68 try { if (msgIdentityCloneTools._pref.getBoolPref("hide_openPGP_messageSignature")) { 65 69 var element = document.getElementById("enigmail_signed_send"); 66 70 if (element.getAttribute("checked") == "true") { -
chrome/content/v_identity/vI_prefDialog.js
r7666cb r9cedc0 42 42 var panelIndex = (tabpanel)?tabpanel:document.getElementById('prefTabbox').selectedIndex 43 43 var prefTree = document.getElementById('prefTabbox').selectedPanel.getElementsByAttribute("class", "vIprefTree")[0]; 44 var currentVersion = document.getElementById(" extVersion").getAttribute("value").split(/\./);44 var currentVersion = document.getElementById("virtualIdentityExtension_extVersion").getAttribute("value").split(/\./); 45 45 var extVersion = currentVersion[0] + "." + currentVersion[1]; 46 46 var url = "https://www.absorb.it/virtual-id/wiki/docs/" + extVersion + "/tab" + panelIndex + "/tree" + prefTree.currentIndex; -
chrome/content/v_identity/vI_prefDialog.xul
r7666cb r9cedc0 739 739 </tabbox> 740 740 <browserbox id="vI_remoteBrowserBox" class="vI_remoteBrowserBox" localCss="localDoc.css" flex="1" hidden="true" type="content" /> 741 <label id=" extVersion" value="&vident.version;" hidden="true" />741 <label id="virtualIdentityExtension_extVersion" value="&vident.version;" hidden="true" /> 742 742 </hbox> 743 743 <!-- -
chrome/content/v_identity/vI_rdfDatasource.js
r7666cb r9cedc0 29 29 if (this._rdfFileName) this.init(); 30 30 if (!dontRegisterObserver) this.AccountManagerObserver.register(); 31 let window = Components.classes['@mozilla.org/appshell/window-mediator;1'] 32 .getService(Components.interfaces.nsIWindowMediator) 33 .getMostRecentWindow("mail:3pane"); 34 this._extVersion = window.virtualIdentityExtension.extensionVersion; 31 35 } 32 36 33 37 rdfDatasource.prototype = { 38 _extVersion : null, 34 39 _rdfVersion : "0.0.5", 35 40 _rdfService : Components.classes["@mozilla.org/rdf/rdf-service;1"] … … 67 72 .createInstance(Components.interfaces.nsIRDFContainer), 68 73 74 _pref : Components.classes["@mozilla.org/preferences-service;1"] 75 .getService(Components.interfaces.nsIPrefService) 76 .getBranch("extensions.virtualIdentity."), 77 69 78 getContainer : function (type) { 70 79 switch (type) { … … 153 162 var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"] 154 163 .getService(Components.interfaces.nsIVersionComparator); 155 // seamonkey doesn't have a extensionmanager, so read version of extension from hidden version-label 156 // var extVersion = this.extensionManager.getItemForID(this._virtualIdentityID).version 157 var extVersion = document.getElementById("extVersion").getAttribute("value"); 158 return (!oldExtVersion || versionChecker.compare(oldExtVersion, extVersion) < 0) 164 return (!oldExtVersion || versionChecker.compare(oldExtVersion, this._extVersion) < 0) 159 165 }, 160 166 // ************** RDF UPGRADE CODE **************************************************** … … 315 321 316 322 storeExtVersion: function() { 317 // seamonkey doesn't have a extensionmanager, so read version of extension from hidden version-label318 // var extVersion = this.extensionManager.getItemForID(this._virtualIdentityID).version319 var extVersion = document.getElementById("extVersion").getAttribute("value");320 323 this._setRDFValue( 321 this._rdfService.GetResource(this._rdfNS + "virtualIdentity"), "version", extVersion)324 this._rdfService.GetResource(this._rdfNS + "virtualIdentity"), "version", this._extVersion) 322 325 this._flush(); 323 326 }, … … 584 587 this._unsetRDFValue(resource, "name", this._getRDFValue(resource, "name")) 585 588 586 var extras = new vI.storageExtras(this, resource);587 extras.loopForRDF(this, resource, "unset");589 var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this, resource):null; 590 if (extras) extras.loopForRDF(this, resource, "unset"); 588 591 this.getContainer(recType).RemoveElement(resource, true); 589 592 }, … … 614 617 var smtp = this._getRDFValue(resource, "smtp") 615 618 if (!smtp) smtp = vI.NO_SMTP_TAG; 616 var extras = new vI.storageExtras(this, resource);619 var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this, resource):null; 617 620 618 621 var localIdentityData = new vI.identityData(email, fullName, id, smtp, extras) … … 621 624 }, 622 625 623 findMatchingFilter : function (recDescription) { 626 __getDescriptionAndType : function (recipient, recipientType) { 627 if (recipientType == "addr_newsgroups") return { recDesc : recipient, recType : "newsgroup" } 628 else if (this.__isMailingList(recipient)) { 629 vI.notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is MailList\n"); 630 return { recDesc : this.__getMailListName(recipient), recType : "maillist" } 631 } 632 else { 633 vI.notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is no MailList\n"); 634 var localIdentityData = new vI.identityData(recipient, null, null, null, null, null, null); 635 return { recDesc : localIdentityData.combinedName, recType : "email" } 636 } 637 }, 638 639 // -------------------------------------------------------------------- 640 // check if recipient is a mailing list. 641 // Similiar to Thunderbird, if there are muliple cards with the same displayName the mailinglist is preferred 642 // see also https://bugzilla.mozilla.org/show_bug.cgi?id=408575 643 __isMailingList: function(recipient) { 644 let abManager = Components.classes["@mozilla.org/abmanager;1"] 645 .getService(Components.interfaces.nsIAbManager); 646 let allAddressBooks = abManager.directories; 647 while (allAddressBooks.hasMoreElements()) { 648 let ab = allAddressBooks.getNext(); 649 if (ab instanceof Components.interfaces.nsIAbDirectory && !ab.isRemote) { 650 let abdirectory = abManager.getDirectory(ab.URI + 651 "?(and(DisplayName,=," + encodeURIComponent(this.__getMailListName(recipient)) + ")(IsMailList,=,TRUE))"); 652 if (abdirectory) { 653 try { // just try, sometimes there are no childCards at all... 654 let cards = abdirectory.childCards; 655 if (cards.hasMoreElements()) return true; // only interested if there is at least one element... 656 } catch(e) { } 657 } 658 } 659 } 660 return false; 661 }, 662 663 // -------------------------------------------------------------------- 664 665 __getMailListName : function(recipient) { 666 if (recipient.match(/<[^>]*>/) || recipient.match(/$/)) { 667 var mailListName = RegExp.leftContext + RegExp.rightContext 668 mailListName = mailListName.replace(/^\s+|\s+$/g,"") 669 } 670 return mailListName; 671 }, 672 673 findMatchingFilter : function (recipient, recipientType) { 674 var recDescription = this.__getDescriptionAndType(recipient, recipientType).recDesc; 624 675 if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: findMatchingFilter for " + recDescription + ".\n"); 625 676 var enumerator = this._filterContainer.GetElements(); … … 660 711 }, 661 712 662 readVIdentityFromRDF : function (recDescription, recType) { 713 readVIdentityFromRDF : function (recipient, recipientType) { 714 var storedRecipient = this.__getDescriptionAndType(recipient, recipientType); 663 715 var email = this._rdfService.GetResource(this._rdfNS + "rdf#email"); 664 var resource = this._getRDFResourceForVIdentity( recDescription,recType);716 var resource = this._getRDFResourceForVIdentity(storedRecipient.recDesc, storedRecipient.recType); 665 717 if (!resource) return null; 666 718 if (!this._rdfDataSource.hasArcOut(resource, email)) { … … 684 736 "' fullName='" + fullName + "' id='" + id + "' smtp='" + smtp + "'\n"); 685 737 686 var extras = new vI.storageExtras(this, resource); 687 if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: extras:" + extras.status() + "\n"); 738 var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this, resource):null; 739 var extras_status = (typeof(vI.storageExtras)=='function')?extras.status():" not used"; 740 if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: extras:" + extras_status + "\n"); 688 741 689 742 var localIdentityData = new vI.identityData(email, fullName, id, smtp, extras) … … 699 752 }, 700 753 701 updateRDFFromVIdentity : function(recDescription, recType) { 702 this.updateRDF(recDescription, recType, 703 document.getElementById("msgIdentity_clone").identityData, 704 (vI.statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true"), 705 (vI.statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true"), 754 updateRDFFromVIdentity : function(identityData, recipientName, recipientType) { 755 var recipient = this.__getDescriptionAndType(recipientName, recipientType) 756 this.updateRDF(recipient.recDesc, recipient.recType, identityData, 757 (!vI.statusmenu && this._pref.getBoolPref("storage_store_base_id") 758 || vI.statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true"), 759 (!vI.statusmenu && this._pref.getBoolPref("storage_store_SMTP") 760 || vI.statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true"), 706 761 null, null); 707 762 }, … … 745 800 this._setRDFValue(resource, "name", recDescription); 746 801 747 localIdentityData.extras.loopForRDF(this, resource, "set");802 if (localIdentityData.extras) localIdentityData.extras.loopForRDF(this, resource, "set"); 748 803 749 804 if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: updateRDF add " + resource.ValueUTF8 + " at position " + position + ".\n"); … … 765 820 return value; 766 821 }, 767 768 822 823 // code adapted from http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html 769 824 AccountManagerObserver : { 770 825 _uninstall : false, … … 795 850 } 796 851 852 853 function rdfDatasourceAccess() { 854 this._rdfDataSource = new rdfDatasource("virtualIdentity.rdf", false); 855 this.stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties"); 856 } 857 858 rdfDatasourceAccess.prototype = { 859 _rdfDataSource : null, 860 stringBundle : null, 861 862 _pref : Components.classes["@mozilla.org/preferences-service;1"] 863 .getService(Components.interfaces.nsIPrefService) 864 .getBranch("extensions.virtualIdentity."), 865 866 clean : function() { 867 this._rdfDataSource.clean(); 868 }, 869 870 updateVIdentityFromStorage : function(recipientName, recipientType, currentIdentity, currentIdentityIsVid, isNotFirstInputElement) { 871 var localIdentities = new vI.identityCollection(); 872 localIdentities.addWithoutDuplicates(this._rdfDataSource.readVIdentityFromRDF(recipientName, recipientType)); 873 if (localIdentities.number == 1) vI.notificationBar.dump("## rdfDatasourceAccess: using data from direct match\n"); 874 localIdentities.addWithoutDuplicates(this._rdfDataSource.findMatchingFilter(recipientName, recipientType)); 875 876 var returnValue = {}; returnValue.identityCollection = localIdentities; 877 if (localIdentities.number == 0) { 878 vI.notificationBar.dump("## rdfDatasourceAccess: updateVIdentityFromStorage no usable Storage-Data found.\n"); 879 } 880 else { 881 vI.notificationBar.dump("## rdfDatasourceAccess: compare with current Identity\n"); 882 if (this._pref.getBoolPref("storage_getOneOnly") && // if requested to retrieve only storageID for first recipient entered 883 isNotFirstInputElement && // and it is now not the first recipient entered 884 !localIdentities.identityDataCollection[0].equalsIdentity(currentIdentity, false).equal) { // and this id is different than the current used one 885 vI.notificationBar.setNote( 886 this.stringBundle.GetStringFromName("vident.smartIdentity.vIStorageCollidingIdentity"), // than drop the potential changes 887 "storage_notification"); 888 returnValue.result = "drop"; 889 } 890 // only update fields if new Identity is different than old one. 891 else { 892 vI.notificationBar.dump("## rdfDatasourceAccess: updateVIdentityFromStorage check if storage-data matches current Identity.\n"); 893 var compResult = localIdentities.identityDataCollection[0].equalsIdentity(currentIdentity, true); 894 if (!compResult.equal) { 895 var warning = this.__getWarning("replaceVIdentity", recipientName, compResult.compareMatrix); 896 if ( !currentIdentityIsVid || 897 !this._pref.getBoolPref("storage_warn_vI_replace") || 898 (this.__askWarning(warning) == "accept")) { 899 returnValue.result = "accept"; 900 } 901 } 902 else { 903 returnValue.result = "equal"; 904 } 905 } 906 } 907 return returnValue; 908 }, 909 910 storeVIdentityToAllRecipients : function(identityData, recipients) { 911 var multipleRecipients = (recipients.length > 1); 912 var dontUpdateMultipleNoEqual = (this._pref.getBoolPref("storage_dont_update_multiple") && multipleRecipients) 913 vI.notificationBar.dump("## rdfDatasource: storeVIdentityToAllRecipients dontUpdateMultipleNoEqual='" + dontUpdateMultipleNoEqual + "'\n") 914 915 for (var j = 0; j < recipients.length; j++) { 916 var returnValue = this.__updateStorageFromVIdentity(identityData, recipients[j].recipient, recipients[j].recipientType, dontUpdateMultipleNoEqual); 917 if (returnValue.update != "accept") break; 918 } 919 return returnValue; 920 }, 921 922 getVIdentityFromAllRecipients : function(allIdentities, recipients) { 923 var initnumber = allIdentities.number; 924 for (var j = 0; j < recipients.length; j++) { 925 allIdentities.addWithoutDuplicates(this._rdfDataSource.readVIdentityFromRDF(recipients[j].recipient, recipients[j].recipientType)); 926 allIdentities.addWithoutDuplicates(this._rdfDataSource.findMatchingFilter(recipients[j].recipient, recipients[j].recipientType)); 927 } 928 vI.notificationBar.dump("## storage: found " + (allIdentities.number-initnumber) + " address(es)\n") 929 }, 930 931 __updateStorageFromVIdentity : function(identityData, recipient, recipientType, dontUpdateMultipleNoEqual) { 932 vI.notificationBar.dump("## rdfDatasource: __updateStorageFromVIdentity.\n") 933 var storageDataByType = this._rdfDataSource.readVIdentityFromRDF(recipient, recipientType); 934 var storageDataByFilter = this._rdfDataSource.findMatchingFilter(recipient, recipientType); 935 936 // update (storing) of data by type is required if there is 937 // no data stored by type (or different data stored) and no equal filter found 938 var storageDataByTypeCompResult = storageDataByType?storageDataByType.equalsIdentity(identityData, true):null; 939 var storageDataByTypeEqual = (storageDataByType && storageDataByTypeCompResult.equal); 940 var storageDataByFilterEqual = (storageDataByFilter && storageDataByFilter.equalsIdentity(identityData, false).equal); 941 942 var doUpdate = "accept"; 943 if ( (!storageDataByType && !storageDataByFilterEqual) || 944 (!storageDataByTypeEqual && !storageDataByFilterEqual && !dontUpdateMultipleNoEqual) ) { 945 vI.notificationBar.dump("## storage: __updateStorageFromVIdentity updating\n") 946 if (storageDataByType && !storageDataByTypeEqual && this._pref.getBoolPref("storage_warn_update")) { 947 vI.notificationBar.dump("## storage: __updateStorageFromVIdentity overwrite warning\n"); 948 doUpdate = this.__askWarning(this.__getWarning("updateStorage", recipient, storageDataByTypeCompResult.compareMatrix)); 949 } 950 } 951 if (doUpdate == "accept") this._rdfDataSource.updateRDFFromVIdentity(identityData, recipient, recipientType); 952 return { update : doUpdate, storedIdentity : storageDataByType }; 953 }, 954 955 __getWarning : function(warningCase, recipient, compareMatrix) { 956 var warning = { title: null, recLabel : null, recipient : null, warning : null, css: null, query : null, class : null }; 957 warning.title = this.stringBundle.GetStringFromName("vident." + warningCase + ".title") 958 warning.recLabel = this.stringBundle.GetStringFromName("vident." + warningCase + ".recipient") + ":"; 959 warning.recipient = recipient; 960 warning.warning = 961 "<table class='" + warningCase + "'><thead><tr><th class='col1'/>" + 962 "<th class='col2'>" + this.stringBundle.GetStringFromName("vident." + warningCase + ".currentIdentity") + "</th>" + 963 "<th class='col3'>" + this.stringBundle.GetStringFromName("vident." + warningCase + ".storedIdentity") + "</th>" + 964 "</tr></thead>" + 965 "<tbody>" + compareMatrix + "</tbody>" + 966 "</table>" 967 warning.css = "vI.DialogBrowser.css"; 968 warning.query = this.stringBundle.GetStringFromName("vident." + warningCase + ".query"); 969 warning.class = warningCase; 970 return warning; 971 }, 972 973 __askWarning : function(warning) { 974 var retVar = { returnValue: null }; 975 var answer = window.openDialog("chrome://v_identity/content/vI_Dialog.xul","", 976 "chrome, dialog, modal, alwaysRaised, resizable=yes", 977 warning, retVar) 978 dump("retVar.returnValue=" + retVar.returnValue + "\n") 979 return retVar.returnValue; 980 }, 981 } 982 983 797 984 // create with name of the file to import into 798 985 function rdfDatasourceImporter(rdfFileName) { … … 949 1136 var smtp = this._rdfImportDataSource._getRDFValue(resource, "smtp") 950 1137 smtp = (smtp && smtp != vI.DEFAULT_SMTP_TAG)?relevantSMTPs[smtp].smtp:smtp 951 var extras = new vI.storageExtras(this._rdfImportDataSource, resource);1138 var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this._rdfImportDataSource, resource):null; 952 1139 var localIdentityData = new vI.identityData(email, fullName, id, smtp, extras) 953 1140 … … 980 1167 } 981 1168 vI.rdfDatasource = rdfDatasource; 1169 vI.rdfDatasourceAccess = rdfDatasourceAccess; 982 1170 vI.rdfDatasourceImporter = rdfDatasourceImporter; 983 1171 }}); -
chrome/content/v_identity/vI_smartIdentity.js
r7666cb r9cedc0 24 24 25 25 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { 26 var smartIdentity = { 26 27 28 function smartIdentityCollection(msgHdr, preseletedID, currentIDisVID, newsgroup, recipients) { 29 this._IDisVID = currentIDisVID; 30 this._preselectedID = preseletedID; 31 this._msgHdr = msgHdr; 32 this._newsgroup = newsgroup; 33 this._unicodeConverter.charset = "UTF-8"; 34 this._recipients = recipients; 35 this._rdfDatasourceAccess = new vI.rdfDatasourceAccess(); 36 this._allIdentities = new vI.identityCollection(); 37 }; 38 39 smartIdentityCollection.prototype = { 27 40 messenger : Components.classes["@mozilla.org/messenger;1"].createInstance() 28 41 .QueryInterface(Components.interfaces.nsIMessenger), 29 30 smartIdentity_BaseIdentity : null, 31 32 clean : function() { 33 smartIdentity.smartIdentity_BaseIdentity = null; 34 }, 35 36 // After Loading the MessageComposeDialog, check if smartIdentity is needed 37 init : function() { 38 var type = gMsgCompose.type; 39 var msgComposeType = Components.interfaces.nsIMsgCompType; 40 vI.notificationBar.dump("## smartIdentity: msgComposeType = " + type + "\n"); 41 42 switch (type) { 43 case msgComposeType.ForwardAsAttachment: 44 case msgComposeType.ForwardInline: 45 case msgComposeType.Reply: 46 case msgComposeType.ReplyAll: 47 case msgComposeType.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later 48 case msgComposeType.ReplyToSender: 49 case msgComposeType.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later 50 case msgComposeType.ReplyWithTemplate: 51 case msgComposeType.ReplyToList: 52 smartIdentity.Reply(); break; 53 case msgComposeType.Draft: 54 case msgComposeType.Template: 55 smartIdentity.Draft(); break; 56 case msgComposeType.New: 57 case msgComposeType.NewsPost: 58 case msgComposeType.MailToUrl: 59 smartIdentity.NewMail(); break; 60 } 61 }, 62 42 _pref : Components.classes["@mozilla.org/preferences-service;1"] 43 .getService(Components.interfaces.nsIPrefService) 44 .getBranch("extensions.virtualIdentity."), 45 _unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] 46 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter), 47 _headerParser : Components.classes["@mozilla.org/messenger/headerparser;1"] 48 .getService(Components.interfaces.nsIMsgHeaderParser), 49 50 _msgComposeTypeReference : Components.interfaces.nsIMsgCompType, 51 52 _IDisVID : false, 53 _preselectedID : null, 54 _allIdentities : null, 55 _selectedValue : null, 56 _newsgroup : null, 57 _rdfDatasourceAccess : null, 58 63 59 // this function adds a timestamp to the current sender 64 60 __autoTimestamp : function() { 65 vI.notificationBar.dump("## smartIdentity: __autoTimestamp()\n");66 if ( document.getElementById("msgIdentity_clone").vid) {67 vI.notificationBar.dump("## smartIdentity: Virtual Identity in use, aborting\n");61 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: __autoTimestamp()\n"); 62 if (this._IDisVID) { 63 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: Virtual Identity in use, aborting\n"); 68 64 return; 69 65 } 70 66 71 var current_email = getCurrentIdentity().email.split("@");67 var current_email = this._preselectedID.email.split("@"); 72 68 var localpart = current_email[0]; 73 69 var domain = current_email[1]; 74 70 75 vI.notificationBar.dump("## smartIdentity: current email: " + current_email[0] + "@" + current_email[1] + "\n");76 77 var autoString = vI.main.preferences.getCharPref("autoString");78 var formatString = vI.main.preferences.getCharPref("autoTimeFormat");71 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: current email: " + current_email[0] + "@" + current_email[1] + "\n"); 72 73 var autoString = this._pref.getCharPref("autoString"); 74 var formatString = this._pref.getCharPref("autoTimeFormat"); 79 75 80 76 var dateObj = new Date(); var dateString = ""; … … 85 81 86 82 var new_email = autoString.replace(/%l/g, localpart).replace(/%d/g, domain).replace(/%t/g,dateString); 87 vI.notificationBar.dump("## smartIdentity: new email: " + new_email + "\n"); 88 89 vI.notificationBar.setNote(vI.main.elements.strings.getString("vident.smartIdentity.vIUsage") + ".", 90 "smart_reply_notification"); 91 92 document.getElementById("msgIdentity_clone").email = new_email; 83 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: new email: " + new_email + "\n"); 84 85 var newIdentity = new vI.identityData(new_email, 86 this._preselectedID.fullName, this._preselectedID.key, this._preselectedID.smtpServerKey, null, null) 87 88 this._allIdentities.addWithoutDuplicates(newIdentity); 89 this._selectedValue = 0; 93 90 }, 94 91 95 92 __ignoreID : function() { 96 vI.notificationBar.dump("## smartIdentity: checking " + vI.main.preferences.getCharPref("idSelection_ignoreIDs") + " against " + vI.main.elements.Obj_MsgIdentity.value+ "\n")93 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: checking " + this._pref.getCharPref("idSelection_ignoreIDs") + " against " + this._preselectedID.key + "\n") 97 94 // check if usage if virtual Identities should be used at all for the currently selected ID 98 if ( vI.main.preferences.getCharPref("idSelection_ignoreIDs").indexOf(":" + vI.main.elements.Obj_MsgIdentity.value+ ":") != -1) {99 vI.notificationBar.dump("## smartIdentity: not using virtual Identites for ID " + vI.main.elements.Obj_MsgIdentity.value+ "\n");95 if (this._pref.getCharPref("idSelection_ignoreIDs").indexOf(":" + this._preselectedID.key + ":") != -1) { 96 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: not using virtual Identites for ID " + this._preselectedID.key + "\n"); 100 97 return true; 101 98 } … … 104 101 105 102 NewMail : function() { 106 if (smartIdentity.__ignoreID()) return; 107 108 var storageIdentities = new vI.identityCollection(); 109 vI.storage.getVIdentityFromAllRecipients(storageIdentities); 110 111 if (storageIdentities.number > 0) smartIdentity.__smartIdentitySelection(storageIdentities, false) 112 else if (vI.main.preferences.getBoolPref("autoTimestamp")) smartIdentity.__autoTimestamp(); 113 }, 114 115 ReplyOnSent : function(hdr) { 116 vI.notificationBar.dump("## smartIdentity: ReplyOnSent() (rules like SmartDraft)\n"); 117 118 var allIdentities = new vI.identityCollection(); 119 120 smartIdentity.__SmartDraftOrReplyOnSent(hdr, allIdentities); 121 var storageIdentities = new vI.identityCollection(); 122 vI.storage.getVIdentityFromAllRecipients(storageIdentities); 123 124 allIdentities.mergeWithoutDuplicates(storageIdentities); 125 126 if (allIdentities.number > 0) smartIdentity.__smartIdentitySelection(allIdentities, true); 127 103 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: NewMail()\n"); 104 if (this.__ignoreID()) return; 105 this._rdfDatasourceAccess.getVIdentityFromAllRecipients(this._allIdentities, this._recipients); 106 if (this._allIdentities.number == 0 && this._pref.getBoolPref("autoTimestamp")) this.__autoTimestamp(); 107 }, 108 109 _foundExistingIdentity : function() { 110 /* compare with existing Identities */ 111 for (var index = 0; index < this._allIdentities.number; index++) { 112 var existingID = this._allIdentities.identityDataCollection[index].isExistingIdentity(false); 113 if (existingID) { 114 this._allIdentities.identityDataCollection[index].id.key = existingID; // set found identity 115 // reorder list of Identities to prefer it on autoselect 116 // has to be done before Identities are added to the Menu 117 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: found existing Identity, reorder to prefer this one.\n"); 118 var firstIdentity = this._allIdentities.identityDataCollection[index]; 119 for (var i = index; index > 0; index--) { 120 this._allIdentities.identityDataCollection[index] = this._allIdentities.identityDataCollection[index-1]; 121 } 122 this._allIdentities.identityDataCollection[0] = firstIdentity; 123 return { key: index }; 124 } 125 } 126 return null; 127 }, 128 129 ReplyOnSent : function() { 130 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: ReplyOnSent() (rules like SmartDraft)\n"); 131 this.__SmartDraftOrReplyOnSent(); 132 this._rdfDatasourceAccess.getVIdentityFromAllRecipients(this._allIdentities, this._recipients); 128 133 }, 129 134 130 135 Draft : function() { 131 vI.notificationBar.dump("## smartIdentity: Draft()\n"); 132 133 var allIdentities = new vI.identityCollection(); 134 135 var draftHdr = smartIdentity.messenger. 136 messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI); 137 // fails with seamonkey 1.1.11, so just try to read to draft id 138 try { draftHdr = smartIdentity.messenger. 139 messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId); 140 } catch (ex) { }; 141 142 smartIdentity.__SmartDraftOrReplyOnSent(draftHdr, allIdentities); 143 var storageIdentities = new vI.identityCollection(); 144 vI.storage.getVIdentityFromAllRecipients(storageIdentities); 145 146 allIdentities.mergeWithoutDuplicates(storageIdentities); 147 148 if (allIdentities.number > 0) smartIdentity.__smartIdentitySelection(allIdentities, true); 149 }, 150 151 __parseHeadersWithArray: function(hdr, allIdentities) { 136 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: Draft()\n"); 137 138 this.__SmartDraftOrReplyOnSent(); 139 this._rdfDatasourceAccess.getVIdentityFromAllRecipients(this._allIdentities, this._recipients); 140 }, 141 142 __parseHeadersWithArray: function(header, identityCollection) { 152 143 var emails = {}; var fullNames = {}; var combinedNames = {}; 153 var number = vI.main.headerParser.parseHeadersWithArray(hdr, emails, fullNames, combinedNames);144 var number = this._headerParser.parseHeadersWithArray(header, emails, fullNames, combinedNames); 154 145 for (var index = 0; index < number; index++) { 155 146 var newIdentity = new vI.identityData(emails.value[index], fullNames.value[index], 156 147 null, vI.NO_SMTP_TAG, null, null); 157 allIdentities.addWithoutDuplicates(newIdentity);148 identityCollection.addWithoutDuplicates(newIdentity); 158 149 } 159 150 }, 160 151 161 152 // this function checks if we have a draft-case and Smart-Draft should replace the Identity 162 __SmartDraftOrReplyOnSent : function( hdr, allIdentities) {163 if (! vI.main.preferences.getBoolPref("smart_draft"))164 { vI.notificationBar.dump("## smartIdentity: SmartDraft deactivated\n"); return; }165 166 vI.notificationBar.dump("## smartIdentity: __SmartDraftOrReplyOnSent()\n");167 168 if ( hdr) {169 smartIdentity.__parseHeadersWithArray(hdr.author,allIdentities)170 vI.notificationBar.dump("## smartIdentity: sender '" +allIdentities.identityDataCollection[0].combinedName + "'\n");171 } 172 else vI.notificationBar.dump("## smartIdentity: __SmartDraftOrReplyOnSent: No Header found, shouldn't happen\n");173 }, 174 175 __filterAddresses : function( smartIdentities) {153 __SmartDraftOrReplyOnSent : function() { 154 if (!this._pref.getBoolPref("smart_draft")) 155 { if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: SmartDraft deactivated\n"); return; } 156 157 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: __SmartDraftOrReplyOnSent()\n"); 158 159 if (this._msgHdr) { 160 this.__parseHeadersWithArray(this._msgHdr.author, this._allIdentities) 161 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: sender '" + this._allIdentities.identityDataCollection[0].combinedName + "'\n"); 162 } 163 else if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: __SmartDraftOrReplyOnSent: No Header found, shouldn't happen\n"); 164 }, 165 166 __filterAddresses : function() { 176 167 var returnIdentities = new vI.identityCollection(); 177 168 178 169 var filterList = 179 vI.main.unicodeConverter.ConvertToUnicode(vI.main.preferences.getCharPref("smart_reply_filter")).split(/\n/)170 this._unicodeConverter.ConvertToUnicode(this._pref.getCharPref("smart_reply_filter")).split(/\n/) 180 171 if (filterList.length == 0) filterList[0] == "" 181 172 … … 184 175 var recentfilterType; var skipRegExp = false; 185 176 if (filterList.length <= 1 && filterList[0] == "") 186 { vI.notificationBar.dump("## smartIdentity: no filters configured\n"); recentfilterType = filterType.None; }177 { if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: no filters configured\n"); recentfilterType = filterType.None; } 187 178 else if (/^[+-]?\/(.*)\/$/.exec(filterList[i])) 188 { vI.notificationBar.dump("## smartIdentity: filter emails with RegExp '"179 { if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: filter emails with RegExp '" 189 180 + filterList[i].replace(/\\/g,"\\\\") + "'\n"); recentfilterType = filterType.RegExp; } 190 else { vI.notificationBar.dump("## smartIdentity: filter emails, compare with '"181 else { if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: filter emails, compare with '" 191 182 + filterList[i] + "'\n"); recentfilterType = filterType.StrCmp; } 192 for (var j = 0; j < smartIdentities.number; j++) { // check if recent email-address (pre-choosen identity) is found in183 for (var j = 0; j < this._allIdentities.number; j++) { // check if recent email-address (pre-choosen identity) is found in 193 184 // copied and adapted from correctIdentity, thank you for the RegExp-idea! 194 185 var add_addr = false; … … 200 191 try { /^[+-]?\/(.*)\/$/.exec(filterList[i]); 201 192 if ( filterList[i][0] == "-" ) { 202 if ( smartIdentities.identityDataCollection[j].email.match(new RegExp(RegExp.$1,"i")))203 smartIdentities.dropIdentity(j--);193 if (this._allIdentities.identityDataCollection[j].email.match(new RegExp(RegExp.$1,"i"))) 194 this._allIdentities.dropIdentity(j--); 204 195 } else 205 add_addr = ( smartIdentities.identityDataCollection[j].email.match(new RegExp(RegExp.$1,"i")));196 add_addr = (this._allIdentities.identityDataCollection[j].email.match(new RegExp(RegExp.$1,"i"))); 206 197 } 207 198 catch(vErr) { 208 vI.notificationBar.addNote(199 if (vI.notificationBar) vI.notificationBar.addNote( 209 200 vI.main.elements.strings.getString("vident.smartIdentity.ignoreRegExp") + 210 201 +filterList[i].replace(/\\/g,"\\\\") + " .", … … 213 204 break; 214 205 case filterType.StrCmp: 215 add_addr = ( smartIdentities.identityDataCollection[j].email.toLowerCase().indexOf(filterList[i].toLowerCase()) != -1)206 add_addr = ( this._allIdentities.identityDataCollection[j].email.toLowerCase().indexOf(filterList[i].toLowerCase()) != -1) 216 207 break; 217 208 } 218 if (add_addr) returnIdentities.addWithoutDuplicates( smartIdentities.identityDataCollection[j])219 } 220 } 221 smartIdentities.takeOver(returnIdentities);222 }, 223 224 __smartReplyCollectAddresses : function( hdr, allIdentities) {209 if (add_addr) returnIdentities.addWithoutDuplicates(this._allIdentities.identityDataCollection[j]) 210 } 211 } 212 this._allIdentities.takeOver(returnIdentities); 213 }, 214 215 __smartReplyCollectAddresses : function() { 225 216 // add emails from selected headers (stored by vI_getHeader.xul/js) 226 var reply_headers = vI.main.unicodeConverter.ConvertToUnicode(vI.main.preferences.getCharPref("smart_reply_headers")).split(/\n/)217 var reply_headers = this._unicodeConverter.ConvertToUnicode(this._pref.getCharPref("smart_reply_headers")).split(/\n/) 227 218 228 219 for (var index = 0; index < reply_headers.length; index++) { … … 243 234 244 235 // if mailing-list ignore to-header (usually the mailing list address) 245 if (replyHeaderNameToRead == "to" && hdr.getStringProperty("vI_list-id")) {246 vI.notificationBar.dump("## smartIdentity: header 'list-id' found (mailinglist), skipping header 'to'\n");236 if (replyHeaderNameToRead == "to" && this._msgHdr.getStringProperty("vI_list-id")) { 237 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: header 'list-id' found (mailinglist), skipping header 'to'\n"); 247 238 continue; 248 239 } 249 240 250 241 // ------------- read the stored header ------------------------------- 251 var value = vI.main.unicodeConverter.ConvertToUnicode(hdr.getStringProperty("vI_" + replyHeaderNameToRead)) 252 vI.notificationBar.dump("## smartIdentity: reading header '" + 242 var value = this._unicodeConverter.ConvertToUnicode(this._msgHdr.getStringProperty("vI_" + replyHeaderNameToRead)) 243 /* let window3pane = Components.classes['@mozilla.org/appshell/window-mediator;1'] 244 .getService(Components.interfaces.nsIWindowMediator) 245 .getMostRecentWindow("mail:3pane"); 246 247 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: found stored header '" + 248 replyHeaderNameToRead + "': '" + window3pane.virtualIdentityExtension.storedHeaders["vI_" + replyHeaderNameToRead] + "'\n");*/ 249 250 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: reading header '" + 253 251 replyHeaderNameToRead + "': '" + value + "'\n"); 254 252 255 253 // ------------- parse address-string to get a field of single email-addresses 256 254 var splitted = new vI.identityCollection(); 257 smartIdentity.__parseHeadersWithArray(value, splitted);258 259 // move found addresses step by step to allIdentities, and change values if requested255 this.__parseHeadersWithArray(value, splitted); 256 257 // move found addresses step by step to this._allIdentities, and change values if requested 260 258 for (var i = 0; i < splitted.number; i++) { 261 259 // if there is no email than it makes no sense to use it as a sender 262 260 if (!splitted.identityDataCollection[i].email.match(/^.*@.*$/)) { 263 vI.notificationBar.dump("## smartIdentity: skipping '" +261 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: skipping '" + 264 262 splitted.identityDataCollection[i].email + "', no email\n") 265 263 continue; … … 268 266 if (replyHeaderEmptyFullNames) splitted.identityDataCollection[i].fullName = "" 269 267 270 allIdentities.addWithoutDuplicates(splitted.identityDataCollection[i]);271 272 vI.notificationBar.dump("## smartIdentity: found '" +268 this._allIdentities.addWithoutDuplicates(splitted.identityDataCollection[i]); 269 270 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: found '" + 273 271 splitted.identityDataCollection[i].combinedName + "'\n") 274 272 } … … 277 275 278 276 Reply : function() { 279 var hdr = smartIdentity.messenger. 280 messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI); 281 282 vI.notificationBar.dump("## smartIdentity: Reply()\n"); 283 284 if (hdr && !gMsgCompose.compFields.newsgroups && !hdr.getStringProperty("vI_content_base")) { 277 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: Reply()\n"); 278 279 if (this._msgHdr && this._newsgroup && !this._msgHdr.getStringProperty("vI_content_base")) { 285 280 // RFC 2821 (http://www.ietf.org/rfc/rfc2821.txt) says: 286 281 // "4.4 Trace Information … … 292 287 // hidden option smart_detectByReceivedHeader will act as a switch for not RFC-compliant servers 293 288 // RFC-compliant 294 if ( vI.main.preferences.getBoolPref("smart_detectByReceivedHeader")) {295 if (! hdr.getStringProperty("vI_received")) { // mail was not received296 vI.notificationBar.dump("## smartIdentity: reply on non-received (sent?) mail. Using SmartDraft. \n");297 smartIdentity.ReplyOnSent(hdr);289 if (this._pref.getBoolPref("smart_detectByReceivedHeader")) { 290 if (!this._msgHdr.getStringProperty("vI_received")) { // mail was not received 291 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: reply on non-received (sent?) mail. Using SmartDraft. \n"); 292 this.ReplyOnSent(); 298 293 return; 299 294 } … … 304 299 const MSG_FOLDER_FLAG_SENTMAIL = 0x0200; 305 300 306 if ( hdr && (hdr.folder.flags & MSG_FOLDER_FLAG_SENTMAIL)) {307 vI.notificationBar.dump("## smartIdentity: reply from Sent folder.");308 if ( hdr.folder.flags & MSG_FOLDER_FLAG_INBOX)309 vI.notificationBar.dump(" Folder is INBOX, assuming Reply-Case. \n");301 if (this._msgHdr && (this._msgHdr.folder.flags & MSG_FOLDER_FLAG_SENTMAIL)) { 302 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: reply from Sent folder."); 303 if (this._msgHdr.folder.flags & MSG_FOLDER_FLAG_INBOX) 304 if (vI.notificationBar) vI.notificationBar.dump(" Folder is INBOX, assuming Reply-Case. \n"); 310 305 else { 311 vI.notificationBar.dump(" Using SmartDraft. \n");312 smartIdentity.ReplyOnSent(hdr);306 if (vI.notificationBar) vI.notificationBar.dump(" Using SmartDraft. \n"); 307 this.ReplyOnSent(); 313 308 return; 314 309 } … … 317 312 } 318 313 319 if ( smartIdentity.__ignoreID()) return;314 if (this.__ignoreID()) return; 320 315 321 316 var storageIdentities = new vI.identityCollection(); 322 vI.storage.getVIdentityFromAllRecipients(storageIdentities); 323 324 var smartIdentities = new vI.identityCollection(); 325 if (storageIdentities.number == 0 || !vI.main.preferences.getBoolPref("idSelection_storage_ignore_smart_reply")) 326 smartIdentity.__SmartReply(hdr, smartIdentities); 327 else vI.notificationBar.dump("## smartIdentity: SmartReply skipped, Identities in Storage found.\n"); 317 this._rdfDatasourceAccess.getVIdentityFromAllRecipients(storageIdentities, this._recipients); 318 319 if (storageIdentities.number == 0 || !this._pref.getBoolPref("idSelection_storage_ignore_smart_reply")) 320 this.__SmartReply(); 321 else if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: SmartReply skipped, Identities in Storage found.\n"); 328 322 329 323 // merge SmartReply-Identities and Storage-Identites 330 if (vI.main.preferences.getBoolPref("idSelection_storage_prefer_smart_reply")) 331 { smartIdentities.mergeWithoutDuplicates(storageIdentities); var allIdentities = smartIdentities; } 332 else 333 { storageIdentities.mergeWithoutDuplicates(smartIdentities); var allIdentities = storageIdentities; } 334 335 vI.notificationBar.dump("## smartIdentity: merged SmartReply & Storage, " + allIdentities.number + " address(es) left\n") 336 337 if (allIdentities.number > 0) smartIdentity.__smartIdentitySelection(allIdentities, false); 324 if (this._pref.getBoolPref("idSelection_storage_prefer_smart_reply")) 325 { this._allIdentities.mergeWithoutDuplicates(storageIdentities); } 326 else { 327 var smartIdentities = this._allIdentities; 328 this._allIdentities = storageIdentities; 329 this._allIdentities.mergeWithoutDuplicates(smartIdentities); 330 } 331 332 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: merged SmartReply & Storage, " + this._allIdentities.number + " address(es) left\n") 338 333 }, 339 334 340 335 // this function checks if we have a reply-case and Smart-Reply should replace the Identity 341 __SmartReply : function( hdr, smartIdentities) {342 if (! vI.main.preferences.getBoolPref("smart_reply"))343 { vI.notificationBar.dump("## smartIdentity: SmartReply deactivated\n"); return; }344 if ( gMsgCompose.compFields.newsgroups && !vI.main.preferences.getBoolPref("smart_reply_for_newsgroups")) {345 vI.notificationBar.dump("## smartIdentity: SmartReply, answering to a newsgroup, aborting\n");336 __SmartReply : function() { 337 if (!this._pref.getBoolPref("smart_reply")) 338 { if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: SmartReply deactivated\n"); return; } 339 if (this._newsgroup && !this._pref.getBoolPref("smart_reply_for_newsgroups")) { 340 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: SmartReply, answering to a newsgroup, aborting\n"); 346 341 return; 347 342 } 348 343 349 vI.notificationBar.dump("## smartIdentity: __SmartReply()\n");350 vI.notificationBar.dump("## smartIdentity: ----------------------------------------------------------\n")351 if ( hdr) {344 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: __SmartReply()\n"); 345 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: ----------------------------------------------------------\n") 346 if (this._msgHdr) { 352 347 /* first step: collect addresses */ 353 smartIdentity.__smartReplyCollectAddresses(hdr, smartIdentities);354 vI.notificationBar.dump("## smartIdentity: " + smartIdentities.number + " address(es) after parsing, before filtering\n")348 this.__smartReplyCollectAddresses(); 349 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: " + this._allIdentities.number + " address(es) after parsing, before filtering\n") 355 350 356 351 /* second step: filter (and sort) addresses */ 357 smartIdentity.__filterAddresses(smartIdentities);358 359 vI.notificationBar.dump("## smartIdentity: filtering done, " + smartIdentities.number + " address(es) left\n")352 this.__filterAddresses(); 353 354 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: filtering done, " + this._allIdentities.number + " address(es) left\n") 360 355 361 356 /* set default FullName */ 362 var smart_reply_defaultFullName = vI.main.unicodeConverter.ConvertToUnicode(vI.main.preferences.getCharPref("smart_reply_defaultFullName"))357 var smart_reply_defaultFullName = this._unicodeConverter.ConvertToUnicode(this._pref.getCharPref("smart_reply_defaultFullName")) 363 358 if (smart_reply_defaultFullName != "") { 364 for (var index = 0; index < smartIdentities.number; index++) {365 if ( smartIdentities.identityDataCollection[index].fullName == "") {366 smartIdentities.identityDataCollection[index].fullName = smart_reply_defaultFullName367 vI.notificationBar.dump("## smartIdentity: added default FullName '" +368 smart_reply_defaultFullName + "' to '" + smartIdentities.identityDataCollection[index].email + "'\n")359 for (var index = 0; index < this._allIdentities.number; index++) { 360 if (this._allIdentities.identityDataCollection[index].fullName == "") { 361 this._allIdentities.identityDataCollection[index].fullName = smart_reply_defaultFullName 362 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: added default FullName '" + 363 smart_reply_defaultFullName + "' to '" + this._allIdentities.identityDataCollection[index].email + "'\n") 369 364 } 370 365 } … … 374 369 /* if match replace FullName with existing one, keep identity in list by now */ 375 370 /* will not be added to the menu but probably choosen with __smartIdentitySelection */ 376 if ( vI.main.preferences.getBoolPref("smart_reply_ignoreFullName")) {377 vI.notificationBar.dump("## smartIdentity: compare with existing Identities (ignoring FullNames).\n")378 379 for (var index = 0; index < smartIdentities.number; index++) {380 var idKey = smartIdentities.identityDataCollection[index].isExistingIdentity(true);371 if (this._pref.getBoolPref("smart_reply_ignoreFullName")) { 372 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: compare with existing Identities (ignoring FullNames).\n") 373 374 for (var index = 0; index < this._allIdentities.number; index++) { 375 var idKey = this._allIdentities.identityDataCollection[index].isExistingIdentity(true); 381 376 if (idKey) { 382 377 var newFullName = gAccountManager.getIdentity(idKey).fullName; 383 smartIdentities.identityDataCollection[index].fullName = newFullName;384 vI.notificationBar.dump("## smartIdentity: replaced Fullname of '" + smartIdentities.identityDataCollection[index].email + "' with '" + newFullName + "' \n");378 this._allIdentities.identityDataCollection[index].fullName = newFullName; 379 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: replaced Fullname of '" + this._allIdentities.identityDataCollection[index].email + "' with '" + newFullName + "' \n"); 385 380 } 386 381 } 387 382 } 388 383 } 389 else vI.notificationBar.dump("## smartIdentity: SmartReply skipped. No Header-information found.\n"); 390 391 vI.notificationBar.dump("## smartIdentity: ----------------------------------------------------------\n") 392 }, 393 394 __smartIdentitySelection : function(allIdentities, autocreate) { 395 /* compare with existing Identities */ 396 for (var index = 0; index < allIdentities.number; index++) { 397 var existingID = allIdentities.identityDataCollection[index].isExistingIdentity(true); 398 if (existingID) { 399 allIdentities.identityDataCollection[index].id.key = existingID; // set found identity 400 // if 'preferExisting' than select it and return 401 if (vI.main.preferences.getBoolPref("idSelection_preferExisting")) { 402 vI.notificationBar.dump("## smartIdentity: found existing Identity, use without interaction.\n"); 403 // add all Indentities to Clone Menu before selecting and leaving the function 404 document.getElementById("msgIdentity_clone").addIdentitiesToCloneMenu(allIdentities); 405 smartIdentity.changeIdentityToSmartIdentity(allIdentities, index); 406 return; 407 } 408 // else reorder list of Identities to prefer it on autoselect 409 // has to be done before Identities are added to the Menu 410 vI.notificationBar.dump("## smartIdentity: found existing Identity, prefer this one.\n"); 411 var firstIdentity = allIdentities.identityDataCollection[index]; 412 for (var i = index; index > 0; index--) { 413 allIdentities.identityDataCollection[index] = allIdentities.identityDataCollection[index-1]; 414 } 415 allIdentities.identityDataCollection[0] = firstIdentity; 416 break; 417 } 418 } 419 420 document.getElementById("msgIdentity_clone").addIdentitiesToCloneMenu(allIdentities); 421 422 if (!autocreate && vI.main.preferences.getBoolPref("idSelection_ask") && 423 ((allIdentities.number == 1 && vI.main.preferences.getBoolPref("idSelection_ask_always")) 424 || allIdentities.number > 1)) { 425 for (var index = 0; index < allIdentities.number; index++) { 426 vI.notificationBar.dump("## smartIdentityReplyDialog index=" + index + ": '" + allIdentities.identityDataCollection[index].combinedName + "' " 427 + "(" + allIdentities.identityDataCollection[index].id.value + "," + allIdentities.identityDataCollection[index].smtp.value + ")\n"); 384 else if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: SmartReply skipped. No Header-information found.\n"); 385 386 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: ----------------------------------------------------------\n") 387 }, 388 389 390 }; 391 392 var smartIdentity = { 393 _pref : Components.classes["@mozilla.org/preferences-service;1"] 394 .getService(Components.interfaces.nsIPrefService) 395 .getBranch("extensions.virtualIdentity."), 396 397 messenger : Components.classes["@mozilla.org/messenger;1"].createInstance() 398 .QueryInterface(Components.interfaces.nsIMessenger), 399 400 _smartIdentityCollection : null, 401 402 // After Loading the MessageComposeDialog, check if smartIdentity is needed 403 init : function() { 404 var msgHdr; 405 var msgComposeTypeReference = Components.interfaces.nsIMsgCompType; 406 var newsgroup = gMsgCompose.compFields.newsgroups; 407 var autocreate = false; 408 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentityCollection: msgComposeTypeReference = " + gMsgCompose.type + "\n"); 409 switch (gMsgCompose.type) { 410 case msgComposeTypeReference.ForwardAsAttachment: 411 case msgComposeTypeReference.ForwardInline: 412 case msgComposeTypeReference.Reply: 413 case msgComposeTypeReference.ReplyAll: 414 case msgComposeTypeReference.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later 415 case msgComposeTypeReference.ReplyToSender: 416 case msgComposeTypeReference.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later 417 case msgComposeTypeReference.ReplyWithTemplate: 418 case msgComposeTypeReference.ReplyToList: 419 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentityCollection: Reply\n"); 420 msgHdr = smartIdentity.messenger. 421 messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI); 422 smartIdentity._smartIdentityCollection = new smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("msgIdentity_clone").vid, newsgroup, this._getRecipients()); 423 smartIdentity._smartIdentityCollection.Reply(); 424 autocreate = false; break; 425 case msgComposeTypeReference.Draft: 426 case msgComposeTypeReference.Template: 427 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentityCollection: Draft\n"); 428 msgHdr = smartIdentity.messenger. 429 messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId); 430 smartIdentity._smartIdentityCollection = new smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("msgIdentity_clone").vid, newsgroup, this._getRecipients()); 431 smartIdentity._smartIdentityCollection.Draft(); 432 autocreate = false; break; 433 case msgComposeTypeReference.New: 434 case msgComposeTypeReference.NewsPost: 435 case msgComposeTypeReference.MailToUrl: 436 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentityCollection: New Mail\n"); 437 smartIdentity._smartIdentityCollection = new smartIdentityCollection(null, getCurrentIdentity(), document.getElementById("msgIdentity_clone").vid, newsgroup, this._getRecipients()); 438 // to enable composing new email with new identity: identity is hidden in subject line 439 // used for instance from conversation addon 440 var subject = gMsgCompose.compFields.subject.split(/\n/); 441 if (subject.length > 1 && subject[1] == "virtualIdentityExtension") { 442 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: NewMail() found stored identity preset: " + subject[2] + "\n"); 443 smartIdentity._smartIdentityCollection.__parseHeadersWithArray(subject[2], smartIdentity._smartIdentityCollection._allIdentities); 444 gMsgCompose.compFields.subject = subject[0]; 445 document.getElementById("msgSubject").value = subject[0]; 446 } 447 else smartIdentity._smartIdentityCollection.NewMail(); 448 autocreate = true; break; 449 } 450 if (smartIdentity._smartIdentityCollection._allIdentities.number > 0) smartIdentity.__smartIdentitySelection(autocreate); 451 }, 452 453 _getRecipients : function() { 454 var recipients = []; 455 for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { 456 var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); 457 if (recipientType == "addr_reply" || recipientType == "addr_followup" || 458 vI.storage.__isDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue; 459 recipients.push( { recipient: awGetInputElement(row).value, recipientType : recipientType } ); 460 } 461 return recipients; 462 }, 463 464 __smartIdentitySelection : function(autocreate) { 465 if (vI.notificationBar) vI.notificationBar.dump("## __smartIdentitySelection autocreate=" + autocreate + "\n"); 466 467 if (smartIdentity._pref.getBoolPref("idSelection_preferExisting")) { 468 var existingIDIndex = smartIdentity._smartIdentityCollection._foundExistingIdentity(); 469 if (existingIDIndex) { 470 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentity: found existing Identity, use without interaction.\n"); 471 // add all Indentities to Clone Menu before selecting and leaving the function 472 document.getElementById("msgIdentity_clone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities); 473 smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, existingIDIndex.key); 474 return; 475 } 476 } 477 478 document.getElementById("msgIdentity_clone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities); 479 if (vI.notificationBar) vI.notificationBar.dump("## __smartIdentitySelection smartIdentity._smartIdentityCollection._allIdentities.number=" + 480 smartIdentity._smartIdentityCollection._allIdentities.number + 481 " smartIdentity._pref.getBoolPref('idSelection_ask_always')=" + 482 smartIdentity._pref.getBoolPref("idSelection_ask_always") + 483 " smartIdentity._pref.getBoolPref('idSelection_ask')=" + 484 smartIdentity._pref.getBoolPref("idSelection_ask") + "\n"); 485 if (!autocreate && smartIdentity._pref.getBoolPref("idSelection_ask") && 486 ((smartIdentity._smartIdentityCollection._allIdentities.number == 1 && smartIdentity._pref.getBoolPref("idSelection_ask_always")) 487 || smartIdentity._smartIdentityCollection._allIdentities.number > 1)) { 488 for (var index = 0; index < smartIdentity._smartIdentityCollection._allIdentities.number; index++) { 489 if (vI.notificationBar) vI.notificationBar.dump("## smartIdentityReplyDialog index=" + index + ": '" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].combinedName + "' " 490 + "(" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].id.value + "," + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].smtp.value + ")\n"); 428 491 } 429 492 window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0, 430 493 "chrome, dialog, modal, alwaysRaised, resizable=yes", 431 allIdentities,494 smartIdentity._smartIdentityCollection._allIdentities, 432 495 /* callback: */ smartIdentity.changeIdentityToSmartIdentity).focus(); 433 496 } 434 else if (autocreate || vI.main.preferences.getBoolPref("idSelection_autocreate")) {435 smartIdentity.changeIdentityToSmartIdentity( allIdentities, 0);497 else if (autocreate || smartIdentity._pref.getBoolPref("idSelection_autocreate")) { 498 smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, 0); 436 499 } 437 500 }, 438 501 439 502 changeIdentityToSmartIdentity : function(allIdentities, selectedValue) { 440 vI.notificationBar.dump("## changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' " 503 if (vI.notificationBar) vI.notificationBar.dump("## changeIdentityToSmartIdentity selectedValue=" + selectedValue + " from " + allIdentities.number + "\n"); 504 if (vI.notificationBar) vI.notificationBar.dump("## changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' " 441 505 + "(" + allIdentities.identityDataCollection[selectedValue].id.value + "," + allIdentities.identityDataCollection[selectedValue].smtp.value + ")\n"); 442 506 document.getElementById("msgIdentity_clone").selectedMenuItem = allIdentities.menuItems[selectedValue]; … … 445 509 if (allIdentities.number > 1) label += " " 446 510 + vI.main.elements.strings.getString("vident.smartIdentity.moreThanOne"); 447 vI.notificationBar.addNote(label + ".", "smart_reply_notification");511 if (vI.notificationBar) vI.notificationBar.addNote(label + ".", "smart_reply_notification"); 448 512 } 449 513 smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue); … … 451 515 452 516 __removeSmartIdentityFromRecipients : function(allIdentities, index) { 453 if (! vI.main.preferences.getBoolPref("idSelection_removeSmartIdentityFromRecipients")) return;517 if (!smartIdentity._pref.getBoolPref("idSelection_removeSmartIdentityFromRecipients")) return; 454 518 455 519 // check if selected email is defined as doBcc address. If so, it should not be removed. … … 488 552 awSetInputAndPopupValue(input, "", popup, "addr_to", -1); 489 553 awCleanupRows() 490 vI.notificationBar.addNote(" " +554 if (vI.notificationBar) vI.notificationBar.addNote(" " + 491 555 vI.main.elements.strings.getString("vident.smartIdentity.remRecipient"), 492 556 "smart_reply_notification"); … … 497 561 } 498 562 vI.smartIdentity = smartIdentity; 563 vI.smartIdentityCollection = smartIdentityCollection; 499 564 }}); -
chrome/content/v_identity/vI_storage.js
r7666cb r9cedc0 30 30 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) { 31 31 var storage = { 32 multipleRecipients : null,33 32 focusedElement : null, 33 _pref : Components.classes["@mozilla.org/preferences-service;1"] 34 .getService(Components.interfaces.nsIPrefService) 35 .getBranch("extensions.virtualIdentity."), 34 36 35 37 lastCheckedEmail : {}, // array of last checked emails per row, 36 38 // to prevent ugly double dialogs and time-consuming double-checks 37 39 38 rdfService : Components.classes["@mozilla.org/rdf/rdf-service;1"] 39 .getService(Components.interfaces.nsIRDFService), 40 41 prefroot : Components.classes["@mozilla.org/preferences-service;1"] 42 .getService(Components.interfaces.nsIPrefService) 43 .getBranch(null).QueryInterface(Components.interfaces.nsIPrefBranch2), 44 45 rdfDatasource : null, // local storage 40 _rdfDatasourceAccess : null, // local storage 46 41 47 42 clean: function() { … … 51 46 storage.firstUsedInputElement = null; 52 47 awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue; 53 if (storage. rdfDatasource) storage.rdfDatasource.clean();48 if (storage._rdfDatasourceAccess) storage._rdfDatasourceAccess.clean(); 54 49 }, 55 50 … … 90 85 init: function() { 91 86 if (!storage.initialized) { 92 storage. rdfDatasource = new vI.rdfDatasource("virtualIdentity.rdf");87 storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess(); 93 88 94 89 // better approach would be to use te onchange event, but this one is not fired in any change case … … 130 125 131 126 firstUsedInputElement : null, // this stores the first Element for which a Lookup in the Storage was successfull 132 updateVIdentityFromStorage: function(inputElement) { 133 if (! vI.main.preferences.getBoolPref("storage"))127 updateVIdentityFromStorage: function(inputElement) { 128 if (!storage._pref.getBoolPref("storage")) 134 129 { vI.notificationBar.dump("## storage: Storage deactivated\n"); return; } 135 130 vI.notificationBar.dump("## storage: updateVIdentityFromStorage()\n"); … … 155 150 } 156 151 storage.lastCheckedEmail[row] = inputElement.value; 157 var recipient = storage.__getDescriptionAndType(inputElement.value, recipientType); 158 159 var matchResults = { storageData : {}, menuItem : {} }; 160 matchResults.storageData[0] = storage.rdfDatasource.readVIdentityFromRDF(recipient.recDesc, recipient.recType); 161 matchResults.storageData[1] = storage.rdfDatasource.findMatchingFilter(recipient.recDesc); 162 163 vI.notificationBar.dump("## storage: updateVIdentityFromStorage add found Identities to CloneMenu.\n"); 164 var matchIndex = null; 165 for (var i = 0; i <= 1; i++) { 166 if (matchResults.storageData[i]) { // check if there is a result in direct match or filter 167 if (matchIndex == null) matchIndex = i; // prefer direct match instead of filter 168 matchResults.menuItem[i] = document.getElementById("msgIdentity_clone") 169 .addIdentityToCloneMenu(matchResults.storageData[i]); 170 } 171 } 172 if (matchIndex == null) { 173 vI.notificationBar.dump("## storage: updateVIdentityFromStorage no usable Storage-Data found.\n"); 174 return; 175 } 176 else { 177 vI.notificationBar.dump("## storage: using data from " + ((matchIndex == 0)?"direct":"filter") + " match\n"); 178 } 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"); 179 161 // found storageData, so store InputElement 180 162 if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement; 181 163 182 vI.notificationBar.dump("## storage: compare with current Identity\n"); 183 if (vI.main.preferences.getBoolPref("storage_getOneOnly") && // if requested to retrieve only storageID for first recipient entered 184 storage.firstUsedInputElement && // and the request for the first recipient was already done 185 storage.firstUsedInputElement != inputElement && // and it's not the same element we changed now 186 !matchResults.storageData[matchIndex].equalsCurrentIdentity(false).equal) // and this id is different than the current used one 187 vI.notificationBar.setNote(vI.main.elements.strings 188 .getString("vident.smartIdentity.vIStorageCollidingIdentity"), // than drop the potential changes 189 "storage_notification"); 190 // only update fields if new Identity is different than old one. 191 else { 192 vI.notificationBar.dump("## storage: updateVIdentityFromStorage check if storage-data matches current Identity.\n"); 193 var compResult = matchResults.storageData[matchIndex].equalsCurrentIdentity(true); 194 if (!compResult.equal) { 195 var warning = storage.__getWarning("replaceVIdentity", recipient, compResult.compareMatrix); 196 var msgIdentityCloneElem = document.getElementById("msgIdentity_clone") 197 if ( !msgIdentityCloneElem.vid || 198 !vI.main.preferences.getBoolPref("storage_warn_vI_replace") || 199 (storage.__askWarning(warning) == "accept")) { 200 msgIdentityCloneElem.selectedMenuItem = matchResults.menuItem[matchIndex]; 201 if (msgIdentityCloneElem.vid) 202 vI.notificationBar.setNote(vI.main.elements.strings.getString("vident.smartIdentity.vIStorageUsage") + ".", 203 "storage_notification"); 204 } 205 } 206 else { 207 vI.notificationBar.dump("## storage: updateVIdentityFromStorage doing nothing - equals current Identity.\n"); 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]) 208 169 } 209 170 } 210 }, 211 212 __getDescriptionAndType : function (recipient, recipientType) { 213 if (recipientType == "addr_newsgroups") return { recDesc : recipient, recType : "newsgroup" } 214 else if (storage.__isMailingList(recipient)) { 215 vI.notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is MailList\n"); 216 return { recDesc : storage.__getMailListName(recipient), recType : "maillist" } 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"); 217 177 } 218 else {219 vI.notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is no MailList\n");220 var localIdentityData = new vI.identityData(recipient, null, null, null, null, null, null);221 return { recDesc : localIdentityData.combinedName, recType : "email" }222 }223 },224 225 storeVIdentityToAllRecipients : function(msgType) {226 if (msgType != nsIMsgCompDeliverMode.Now) return true;227 vI.notificationBar.dump("## storage: ----------------------------------------------------------\n")228 if (!vI.main.preferences.getBoolPref("storage"))229 { vI.notificationBar.dump("## storage: Storage deactivated\n"); return true; }230 231 if (vI.statusmenu.objStorageSaveMenuItem.getAttribute("checked") != "true") {232 vI.notificationBar.dump("## storage: SaveMenuItem not checked.\n")233 return true;234 }235 236 vI.notificationBar.dump("## storage: storeVIdentityToAllRecipients()\n");237 238 // check if there are multiple recipients239 storage.multipleRecipients = false;240 var recipients = 0;241 for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {242 var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");243 if (recipientType == "addr_reply" || recipientType == "addr_followup" ||244 storage.__isDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue;245 if (recipients++ == 1) {246 storage.multipleRecipients = true247 vI.notificationBar.dump("## storage: multiple recipients found.\n")248 break;249 }250 }251 252 for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {253 var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");254 if (recipientType == "addr_reply" || recipientType == "addr_followup" ||255 storage.__isDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue;256 if (!storage.__updateStorageFromVIdentity(awGetInputElement(row).value, recipientType)) {257 vI.notificationBar.dump("## storage: -------------- aborted ---------------------------------\n")258 return false; // abort sending259 }260 }261 vI.notificationBar.dump("## storage: ----------------------------------------------------------\n");262 return true;263 },264 265 __getWarning : function(warningCase, recipient, compareMatrix) {266 var warning = { title: null, recLabel : null, recipient : null, warning : null, css: null, query : null, class : null };267 warning.title = vI.main.elements.strings.getString("vident." + warningCase + ".title")268 warning.recLabel = vI.main.elements.strings.getString("vident." + warningCase + ".recipient") + " (" + recipient.recType + "):"269 warning.recipient = recipient.recDesc;270 warning.warning =271 "<table class='" + warningCase + "'><thead><tr><th class='col1'/>" +272 "<th class='col2'>" + vI.main.elements.strings.getString("vident." + warningCase + ".currentIdentity") + "</th>" +273 "<th class='col3'>" + vI.main.elements.strings.getString("vident." + warningCase + ".storedIdentity") + "</th>" +274 "</tr></thead>" +275 "<tbody>" + compareMatrix + "</tbody>" +276 "</table>"277 warning.css = "vI.DialogBrowser.css";278 warning.query = vI.main.elements.strings.getString("vident." + warningCase + ".query");279 warning.class = warningCase;280 return warning;281 },282 283 __askWarning : function(warning) {284 var retVar = { returnValue: null };285 var answer = window.openDialog("chrome://v_identity/content/vI_Dialog.xul","",286 "chrome, dialog, modal, alwaysRaised, resizable=yes",287 warning, retVar)288 return retVar.returnValue;289 },290 291 __updateStorageFromVIdentity : function(recipient, recipientType) {292 vI.notificationBar.dump("## storage: __updateStorageFromVIdentity.\n")293 var dontUpdateMultipleNoEqual = (vI.main.preferences.getBoolPref("storage_dont_update_multiple") &&294 storage.multipleRecipients)295 vI.notificationBar.dump("## storage: __updateStorageFromVIdentity dontUpdateMultipleNoEqual='" + dontUpdateMultipleNoEqual + "'\n")296 recipient = storage.__getDescriptionAndType(recipient, recipientType);297 298 var storageDataByType = storage.rdfDatasource.readVIdentityFromRDF(recipient.recDesc, recipient.recType);299 var storageDataByFilter = storage.rdfDatasource.findMatchingFilter(recipient.recDesc);300 301 // update (storing) of data by type is required if there is302 // no data stored by type (or different data stored) and no equal filter found303 var storageDataByTypeCompResult = storageDataByType?storageDataByType.equalsCurrentIdentity(true):null;304 var storageDataByTypeEqual = (storageDataByType && storageDataByTypeCompResult.equal);305 var storageDataByFilterEqual = (storageDataByFilter && storageDataByFilter.equalsCurrentIdentity(false).equal);306 307 var doUpdate = "";308 if ( (!storageDataByType && !storageDataByFilterEqual) ||309 (!storageDataByTypeEqual && !storageDataByFilterEqual && !dontUpdateMultipleNoEqual) ) {310 vI.notificationBar.dump("## storage: __updateStorageFromVIdentity updating\n")311 var doUpdate = "accept";312 if (storageDataByType && !storageDataByTypeEqual && vI.main.preferences.getBoolPref("storage_warn_update")) {313 vI.notificationBar.dump("## storage: __updateStorageFromVIdentity overwrite warning\n");314 doUpdate = storage.__askWarning(storage.__getWarning("updateStorage", recipient, storageDataByTypeCompResult.compareMatrix));315 if (doUpdate == "takeover") {316 var msgIdentityCloneElem = document.getElementById("msgIdentity_clone");317 msgIdentityCloneElem.selectedMenuItem = msgIdentityCloneElem.addIdentityToCloneMenu(storageDataByType);318 return false;319 }320 if (doUpdate == "abort") return false;321 }322 }323 if (doUpdate == "accept") storage.rdfDatasource.updateRDFFromVIdentity(recipient.recDesc, recipient.recType);324 return true;325 },326 327 // --------------------------------------------------------------------328 // check if recipient is a mailing list.329 // Similiar to Thunderbird, if there are muliple cards with the same displayName the mailinglist is preferred330 // see also https://bugzilla.mozilla.org/show_bug.cgi?id=408575331 __isMailingList: function(recipient) {332 let abManager = Components.classes["@mozilla.org/abmanager;1"]333 .getService(Components.interfaces.nsIAbManager);334 let allAddressBooks = abManager.directories;335 while (allAddressBooks.hasMoreElements()) {336 let ab = allAddressBooks.getNext();337 if (ab instanceof Components.interfaces.nsIAbDirectory && !ab.isRemote) {338 let abdirectory = abManager.getDirectory(ab.URI +339 "?(and(DisplayName,=," + encodeURIComponent(storage.__getMailListName(recipient)) + ")(IsMailList,=,TRUE))");340 if (abdirectory) {341 try { // just try, sometimes there are no childCards at all...342 let cards = abdirectory.childCards;343 if (cards.hasMoreElements()) return true; // only interested if there is at least one element...344 } catch(e) { }345 }346 }347 }348 return false;349 },350 351 // --------------------------------------------------------------------352 353 __getMailListName : function(recipient) {354 if (recipient.match(/<[^>]*>/) || recipient.match(/$/)) {355 var mailListName = RegExp.leftContext + RegExp.rightContext356 mailListName = mailListName.replace(/^\s+|\s+$/g,"")357 }358 return mailListName;359 178 }, 360 179 … … 373 192 } 374 193 return false 375 },376 377 getVIdentityFromAllRecipients : function(allIdentities) {378 if (!vI.main.preferences.getBoolPref("storage"))379 { vI.notificationBar.dump("## storage: Storage deactivated\n"); return; }380 vI.notificationBar.dump("## storage: getVIdentityFromAllRecipients()\n");381 382 for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {383 var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");384 if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.__isDoBcc(row)) continue;385 storage.lastCheckedEmail[row] = awGetInputElement(row).value;386 var recipient = storage.__getDescriptionAndType(awGetInputElement(row).value, recipientType);387 var storageData = storage.rdfDatasource.readVIdentityFromRDF(recipient.recDesc, recipient.recType);388 if (storageData) allIdentities.addWithoutDuplicates(storageData);389 storageData = storage.rdfDatasource.findMatchingFilter(recipient.recDesc);390 if (storageData) allIdentities.addWithoutDuplicates(storageData);391 }392 vI.notificationBar.dump("## storage: found " + allIdentities.number + " address(es)\n")393 194 } 394 195 } -
chrome/content/v_identity/vI_upgrade.js
r7666cb r9cedc0 59 59 nextVersion += parseInt(currentVersion[2]) 60 60 else nextVersion += parseInt(currentVersion[2]) + 1 61 var extVersion = document.getElementById("extVersion").getAttribute("value"); 62 61 62 let window = Cc['@mozilla.org/appshell/window-mediator;1'] 63 .getService(Ci.nsIWindowMediator) 64 .getMostRecentWindow("mail:3pane"); 65 var extVersion = window.virtualIdentityExtension.extensionVersion; 66 63 67 // don't show the dialog if we do a one-step upgrade 64 68 if (upgrade.versionChecker.compare(extVersion, nextVersion) <= 0) { -
chrome/content/v_identity/vI_upgradeOverlay.js
r7666cb r9cedc0 58 58 }); 59 59 60 const virtualIdentity_ID="{dddd428e-5ac8-4a81-9f78-276c734f75b8}" 61 AddonManager.getAddonByID(virtualIdentity_ID, function(addon) { 62 if (addon) vI.extensionVersion = addon.version; 63 }); 60 64 61 65 if (prefroot.getBoolPref("extensions.virtualIdentity.error_console")) { -
chrome/content/v_identity/vI_upgradeOverlay.xul
r7666cb r9cedc0 41 41 <script type="application/x-javascript" src="chrome://v_identity/content/vI_account.js" /> 42 42 <script type="application/x-javascript" src="chrome://v_identity/content/vI_rdfDatasource.js" /> 43 <script type="application/x-javascript" src="chrome://v_identity/content/vI_storageExtras.js" />44 43 <script type="application/x-javascript" src="chrome://v_identity/content/vI_upgradeOverlay.js" /> 45 44 46 // include following scripts to enable quick_upgrade45 <!-- include following scripts to enable quick_upgrade --> 47 46 <script type="application/x-javascript" src="chrome://v_identity/content/vI_upgrade.js" /> 48 47 <script type="application/x-javascript" src="chrome://v_identity/content/vI_storage.js" /> 49 48 <script type="application/x-javascript" src="chrome://v_identity/content/vI_identityData.js" /> 50 49 <script type="application/x-javascript" src="chrome://v_identity/content/vI_helper.js" /> 50 <!-- include following script to enable conversation plugin --> 51 <script type="application/x-javascript" src="chrome://v_identity/content/vI_smartIdentity.js" /> 51 52 52 53 <vbox id="messagepanebox" > 53 <!-- following element just stores the Ext-Version, seamonkey has no extensionmanager -->54 <label id="extVersion" value="&vident.version;" hidden="true" />55 54 <splitter id="vIErrorBoxSplitter" hidden="true" /> 56 55 <vbox id="vIErrorBox" context="ConsoleContext" sortOrder="reverse" hidden="true" /> 57 58 56 </vbox> 59 57 </overlay> -
chrome/content/v_identity/v_identity.js
r7666cb r9cedc0 34 34 unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] 35 35 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter), 36 37 accountManager : Components.classes["@mozilla.org/messenger/account-manager;1"] 38 .getService(Components.interfaces.nsIMsgAccountManager), 39 36 40 37 41 gMsgCompose : null, // to store the global gMsgCompose after MsgComposeDialog is closed … … 80 84 FillIdentityList: function(menulist) { 81 85 vI.notificationBar.dump("## v_identity: mod. FillIdentityList\n"); 82 var mgr = Components.classes["@mozilla.org/messenger/account-manager;1"] 83 .getService(Components.interfaces.nsIMsgAccountManager); 84 var accounts = queryISupportsArray(mgr.accounts, 86 var accounts = queryISupportsArray(main.accountManager.accounts, 85 87 Components.interfaces.nsIMsgAccount); 86 88 … … 88 90 accounts = accounts.filter(function isNonSuckyAccount(a) { return !!a.incomingServer; }); 89 91 function sortAccounts(a, b) { 90 if (a.key == m gr.defaultAccount.key)92 if (a.key == main.accountManager.defaultAccount.key) 91 93 return -1; 92 if (b.key == m gr.defaultAccount.key)94 if (b.key == main.accountManager.defaultAccount.key) 93 95 return 1; 94 96 var aIsNews = a.incomingServer.type == "nntp"; … … 133 135 vI.storage.awOnBlur(vI.storage.focusedElement); 134 136 135 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]136 .getService(Components.interfaces.nsIPromptService);137 137 vI.notificationBar.dump("\n## v_identity: VIdentity_GenericSendMessage\n"); 138 138 139 if (msgType == Components.interfaces.nsIMsgCompDeliverMode.Now) { vI.msgIdentityCloneTools.addReplyToSelf(); } 140 139 141 var vid = document.getElementById("msgIdentity_clone").vid 140 141 if (msgType == nsIMsgCompDeliverMode.Now) { 142 if ( (vid && main.preferences.getBoolPref("warn_virtual") && 143 !(promptService.confirm(window,"Warning", 144 main.elements.strings.getString("vident.sendVirtual.warning")))) || 145 (!vid && main.preferences.getBoolPref("warn_nonvirtual") && 146 !(promptService.confirm(window,"Warning", 147 main.elements.strings.getString("vident.sendNonvirtual.warning")))) ) { 142 var virtualIdentityData = document.getElementById("msgIdentity_clone").identityData; 143 144 returnValue = vI.prepareSendMsg( vid, msgType, virtualIdentityData, 145 main.accountManager.getIdentity(main.elements.Obj_MsgIdentity.value), 146 main._getRecipients() ); 147 if (returnValue.update == "abort") { 148 main.replacement_functions.GenericSendMessageInProgress = false; 149 vI.notificationBar.dump("## sending: -------------- aborted ---------------------------------\n") 150 return; 151 } 152 else if (returnValue.update == "takeover") { 153 var msgIdentityCloneElem = document.getElementById("msgIdentity_clone"); 154 msgIdentityCloneElem.selectedMenuItem = msgIdentityCloneElem.addIdentityToCloneMenu(returnValue.storedIdentity); 148 155 main.replacement_functions.GenericSendMessageInProgress = false; 156 vI.notificationBar.dump("## sending: -------------- aborted ---------------------------------\n") 149 157 return; 150 } 151 if (!vI.storage.storeVIdentityToAllRecipients(msgType)) { 152 // vI.notificationBar.dump("## v_identity: sending aborted\n"); 153 main.replacement_functions.GenericSendMessageInProgress = false; 154 return; 155 } 156 vI.msgIdentityCloneTools.addReplyToSelf(); 157 } 158 if (vid) main.prepareAccount(); 158 } 159 160 if (vid) main.addVirtualIdentityToMsgIdentityMenu(); 161 162 // final check if eyerything is nice before we handover to the real sending... 163 if (vI.finalCheck(virtualIdentityData, getCurrentIdentity())) { 164 main.replacement_functions.GenericSendMessageInProgress = false; 165 main.original_functions.GenericSendMessage(msgType); 166 } 167 else main.Cleanup(); 159 168 main.replacement_functions.GenericSendMessageInProgress = false; 160 // vI.notificationBar.dump("## v_identity: original_functions.GenericSendMessage\n"); 161 162 // final check if eyerything is nice before we handover to the real sending... 163 var virtualIdentityData = document.getElementById("msgIdentity_clone").identityData; 164 165 var currentIdentity = getCurrentIdentity(); 166 // vI.identityData(email, fullName, id, smtp, extras, sideDescription, existingID) 167 var currentIdentityData = new vI.identityData(currentIdentity.email, currentIdentity.fullName, null, currentIdentity.smtpServerKey, null, null, null); 168 169 vI.notificationBar.dump("\n## vI.identityData GenericSendMessage Final Check\n"); 170 vI.notificationBar.dump("## vI.identityData currentIdentity: fullName='" + currentIdentityData.fullName + "' email='" + currentIdentityData.email + "' smtp='" + currentIdentityData.smtp.key + "'\n"); 171 vI.notificationBar.dump("## vI.identityData virtualIdentityData: fullName='" + virtualIdentityData.fullName + "' email='" + virtualIdentityData.email + "' smtp='" + virtualIdentityData.smtp.key + "'\n"); 172 173 if (currentIdentityData.fullName.toLowerCase() == virtualIdentityData.fullName.toLowerCase() && 174 currentIdentityData.email.toLowerCase() == virtualIdentityData.email.toLowerCase() && 175 virtualIdentityData.smtp.equal(currentIdentityData.smtp) ) { 176 main.original_functions.GenericSendMessage(msgType); 177 } 178 else { 179 if (!(currentIdentityData.fullName.toLowerCase() == virtualIdentityData.fullName.toLowerCase())) vI.notificationBar.dump("\n## vI.identityData failed check for fullName.\n"); 180 if (!(currentIdentityData.email.toLowerCase() == virtualIdentityData.email.toLowerCase())) vI.notificationBar.dump("\n## vI.identityData failed check for email.\n"); 181 if (!(virtualIdentityData.smtp.equal(currentIdentityData.smtp))) vI.notificationBar.dump("\n## vI.identityData failed check for SMTP.\n"); 182 alert(main.elements.strings.getString("vident.genericSendMessage.error")); 183 main.Cleanup(); 184 } 185 // vI.notificationBar.dump("## v_identity: original_functions.GenericSendMessage done\n"); 169 // vI.notificationBar.dump("## v_identity: original_functions.GenericSendMessage done\n"); 186 170 }, 187 171 … … 199 183 main.Cleanup(); 200 184 vI.storage.clean(); 185 }, 186 187 _getRecipients : function(row) { 188 var recipients = []; 189 for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) { 190 var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); 191 if (recipientType == "addr_reply" || recipientType == "addr_followup" || 192 main._recipientIsDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue; 193 recipients.push( { recipient: awGetInputElement(row).value, recipientType : recipientType } ); 194 } 195 return recipients; 196 }, 197 198 _recipientIsDoBcc : function(row) { 199 var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value"); 200 if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false 201 202 var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {}); 203 204 for (var index = 0; index < doBccArray.count; index++ ) { 205 if (doBccArray.StringAt(index) == awGetInputElement(row).value) { 206 vI.notificationBar.dump("## main _recipientIsDoBcc: ignoring doBcc field '" + 207 doBccArray.StringAt(index) + "'.\n"); 208 return true; 209 } 210 } 211 return false 201 212 }, 202 213 … … 231 242 document.getElementById("msgIdentity_clone").init(); 232 243 vI.statusmenu.init(); 244 vI.notificationBar.dump("## v_identity: initSystemStage1 done.\n") 233 245 }, 234 246 … … 238 250 vI.storage.init(); 239 251 vI.smartIdentity.init(); 252 vI.notificationBar.dump("## v_identity: initSystemStage2 done.\n") 240 253 }, 241 254 … … 286 299 // clean all elements 287 300 document.getElementById("msgIdentity_clone").clean(); 288 vI.smartIdentity.clean();289 301 vI.notificationBar.dump("## v_identity: everything cleaned.\n") 290 302 … … 356 368 prepareAccount : function() { 357 369 main.Cleanup(); // just to be sure that nothing is left (maybe last time sending was irregularily stopped) 358 vI.account.createAccount(); 370 vI.account.createAccount(document.getElementById("msgIdentity_clone").identityData, 371 main.accountManager.getIdentity(main.elements.Obj_MsgIdentity.value)); 359 372 main.addVirtualIdentityToMsgIdentityMenu(); 360 373 }, -
chrome/content/v_identity/v_identity.xul
r7666cb r9cedc0 52 52 <stringbundle id="vIdentBundle" src="chrome://v_identity/locale/v_identity.properties" /> 53 53 <stringbundle id="vIStorageExtrasBundle" src="chrome://v_identity/locale/vI_storageExtras.properties" /> 54 <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties" />55 54 </stringbundleset> 56 55
Note: See TracChangeset
for help on using the changeset viewer.