]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
sh-function: add insert_header function
authorJacob Keller <jacob.e.keller@intel.com>
Sat, 15 Mar 2014 00:15:58 +0000 (17:15 -0700)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tue, 18 Mar 2014 13:35:14 +0000 (15:35 +0200)
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 <jacob.e.keller@intel.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
email/aiaiai-email-lda
helpers/aiaiai-sh-functions

index c0a18875ff20d962b4e81e09daa9443ffd64375a..5db3f15e9918af3e66ef83f79577000b6dba03ed 100755 (executable)
@@ -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
index 8d155705eb7b7361441d3dbed8dce7088e691aeb..b515cf02eba2dc7b28a6edb303403946c5483331 100644 (file)
@@ -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 <mbox_file> <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"