NotifyScriptExecute - Ein Plugin für Poptray

version 0.1 für Poptray von Enrico Schättin
Beschreibung

NotifyScriptExecute ist ein Notification-Plugin für das E-Mail Benachrichtigungsprogramm Poptray. Dieses Plugin ermöglicht es beim Empfang von E-Mails mit Poptray vordefinierte Windowsskriptfunktionen in Javascript oder Visual Basic Skript auszufüren. So ist man in der Lage z.B.:

  • den Inhalt von E-Mails in einem Verzeichnis auf der Festplatte zu speichern,
  • ein Programm bezogen auf den Inhalt und/oder mit dem Inhalt selbst zu starten,
  • eine E-Mail zu erstellen und abzusenden als eine Art automatische E-Mail-Beantwortung zu empfangenen E-Mails,
  • oder weitere Möglichkeiten mit den Informationen aus einer E-Mail und deren Inhalt ...

Man braucht nur einige Grundkenntnisse in Visual Basic Skript oder auch Javaskript, um solche Funktionalitäten in diesen Skriptsprachen zu erstellen, um das Plugin mit Leben zu füllen. Dabei ist jedoch zu bedenken, dass diese Skripte vom Plugin als serverseitige Skripte ausgeführt werden. So ist es nicht möglich, innerhalb dieser Skripte Interaktionen mit dem Desktop oder dem Benutzer auszuführen.

Anforderungen

Alles was man dazu benötigt ist das E-Mail Benachrichtigungsprogramm Poptray ab der Version 3.2. Dieses Programm steht als Download unter www.poptray.org zur Verfügung. Das Plugin nutzt den Microsoft Windows Script Host, um diese Skripte auszuführen. Dieser wird standardmäßig mit mit Windows 98 und späteren Versionen von Microsoft Windows installiert. Standardmäßig interprätiert der Skripthost JScript (.JS files) und VBScript (.VBS files) und führt diese aus. So ist es nicht notwendig weitere Programme zu installieren.

Download

Download the archive NotifyScriptExecute.zip and save it to your hard drive. Keep in mind where you saved it. For Installation you need a program to unpack the archive. How to unpack an archive you can find a description here, otherwise you can use WinZip, ExtractNow or UnZipper.

Installation
  1. Download the archive.
  2. Unpack it to the plugin directory of your Poptray installation.
  3. Close and restart PopTray.
  4. Go to the options window in PopTray and select the plugin settings and activate the plugin "Script Execution".
  5. Now the plugin should work, and you can fill out the scripts with life and functionality.
Wie funktioniert es?

This plugin is reading two script files in the plugin directory

  • NotfiyScriptExecute.vbs - contains VB-Script code
  • NotfiyScriptExecute.js - contains Javascript code

In each script the plugin is looking for following functions and if it exists the plugin will call this function:

MessageCheck (MsgFrom, MsgTo, Subject, MsgTime, Viewed, New, Important, Spam)

would be called with following parameters each time poptray retrieves a mail and reads it header information.

  • MsgFrom - contains the mail sender
  • MsgTo - contains the mail receiver
  • Subject - contains the mail subject
  • MsgTime - contains the date time
  • Viewed - is set to "1" when mail is already viewed, otherwise is set to "0"
  • New - is set to "1" when mail is new, otherwise is set to "0"
  • Important - is set to "1" when mail is signed as importent, otherwise is set to "0"
  • Spam - is set to "1" when mail is signed as spam, otherwise is set to "0"
MessageBody (MsgFrom, MsgTo, Subject, MsgTime, Viewed, New, Important, Spam, Header, Body)

would be called with following parameters each time Poptray retrieves a mail and reads it content

  • MsgFrom - contains the mail sender
  • MsgTo - contains the mail receiver
  • Subject - contains the mail subject
  • MsgTime - contains the date time
  • Viewed - is set to "1" when mail is already viewed, otherwise is set to "0"
  • New - is set to "1" when mail is new, otherwise is set to "0"
  • Important - is set to "1" when mail is signed as importent, otherwise is set to "0"
  • Spam - is set to "1" when mail is signed as spam, otherwise is set to "0"
  • Header - contains the raw header information of the mail
  • Body - contains the full body of the mail (only if the option "Download Body while Checking" is switched on.)
NotifyAccount (AccountNo, AccountName, AccountColor, MailCount, UnviewedCount, NewCount, ResetTray)

would be called with following parameters each time poptray has finished to check mails on an account.

  • AccountNo - Number of the account in your Poptray configuration
  • AccountName - Name of the account in your Poptray configuration
  • AccountColor - Color of the account in your Poptray configuration
  • MailCount - Count of all mails of this account
  • UnviewedCount - Count of unviewed mails of this account
  • NewCount - Count of news mails of this account
  • ResetTray - Reset the tray
Notify (MailCount,UnviewedCount,NewCount,ResetTray)

would be called with following parameters each time poptray has finished to check all mails on all accounts.

  • MailCount - Count of all mails of all accounts
  • UnviewedCount - Count of unviewed mails of all accounts
  • NewCount - Count of new mails of all accounts
  • ResetTray - Reset the tray
Samples or Templates

Here is a sample for Visual Basic Script and a sample for Java Script, in each sample are declared all possible functions, that would be called by the plugin. In the following samples each function does nothing. You can take these samples as templates to create your own script functionality.

NotifyScriptExecute.vbs
Function MessageCheck (MsgFrom, MsgTo, Subject, MsgTime, MsgViewed, MsgNew, Important, Spam)   'Do something with given information End Function  Function MessageBody (MsgFrom, MsgTo, Subject, MsgTime, MsgViewed, MsgNew, Important, Spam, Header, Body)   'Do something with given information End Function  Function NotifyAccount (AccountNo,AccountName,AccountColor,MailCount,UnviewedCount,NewCount,ResetTray)   'Do something with given information End Function  Function Notify (MailCount,UnviewedCount,NewCount,ResetTray)   'Do something with given information End Function   
NotifyScriptExecute.js
function MessageCheck (MsgFrom, MsgTo, Subject, MsgTime, Viewed, New, Important, Spam) {   // Do something with given information }  function MessageBody (MsgFrom, MsgTo, Subject, MsgTime, Viewed, New, Important, Spam, Header, Body) {   // Do something with given information }  function NotifyAccount (AccountNo,AccountName,AccountColor,MailCount,UnviewedCount,NewCount,ResetTray) {   // Do something with given information }  function Notify (MailCount,UnviewedCount,NewCount,ResetTray) {   // Do something with given information }   
More examples for Visual Basic Script

Below you can find a Visual Basic Script sample, that is tracing all function calls by the plugin.

NotifyScriptExecute.vbs
Function TraceFunctionCall (FileName, FileText)   Set FS = CreateObject("scripting.filesystemobject")   strFile = FileName   If Not FS.FileExists(strFile) Then     FS.CreateTextFile(strFile)   End If   Set FS = Nothing   Set FS = CreateObject("scripting.filesystemobject")   Set schreibeDatei = FS.OpenTextFile(strFile, 8)   schreibeDatei.writeline "" & Date & " " & Time & " " & FileText   schreibeDatei.close 'Schließen der Datei   Set schreibeDatei = nothing 'Objekt zerstören End Function  Function MessageCheck (MsgFrom, MsgTo, Subject, MsgTime, MsgViewed, MsgNew, Important, Spam)   TraceFunctionCall "Plugins\\NotifyScriptExecute.trc", "MessageCheck (" & MsgFrom & ", " & MsgTo & ", " & Subject & ", " & MsgTime & ", " & MsgViewed & ", " & MsgNew & ", " & Important & ", " & Spam & ")" End Function  Function NotifyAccount (AccountNo,AccountName,AccountColor,MailCount,UnviewedCount,NewCount,ResetTray)   TraceFunctionCall "Plugins\\NotifyScriptExecute.trc", "NotifyAccount (" & AccountNo & ", " & AccountName & ", " & AccountColor & ", " & MailCount & ", " & UnviewedCount & ", " & NewCount & ", " & ResetTray & ")" End Function  Function Notify (MailCount,UnviewedCount,NewCount,ResetTray)     TraceFunctionCall "Plugins\\NotifyScriptExecute.trc", "Notify (" & MailCount & ", " & UnviewedCount & ", " & NewCount & ", " & ResetTray & ")" End Function   

Below you can find a Visual Basic Script sample, that is storing all mails to a defined directory on your harddrive.

NotifyScriptExecute.vbs
Function MessageSave (MsgFrom, MsgTo, Subject, MsgTime, MsgViewed, MsgNew, Important, Spam, Header, Body)   Set FS = CreateObject("scripting.filesystemobject")   DateTimeVal = ""   If (MsgTime = "") Then     DateTimeVal = Now   Else     DateTimeVal = MsgTime   End If   strDateTime = Mid(DateTimeVal, 7, 4) & Mid(DateTimeVal, 4, 2) & Mid(DateTimeVal, 1, 2) & Mid(DateTimeVal, 12, 2) & Mid(DateTimeVal, 15, 2) & Mid(DateTimeVal, 18, 2)   strFile = "c:\\tmp\\msg_" & strDateTime & ".txt"   If Not FS.FileExists(strFile) Then     FS.CreateTextFile(strFile)   End If   Set FS = Nothing   Set FS = CreateObject("scripting.filesystemobject")   Set schreibeDatei = FS.OpenTextFile(strFile, 2)   schreibeDatei.writeline Header   schreibeDatei.writeline Body   schreibeDatei.close 'Schließen der Datei   Set schreibeDatei = nothing 'Objekt zerstören End Function  Function MessageBody (MsgFrom, MsgTo, MsgSubject, MsgTime, MsgViewed, MsgNew, Important, Spam, Header, Body) {   MessageSave MsgFrom, MsgTo, Subject, MsgTime, MsgViewed, MsgNew, Important, Spam, Header, Body End Function