jobisoft / quicktext

An extension for Thunderbird that lets you create templates that can be easily inserted into your own emails.
Mozilla Public License 2.0
187 stars 53 forks source link

How to include greeting for each addressee? #339

Closed ReaderGuy42 closed 1 year ago

ReaderGuy42 commented 1 year ago

See below for the scripts I use, which are adapted from your wiki or other threads.

I'd like to have the script include a "Dear" for each addressee, so each person I add to the message as an email address.

So far it looks like this Dear Mike, Stephen if I've added emails for Mike and Stephen. But is there a way so it'd look like Dear Mike, dear Stephen?

Scripts:

EN-TemplateByTypeSemiFormal

// get subject from email if possible
if(!this.mWindow.document.getElementById('msgSubject')) return "";
let subject = this.mWindow.document.getElementById('msgSubject').value;

// detect first prefix
let firstPrefix = "";
firstPrefix="";
if(subject.toLowerCase().startsWith("re: "))  firstPrefix = "Re: ";
if(subject.toLowerCase().startsWith("fwd: ")) firstPrefix = "Fwd: ";

// search and remove all prefixes
let previousLength = 0;
while(previousLength != subject.length) { // repeat the process if something gets shortened
  previousLength = subject.length;

  subject = subject.replace(/^(re:\s|r:\s|aw:\s|antw:\s|antwort:\s)/i, "");    
// replace "Re: ", "R: ", "Aw: ", "Antw: ", "Antwort: "
  subject = subject.replace(/^(fwd:\s|fw:\s|wg:\s|wt:\s|wtrlt:\s)/i, "");      
// replace "Fwd: ", "Fw: ", "Wg: ", "Wt: ", "Wtrlt: "
  subject = subject.replace(/^(Re-\d:\s|Re\[\d\]:\s)/i, "");                   
// replace "Re-1: ", "Re-2: ", "Re[1]: ", "Re[2]: "
  subject = subject.replace(/^(\*\*\*\*SPAM\*\*\*\*\s|\[SPAM\]\s)/i, "");      
// replace "****Spam**** ", "[Spam] "
  subject = subject.replace(/^(Automatische Antwort:\s)/i, "");                
// replace "Automatische Antwort: "
  subject = subject.replace(/^(\[Extern]\s-\s|\[Extern]\s|\[Extern]:\s)/i,""); 
// replace "[Extern] - ", "[Extern] ", "[Extern]: "
  subject = subject.replace(/^(\[Probable Suspicious URLs\]\s)/i,"");          
// replace "[Probable Suspicious URLs] "
  subject = subject.trim();
}

// reuse first prefix and change subject
subject = firstPrefix + subject;
this.mWindow.document.getElementById('msgSubject').value = subject;

//GetMailBody script to replece selected text with template + that same text
var editor = this.mWindow.gMsgCompose.editor;
var text = editor.outputToString('text/html', 1);

switch(firstPrefix){
case "":
return "[[SCRIPT=EN-GoodMorningSemiFormal]]"+text+"[[CURSOR]][[FILE=/home/ReaderGuy/.thunderbird/signatures/EN-semisignature.html]]"
break;
case "Re: ":
return "[[SCRIPT=EN-GoodMorningSemiFormal]]"+text+"[[CURSOR]][[FILE=/home/ReaderGuy/.thunderbird/signatures/EN-response.html]]"
break;
case "Fwd: ":
return "[[SCRIPT=EN-GoodMorningSemiFormal]]"+
"[[CURSOR]][[FILE=/home/ReaderGuy/.thunderbird/signatures/EN-response.html]]";

}

EN-GoodMorningSemiFormal

var date = new Date();
if (date.getHours() <  5) return "Dear [[TO=firstname]],";
if (date.getHours() < 12) return "Dear [[TO=firstname]],";
if (date.getHours() < 16) return "Dear [[TO=firstname]],";
if (date.getHours() < 21) return "Dear [[TO=firstname]],";

return "Dear [[TO=firstname]],";

Any ideas? Thanks!

SamuelPlentz commented 1 year ago

How about: Dear [[TO=firstname|, dear ]], or: Dear [[TO=firstname|,\ndear ]],

ReaderGuy42 commented 1 year ago

Wow that was quick and it works! Would you mind briefly explaining how that works? Because I'm not seeing a second variable for the second name.

SamuelPlentz commented 1 year ago

Have a look here: https://github.com/jobisoft/quicktext/wiki/List-of-all-supported-tags#to There are several Parameters possible for TO. In this case Dear [[TO=firstname|, dear ]], the first parameter is firstname and the second parameter is , dear

ReaderGuy42 commented 1 year ago

Thanks :)