-
Notifications
You must be signed in to change notification settings - Fork 53
Script: Identity
Samuel Plentz edited this page Feb 24, 2023
·
2 revisions
Change identity (address in from
field), get the currently active identity or get a list of all supported identities.
Scriptname: Identity
let action = this.mVariables[0];
let setIdentity = this.mVariables[1];
if(action == "getAllIdentities") {
let identityList = this.mWindow.document.getElementById("msgIdentity");
let identities = identityList.getElementsByAttribute("identitykey", "*");
let result = "";
for(let identity of identities) {
result += identity.getAttribute("identitykey") + " - " + identity.getAttribute("label") + "\r\n";
}
return result;
}
if(action == "getCurrentIdentity") {
let identityList = this.mWindow.document.getElementById("msgIdentity");
let identities = identityList.getElementsByAttribute("identitykey", "*");
let result = "";
for(let identity of identities) {
if(identity.getAttribute("selected") != "true") continue;
result += identity.getAttribute("identitykey") + " - " + identity.getAttribute("label") + "\r\n";
}
return result;
}
if(action == "setIdentity") {
// Since switching the signature loses the caret position, we record it
// and restore it later.
let selection = this.mWindow.gMsgCompose.editor.selection;
let range = selection.getRangeAt(0);
let start = range.startOffset;
let startNode = range.startContainer;
this.mWindow.gMsgCompose.editor.enableUndo(false);
let identityList = this.mWindow.document.getElementById("msgIdentity");
identityList.selectedItem = identityList.getElementsByAttribute("identitykey", setIdentity)[0];
this.mWindow.LoadIdentity(false);
this.mWindow.gMsgCompose.editor.enableUndo(true);
this.mWindow.gMsgCompose.editor.resetModificationCount();
selection.collapse(startNode, start);
}
return "";
Get a list of all supported identities: (example: id1 - John Doe <[email protected]> | id2 - Jane Doe <[email protected]>
)
[[SCRIPT=Identity|getAllIdentities]]
Get the currently active identity: (example: id1 - John Doe <[email protected]>
)
[[SCRIPT=Identity|getCurrentIdentity]]
Change identity to id2
:
[[SCRIPT=Identity|setIdentity|id2]]