mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-08-03 09:44:28 +02:00
thunderbird: simplify headers decoding
This commit is contained in:
parent
3985ffa085
commit
fa4bbc3f92
1 changed files with 6 additions and 13 deletions
|
@ -14,7 +14,7 @@ import argparse
|
|||
import os
|
||||
import subprocess
|
||||
import email.parser
|
||||
import email.header
|
||||
import email.policy
|
||||
from pydbus import SessionBus
|
||||
from gi.repository import GLib, Gio
|
||||
|
||||
|
@ -24,15 +24,6 @@ parser.add_argument("folder", metavar="FOLDER", help="folder to monitor", nargs=
|
|||
options = parser.parse_args()
|
||||
|
||||
|
||||
def decode(header):
|
||||
return " ".join(
|
||||
(
|
||||
decoded.decode(charset or "ascii") if type(decoded) is bytes else decoded
|
||||
for decoded, charset in email.header.decode_header(header)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def process(path):
|
||||
new_watermark = None
|
||||
watermark = watermarks.get(path)
|
||||
|
@ -87,7 +78,9 @@ def process(path):
|
|||
|
||||
# Parse the message to extract subject, author and Message-ID
|
||||
message = b"\n".join(message[1:])
|
||||
parsed = email.parser.BytesParser().parsebytes(message, headersonly=True)
|
||||
parsed = email.parser.BytesParser(policy=email.policy.default).parsebytes(
|
||||
message, headersonly=True
|
||||
)
|
||||
subject = parsed.get("subject")
|
||||
author = parsed.get("from")
|
||||
messageid = parsed.get("message-id")
|
||||
|
@ -97,8 +90,8 @@ def process(path):
|
|||
"Thunderbird",
|
||||
0,
|
||||
"thunderbird",
|
||||
f"Mail from {decode(author)}",
|
||||
decode(subject),
|
||||
f"Mail from {author}",
|
||||
subject,
|
||||
actions,
|
||||
{},
|
||||
10000,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue