【问题标题】:Apply Regex in filter() in exchangelib在 exchangelib 中的 filter() 中应用正则表达式
【发布时间】:2018-03-07 19:01:27
【问题描述】:

我正在编写一个需要使用正则表达式过滤主题的脚本。 exchangelib 支持吗?如果是这样,我可以举一些例子吗?

【问题讨论】:

    标签: python exchangelib


    【解决方案1】:

    正则表达式是not supported in EWS,所以不能做服务器端的过滤。您必须提取所有项目并在客户端进行过滤:

    for item in account.inbox.all():
        if re.match(r'some_regexp', item.subject):
            # Do something
    

    如果您希望只匹配很少的项目,您可以先只获取主题字段,然后再获取完整项目:

    matches = []
    for item in account.inbox.all().only('subject'):
        if re.match(r'some_regexp', item.subject):
            matches.append(item)
    full_items = account.fetch(matches)
    

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 2016-06-15
      • 2015-05-05
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      相关资源
      最近更新 更多