本文转自:https://blogs.msdn.microsoft.com/andrewdelin/2005/05/10/doing-more-with-outlook-filter-and-sql-dasl-syntax/

When I returned from an overseas trip earlier this year I needed to hack through a pile of emails that had accumulated. So I explored the Outlook filter search syntax (DASL) to see what could be achieved.

(I am using Outlook 2003. I know some of this works with previous versions of Outlook.)

Firstly, I recommend you add the [Filter...] button to a toolbar in Outlook. To do this, right-mouse-click on an empty area of the toolbar area at the top of Outlook, and select Customize from the menu. Pick the Commands tab and then select View in the Categories list. On the right, scroll down the Commands list until you see 'Filter' and then drag this entry up, up and away to a toolbar spot where you'd like it. You should now have a Filter button in your toolbar at the top of Outlook. You can close the Customize dialog.

The Filter dialog is a somewhat hidden but powerful tool for finding all kinds of Outlook items. It is organised as four tabs: Messages, More Choices, Advanced and SQL. I recommend you play with this dialog if it's not familiar to you. When you apply a Filter on a folder, you will see a small legend above your email (on the right) saying 'Filter Applied' - a hint that not all items are being shown! You use the Clear All button in the Filter dialog to remove the filter so you can see everything again.

I prefer to use the Advanced and SQL tabs of the Filter dialog because you can establish very specific queries that meet your needs. You will need to check 'Edit these criteria directly' to enter SQL queries. Switch to the SQL tab and try the following.

Examples

To find email from a specific person (for example, your manager), try this:

"urn:schemas:httpmail:fromname" LIKE '%Gerard O''Driscoll%'

Note the use of double ' which escapes the apostrophe in the name.

To find all those Declined, Accepted and Tentative meeting responses, try this:

NOT "http://schemas.microsoft.com/mapi/proptag/0x001a001e" = 'IPM.Note'

This finds stuff that isn't email. I found this useful on both Sent Items as well as Inbox.

To find items that weren't sent directly to me, try this:

NOT
      ("urn:schemas:httpmail:displayto" LIKE '%Andrew Delin%'
    OR "urn:schemas:httpmail:displaycc" LIKE '%Andrew Delin%')

This shows items where I am not on the To: line nor the Cc: line.

To show items that you haven't read:

"urn:schemas:httpmail:read" = 0

You either haven't read these items, or you have marked them Unread again.

This appears to find mail that came from outside Microsoft:

NOT "urn:schemas:httpmail:fromemail" LIKE '%microsoft%'

You will need to change the company name in this filter for your own details, and test thoroughly. It may not behave the same way.

This seems to find internal mail (from within Microsoft) which wasn't addressed to me:

"urn:schemas:httpmail:fromemail" LIKE '%microsoft%'
  AND NOT
    ("urn:schemas:httpmail:displayto" LIKE '%Andrew Delin%'
    OR "urn:schemas:httpmail:displaycc" LIKE '%Andrew Delin%')

Note I am checking both To and Cc addresses. To try this, you'll need to substitute your company name in the first clause. And test that it works.

It would be nice to find emails that have attachments. BUT:

"urn:schemas:httpmail:hasattachment" = 1

-this DOESN'T work the way you expect, because it seems in-line pictures embedded in certain email formats are considered attachments:o(

Looking for items with normal or low priority:

"urn:schemas:httpmail:importance" <= 1

Items with no flag set:

NOT "urn:schemas:httpmail:messageflag" > 0

Take care with flags, because it appears more than one attribute composes the email flag functionality. You can for example test for specific color flags being set; this tests for Purple flagged items:

"http://schemas.microsoft.com/mapi/proptag/0x10950003" = 1

And this looks for NO color flag being set:

NOT "http://schemas.microsoft.com/mapi/proptag/0x10950003" > 0

Beware, because I found that  "NOT ... > 0"  is not the same as  "= 0". With the latter, you won't get the list of unflagged items you might expect.

Email sent to one of the groups (distribution lists, DLs) which I belong to:

"urn:schemas:httpmail:displayto" LIKE '%Australia Consulting%'
  OR
  "urn:schemas:httpmail:displaycc" LIKE '%Australia Consulting%'

This tests both the To: and Cc: address fields. Note this is the long name of the group, not the short alias name (8 characters). You could easily add more tests to make a filter that shows 'emails to Australian groups I belong to'.

To find email items you have replied to, you might attempt a field query like "Tracking Status equals Replied" which produces this syntax in the SQL tab:

"http://schemas.microsoft.com/mapi/id/{0006200B-0000-0000-C000-000000000046}/88090003" = 7

BUT I found this DOESN'T work because email tracking is usually disabled between Outlook and Exchange, to reduce sync overhead (this was the feature where Outlook recorded that you had replied to individual items). Instead, a reasonable proxy for this is to look for Inbox items which contain your name in the body of the mail (when you reply, the mail client inserts something like  From: Andrew Delin  in the body):

"urn:schemas:httpmail:textdescription" LIKE '%Andrew Delin%'

Putting it all together

Unread items received last month, not sent directly to me:

NOT
    ("urn:schemas:httpmail:displayto" LIKE '%Andrew Delin%'
    OR "urn:schemas:httpmail:displaycc" LIKE '%Andrew Delin%')
  AND
  %lastmonth("urn:schemas:httpmail:datereceived")%
  AND
    "urn:schemas:httpmail:read" = 0

Non-urgent Inbox mail from inside Microsoft which is 3+ months old, not flagged, not addressed to me, and which is either 'unread' or which I didn't reply to (proxy):

"urn:schemas:httpmail:fromemail" LIKE '%microsoft%'
  AND
  "urn:schemas:httpmail:importance" <= 1
  AND
  "urn:schemas:httpmail:datereceived" < '1/02/2005 12:00 AM'
  AND NOT "urn:schemas:httpmail:messageflag" > 0
  AND NOT
    ("urn:schemas:httpmail:displayto" LIKE '%Andrew Delin%'
    OR "urn:schemas:httpmail:displaycc" LIKE '%Andrew Delin%')
  AND (
    "urn:schemas:httpmail:read" = 0
    OR
    (NOT "urn:schemas:httpmail:textdescription" LIKE '%Andrew Delin%')
  )

If you want to try this, update the date constant (see datereceived) to something appropriate, as well as changing %microsoft% to your company and removing my name! Please test the result thoroughly.

Views

Once you have some queries you like, you can define these so they're available in your Views drop-down list. To create a new view, use the View menu / Arrange By / Current View / Define Views / New button. Choose 'Table' and then you'll see several buttons to setup the View, including Filter - which you'll recognise as the same dialog from above. Enter your carefully crafted syntax and the filter will activate whenever you select this view on your folder. I have defined views for my main group memberships and external email so I can quickly filter my Inbox.

Other notes

Be patient with the Outlook Filter dialog. Sometimes you need to use Clear All then OK to get the full list of items to appear in your Inbox, before trying another filter query.

I found it was important to test my filter expressions carefully. Sometimes 'NOT' doesn't produce the opposite list of what you're seeing, and some fields aren't populated the way you expect (for example, there are several flag attributes - see above; there are also a number of similar-sounding email address fields to check and you may not get the results you first guess at).

A syntax reference for using DASL through the Outlook filter isn't easily found. I tried looking in the Exchange SDKs and while I got a list of attributes, it wasn't very Outlook-friendly. For example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_urn_content-classes_message.asp

There's also a list of Outlook IPM message types here, if you want to search for specific mail item types (eg Meeting requests):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/olfm11/html/rerefaboutitemtypesmessageclasses_HV01044391.asp

I did find some bits in Thomas Rizzo's book on pages 197 and 701 ("Programming Microsoft Outlook and Microsoft Exchange 2003").

If you want to do date dynamic date calculations in Outlook filters, you will need to use the today(S) function with a positive or negative offset in seconds. I have written about this here (thanks Patrick!). Otherwise there is a fixed set of date functions like '%lastmonth' or you can enter literal dates such as <= '1/1/2005 12:00 AM'. Here is a list of these fixed date functions - for the syntax, just use the Advanced tab in the Outlook Filter dialog, and add the mail field called 'Received' (Outlook will display something like 'Received yesterday|today|tomorrow|in the last 7 days ...' etc. If you switch to the SQL tab, it will show you the syntax to use.

%yesterday
  %today
  %tomorrow
  %last7days
  %next7days
  %lastweek
  %thisweek
  %nextweek
  %lastmonth
  %thismonth
  %nextmonth

I hope the above helps. If you try any of the above ideas, please be sure to test the results thoroughly.

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

[转]Doing more with Outlook filter and SQL DASL syntax的更多相关文章

  1. ignore users and roles by filter in sql source control

    https://www.red-gate.com/hub/product-learning/sql-source-control/source-controlling-database-permiss ...

  2. Java Filter防止sql注入攻击

    原理,过滤所有请求中含有非法的字符,例如:, & < select delete 等关键字,黑客可以利用这些字符进行注入攻击,原理是后台实现使用拼接字符串,案例:某个网站的登入验证的SQ ...

  3. mini filter driver sql server

    https://blogs.msdn.microsoft.com/sql_pfe_blog/2013/04/23/identifying-the-cause-of-sql-server-io-bott ...

  4. SQL CASE Syntax

    CASE case_value WHEN when_value THEN statement_list [WHEN when_value THEN statement_list] ... [ELSE ...

  5. 转载-SQL中的where条件,在数据库中提取与应用浅析

    1        问题描述 一条SQL,在数据库中是如何执行的呢?相信很多人都会对这个问题比较感兴趣.当然,要完整描述一条SQL在数据库中的生命周期,这是一个非常巨大的问题,涵盖了SQL的词法解析.语 ...

  6. 走FILTER效率高的2种情况

    FILTER的适用范围: 1. 主表返回的记录数较少 2.子查询返回记录数较小 下面做实验证明: select department_name from hr.dept_1 dept where de ...

  7. 6. SQL Server数据库监控 - 如何告警

    原文:6. SQL Server数据库监控 - 如何告警 常用的告警方式大致有:短信.邮件.应用程序 (beep提示,图标提示,升窗提示等),可是不能一直坐在电脑前看着应用程序,或者用脚本部署监控,根 ...

  8. SQL MySQL

    SQL 结构化查询语言(英语:Structural Query Language,缩写:SQL),是一种特殊目的之编程语言,用于数据库中的标准数据查询语言. 各种通行的数据库系统在其实践过程中都对SQ ...

  9. DAX基础入门 - 30分钟从SQL到DAX -- PowerBI 利器

    看到漂漂亮亮的PowerBI报表,手痒痒怎么办?! 有没有面对着稀奇古怪的DAX而感到有点丈八金刚摸不着头脑或者干瞪眼?! 有没有想得到某个值想不出来DAX怎么写而直跳脚!? 看完这篇文章,你会恍然大 ...

随机推荐

  1. C#_.NetFramework_Web项目_NPOI_EXCEL数据导入

    [推荐阅读我的最新的Core版文章,是最全的介绍:C#_.NetCore_Web项目_EXCEL数据导出] 项目需要引用NPOI的Nuget包: B-2--EXCEL数据导入--NPOI--C#获取数 ...

  2. Wpf Dispatcher.BeginInvoke((Action)delegate{}));

    <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/w ...

  3. Selenium(四):CSS选择器(一)

    1. CSS选择器 前面我们学习了根据 id.class属性.tag名选择元素. 如果我们要选择的元素没有id.class 属性,或者有些我们不想选择的元素也有相同的id.class属性值,怎么办呢? ...

  4. JS基础语法---创建对象---三种方式创建对象:调用系统的构造函数;自定义构造函数;字面量的方式

    创建对象三种方式: 调用系统的构造函数创建对象 自定义构造函数创建对象(结合第一种和需求通过工厂模式创建对象) 字面量的方式创建对象 第一种:调用系统的构造函数创建对象 //小苏举例子: //实例化对 ...

  5. google跟踪代码管理器gtm无法给相同class元素绑定click事件埋点解决

    Google 跟踪代码管理器是一个跟踪代码管理系统 (TMS),可以帮助您快速轻松地更新网站或移动应用上的跟踪代码及相关代码段(统称为“代码”).将一小段跟踪代码管理器代码添加到项目后,您可以通过网页 ...

  6. JS If...Else

    JS If...Else 条件语句用于基于不同的条件来执行不同的动作. 条件语句 通常在写代码时,您总是需要为不同的决定来执行不同的动作.您可以在代码中使用条件语句来完成该任务. 在 JavaScri ...

  7. Django_xadmin_TypeError: Related Field got invalid lookup: icontains

    问题: 当我在给某一张表加上外键搜索的时候,会出现 TypeError: Related Field got invalid lookup: icontains 问题原因: a 表关联 b表,也就是说 ...

  8. Fiddler应用——Fiddler过滤功能

    Fiddler的过滤功能在Fiddler右面板处,点击Filters显示如图所示面板. 如图所示,Fiddler的过滤面板主要分为几个部分: 1.Use Filters:是否启用过滤器 2.Actio ...

  9. R-3 t分布--t置信区间--t检验

    本节内容: 1:t分布存在的意义是什么 2:t分布的置信区间 3:t分布检验 一.t分布存在的意义是什么 数据分析中有一块很大的版图是属于均值对比的,应用广泛. 例如:对比试验前后病人的症状,证明某种 ...

  10. Day14 - Python基础14 事件驱动模型、IO模型

    本节内容: 1:事件驱动模型 2:IO模型前戏准备 3:4种IO模型 1:事件驱动模型 传统的编程是如下线性模式的: 开始--->代码块A--->代码块B--->代码块C---> ...