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 the 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
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
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 to the final mbox, as it is just the
+ # cover letter and does not contain any patch
+ for fname in $(ls --ignore=0 -A -- "$dir" | sort -n); do
cat -- "$dir/$fname" >> "$mbox"
echo >> "$mbox"
done
+
+ if [ -f "$dir/0" ]; then
+ # Save the subject and message ID of the cover letter
+ # in the final mbox in order to be able to reply to the
+ # cover letter later.
+ local subj="$(fetch_header "Subject" < "$dir/0")"
+ subj="X-Aiaiai-Cover-Letter-Subject: $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
+ message "Adding \"$subj\""
+ formail -s formail -I "$subj" <&3 > "$mbox"
+
+ exec 3<$mbox
+ rm $verbose "$mbox" >&2
+ message "Adding \"$id\""
+ formail -s formail -I "$id" <&3 > "$mbox"
+ fi
queue_mboxfile
rm $verbose -rf -- "$dir" >&2
fi
[ "$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
}
cat > "$mbox"
fi
-fetch_header_or_die subj "Subject" < "$mbox"
+cat "$mbox"
+# Use the cover letter subject and message ID if possible. If the cover letter
+# was present, 'aiaiai-email-lda' would save them in special privat headers.
+subj="$(fetch_header "X-Aiaiai-Cover-Letter-Subject" < "$mbox")"
+[ -n "$subj" ] || fetch_header_or_die subj "Subject" < "$mbox"
+
+id="$(fetch_header "X-Aiaiai-Cover-Letter-Message-Id" < "$mbox")"
+[ -n "$id" ] || fetch_header_or_die id "Message-Id" < "$mbox"
+
fetch_header_or_die from "From" < "$mbox"
-fetch_header_or_die id "Message-Id" < "$mbox"
to="$(fetch_header "To" < "$mbox")"
cc="$(fetch_header "Cc" < "$mbox")"