[PATCH] email-lda: use cover letter subject if available

Artem Bityutskiy artem.bityutskiy at linux.intel.com
Wed Feb 5 02:53:14 PST 2014


From: Jacob Keller <jacob.e.keller at intel.com>

Often, a patch series will be sent with a cover letter which describes the
series and is given the '0/n' patch number. Rather than dropping these
patches, keep track of them in series. We do this by checking whether the 1/n
patch has an "In-Reply-To" header. This usually means that their will be an
associated cover letter. Once this is found, rather than sending the patch
directly on to the test program, we use the cover letter's subject by using
formail to add a special "Series-Subject". This makes it so that the
aiaiai-email will end up as a reply to the cover letter which is a bit more
aesthetically pleasing to users.

To help this process, a new "series_is_complete" function is added in place of
the original series complete check. This function reports whether the series
is completely queued, for both cases of cover letter and no cover letter.

Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
---
 email/aiaiai-email-lda           |   41 ++++++++++++++++++++++++++++++++------
 email/aiaiai-email-test-patchset |    6 +++++-
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/email/aiaiai-email-lda b/email/aiaiai-email-lda
index cebe8f5..3f7746e 100755
--- a/email/aiaiai-email-lda
+++ b/email/aiaiai-email-lda
@@ -149,6 +149,27 @@ find_relatives()
 	fi
 }
 
+series_is_complete()
+{
+	local dir="$1"; shift
+	local n="$1" ; shift
+
+	# First check if we have all the non-cover patches yet
+	if [[ "$(ls -1 --ignore=0 -- "$dir" | wc -l)" -eq "$n" ]]; then
+		local first_parent="$(fetch_header "In-Reply-To" < "$dir/1")"
+		if [[ -n "$first_parent" && ! ( -f "$dir/0" ) ]]; then
+			# Series is not complete, we are missing a cover letter
+			return 1
+		else
+			# Series is complete, no cover letter was sent
+			return 0
+		fi
+	else
+		# Don't have all the patches yet
+		return 1
+	fi
+}
+
 move_to_series()
 {
 	local file="$1"; shift
@@ -184,9 +205,9 @@ process_series_mbox()
 	local fname
 	local dir
 
-	# Only patch 1/n is allowed to have no parent
+	# Only patch 0/n or 1/n is allowed to have no parent
 	local parent_id="$(fetch_header "In-Reply-To" < "$mbox")"
-	if [ -z "$parent_id" ] && [ "$m" != 1 ]; then
+	if [ -z "$parent_id" ] && [ "$m" != 1 ] && [ "$m" != 0 ]; then
 		reject_and_reply "$mbox" <<EOF
 You sent a patch that does not conform to the requirements for Aiaiai's Local
 Delivery Agent. This patch is part of a series as indicated by its subject
@@ -248,12 +269,22 @@ EOF
 	done
 
 	# If the series is complete - queue it
-	if [ "$(ls -1 -- "$dir" | wc -l)" -eq "$n" ]; then
+	if series_is_complete "$dir" "$n"; then
 		message "Patch-set at \"$dir\" is complete, queue it"
-		for fname in $(ls -A -- "$dir" | sort -n); do
+		# Don't add the 0th patch, as it should be empty, and screws up git-am
+		for fname in $(ls --ignore=0 -A -- "$dir" | sort -n); do
 			cat -- "$dir/$fname" >> "$mbox"
 			echo >> "$mbox"
 		done
+
+		# Add the series subject if it exists
+		if [[ -f "$dir/0" ]]; then
+			program_required "sponge" "Installed with the moreutils package."
+			series_subject="$(fetch_header "Subject" < "$dir/0")"
+			# Use sponge so we don't have to store to use two separate temporary files
+			formail -s formail -I "X-Series-Subject: $series_subject" < "$mbox" | sponge "$mbox"
+		fi
+
 		queue_mboxfile
 		rm $verbose -rf -- "$dir" >&2
 	fi
@@ -304,8 +335,6 @@ process_mbox()
 		[ "$n" -ne 0 ] || \
 			{ reject "$mbox" "Prefix \"$prefix_format\" cannot have n = 0";
 			  return; }
-		[ "$m" -ne 0 ] || \
-			{ message "Dropping patch \"0/$n\""; return; }
 		process_series_mbox "$id" "$m" "$n"
 	fi
 }
diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset
index 0920d85..133deea 100755
--- a/email/aiaiai-email-test-patchset
+++ b/email/aiaiai-email-test-patchset
@@ -168,7 +168,11 @@ if [ -z "$mbox" ]; then
 	cat > "$mbox"
 fi
 
-fetch_header_or_die subj "Subject" < "$mbox"
+# Use the series subject if it exists
+subj="$(fetch_header "X-Series-Subject" < "$mbox")"
+if [[ -z $subj ]]; then
+	fetch_header_or_die subj "Subject" < "$mbox"
+fi
 fetch_header_or_die from "From" < "$mbox"
 fetch_header_or_die id "Message-Id" < "$mbox"
 msgname="$from: $subj (Message-Id: $id)"


-- 
Best Regards,
Artem Bityutskiy




More information about the aiaiai mailing list