]> git.ozlabs.org Git - next-scripts/blobdiff - send_email
update to_build_host a bit
[next-scripts] / send_email
index 60842a7a991cdd472b88a933b0b91be785d90893..b2b1b54cb92927973c1d01bc67fbb1cd2f9a7ea4 100755 (executable)
@@ -1,23 +1,33 @@
 #!/bin/bash
 
-TARGET="$(realpath --relative-to=. $(dirname $0)/../mails)"/$(date +"%Y-%m-%d+%s").email
+mail_dir=$(realpath --relative-to=. "$(dirname "$0")/../mails")
+printf -v TARGET '%s/%(%Y-%m-%d+%s)T.email' "$mail_dir" -1
 
+subject="$1"
+shift
 to="$1"
-cc="$2"
-subject="$3"
+shift
+readarray -t cc < <(printf '%s\n' "$@" | sort -u)
 
-(
-       cat <<EOF
-To: $to
-Cc: $cc
-Subject: $subject
+for i in "${!cc[@]}"; do
+       e=${cc[$i]##*<}
+       e=${e%%>*}
+       if grep -q -F "<$e>" <<<"$to"; then
+               unset "cc[$i]"
+       fi
+done
 
-EOF
+{
+       printf 'To: %s\n' "$to"
+       if [ "${#cc[@]}" -gt 0 ]; then
+               printf 'Cc: %s\n' "${cc[@]}"
+       fi
+       printf 'Subject: %s\n\n' "$subject"
        cat
-) > $TARGET
+} > "$TARGET"
 
-gvim $TARGET
+gvim "$TARGET"
 
-echo "When you're finished editing you need to send $TARGET"
+printf 'When you are finished editing you need to send %s\n' "$TARGET"
 
 exit 0