/ Forums / Advansys Formativ / Creating Solutions with Formativ / Save message text to a file

  • Creator
    Topic
  • #3868
    B.Olds
    Participant

      I am trying to write an applet that checks incoming messages and if they have a certain subject field, saves the message text to a file. I used your Virus scanning applet as a base and have all except the last function seems to work. I have 2 problems.
      1) Although the applet finds the correct message(s) they are not selected
      2) Despite many attempts I can’t seem to get the savemessage command to work (unless I get it to display the dialog box. It either complains about the syntax or does nothing at all.

      Also I would like the message to show as read after the message text is saved.

      Can you help?

      Code:



      ‘ Insert your comments here



      ‘Global variables
      dim Msg
      dim HRT
      dim FSO
      dim iCount
      dim FILENAME
      dim StringList
      dim MailBoxObj
      dim NewMsgObj
      dim NewMailCount
      dim AttachmentName

      DEFAULTFOLDER = Utilities.GetDataDirectory

      const CAPTION = “Groupwise Solutions”
      HLine = “____________________________________________________________________________”

      ”””””””””””””””””””””””””””””””””””””””’
      ‘ Mainline processing
      ”””””””””””””””””””””””””””””””””””””””’
      Sub Main(Client, GWEvent)

      dim StatusDlg
      dim sFilter
      HRT = Chr(13) & Chr(10)

      FILENAME = DEFAULTFOLDER&”CheckOnce.ol”
      set StringList = Utilities.StringList
      set FSO = CreateObject(“Scripting.FileSystemObject”)

      ‘ Check all messages first and create a file. If file exists then only check the
      ‘ incoming messages.

      if FSO.FileExists(FILENAME) then
      CheckNewMessages
      else
      sFilter = (“(MAIL)AND(BOX_TYPE = INCOMING)”)
      Set MailBoxObj = GroupWise.Account.MailBox.FindMessages(sFilter)
      iCount = MailBoxObj.Count
      if (iCount > 1) then
      CheckAllInboxMessages
      end if
      set MailBoxObj = nothing
      end if

      ‘ Cleanup all object we created in startup
      set FSO = nothing
      set StringList = nothing

      end sub

      ”””””””””””””””””””””””””””””””””””””””
      ‘ Check all inbox messages.
      ‘ This function will run once only. Next time only received mail will check.
      ”””””””””””””””””””””””””””””””””””””””
      sub CheckAllInboxMessages

      dim ReadVal
      dim MailFound

      On Error Resume Next
      Set StatusDlg = Utilities.NewStatusDialog
      StatusDlg.ProgressRange = iCount
      StatusDlg.Title = CAPTION
      StatusDlg.CanCancel = TRUE
      StatusDlg.Show

      ‘ set each message object
      for x = 1 to iCount
      set Msg = MailBoxObj.Item(x)
      ‘Store read property
      ReadVal = Msg.Read
      MessageCheck
      ‘ Check mail for the correct message

      StatusDlg.ProgressPosition = x
      StatusDlg.MainText = “Mails checked: “&x
      StatusDlg.StatusText = “Sender: “&Msg.Sender.DisplayName

      ‘ Quit whole process if user select to exit
      if StatusDlg.Cancel then
      StatusDlg.Hide
      exit sub
      end if

      ‘Set the read property
      Msg.Read = ReadVal

      set Msg = nothing
      next

      ‘ create the file so we don’t check all message next time.
      dim TextStream
      set TextStream = FSO.CreateTextFile(FILENAME)
      TextStream.Write(“Created by – Message Check applet. Date: “&now)
      TextStream.Close
      set TextStream = nothing

      StatusDlg.Hide
      set Msg = nothing
      set StatusDlg = nothing

      GroupWise.Account.MailBox.Refresh

      end sub

      ”””””””””””””””””””””””””””””””””””””””’
      ‘ Check only new mails
      ”””””””””””””””””””””””””””””””””””””””’
      function CheckNewMessages

      dim sFilter

      sFilter = (“(MAIL)AND(BOX_TYPE = INCOMING)AND(NOT READ)”)

      On Error Resume Next
      Set NewMsgObj = GroupWise.Account.MailBox.FindMessages(sFilter)
      NewMailCount = NewMsgObj.Count

      if NewMailCount> 0 then
      CheckMail
      end if

      set NewMsgObj = nothing

      GroupWise.Account.MailBox.Refresh

      end function

      ”””””””””””””””””””””””””””””””””””””””’
      ‘ Check new mail
      ”””””””””””””””””””””””””””””””””””””””’
      function CheckMail

      dim ReadVal

      for x = 1 to NewMailCount
      set Msg = NewMsgObj.Item(x)
      ‘Store read property
      ReadVal = Msg.Read
      MessageCheck
      Msg.Read = ReadVal
      set Msg = nothing
      next

      end function

      ”””””””””””””””””””””””””””””””””””””””’
      ‘ This function will check for the right message and save it to a message file
      ”””””””””””””””””””””””””””””””””””””””’
      function MessageCheck
      If Msg.Subject = “BCP status report” then
      Set MsgSubj = Msg.Subject
      MsgBox(“found it” + ” ” + MsgSubj)
      ‘GroupWise.ItemSaveMessage (“X00”, “C:Testtestsave.mlm”, 106)
      ‘GroupWise.ItemSaveMessage(Msg, “C:Testtestsave.mlm”, 106)
      GroupWise.ItemSaveMessageDlg
      ReadVal = TRUE
      end if
      end function

    • Author
      Replies
    • #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
      Viewing 1 replies (of 1 total)
      • You must be logged in to reply to this topic.