summaryrefslogtreecommitdiff
path: root/alot/widgets
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-01-22 12:37:03 +0100
committerAnton Khirnov <anton@khirnov.net>2021-01-24 17:36:05 +0100
commit501b0d80d5ade91fb31619432f706c674ff4e71a (patch)
treee06dfb010990ca370ec1f44c29022098d44a3a39 /alot/widgets
parentec10bd2eda5d768a054af85608a8f52d8f7420b9 (diff)
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.
Diffstat (limited to 'alot/widgets')
-rw-r--r--alot/widgets/thread.py6
1 files changed, 2 insertions, 4 deletions
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')