Script: GetMailBody - jobisoft/quicktext GitHub Wiki

Sometimes, you want to perform action based on some item(s) present(s) in the body of the mail. For now, Quicktext has no shortcut to access it. Here is a short script that return you the body in plaintext or html format. It is also possible to return only the current selection.

Script

GetMailBody

var editor = this.mWindow.gMsgCompose.editor;
var text = editor.outputToString('text/plain', 0);
return text;

The two parameters formatType = 'text/plain' and flags = 0 of the function outputToString can be tweaked like documented here. For example using the following line would return the current selection as html:

var text = editor.outputToString('text/html', 1);

First parameter formatType:

  • 'text/plain' return unformatted content (text)
  • 'text/html' return formatted content (html)

Second parameter flags can be combined (for example 1 + 8 = 9) from the following values:

  • 0 no special behaviour
  • 1 OutputSelectionOnly
  • 2 OutputFormatted
  • 4 OutputRaw
  • 8 OutputBodyOnly
  • 16 OutputPreformatted
  • 32 OutputWrap
  • 64 OutputFormatFlowed
  • 256 OutputEncodeW3CEntities
  • 258 OutputAbsoluteLinks
  • 512 OutputCRLineBreak
  • 1024 OutputLFLineBreak
  • 2048 OutputNoScriptContent
  • 4096 OutputNoFramesContent
  • 8192 OutputNoFormattingInPre
  • 16384 OutputEncodeBasicEntities
  • 32768 OutputEncodeLatin1Entities
  • 65536 OutputEncodeHTMLEntities
  • 131072 OutputPersistNBSP

Usage

Then, you can now use it to retrieve the body text in any other script:

MyWonderfulScript

text = await this.mQuicktext.get_script(["GetMailBody"])

//process the text string as you wish

An example for use with schleuder mailing list is explain here: Script: SchleuderResend.