Changeset dbf0b6
- Timestamp:
- Aug 25, 2018, 11:58:03 AM (4 years ago)
- Branches:
- ng_0.9
- Children:
- e95c6f
- Parents:
- 8518b6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/vI_account.js
r8518b6 rdbf0b6 23 23 * ***** END LICENSE BLOCK ***** */ 24 24 25 var EXPORTED_SYMBOLS = ["vIaccount_cleanupSystem", "get_vIaccount", 26 "vIaccount_prepareSendMsg", "vIaccount_finalCheck", 27 "vIaccount_createAccount", "vIaccount_removeUsedVIAccount" 28 ] 25 var EXPORTED_SYMBOLS = ["vIaccount_cleanupSystem"] 29 26 30 27 const { … … 44 41 let Log = setupLogging("virtualIdentity.account"); 45 42 46 function vIaccount_prepareSendMsg(currentWindow, vid, msgType, identityData, baseIdentity, recipients) {47 var stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties");48 49 var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]50 .getService(Ci.nsIPromptService);51 52 var AccountManager = Cc["@mozilla.org/messenger/account-manager;1"]53 .getService(Ci.nsIMsgAccountManager);54 55 Log.debug("prepareSendMsg " + msgType + " " + Ci.nsIMsgCompDeliverMode.Now);56 57 returnValue = {};58 59 if (msgType == Ci.nsIMsgCompDeliverMode.Now) {60 if ((vid && vIprefs.get("warn_virtual") &&61 !(promptService.confirm(currentWindow, "Warning",62 stringBundle.GetStringFromName("vident.sendVirtual.warning")))) ||63 (!vid && vIprefs.get("warn_nonvirtual") &&64 !(promptService.confirm(currentWindow, "Warning",65 stringBundle.GetStringFromName("vident.sendNonvirtual.warning"))))) {66 return {67 update: "abort",68 storedIdentity: null69 }; // completely abort sending70 }71 if (vIprefs.get("storage") && vIprefs.get("storage_store")) {72 var localeDatasourceAccess = new rdfDatasourceAccess(currentWindow);73 var returnValue = localeDatasourceAccess.storeVIdentityToAllRecipients(identityData, recipients)74 if (returnValue.update == "abort" || returnValue.update == "takeover") {75 Log.debug("prepareSendMsg: sending aborted");76 return returnValue;77 }78 } else Log.debug("prepareSendMsg: storage deactivated");79 }80 if (vid) {81 account.removeUsedVIAccount();82 account.createAccount(identityData, baseIdentity);83 }84 return {85 update: "accept",86 storedIdentity: null87 };88 };89 90 function vIaccount_finalCheck(currentWindow, virtualIdentityData, currentIdentity) {91 var stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties");92 93 // identityData(email, fullName, id, smtp, extras, sideDescription, existingID)94 var currentIdentityData = new identityData(currentWindow, currentIdentity.email, currentIdentity.fullName, null, currentIdentity.smtpServerKey, null, null, null);95 96 Log.debug("SendMessage Final Check");97 Log.debug("currentIdentity: fullName='" + currentIdentityData.fullName + "' email='" + currentIdentityData.email + "' smtp='" + currentIdentityData.smtp.key + "'");98 Log.debug("virtualIdentityData: fullName='" + virtualIdentityData.fullName + "' email='" + virtualIdentityData.email + "' smtp='" + virtualIdentityData.smtp.key + "'");99 100 if (currentIdentityData.fullName.toLowerCase() == virtualIdentityData.fullName.toLowerCase() &&101 currentIdentityData.email.toLowerCase() == virtualIdentityData.email.toLowerCase() &&102 virtualIdentityData.smtp.equal(currentIdentityData.smtp)) {103 return true104 } else {105 let alertMsg = stringBundle.GetStringFromName("vident.genericSendMessage.error") + "\n\n"106 if (!(currentIdentityData.fullName.toLowerCase() == virtualIdentityData.fullName.toLowerCase())) {107 alertMsg += "failed check for fullName:\n" +108 "current : " + currentIdentityData.fullName + "\n" +109 "required: " + virtualIdentityData.fullName + "\n"110 Log.error("failed check for fullName.");111 }112 if (!(currentIdentityData.email.toLowerCase() == virtualIdentityData.email.toLowerCase())) {113 alertMsg += "failed check for email:\n" +114 "current : " + currentIdentityData.email + "\n" +115 "required: " + virtualIdentityData.email + "\n"116 Log.error("failed check for email.");117 }118 if (!(virtualIdentityData.smtp.equal(currentIdentityData.smtp))) {119 alertMsg += "failed check for SMTP:\n" +120 "current : " + currentIdentityData.smtp + "\n" +121 "required: " + virtualIdentityData.smtp + "\n"122 Log.error("failed check for SMTP.");123 }124 alertMsg += "\n" + stringBundle.GetStringFromName("vident.genericSendMessage.error_post")125 return currentWindow.confirm(alertMsg);126 }127 };128 129 43 var account = { 130 _account: null,131 132 _baseIdentity: null,133 134 _AccountManager: Cc["@mozilla.org/messenger/account-manager;1"]135 .getService(Ci.nsIMsgAccountManager),136 137 _unicodeConverter: Cc["@mozilla.org/intl/scriptableunicodeconverter"]138 .createInstance(Ci.nsIScriptableUnicodeConverter),139 140 _copyBoolAttribute: function (name) {141 Log.debug("copy attribute '" + name + "', value='" + account._baseIdentity.getBoolAttribute(name) + "'");142 account._account.defaultIdentity.setBoolAttribute(name,143 account._baseIdentity.getBoolAttribute(name));144 },145 146 _copyIntAttribute: function (name) {147 Log.debug("copy attribute '" + name + "', value='" + account._baseIdentity.getIntAttribute(name) + "'");148 account._account.defaultIdentity.setIntAttribute(name,149 account._baseIdentity.getIntAttribute(name));150 },151 152 _copyCharAttribute: function (name) {153 Log.debug("copy attribute '" + name + "', value='" + account._baseIdentity.getCharAttribute(name) + "'");154 account._account.defaultIdentity.setCharAttribute(name,155 account._baseIdentity.getCharAttribute(name));156 },157 158 _copyUnicharAttribute: function (name) {159 Log.debug("copy attribute '" + name + "', value='" + account._baseIdentity.getUnicharAttribute(name) + "'");160 account._account.defaultIdentity.setUnicharAttribute(name,161 account._baseIdentity.getUnicharAttribute(name));162 },163 164 _copyPreferences: function () {165 if (vIprefs.get("copySMIMESettings")) {166 // SMIME settings167 Log.debug("copy S/MIME settings")168 account._copyUnicharAttribute("signing_cert_name");169 account._copyUnicharAttribute("encryption_cert_name");170 account._copyIntAttribute("encryptionpolicy");171 }172 if (vIprefs.get("copyNewEnigmailSettings")) {173 // pgp/enigmail settings174 Log.debug("copy PGP settings")175 account._copyBoolAttribute("enablePgp");176 account._copyIntAttribute("pgpKeyMode");177 account._copyCharAttribute("pgpkeyId");178 account._copyIntAttribute("defaultSigningPolicy");179 account._copyIntAttribute("defaultEncryptionPolicy");180 account._copyBoolAttribute("pgpMimeMode");181 account._copyBoolAttribute("pgpSignEncrypted");182 account._copyBoolAttribute("pgpSignPlain");183 account._copyBoolAttribute("autoEncryptDrafts");184 account._copyIntAttribute("openPgpHeaderMode");185 account._copyCharAttribute("openPgpUrlName");186 account._copyBoolAttribute("attachPgpKey");187 }188 if (vIprefs.get("copyAttachVCardSettings")) {189 // attach vcard190 Log.debug("copy VCard settings")191 account._copyBoolAttribute("attachVCard");192 account._copyCharAttribute("escapedVCard");193 }194 },195 196 44 // checks if directory is empty, not really used 197 45 // ignores files ending with *.msf, else reports if a non-zero file is found. … … 241 89 Log.debug("done.") 242 90 }, 243 91 244 92 cleanupSystem: function () { 245 93 Log.debug("checking for leftover VirtualIdentity accounts ...") … … 326 174 account.__removeAccountPrefs(key); 327 175 }, 328 329 removeUsedVIAccount: function () {330 var mailWindow = Cc["@mozilla.org/appshell/window-mediator;1"].getService()331 .QueryInterface(Ci.nsIWindowMediator)332 .getMostRecentWindow("mail:3pane");333 if (mailWindow) { // it's not sure that we have an open 3-pane-window334 var selectedFolder = (mailWindow.gFolderTreeView) ? mailWindow.gFolderTreeView.getSelectedFolders()[0] : null;335 var selectedMessages = (mailWindow.gFolderDisplay) ? mailWindow.gFolderDisplay.selectedMessages : null;336 }337 if (account._account) {338 account.__removeAccount(account._account);339 account._account = null;340 try {341 if (selectedFolder) mailWindow.gFolderTreeView.selectFolder(selectedFolder);342 if (selectedMessages) mailWindow.gFolderDisplay.selectMessages(selectedMessages, false, false);343 } catch (e) {};344 }345 },346 347 createAccount: function (identityData, baseIdentity) {348 if (account._account) { // if the Account is still created, then leave all like it is349 var mailWindow = Cc["@mozilla.org/appshell/window-mediator;1"].getService()350 .QueryInterface(Ci.nsIWindowMediator)351 .getMostRecentWindow("mail:3pane");352 mailWindow.alert("account already created, shouldn't happen");353 return;354 }355 account._baseIdentity = baseIdentity;356 /*357 // the easiest way would be to get all requiered Attributes might be to duplicate the default account like this358 var recentAccount = account._AccountManager.getAccount(vI.main.elements.Obj_MsgIdentity.selectedItem.getAttribute("accountkey"));359 vI.main.VIdent_Account = account._AccountManager.duplicateAccount(recentAccount);360 // but this ends up in the following exception:361 // "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIMsg_AccountManager.duplicateAccount]"362 // so I have to do this by hand ;(363 */364 365 account._account = account._AccountManager.createAccount();366 prefroot.setBoolPref("mail.account." + account._account.key + ".vIdentity", true)367 account._account.addIdentity(account._AccountManager.createIdentity());368 369 Log.debug("createAccount create Identity based on baseIdentity (" + baseIdentity.key + ") " + baseIdentity.fullName + " <" + baseIdentity.email + ">");370 // the new account uses the same incomingServer than the base one,371 // it's especially required for NNTP cause incomingServer is used for sending newsposts.372 // by pointing to the same incomingServer stored passwords can be reused373 // the incomingServer has to be replaced before the account is removed, else it get removed ether374 if (typeof (this._AccountManager.getServersForIdentity) == 'function') { // new style375 var servers = this._AccountManager.getServersForIdentity(baseIdentity);376 } else {377 var servers = this._AccountManager.GetServersForIdentity(baseIdentity);378 }379 try {380 if (typeof (this._AccountManager.getServersForIdentity) == 'function') { // new style381 var server = servers.queryElementAt(0, Ci.nsIMsgIncomingServer);382 } else {383 var server = servers.QueryElementAt(0, Ci.nsIMsgIncomingServer);384 }385 } catch (NS_ERROR_FAILURE) {386 Log.debug("createAccount missing incomingServer for baseIdentity, using default one");387 var server = account._AccountManager.defaultAccount.incomingServer;388 }389 // we mark the server as invalid so that the account manager won't390 // tell RDF about the new server - we don't need this server for long391 // but we should restore it, because it's actually the same server as the one of the base identity392 server.valid = false;393 account._account.incomingServer = server;394 server.valid = true;395 account._copyIdentityData(identityData, baseIdentity);396 account._copyPreferences();397 account._unicodeConverter.charset = "UTF-8";398 account._setupFcc();399 account._setupDraft();400 account._setupTemplates();401 },402 403 _copyIdentityData: function (identityData, baseIdentity) {404 account._account.defaultIdentity.setCharAttribute("useremail", identityData.email);405 account._account.defaultIdentity.setUnicharAttribute("fullName", identityData.fullName);406 407 account._account.defaultIdentity.smtpServerKey = identityData.smtp.keyNice; // key with "" for vI.DEFAULT_SMTP_TAG408 if (account._account.defaultIdentity.smtpServerKey == NO_SMTP_TAG)409 account._account.defaultIdentity.smtpServerKey = baseIdentity.smtpServerKey;410 411 Log.debug("Stored virtualIdentity (name " + account._account.defaultIdentity.fullName + " email " + account._account.defaultIdentity.email + " smtp " + account._account.defaultIdentity.smtpServerKey + ")");412 },413 414 _setupFcc: function () {415 if (vIprefs.get("doFcc")) {416 switch (vIprefs.get("fccFolderPickerMode")) {417 case "2":418 Log.debug("preparing Fcc --- use Settings of Default Account");419 account._account.defaultIdentity.doFcc = account._AccountManager.defaultAccount.defaultIdentity.doFcc;420 account._account.defaultIdentity.fccFolder = account._AccountManager.defaultAccount.defaultIdentity.fccFolder;421 account._account.defaultIdentity.fccFolderPickerMode = account._AccountManager.defaultAccount.defaultIdentity.fccFolderPickerMode;422 account._account.defaultIdentity.fccReplyFollowsParent = account._AccountManager.defaultAccount.defaultIdentity.fccReplyFollowsParent;423 break;424 case "3":425 Log.debug("preparing Fcc --- use Settings of Modified Account");426 account._account.defaultIdentity.doFcc = account._baseIdentity.doFcc;427 account._account.defaultIdentity.fccFolder = account._baseIdentity.fccFolder;428 account._account.defaultIdentity.fccFolderPickerMode = account._baseIdentity.fccFolderPickerMode;429 account._account.defaultIdentity.fccReplyFollowsParent = account._baseIdentity.fccReplyFollowsParent;430 break;431 default:432 Log.debug("preparing Fcc --- use Virtual Identity Settings");433 account._account.defaultIdentity.doFcc = vIprefs.get("doFcc");434 account._account.defaultIdentity.fccFolder = account._unicodeConverter.ConvertToUnicode(vIprefs.get("fccFolder"));435 account._account.defaultIdentity.fccFolderPickerMode = vIprefs.get("fccFolderPickerMode");436 account._account.defaultIdentity.fccReplyFollowsParent = vIprefs.get("fccReplyFollowsParent");437 438 break;439 }440 } else {441 dump("dont performing Fcc\n");442 account._account.defaultIdentity.doFcc = false;443 }444 Log.debug("Stored (doFcc " + account._account.defaultIdentity.doFcc + " fccFolder " +445 account._account.defaultIdentity.fccFolder + " fccFolderPickerMode " +446 account._account.defaultIdentity.fccFolderPickerMode + "(" +447 vIprefs.get("fccFolderPickerMode") + "))");448 },449 450 _setupDraft: function () {451 switch (vIprefs.get("draftFolderPickerMode")) {452 case "2":453 Log.debug("preparing Draft --- use Settings of Default Account");454 account._account.defaultIdentity.draftFolder = account._AccountManager.defaultAccount.defaultIdentity.draftFolder;455 account._account.defaultIdentity.draftsFolderPickerMode = account._AccountManager.defaultAccount.defaultIdentity.draftsFolderPickerMode;456 break;457 case "3":458 Log.debug("preparing Draft --- use Settings of Modified Account");459 account._account.defaultIdentity.draftFolder = account._baseIdentity.draftFolder;460 account._account.defaultIdentity.draftsFolderPickerMode = account._baseIdentity.draftsFolderPickerMode;461 break;462 default:463 Log.debug("preparing Draft --- use Virtual Identity Settings");464 account._account.defaultIdentity.draftFolder = account._unicodeConverter.ConvertToUnicode(vIprefs.get("draftFolder"));465 account._account.defaultIdentity.draftsFolderPickerMode = vIprefs.get("draftFolderPickerMode");466 break;467 }468 Log.debug("Stored (draftFolder " +469 account._account.defaultIdentity.draftFolder + " draftsFolderPickerMode " +470 account._account.defaultIdentity.draftsFolderPickerMode + "(" +471 vIprefs.get("draftFolderPickerMode") + "))");472 },473 474 _setupTemplates: function () {475 switch (vIprefs.get("stationeryFolderPickerMode")) {476 case "2":477 Log.debug("preparing Templates --- use Settings of Default Account");478 try {479 // if no defaultIdentity (received bug-report) use Settings of Modified Account instead480 account._account.defaultIdentity.stationeryFolder = account._AccountManager.defaultAccount.defaultIdentity.stationeryFolder;481 account._account.defaultIdentity.tmplFolderPickerMode = account._AccountManager.defaultAccount.defaultIdentity.tmplFolderPickerMode;482 break;483 } catch (e) {484 Log.debug("something went wrong while trying to access default Identity");485 Log.debug(e);486 }487 case "3":488 Log.debug("preparing Templates --- use Settings of Modified Account");489 account._account.defaultIdentity.stationeryFolder = account._baseIdentity.stationeryFolder;490 account._account.defaultIdentity.tmplFolderPickerMode = account._baseIdentity.tmplFolderPickerMode;491 break;492 default:493 Log.debug("preparing Templates --- use Virtual Identity Settings");494 account._account.defaultIdentity.stationeryFolder = account._unicodeConverter.ConvertToUnicode(vIprefs.get("stationeryFolder"));495 account._account.defaultIdentity.tmplFolderPickerMode = vIprefs.get("stationeryFolderPickerMode");496 break;497 }498 Log.debug("Stored (stationeryFolder " +499 account._account.defaultIdentity.stationeryFolder + " tmplFolderPickerMode " +500 account._account.defaultIdentity.tmplFolderPickerMode + "(" +501 vIprefs.get("stationeryFolderPickerMode") + "))");502 }503 176 } 504 505 function get_vIaccount() {506 return account._account;507 };508 177 var vIaccount_cleanupSystem = account.cleanupSystem; 509 var vIaccount_createAccount = account.createAccount;510 var vIaccount_removeUsedVIAccount = account.removeUsedVIAccount;
Note: See TracChangeset
for help on using the changeset viewer.