Scripting Scribe

Overview
Scribe can execute scripts to extend it's functionality in the following locations: Scripts are written in a C like language, the exact syntax is described here. Scripts are stored in 2 places, either in the Script tab of a filter or as a .script file in the Scripts subfolder where the executable is located. Files with the extension ".script" in that folder are loaded and executed when Scribe starts, and they for the most part install a call back that is called when some event happens later. Scripts can print debugging information to the scripting console via the Print(...) method. That console can be openned via the Debug -> Show Scripting Console menu.

For information about what properties various objects support please consult the "Dom.txt" in the Scripts sub-folder. That file is generated from the application's source code as part of the release process so is always fully up to date for the currently installed build.

Scribe Specific Methods
These methods are defined for all scripts run within Scribe, in addition to the various scripts defined by the system library (which are available in any script enabled Lgi application).

List of system folder identifiers:
FOLDER_INBOX 0
FOLDER_OUTBOX 1
FOLDER_SENT 2
FOLDER_TRASH 3
FOLDER_CONTACTS 4
FOLDER_TEMPLATES 5
FOLDER_FILTERS 6
FOLDER_CALENDAR 7
FOLDER_GROUPS 8
FOLDER_SPAM 9
List of item types:
MAGIC_MAIL 0xAAFF0001
MAGIC_CONTACT 0xAAFF0002
MAGIC_ATTACHMENT 0xAAFF0005
MAGIC_FILTER 0xAAFF0007
MAGIC_CALENDAR 0xAAFF000b
MAGIC_GROUP 0xAAFF000d
List of system functions:
File Based Scripts
When you create a file based script in the ./Scripts subfolder it has to have the extension .script. It will only be loaded at startup, changes to the script after Scribe loads will not be loaded until next start up. Scripts should be utf-8 text with \r\n or \n end of line characters. They should have a method called "Main" and optionally one or more callback methods. The Main function should register the callback(s) via AddToolsMenuItem, AddThingMenuCallback, AddThingUiButton or AddCallback.

See the existing scripts in that folder for some examples.
Filter Based Scripts
Filter based scripts exist in the Script tab of a filter object. When the script tab has some content any existing filter conditions are ignored and the script is executed. There doesn't need to be a method defined in the script. Several pre-defined variables are available:
App The main application object.
Filter The filter being evaluated.
Mail The mail being filtered.

In your script you can call being into the filter object to evaluate the conditions in the filter against the mail object being filtered by using the syntax:

Filter.TestConditions
Which returns a boolean true of the mail matches the filter's conditions or false otherwise. Also to execute the actions attached to the filter you can call:
Filter.DoActions(Mail)
The default behaviour of a filter with no script is:
if (Filter.TestConditions)
{
    Filter.DoActions(Mail);
}
You can use that as a template to build up to the functionality you want. Alternatively you can replace Filter.DoActions(...) with a set of custom calls to manipulate objects directly from the script.

To stop further filtering of the current email use the StopFiltering method:
Filter.StopFiltering();
Specific Notes on Fields
The Mail.Flags object is a group of flags typically expressed as an Integer. However if you want to get or set a specific flag you can use a string in the array reference to specify which. The flags are as follows (case sensitive):
SENTEmail has been sent via SMTP
RECEIVEDEmail was received by POP or IMAP
CREATEDUser created email
FORWARDEDEmail has been forwarded
REPLIEDEmail has been replied to
ATTACHMENTSEmail has attachments (can be wrong if email hasn't been parsed yet, more a display hint for user)
READUser requested monospace font
READY_TO_SENDEmail is marked for sending in the next SMTP connection
READ_RECEIPTUser requested a receipt
IGNOREUser requested thread to be ignored
FIXED_WIDTH_FONTUser requested monospace font
BOUNCEDMessaged was bounced to somewhere
BOUNCEMessage IS a bounce (copy that is sent onwards)
SHOW_IMAGESUser requested external resources
BAYES_HAMCurrently classified as 'Ham' by the spam filter
BAYES_SPAMCurrently classified as 'Spam'
NEWEmail has been newly received
STORED_FLATEncrpytion implementation specific (don't use)
For example:
if (MailObj.Flags["NEW"])
    Print("New mail!\n");

The ScribeWnd.Folders field takes an array parameter to look up system folders. You can use an integer:
FOLDER_INBOX 0The mail3 Inbox.
FOLDER_OUTBOX 1The mail3 Outbox.
FOLDER_SENT 2The mail3 Sent folder.
FOLDER_TRASH 3The trash.
FOLDER_CONTACTS 4The mail3 Contacts folder.
FOLDER_TEMPLATES5The templates folder.
FOLDER_FILTERS 6The filters.
FOLDER_CALENDAR 7The primary calendar folder.
FOLDER_GROUPS 8The contact groups.
FOLDER_SPAM 9All the spam.
Or specify a path as a string. When specifying a path, it should be in the form:
/{MailStoreName}/{LocalPath}
© 1999-2018 Matthew Allen