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