patchfile="$(mktemp -t tg-mail.XXXXXX)"
-$tg patch $name >"$patchfile"
+$tg patch "$name" >"$patchfile"
-hlines=$(grep -n -m 1 '^---' "$patchfile" | sed 's/:---//')
-header=$(head -n $(($hlines - 1)) "$patchfile")
+header="$(sed -e '/^$/,$d' "$patchfile")"