Link to home
Start Free TrialLog in
Avatar of lucavilla
lucavillaFlag for Italy

asked on

filter Outlook 2010 emails by regular expressions?

Is there an add-in for Outlook 2010 that let me filter subjects or bodies of the emails by custom regexs?
Avatar of morganmce
morganmce
Flag of Ireland image

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?
Avatar of lucavilla

ASKER

regular expressions, it's a popular "language" for defining strings with advanced wildcards, see here: http://www.regular-expressions.info/ 
@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).
Avatar of Chris Bottomley
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
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?
In that case do you want to look at incoming mails and pass / fail them according to a criteria expressed as a regex?

Chris
exactly Chris
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
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.
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
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...
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
well so... if you have a working solution to add rules in Outlook based on regular expressions I would be interested
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

I searched for a graphic (GUI) solution but I'm grateful to you for this GUIless solution too...
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
Thank you Chris!