From 501b0d80d5ade91fb31619432f706c674ff4e71a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 22 Jan 2021 12:37:03 +0100 Subject: widgets/thread: better heuristics for detecting git patches Do not use the X-Mailer header, since git-send-email can be used for other things than patches (such as cover letters) and not all git-formatted patches are sent with git-send-email. Instead, detect the distinctive keywords that hopefully appear only in git-formatted patches. --- alot/widgets/thread.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'alot/widgets') diff --git a/alot/widgets/thread.py b/alot/widgets/thread.py index a411e31e..52e23d07 100644 --- a/alot/widgets/thread.py +++ b/alot/widgets/thread.py @@ -439,11 +439,9 @@ class _TextPart(_MIMEPartWidget): logging.debug('No pygments lexer for MIME type: %s', part.content_type) # handle git-send-email patches, which are sent as text/plain - if ('x-mailer' in part.headers and - part.headers['x-mailer'][0].startswith('git-send-email') and - '\ndiff' in text): + if all(s in text for s in ('\ndiff --git', '\nindex', '\n---', '\n+++')): try: - lexer = pygments.lexers.get_lexer_by_name('diff') + lexer = pygments.lexers.get_lexer_by_name('diff') except pygments.util.ClassNotFound: logging.warning('Could not get a lexer/formatter for diff highlighting') -- cgit v1.2.3