Hello.

I've written a VBS script that generates a summary of the messages
treated by my TB! Incoming mail filters. My filters direct one or more
messages to various folders. I wanted one message to summarize what
each folder received.

I hope the script is self-explanatory. Most of it is comments, not
code.

I'd very much appreciate receiving suggestions. Is there an easier way
to do this in the first place? Are there any bugs? Is there a better
way to avoid multiple instances? Should the connection be monitored
differently to tell when message retrieval has completed? Is the
script usable with dial-up? What regexp can replace the line-by-line
parse of the export file? Et cetera...

regards, Andy

[Using The Bat! 1.53t under Windows 2000 Pro SP2
 on a "made from scratch" PIII-500 MHz/384 MB RAM]


Option Explicit

'this script is designed to produce a summary message showing the
'number of messages retrieved meeting the criteria of one or more
'filters
'
'to use this script, build filters and check the Actions "Export
'message to file" and "Run external program".
'
'build a template for each filter that puts the essential info about
'each filtered message into the export file. The template should
'contain a string, strToken, that can be counted to yield the total
'number of filtered messages
'
'The "strExFilDir" directory (see below) must point to the export file
'directory. The external program is this script. The exported filename
'only (not its extension) *must* be used as a command line parameter
'to this script.
'
'Ex: if the export file is to be c:\d2\fud.ext and this script is
'c:\d1\msgcollector.vbs, then:
' Export message to file: c:\d2\fud.ext
' Run external program: wscript.exe c:\d1\msgcollector.vbs fud
' strExFilDir = "c:\d2"
'
'If the same export file name is used for several filters, the
'combined filter results will be held in a single message.
'
'The script has been written using broadband. If dial-up is used,
'then intSec has to be increased to allow for slower message
'transfer speeds and this script may not be very useful.
'
'SIX CONFIGURABLE PARAMETERS
'
'EXPORT FILE DIRECTORY
Dim strExFilDir : strExFilDir = "export_file_directory"
'
'TB! ACCOUNT
'Account Inbox that will receive the summary msg
Dim strUserAcct : strUserAcct = "account_name"
'
'TB! MESSAGE
'message subject line is built later from intMsg, strFileName & strMsg (see below)
'recipient of the summary msg
Dim strTo : strTo = "your_email_address"
Dim strToken : strToken = "string_from_export_file_text"
'strToken appears in each export file macro
'Ex: if the export file macro contains the sentence:
'    "The message has been placed into the Spam folder"
'    then strToken can be "The message"
'
'SCRIPT LOOP
Dim intLoop : intLoop = 4  'number of loops
Dim intSec : intSec = 5  'number of seconds to wait, per loop, for a
'change to the export file size
'the script will run no longer than intLoop*intSec seconds. If it
'detects that the export file hasn't changed size in intSec, it will
'assume that mail retrieval has finished and generate the summary
'message.

'objects
Dim Wshso : Set Wshso = WScript.CreateObject("WScript.Shell")
Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim WshoArgs : Set WshoArgs = WScript.Arguments
Dim envProc : Set envProc = Wshso.Environment("PROCESS")
Dim oFilFile

'path strings
Dim strFileName : strFileName = Trim(CStr(WshoArgs(0)))
Dim strFilePath : strFilePath = strExFilDir & "\" & strFileName & ".txt"
Dim strTempFN : strTempFN = envProc("TEMP") & "\The Bat! " &_
 strFileName & " filter script is running.txt"

'other strings, dates & integers
Dim datFFini, datFFfin, i, strLine, strTBexe
Dim intMsg : intMsg = 0
Dim strMsg : strMsg = " Msg"

On Error Resume Next

'quit if this script already running
Dim oFN : Set oFN = Fso.OpenTextFIle(strTempFN,2,True)
If Err.Number <> 0 Then
 Set WshoArgs=Nothing
 Set Fso=Nothing
 Set Wshso=Nothing
 WScript.Quit
End If

On Error Goto 0

'create collect file if it doesn't already exist
If Not Fso.FileExists(strFilePath) Then
 Set oFilFile = Fso.OpenTextFIle(strFilePath,2,True)
 oFilFile.Close
 Set oFilFile=Nothing
End If

'get the collect file object
Set oFilFile = Fso.GetFile(strFilePath)

'save its last modified date
datFFini = oFilFile.DateLastModified

'loop for intLoop*intSec sec, intSec seconds per loop
For i = 0 to (intLoop-1)

 'wait intSec sec
 WScript.Sleep intSec*1000

 'find the current last modified date
 datFFfin = oFilFile.DateLastModified

 'if date hasn't changed
 If datFFini = datFFfin Then

  'if file contains data
  If oFilFile.Size > 0 Then

   'find number of messages
   Dim oTxtFile : Set oTxtFile = Fso.OpenTextFIle(strFilePath,1) 

   Do While Not oTxtFile.AtEndOfStream
    strLine = oTxtFile.ReadLine
    If InStr(strLine,strToken) <> 0 Then intMsg = intMsg + 1
   Loop

   oTxtFile.Close
   Set oTxtFile=Nothing

   If intMsg > 1 Then strMsg = strMsg & "s"

   Dim strMailFile : strMailFile = strExFilDir & "\" & strFileName & ".sav"

   'make backup .SAV file
   oFilFile.Copy strMailFile,TRUE

   'delete the .TXT file so filter ready for next append cycle
   oFilFile.Delete
   Set oFilFile=Nothing

   'read registry for location of thebat.exe
   strTBexe = Wshso.RegRead ("HKCU\SOFTWARE\RIT\The Bat!\EXE path")

   'send the .SAV file to The Bat!
   Wshso.Run Chr(34) & strTBexe & Chr(34) &_
    " /MAILU=" & Chr(34) & strUserAcct & Chr(34) &_
    ";TO=" & Chr(34) & strTo & Chr(34) &_ 
    ";S=" & Chr(34) & "Rcpt of " & intMsg & Space(1) & strFileName & strMsg & Chr(34) 
&_
    ";C=" & Chr(34) & strMailFile & Chr(34) &_
    ";SEND",0,TRUE

  End If  'file contains data IF

 'exit the loop
 Exit For

 'else date has changed
 Else

  'set initial date to current date
  datFFini = datFFfin

  'file date change IF
 End If

'attribute check loop
Next

'delete instance lock file
oFN.Close
Set oFN=Nothing
Set oFN = Fso.GetFile(strTempFN) 
oFN.Delete
Set oFN=Nothing

'clean up
Set envProc=Nothing
Set Fso=Nothing
Set WshoArgs=Nothing
Set Wshso=Nothing


-- 
______________________________________________________
Archives   : http://tbtech.thebat.dutaint.com
Moderators : mailto:[EMAIL PROTECTED]
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to