From 58ef2bccea518a0b27a2c61fe68296e3a954682d Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Tue, 25 Aug 2015 18:00:06 -0700 Subject: [PATCH] email-lda: use git-apply to more accurately find patch emails Instead of using the subject as the sole arbiter of whether an email contains a patch, reject all emails which cannot be recognized by git-apply. In this way, we can locate even patches with non-standard subject lines. Use the subject line to differentiate between patch series and individual patches when possible. Signed-off-by: Jacob Keller --- email/aiaiai-email-lda | 31 +++++++++++++++++++++---------- email/aiaiai-email-sh-functions | 11 +++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/email/aiaiai-email-lda b/email/aiaiai-email-lda index 4927dd1..0ac9f0b 100755 --- a/email/aiaiai-email-lda +++ b/email/aiaiai-email-lda @@ -348,13 +348,12 @@ separator() fi } -# Process one e-mail. This e-mail may be part of a patch-set, or an individual -# patch, or not a patch at all. The patches and non-patches are distinguished -# using the subject (see the 'subject_check()' function). Non-patches are -# dropped. Individual patches are queued right away. Patch-sets are stored in -# a temporary directory and queued only when all the of them are collected. -# -# The e-mail to process is passed in "$1" in form of a path to the mbox file. +# Proccess one e-mail. This e-mail may be part of a patch-set, may contain an +# individual patch, or may not contain a patch at all. The patches and +# non-patches are distinguished using is_email_patch() which is based on "git +# apply --stat". Patch-set emails are distinquished from patches via use of the +# subject line. Individual patches are queued right away. Patch-sets are stored +# in a temporary location and queued when the entire patch set is collected. process_mbox() { local mbox="$1"; @@ -379,9 +378,21 @@ process_mbox() verbose " Subject: $subj" verbose " Message-Id: $id" - # Filter out e-mails which do not start with the right prefix" - subject_check "$subj" || - { reject "$mbox" "\"$prefix_format\" prefix not found"; return; } + + + # Filter out e-mails which do not contain a patch + if ! email_contains_patch "$mbox" ; then + # Keep cover letter patches, but discard anything else + [ $(subject_m "$subj") = "0" ] || + { reject "$mbox" "mbox contains no patch and is not a cover letter"; return ; } + fi + + # Queue patches which don't match subject format immediately + if ! subject_check "$subj" ; then + verbose "Queuing stand-alone patch with unrecognized subject format \"$subj\"" + queue_mboxfile "$mbox" "" + return + fi # If the patch prefix contains m/n, fetch m and n. local m="$(subject_m "$subj")" diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions index cb0feed..b4c6763 100644 --- a/email/aiaiai-email-sh-functions +++ b/email/aiaiai-email-sh-functions @@ -60,6 +60,17 @@ subject_check() [ -n "$(printf "%s" "$1" | LC_ALL=C sed -n -E "/$__single/ p")" ] } +# Check that an mbox will be recognized by git-apply +# Usage: email_contains_patch +# +# Based on return code from "git apply --stat". This command will print +# diffstat information about the patch, and will fail with exit code 128 if the +# file can't be recognized as a patch. +email_contains_patch() +{ + git apply --stat "$1" >/dev/null +} + # Strip an e-mail address from the comma-separated list of e-mail addresses # Usage: strip_address strip_address() -- 2.49.0