Advertisement
Guest User

CreateNewRule

a guest
Mar 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $OL = New-Object -ComObject Outlook.Application
  2. $olFolderInbox = 6
  3. $ns = $ol.GetNameSpace('MAPI')
  4. $inbox = $ns.GetDefaultFolder($olFolderInbox)
  5. $MacroBlockedEmailsFolder = $inbox.Folders | where-object { $_.name -eq "Macro Blocked Emails" }
  6. $NonMaliciousFolder = $MacroBlockedEmailsFolder.Folders | where-object { $_.name -eq "Non-Malicious" }
  7. $regex = '\b[A-Za-z0-9]+[.]+[A-Za-z0-9.]+@[atos|capgemini]+\.[A-Za-z]{2,4}\b'
  8. $NonMaliciousFolder.items | Select -First 1 | foreach {
  9. If($_.body -match $regex){
  10. $rules = $OL.session.DefaultStore.GetRules()
  11. $rule = $rules.Create($matches[0],$olRuleType::OlRuleReceive)
  12. $bodyCondition = $rule.Conditions.Body
  13. $bodyCondition.Enabled = $true
  14. $bodyCondition.Text.Add($matches[0])
  15. $bodyCondition.Text.ResolveAll()
  16. $moveRuleAction = $rule.actions.MoveToFolder
  17. $moveRuleAction.Folder = $NonMaliciousFolder
  18. $moveRuleAction.Enabled = $true
  19. $rules.save()
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement