• Creator
    Topic
  • #4069
    stuartcross
    Participant

    We have the requirement to create a standard rule in users mailboxes. This rule is to be set up to forward emails to a particular user if they meet certain criteria. We would like to forward the mails if the mail is from ‘Admin User’ or the mail contains ‘FAX’ in the from address and the subject contains ‘Received from’. The code I am using is below:

    Sub Main(Client, GWEvent)

    Dim hFilter

    hFilter = GroupWise.FilterCreate(fttInbox, TRUE)
    call GroupWise.FilterSetText(hFilter, fldFrom, “Admin User”, matSubtext, “”, “”)
    call GroupWise.FilterGroupMarker(hFilter, bopOr)
    call GroupWise.FilterGroupBegin(hFilter, bopAnd)

    call GroupWise.FilterSetText(hFilter, fldFrom, “FAX”, matSubtext, “”, “”)
    call GroupWise.FilterSetText(hFilter, fldSubject, “Received From”, matSubtext, “”, “”)

    call GroupWise.FilterGroupEnd(hFilter)

    Call GroupWise.RuleCreate(“”, “TEST”, racNewItem, “”, hFilter, btoDontCare)

    Call GroupWise.RuleAddActionForward(“”,”TEST”,”gwadmin”,””,””,”Forwarded by Fax Rule”,””,””,””)

    End Sub

    This will create a rule called ‘TEST’ with what looks like the correct logic. However, when emails are received with the correct settings they are not forwarded.

    If I edit the Filters to only include the From ‘Admin USer’ section then it will work and the same for the other section. It is only when they are both put together that the probelm arises.

    Any thoughts on where I am going wrong? Any help would be greatly appreciated.

  • Author
    Replies
  • #7005
    Support 1
    Participant

    Thank you for your enquiry.

    I created a Formativ applet to run your code. Then I opened the GroupWise rule editor (Tools | Rules | select rule | Edit…), and it displays the following filter expression:

    Act on items where
    (From  contains 'Admin User') OR
    (From  contains 'FAX' and Subject  contains 'Received From')

    I found that on sending a message with From = ‘Admin User’, the rule did nothing. Same with From = ‘FAX’ and Subject = ‘Received From Bill & Ben’.

    Then I tried creating the same rule manually, using the rule editor. Same filter expression, same action, and it works!

    I’m told that using parentheses in a filter expression, ie. with FilterGroupMarker() is flaky. It seems to work manually but not via the API.

    The following modified version of your applet appears to do the job. As I understand your requirement, the resulting filter condition is not strictly correct (correctness requires parentheses). It just happens to work because of the order of terms in the expression.

      dim hFilter
    
      hFilter = GroupWise.FilterCreate(fttInbox, true)
    
      call GroupWise.FilterGroupBegin(hFilter, bopOr)
      call GroupWise.FilterSetText(hFilter, fldFrom, "Admin User", matSubtext, "", "")
    
      call GroupWise.FilterGroupBegin(hFilter, bopAnd)
      call GroupWise.FilterSetText(hFilter, fldFrom, "FAX", matSubtext, "", "")
      call GroupWise.FilterSetText(hFilter, fldSubject, "Received From", matSubtext, "", "")
    
      call GroupWise.RuleCreate("", "TEST", racNewItem, "", hFilter, btoDontCare)
      call GroupWise.RuleAddActionForward("", "TEST", "gwadmin", "", "", _
        "Forwarded by Fax Rule", "", "", "")
    
      ' Delete the filter handle
      GroupWise.FilterDelete(hFilter)

    Interestingly, the above works even though FilterGroupEnd() is not used.

    I hope this helps you.

    Advansys Support

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.