?
Solved

filter Outlook 2010 emails by regular expressions?

Posted on 2010-09-22
20
Medium Priority
?
5,570 Views
Last Modified: 2012-05-10
Is there an add-in for Outlook 2010 that let me filter subjects or bodies of the emails by custom regexs?
0
Comment
Question by:lucavilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
20 Comments
 
LVL 9

Expert Comment

by:morganmce
ID: 33739061
What sort of expressions are you looking to search by?

I assume you have come across the options available under View -> View settings -> Filter -> and then Advanced or SQL tabs?
0
 

Author Comment

by:lucavilla
ID: 33739734
regular expressions, it's a popular "language" for defining strings with advanced wildcards, see here: http://www.regular-expressions.info/ 
0
 
LVL 13

Expert Comment

by:gbanik
ID: 34223858
@lucavilla, is there a reason why you are looking specifically for regular expressions??

If "search" is your criteria, I would highly recommend Google Desktop Search. Google Desktop gets integrated with Outlook (optional component) and opens an interface within Outlook (other than the normal Desktop Search). It is an excellent tool to search anything you like - subject, body, recipients, dates, all.

Try it. (And uninstall it if you dont like it... most likely you wont).
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34225419
It is possible to use wild crds in filters ... but not as part of regular expression ... to my knowledge.

Can you put more flesh on what you're trying to do ... and hopefully we can create a filter to help.

Chris
0
 

Author Comment

by:lucavilla
ID: 34771491
My need is to filter some specific annoying series of spam messages that cross my ISP and Outlook antispam filters.
I would filter this spam using some fine-tuned regular expressions.
So the question is still open: is there an add-in for Outlook 2010 that let me filter subjects or bodies of the emails by custom regexs?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34771883
In that case do you want to look at incoming mails and pass / fail them according to a criteria expressed as a regex?

Chris
0
 

Author Comment

by:lucavilla
ID: 34776109
exactly Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34776710
DO you have a regex to do the filtering ... and will it be applied to the subject and or body of the incoming?

My working premise is a rule that fires on all incoming emails ... you would need to do that of course and fires a script ... me/us to create but easy enough.  This script then uses the regex to decide if the email should be deleted straight off or not ... ideally dropped in the deleted items folder for later permanent deletion.

If the goal is in fact to move the mails to specific folders then that too could be done.

Chris
0
 

Author Comment

by:lucavilla
ID: 34796110
Ideally I should have the choice to specify a regex for subject and a regex for body, for each spam email model.

I should have the possibility to create and activate a list of (couple of) regex(es), one for each model of spam email that I want to contrast.

It should accept regexes like for example "^.{0,20}\bv *i *a * g *r *a *\b.{0,20}$" where "^" is the beginning of the subject or body and "$" the end.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34797275
IN VBA terms the beginning and end do not work the same but yes that is certainly still sounding possible.

What we can do is create a sub that you call via a rule which is fired for all incoming mails and then runs one or more checks using regular expressions that you define.  This being so then I believe we can move forwards.

Ideally if you can provide the expressions and some sample mail bodies / subjects then I / we can test them as part of the operation.

Chris
0
 

Author Comment

by:lucavilla
ID: 34827247
Are you sure that the regular expression engine in VBA doesn't support "^" and "$"?
I thought they were special characters supported in all the regular expression engines...
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34828956
Beg your pardon looks like they do ... I have have some issues with them so discount them ... thouh that may be my skill level!

As I said though - can do irrespective

Chris
0
 

Author Comment

by:lucavilla
ID: 34841218
well so... if you have a working solution to add rules in Outlook based on regular expressions I would be interested
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 34841312
The following is a rule that you can populate with your regex, (replace the string ".*" i.e. .* with your own regex but remember to wrap it in quotes) ... the check for body is as therein  to check for subject then of course:

str = findPatt(mai.subject, ".*")

Tweaks beyond this of course then please supply details

Chris
Sub ee_answers(mai As MailItem)
Dim str As String

    str = findPatt(mai.body, ".*")
    Debug.Print str
    
End Sub

Function findPatt(str As String, patt As String) As String
Dim regex As Object
Dim matches As Variant
Dim ln As Variant
    
    Set regex = CreateObject("vbscript.regexp")
    With regex
        .Global = True
        .IgnoreCase = True
        .MultiLine = True
        .Pattern = patt
    End With
    Set matches = regex.Execute(LCase(str))
    For Each ln In matches
        If ln <> vbCr And ln <> vbLf & vb <> ht And ln <> "" Then
            Debug.Print ln
        End If
    Next
    
End Function

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34841347
Sorry grabbed some old code without testing for your specific ... modified to simply test for the string pattern and return true/false accordingluy so in ee_answers you would then simply test the return value to move or delete your subject mail according to your wishes.

Chris
Sub ee_answers(mai As MailItem)
Dim str As String

    str = findPatt(mai.body, ".*")
    Debug.Print str
    
End Sub

Function findPatt(str As String, patt As String) As String
Dim regex As Object
    
    Set regex = CreateObject("vbscript.regexp")
    With regex
        .Global = True
        .IgnoreCase = True
        .MultiLine = True
        .Pattern = patt
    End With
    findPatt = regex.test(str)
    
End Function

Open in new window

0
 

Author Closing Comment

by:lucavilla
ID: 34841742
I searched for a graphic (GUI) solution but I'm grateful to you for this GUIless solution too...
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34841804
I would imagine there will be a commercial application somewhere but it is the coding side I enjoy and hence i'm glad to have helped.

Chris
0
 

Author Comment

by:lucavilla
ID: 34846943
Thank you Chris!
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question