Script: SaveAsNote - jobisoft/quicktext GitHub Wiki
With this script you are able to create notes which are stored as usual messages in a separate folder named Notes.
If you create it as a reply to another message, it will be part of the thread.
Script
let win = this.mWindow;
// Get folders
let draftFolderURI = win.gCurrentIdentity.draftFolder;
let notesFolderURI = draftFolderURI.replace("/Drafts", "/Notes");
let folder = win.MailUtils.getExistingFolder(notesFolderURI);
//let folder = win.MailUtils.getOrCreateFolder(notesFolderURI);
if (!folder) {
win.alert('Notes folder does not exist:\n' + notesFolderURI);
return '';
}
// Reset email addresses
// TO
let toRow = win.document.getElementById("addressRowTo");
win.addressRowClearPills(toRow);
win.addressRowAddRecipientsArray(toRow, [win.gCurrentIdentity.fullAddress]);
// CC
let ccRow = win.document.getElementById("addressRowCc");
win.addressRowClearPills(ccRow);
// BCC
let bccRow = win.document.getElementById("addressRowBcc");
win.addressRowClearPills(bccRow);
// REPLY-TO
let replyRow = win.document.getElementById("addressRowReply");
win.addressRowClearPills(replyRow);
// Prefix subject
let prefix = this.mVariables[0];
let msgSubject = win.document.getElementById('msgSubject')
if (prefix && !msgSubject.value.startsWith(prefix + ':')) {
msgSubject.value = prefix + ": " + msgSubject.value;
}
// Set background color
let bgcolor = this.mVariables[1];
let doc = win.gMsgCompose.editor.document;
let body = doc.getElementsByTagName("BODY")[0];
if (bgcolor && !body.getAttribute("bgcolor")) {
body.setAttribute("bgcolor", bgcolor);
}
// Remove draft if already saved
//if (win.gMsgCompose.compFields.draftId) {
if (win.gMsgCompose.savedFolderURI == draftFolderURI) {
await win.RemoveDraft();
}
// Save to notes folder and close compose window
win.gCurrentIdentity.draftFolder = notesFolderURI;
try {
await win.SaveAsDraft();
win.gCurrentIdentity.draftFolder = draftFolderURI;
win.MsgComposeCloseWindow();
}
catch(err) {
win.gCurrentIdentity.draftFolder = draftFolderURI;
}
Usage
First create the folder Notes under your account.
The script accepts two optional arguments:
- The first one is a prefix of the subject to set.
- The second one is a background color of the message.
[SCRIPT=SaveAsNote](/jobisoft/quicktext/wiki/NOTE|#FBFEBF)