From: Sebastian Poeplau <sebastian.poeplau@eurecom.fr>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: Handling mislabeled emails encoded with Windows-1252
Date: Tue, 24 Jul 2018 15:55:54 +0200 [thread overview]
Message-ID: <87k1pkzqj9.fsf@eurecom.fr> (raw)
In-Reply-To: <87o9exyseg.fsf@eurecom.fr>
[-- Attachment #1: Type: text/plain, Size: 765 bytes --]
Hi again,
>> Everyone's mail situation is unique, but I haven't noticed this
>> problem. Do you have a mechanical (e.g. scripted) way of detecting such
>> mails? I suppose it could just look for characters in the range 0x80 to
>> 0x95 in allegedly ISO_8859-1 messages. A census of the situation in my
>> own mail would help me think about this problem, I think.
>
> Yes, I guess that should be a good enough heuristic for detecting
> affected mail. I'll try to come up with a simple script and post it
> here.
Attached is a Python script that checks individual message files and
prints their name if it finds them to contain mislabeled Windows-1252
text. The heuristic seems to work well on my mail - let me know if you
encounter any issues!
Cheers,
Sebastian
[-- Attachment #2: find_mislabeled_cp1252.py --]
[-- Type: application/octet-stream, Size: 840 bytes --]
#!/usr/bin/env python3
from email.parser import BytesParser
import email.policy
mail_parser = BytesParser(policy=email.policy.default)
def check_message(filename):
"""
Return True if the specified message contains mislabeled Windows-1252 text.
"""
with open(filename, 'rb') as f:
message = mail_parser.parse(f)
for part in message.walk():
if part.get_content_type() != 'text/plain' or \
part.get_content_charset() != 'iso-8859-1':
continue
body = part.get_content()
for char in body:
code = ord(char)
if code > 0x80 and code < 0xa0:
return True
return False
def main(args):
for arg in args:
if check_message(arg):
print(arg)
if __name__ == '__main__':
import sys
main(sys.argv)
next prev parent reply other threads:[~2018-07-24 13:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-14 12:40 Handling mislabeled emails encoded with Windows-1252 Sebastian Poeplau
2018-07-24 1:49 ` David Bremner
2018-07-24 8:00 ` Sebastian Poeplau
2018-07-24 13:55 ` Sebastian Poeplau [this message]
2018-07-24 14:09 ` Jeffrey Stedfast
2018-07-24 14:19 ` Sebastian Poeplau
2018-07-28 11:22 ` Sebastian Poeplau
2018-07-28 12:25 ` Jeffrey Stedfast
2018-07-30 7:28 ` Sebastian Poeplau
2018-07-30 7:47 ` Sebastian Poeplau
2018-07-31 9:07 ` David Bremner
2018-07-31 9:49 ` Sebastian Poeplau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k1pkzqj9.fsf@eurecom.fr \
--to=sebastian.poeplau@eurecom.fr \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).