Imaplib使用python搜索带有特殊字符的主题行

时间:2018-12-14 01:18:37

标签: python imaplib

我正在尝试使用

搜索特殊字符主题行
const weekdayRegex = /\b((?:mon|tues|wed(?:nes)?|thur(?:s)?|fri|sat(?:ur)?|sun)(?:day)?)\b/;
const monthRegex = /\b(jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:tember)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)\b/;
const dayOfMonthRegex = /\b\d{1,2}(?:th|nd|st|rd)?\b/;
const dateRegex = new RegExp('^.*?' + weekdayRegex.source + '\\W+((' + monthRegex.source + '\\s+' + dayOfMonthRegex.source + ')|(' + dayOfMonthRegex.source + '\\s+(of\\s+)?' + monthRegex.source + ')).*$', 'i');
let strings = ["help me on monday, january 8 take the dog out","today is tuesday 12th of november", "I like wednesday Feb 11, it's my birthday!", "Sun jan 5th", "january 8", "12th of november"];
strings.map(text => { console.log(dateRegex.test(text) ? text.replace(dateRegex, '$2') : text + ' didn\'t match!'); });

但是它引发了错误的请求命令错误。

任何想法,为什么会发生,以及任何解决方案。

以下解决方案不起作用。

Python3 IMAP search special characters

1 个答案:

答案 0 :(得分:1)

首先,您的问题是在带引号的字符串中有双引号,这是一种语法错误:

let s = v4_or_v6.to_string();

尝试转义内部引号:

typ, msg_ids = self.imap.uid('search', None, 'SUBJECT "Report #160496147 : "AU report QTD date wise MediaOps" from Dhruv Sapra"')

还要注意typ, msg_ids = self.imap.uid('search', None, 'SUBJECT "Report #160496147 : \"AU report QTD date wise MediaOps\" from Dhruv Sapra"') 的实际工作方式是特定于实现的。搜索一两个单词通常效果很好,但是搜索文字字符串通常效果不佳,这取决于服务器如何为它建立索引。例如,gmail服务器仅索引单词,而搜索子字符串或标点符号通常不起作用。如果您的服务器兼容,则仅搜索带有或不带有#的报告编号可能会或可能不会带来更好的结果。

SEARCH