]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
sh-functions: add fetch_all_headers function
authorJacob Keller <jacob.e.keller@intel.com>
Tue, 11 Feb 2014 17:50:33 +0000 (09:50 -0800)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Wed, 12 Feb 2014 11:32:24 +0000 (13:32 +0200)
This patch adds a fetch_all_headers function which is used to get every
occurrence of an mbox header, rather than just the first. In combination
with the change to merge_addresses, this can be used to grab every Cc,
and To address.

Artem: massage comments

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
helpers/aiaiai-sh-functions

index 15fb5db2ace848b5c3f4ec9033642179cc7f1594..8d155705eb7b7361441d3dbed8dce7088e691aeb 100644 (file)
@@ -81,7 +81,7 @@ compile_helpers()
        done
 }
 
-# Fetch the first occurrence of an mbox header from a file
+# Fetch the first occurrence of header "$1" from the mbox file
 # Usage: fetch_header <header_name> < <mbox_file>
 fetch_header()
 {
@@ -93,6 +93,19 @@ fetch_header()
        formail -z -c -x "$hdr:" | head -n1 | aiaiai-decode-rfc-2047
 }
 
+# Fetch all occurrences of header "$1" from the first e-mail in the mbox file
+# Usage: fetch_header <header_name> < <mbox_file>
+fetch_all_headers()
+{
+       local hdr="$1"
+
+       program_required "formail" ""
+
+       # Take every occurrence of the header. This will only take occurrences
+       # from the first of a combined mbox.
+       formail -z -c -x "$hdr:" | aiaiai-decode-rfc-2047
+}
+
 # Similar to fetch_header, but exits with code 1 if the header hasn't been
 # found, and has a little bit different interface (the result is stored in
 # "<var>").