I messed up with the version that I attached previously (it lacked the clean up process for the -temp file that was being used to rename the file before moving it). This version has that process included. Sorry about the confusion that this might have created.

Matt

--
=====================================================
MailPure custom filters for Declude JunkMail Pro.
http://www.mailpure.com/software/
=====================================================

Dim fso
Dim sYY, sYYYY, sMM, sDD
Dim sIMailDir, sJunkMailDir, sVirusDir, sSnifferDir, sORFDir
Dim sIMailName, sJunkMailName, sVirusName, sSnifferName, sSnifferRename, 
sORFName
Dim sIMailStamp, sJunkMailStamp, sVirusStamp, sSnifferStamp, sORFStamp
Dim sIMailExt, sJunkMailExt, sVirusExt, sSnifferExt, sORFExt
Dim sIMailDest, sJunkMailDest, sVirusDest, sSnifferDest, sORFDest


'---------------------------------------------------------------------------
' Generate Variables
'---------------------------------------------------------------------------
' Populate the Date strings
If DatePart("h", Now()) > 0 Then
        sYY = Right(DatePart("yyyy", Now()), 2)
        sYYYY = DatePart("yyyy", Now())

        If DatePart("m", Now()) < 10 Then
                sMM = "0" & DatePart("m", Now())
        Else
                sMM = DatePart("m", Now())
        End If

        If DatePart("d", Now()) < 10 Then
                sDD = "0" & DatePart("d", Now())
        Else
                sDD = DatePart("d", Now())
        End If
Else
        sYY = Right(DatePart("yyyy", DateAdd("h", -1, Now())), 2)
        sYYYY = DatePart("yyyy", DateAdd("h", -1, Now()))

        If DatePart("m", DateAdd("h", -1, Now())) < 10 Then
                sMM = "0" & DatePart("m", DateAdd("h", -1, Now()))
        Else
                sMM = DatePart("m", DateAdd("h", -1, Now()))
        End If

        If DatePart("d", DateAdd("h", -1, Now())) < 10 Then
                sDD = "0" & DatePart("d", DateAdd("h", -1, Now()))
        Else
                sDD = DatePart("d", DateAdd("h", -1, Now()))
        End If

End If


' Assign directories
sIMailDir = "F:\"
sJunkMailDir = "F:\"
sVirusDir = "F:\"
sSnifferDir = "C:\IMail\Declude\Sniffer\"
sORFDir = "F:\"


' Assign file name prefixes
sIMailName = "log"
sJunkMailName = "spam"
sVirusName = "virus"
sSnifferName = "your-sniffer-code"
sSnifferRename = "sniffer"
sORFName = "orf"


' Assign file name stamps
sIMailStamp = sMM & sDD
sJunkMailStamp = sMM & sDD
sVirusStamp = sMM & sDD
sSnifferStamp = sMM & sDD
sORFStamp = sMM & sDD


' Assign extensions
sIMailExt = ".txt"
sJunkMailExt = ".log"
sVirusExt = ".log"
sSnifferExt = ".log"
sORFExt = ".log"


' Assign destination directories
sIMailDest = "W:\IMail\"
sJunkMailDest = "W:\Spam\"
sVirusDest = "W:\Virus\"
sSnifferDest = "W:\Sniffer\"
sORFDest = "W:\ORF\"


'---------------------------------------------------------------------------
' Main Script
'---------------------------------------------------------------------------
'Create the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")


' Rename to temporary and combine files with those in the destination folder, 
or just move them if current file does not exist
Call CombineOrMove(sIMailDir & sIMailName & sImailStamp & sIMailExt, 
sIMailDest, sIMailName & sImailStamp & sIMailExt)
Call CombineOrMove(sJunkMailDir & sJunkMailName & sJunkMailStamp & 
sJunkMailExt, sJunkMailDest, sJunkMailName & sJunkMailStamp & sJunkMailExt)
Call CombineOrMove(sVirusDir & sVirusName & sVirusStamp & sVirusExt, 
sVirusDest, sVirusName & sVirusStamp & sVirusExt)
Call CombineOrMove(sSnifferDir & sSnifferName & sSnifferExt, sSnifferDest, 
sSnifferRename & sSnifferStamp & sSnifferExt)


' At midnight, move the ORF log to archive and copy a version of the Sniffer 
log file for uploading
If DatePart("h", Now()) = 0 Then
        fso.CopyFile sSnifferDest & sSnifferRename & sSnifferStamp & 
sSnifferExt, sSnifferDest & "your-sniffer-code.log"
        fso.MoveFile sORFDir & sORFName & sORFStamp & sORFExt, sORFDest & 
sORFName & sORFStamp & sORFExt
End If


' Zip up files at 2 a.m.
If DatePart("h", Now()) = 2 Then
        sYY = Right(DatePart("yyyy", DateAdd("h", -3, Now())), 2)
        sYYYY = DatePart("yyyy", DateAdd("h", -3, Now()))

        If DatePart("m", DateAdd("h", -3, Now())) < 10 Then
                sMM = "0" & DatePart("m", DateAdd("h", -3, Now()))
        Else
                sMM = DatePart("m", DateAdd("h", -3, Now()))
        End If

        If DatePart("d", DateAdd("h", -3, Now())) < 10 Then
                sDD = "0" & DatePart("d", DateAdd("h", -3, Now()))
        Else
                sDD = DatePart("d", DateAdd("h", -3, Now()))
        End If

        sIMailStamp = sMM & sDD
        sJunkMailStamp = sMM & sDD
        sVirusStamp = sMM & sDD
        sSnifferStamp = sMM & sDD
        sORFStamp = sMM & sDD

wscript.echo(sIMailStamp)

        Call DoZip(sIMailDest, sIMailName & sImailStamp, sIMailExt)
        Call DoZip(sJunkMailDest, sJunkMailName & sJunkMailStamp, sJunkMailExt)
        Call DoZip(sVirusDest, sVirusName & sVirusStamp, sVirusExt)
        Call DoZip(sSnifferDest, sSnifferRename & sSnifferStamp, sSnifferExt)
        Call DoZip(sORFDest, sORFName & sORFStamp, sORFExt)
End If


'Destroy the FileSystemObject
Set fso = Nothing




'---------------------------------------------------------------------------
' Sub:          CombineOrMove
' Contents:     Moves a file to a temporary directory
' Arguments:    Source file, destination directory, destination file name
' Returns:      No value
'---------------------------------------------------------------------------
Sub CombineOrMove(ByVal sSource, ByVal sDestinationDir, ByVal sDestinationFile)
Dim oFileName
Dim oSource
Dim oDestination


' Disable error handling
On Error Resume Next


' Rename the specified file, retry after 5 seconds if error is found, limit to 
30 tries.
intRetry = 30
Do While intRetry > 0
        Set oFileName = fso.GetFile(sSource)
        oFileName.Name = Right(sSource, Len(sSource) - InstrRev(sSource, "\", 
-1, 1)) & "-temp"
        If Err <> 0 Then
                WScript.Sleep 5000
                Err.Clear
                intRetry = intRetry - 1
        Else
                intRetry = -1
        End If
Loop

' Quit the script if it has retried the rename operation 30 times
If intRetry = 0 Then
        WScript.Quit(0)
End If


' Re-enable error handling and close the oFileName object
On Error GoTo 0
Set oFileName = Nothing


' Combine or move the contents
If (fso.FileExists(sDestinationDir & sDestinationFile)) Then
        Set oSource = fso.OpenTextFile(sSource & "-temp", 1, False)
        Set oDestination = fso.OpenTextFile(sDestinationDir & sDestinationFile, 
8, True)

        Do While Not oSource.AtEndOfStream
                oDestination.WriteLine oSource.ReadLine
        Loop

        oSource.Close
        oDestination.Close
Else
        fso.MoveFile sSource & "-temp", sDestinationDir & sDestinationFile
End If


' Delete the -temp file if it exists
If (fso.FileExists(sSource & "-temp")) Then
        fso.DeleteFile(sSource & "-temp")
End If


End Sub


'---------------------------------------------------------------------------
' Sub:          DoZip
' Contents:     Moves a file to a temporary directory
' Arguments:    Directory, file name, file extension
' Returns:      No value
'---------------------------------------------------------------------------
Sub DoZip(ByVal sDirectory, ByVal sFileName, ByVal sExtension)

set shell = WScript.CreateObject("WScript.Shell")
shell.run "C:\Progra~1\WinZip\wzzip -m -ybc " & sDirectory & sFileName & ".zip 
" & sDirectory & sFileName & sExtension
Set shell = Nothing

End Sub

Reply via email to