Solved

filter Outlook 2010 emails by regular expressions?

Posted on 2010-09-22
20
4,580 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
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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now