From: Jacob Keller Date: Sat, 15 Mar 2014 00:15:58 +0000 (-0700) Subject: sh-function: add insert_header function X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d12f98509f018a9c9e9a22152a8bebd87805becf;p=users%2Fdedekind%2Faiaiai.git sh-function: add insert_header function Since we use a special trick to insert header information into the mbox, this could be extraced into a function in aiaiai-sh-functions. This will help future work which will want to add multiple headers into this mbox file, using the same file descriptor trick. Signed-off-by: Jacob Keller Signed-off-by: Artem Bityutskiy --- diff --git a/email/aiaiai-email-lda b/email/aiaiai-email-lda index c0a1887..5db3f15 100755 --- a/email/aiaiai-email-lda +++ b/email/aiaiai-email-lda @@ -217,24 +217,11 @@ queue_series() # later. local subj="$(fetch_header "Subject" < "$dir/0")" subj="X-Aiaiai-Cover-Letter-Subject: $subj" + insert_header "$mbox" "$subj" local id="$(fetch_header "Message-Id" < "$dir/0")" id="X-Aiaiai-Cover-Letter-Message-Id: $id" - - # The below trick allows us to avoid creating a separate - # temporary file: open the "$mbox" file, unlink, use the open - # file descriptor for reading and redirect the output to the - # new version of the "$mbox" file. We could instead use the - # "sponge" tool, though. - exec 3<$mbox - rm $verbose "$mbox" >&2 - verbose "Adding \"$subj\"" - formail -s formail -I "$subj" <&3 > "$mbox" - - exec 3<$mbox - rm $verbose "$mbox" >&2 - verbose "Adding \"$id\"" - formail -s formail -I "$id" <&3 > "$mbox" + insert_header "$mbox" "$id" fi queue_mboxfile "$mbox" "$n" rm $verbose -rf -- "$dir" >&2 diff --git a/helpers/aiaiai-sh-functions b/helpers/aiaiai-sh-functions index 8d15570..b515cf0 100644 --- a/helpers/aiaiai-sh-functions +++ b/helpers/aiaiai-sh-functions @@ -132,6 +132,24 @@ fetch_header_per_patch() formail -s sh -c "formail -z -c -x \"$hdr:\" | head -n1" | aiaiai-decode-rfc-2047 } +# Insert a header into the given mbox file +# Usage: insert_header
+insert_header() +{ + local mbox="$1"; shift + local header="$1"; shift + + # The below trick allows us to avoid creating a separate temporary + # file; open the "$mbox" file, unlink, use the open file descriptor for + # reading and redirect the output to the new version of the "$mbox" + # file. We could instead use the "sponge" tool, however. + exec 3<$mbox + rm $verbose "$mbox" >&2 + verbose "Adding \"$header\"" + formail -s formail -I "$header" <&3 > "$mbox" + exec 3<&- +} + git_dir() { local path="$1"