Thanks for the proposed localpostproc, Ken!
Unfortunately, I don't think I can use it, due to a lack of a
looping mechanism -- or, at least, a "there-exists" mechanism.
I need something that checks the recipients' host(s), which
means potentially checking more than 1 string. The pseudo-code
would be roughly
if @.*stanford.edu in {%(host{to}), %(host{cc}), %(host{bcc})}
postflags=""
else
postflags="-server smtp.gmail.com -port submission -tls -sasl -user
dnc2dnc"
I could break up the if-clause into 3 scan(1) invocations, but
things break down when there's more than 1 address in a given
component since, quoting from the mh-format(5) page:
The return value of functions noted with `*' is computed
from the first address present in the header component.
[...]
host addr string the host domain*
Am I missing an obvious solution?
Thanks!
Bob
On Wed, 04 Mar 2015 12:25:41 -0500 Ken Hornstein <kenh@pobox.com> sez:
So after testing it for a day, I found a problem.
Specifically, if you're using annotations on replies my simple
script broke. The reason is that the arguments ended up being:
[...] draft filename -idanno N
Where "N" was the file descriptor to write the annotation to;
my previous iteration assumed the last argument to post was the
filename.
I ended up having to do this code (complete script appended at
the end):
find_draftmessage() {
skip_next=0
for arg; do
case "$arg" in
-al* | -filt* | -wi* | -client | -idanno | -server | \
-partno | -saslmaxssf | -saslmech | -user | -por* | \
-file* | -mhl* | -mt* | -cr* | -lib* | -oauth)
skip_next=1
;;
-*) skip_next=0;
;;
*)
if [ "$skip_next" -eq 0 ]; then
draftmessage="$arg"
return 0
fi
skip_next=0
;;
esac
done
echo "Cannot find draft message name in argument list"
exit 1
}
I am just wondering out loud if there is a better way than
putting knowledge in the script of whether a particular switch
takes an argument. It just seems brittle to me. Ideas? Other
approaches?
--Ken
#!/bin/sh
#
# localpostproc - decide where to send email based on the draft message
#
#
# Find out which message is the draft message; yes, this sucks
#
find_draftmessage() {
skip_next=0
for arg; do
case "$arg" in
-al* | -filt* | -wi* | -client | -idanno | -server | \
-partno | -saslmaxssf | -saslmech | -user | -por* | \
-file* | -mhl* | -mt* | -cr* | -lib* | -oauth)
skip_next=1
;;
-*) skip_next=0;
;;
*)
if [ "$skip_next" -eq 0 ]; then
draftmessage="$arg"
return 0
fi
skip_next=0
;;
esac
done
echo "Cannot find draft message name in argument list"
exit 1
}
realpost="$(mhparam libdir)/post"
if [ $# -eq 0 ]; then
echo "Usage: [post switches] filename"
exit 1
fi
find_draftmessage "$@"
fromhost=$(scan -format '%(host{from})' -file "$draftmessage")
if [ $? -ne 0 ]; then
echo "Unable to run scan on draft file $draftmessage, aborting"
exit 1
fi
if [ -z "$fromhost" ]; then
echo "Could not determine hostname of From: address"
exit 1;
fi
case "$fromhost" in
*.some.other.host)
postflags="-server some.other.server -sasl -port submission"
;;
pobox.com)
postflags="-server smtp.pobox.com -sasl -tls -port submission"
;;
*)
echo "Don't know how to send email from $fromhost"
exit 1
;;
esac
exec "$realpost" $postflags "$@"
_______________________________________________
Nmh-workers mailing list
Nmh-workers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/nmh-workers