python 错误报告中描述了该问题:
我将那里发布的解决方案改编为处理 gmail 邮件,其中主题行有时会插入不正确的字符:
try:
iid = self.lib_tree.insert("", tk.END, tags="unchecked",
values=(message_id, subject, sender, epoch, date, labels,
snippet))
except tk.TclError:
print('old subject:', subject)
import re
# From: https://bugs.python.org/issue21084
astral = re.compile(r'([^\x00-\uffff])')
s = subject
new_subject = ""
for i, ss in enumerate(re.split(astral, s)):
if not i%2:
new_subject += ss
else:
new_subject += '?'
print('new_subject:', new_subject)
continue
加载大约 5,000 条 gmail 消息的程序输出:
$ bserve.py
old subject: Mserve June 18/2021
new_subject: Mser?e June 18/2021
old subject: mserve December 7, 2020
new_subject: mser?e December 7, 2020
old subject: Re: WinEunuuchs2Unix
new_subject: Re: WinEunuuchs2Uni?
old subject: ? ORDER UPDATE: 2019 Cigarette Light...
new_subject: ? ORDER UPDATE: 2019 Cigarette Light...
old subject: ? You've got 18 new ideas waiting for you!
new_subject: ? You'?e got 18 ne? ideas ?aiting for ?ou!
old subject: ? Get inspired with these 18 trending ideas
new_subject: ? Get inspired ?ith these 18 trending ideas
old subject: ? 18 popular Pins for you
new_subject: ? 18 popular Pins for ?ou
old subject: ? Get inspired with these 18 trending ideas
new_subject: ? Get inspired ?ith these 18 trending ideas
old subject: ? Get inspired with these 18 trending ideas
new_subject: ? Get inspired ?ith these 18 trending ideas
old subject: ? You've got 18 new ideas waiting for you!
new_subject: ? You'?e got 18 ne? ideas ?aiting for ?ou!
old subject: ? We picked some Puzzle art Pins for you
new_subject: ? We picked some Pu??le art Pins for ?ou
old subject: ? INFANTRY Mens LCD Digital Quartz Wrist Watch Tactical Sport Stainless Steel Navy is HOT on eBay, but quantity is limited
new_subject: ? INFANTRY Mens LCD Digital Quart? Wrist Watch Tactical Sport Stainless Steel Na?? is HOT on eBa?, but quantit? is limited
old subject: ? POLJOT AVIATOR ATTACK PLANE MEN`S RUSSIAN MILITARY WATCH is HOT on eBay, but quantity is limited
new_subject: ? POLJOT AVIATOR ATTACK PLANE MEN`S RUSSIAN MILITARY WATCH is HOT on eBa?, but quantit? is limited
有些是显而易见的原因,例如“?”。有些不太明显,例如“Mserve”有无效的“v”并变成“Mser?e”。
我想当我在旅行结束时回到家时用 Android 写 mserve 项目电子邮件时出现了故障。