• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6051
  • Last Modified:

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?
0
lucavilla
Asked:
lucavilla
1 Solution
 
morganmceCommented:
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
 
lucavillaAuthor Commented:
regular expressions, it's a popular "language" for defining strings with advanced wildcards, see here: http://www.regular-expressions.info/ 
0
 
gbanikCommented:
@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
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
exactly Chris
0
 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
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
 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
well so... if you have a working solution to add rules in Outlook based on regular expressions I would be interested
0
 
Chris BottomleyCommented:
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
 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
I searched for a graphic (GUI) solution but I'm grateful to you for this GUIless solution too...
0
 
Chris BottomleyCommented:
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
 
lucavillaAuthor Commented:
Thank you Chris!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now