#6443
Support 2
Moderator

Please let us know if you have any questions.

Regards,

Advansys Support


'-------------------------------------------------------------------------------
' Formativ Solutions for GroupWise
' Store messages into file
' Designed by: Formativ Business Solution Team
' Copyright (c) 2002 Advansys Corporation (www.advansyscorp.com)
' Version 1.0
'
' Description:
' This applet will store the incoming messages and file type attachments. You need
' to replace the constant value MARKER with the text the applet will search for each message's subject.
' You need to provide the folder path where the messages will be saved. This applet
' will save the file with an unique id using current date time stamp (eg test_020314153920.doc).
' Change the constant value UNIQUE_NAME to false if you do not want the unique id. Change
' the constant CONFIRMATION_DIALOG to false if you do not want to display any confirmation
' dialog.
'
' INTEGRATIONS: This applet requires integration with GroupWise message arrival and
' On Startup.
'-------------------------------------------------------------------------------


' The text applet will search in the message's subject
const MARKER = "F023"
' Set the file extension
const FILE_EXTENSION = ".doc"
' the folder where the messages will be saved
const FOLDER = "c:"
' Produce a unique name for each file (Using date time stamp)
const UNIQUE_NAME = TRUE
' Save the file type attachments
const SAVE_FILE_TYPE_ATTACHMENTS = TRUE
' Display the confirmation dialog at the end
const CONFIRMATION_DIALOG = TRUE

const CAPTION = "Formativ Business Solutions"
HRT = Chr(13) & Chr(10)
FILE_NAME = Utilities.GetDataDirectory & "CheckOnce.ol"

'-------------------------------------------------------------------------------
' Main line processing
'-------------------------------------------------------------------------------
Sub Main(Client, GWEvent)

dim iMessageClass

if (FOLDER <> "") and (MARKER <> "") and (FILE_EXTENSION <> "") then
set iMessageClass = new MessageClass
' Perform the processing
iMessageClass.DetermineAction
set iMessageClass = nothing
end if

End Sub


'-------------------------------------------------------------------------------
' Message class
'-------------------------------------------------------------------------------
Class MessageClass

private iFSO
private iMailBox
private iMessagesCount
private iMessagesObj
private iCommander
private iStatusDlg

' Constructor
private sub class_initialize
set iMailBox = GroupWise.Account.MailBox
Set iStatusDlg = Utilities.NewStatusDialog
Set iFSO = CreateObject("Scripting.FileSystemObject")
Set iCommander = CreateObject("GroupWiseCommander")
end sub

' Destructor
private sub class_terminate
set iFSO = nothing
set iStatusDlg = nothing
set iMailBox = nothing
set iMessagesObj = nothing
set iCommander = nothing
end sub


' Get the current date time
private function GetCurrentDateTime
iDay = Day(date)
if len(iDay) = 1 then
iDay = "0" & iDay
end if

iMonth = Month(date)
if len(iMonth) = 1 then
iMonth = "0" & iMonth
end if

iYear = Year(date)
if len(iYear) > 2 then
iYear = right(iYear, 2)
end if

iTime = FormatDateTime(Time, vbShortTime)
iTime = Replace(iTime, ":", "")
iTime = Replace(iTime, ",", "")
iTime = Replace(iTime, " ", "")

GetCurrentDateTime = "_" & iYear & iMonth & iDay & iTime & Second(Now)
end function

' Store each message
private sub StoreMessages
with iStatusDlg
.MainText = "Saving messages ..."
.ProgressRange = iMessagesCount
.Show
end with

for x = 1 to iMessagesCount
set iMsg = iMessagesObj.Item(x)
if isobject(iMsg) then
iFileName = GetFileName(iMsg.Subject)
if iFileName <> "" then
' Save the message into the file. You can set the file format as (Ansitext - fmtAnsitexts) or (Word perfect 6 - fmtWordPerfect60)
iToken = "ItemSaveMessage(""" & iMsg.MessageID & """;""" & iFileName & """;" & fmtWordPerfect60 & ")"
' Execute the token through the commander
Call iCommander.Execute(iToken, "")
' You can also save the file type attachments as follow:
if (iMsg.attachments.count > 0) and SAVE_FILE_TYPE_ATTACHMENTS then
for iNum = 1 to iMsg.attachments.count
set iAttachment = iMsg.attachments.item(iNum)
if iAttachment.ObjType = fgwFile then
iAttachment.save(FOLDER & iAttachment.FileName)
end if
set iAttachment = nothing
next
end if
end if
iStatusDlg.ProgressPosition = x
iStatusDlg.StatusText = "Subject: " & iMsg.Subject
end if
' Mark this message as read
iMsg.Read = TRUE
set iMsg = nothing
next
iStatusDlg.Hide
end sub


' Set the file name with the file extension
private function GetFileName(aSubject)

' Replace some characters which not acceptable as the file name
aSubject = replace(aSubject, "/", "")
aSubject = replace(aSubject, "", "")
aSubject = replace(aSubject, "*", "")
aSubject = replace(aSubject, "?", "")
aSubject = replace(aSubject, """", "")
aSubject = replace(aSubject, "'", "")
aSubject = replace(aSubject, "<", "")
aSubject = replace(aSubject, ">", "")
aSubject = replace(aSubject, "|", "")
aSubject = replace(aSubject, ":", "")

' Produce a unique file name for each messages using the current date time and second
if UNIQUE_NAME then
GetFileName = FOLDER & aSubject & GetCurrentDateTime & FILE_EXTENSION
else
GetFileName = FOLDER & aSubject & FILE_EXTENSION
end if

end function


' Determine what action we have to take. Do we have to check all messages
' or only the unread messages.
public sub DetermineAction
if iFSO.FileExists(FILE_NAME) then
iFilter = ("(MAIL)AND(BOX_TYPE = INCOMING)AND(NOT READ)AND(SUBJECT CONTAINS """ & MARKER & """)")
Set iMessagesObj = iMailBox.FindMessages(iFilter)
iMessagesCount = iMessagesObj.Count
if iMessagesCount > 0 then
StoreMessages
end if
else
iFilter = ("(MAIL)AND(BOX_TYPE = INCOMING)AND(SUBJECT CONTAINS """ & MARKER & """)")
Set iMessagesObj = iMailBox.FindMessages(iFilter)
iMessagesCount = iMessagesObj.Count
if (iMessagesCount > 0) then
StoreMessages
end if
end if

' Display confirmation dialog
if (iMessagesCount > 0) and CONFIRMATION_DIALOG then
call msgbox("Messages saved." & HRT & "Folder: " & FOLDER, vbInformation, CAPTION)
end if
end sub

end class