commit de92c35b43ca1a9fc04093bf314094fc2e5673c6
parent 29e6a06932c6ddf90d05bda17346869845dc875f
Author: Jaromil <jaromil@dyne.org>
Date: Wed, 7 May 2014 15:27:31 +0200
various relevant usage fixes
Diffstat:
3 files changed, 46 insertions(+), 38 deletions(-)
diff --git a/src/zlibs/email b/src/zlibs/email
@@ -74,7 +74,6 @@ queue() {
mv "$MAILDIRS/outbox/*" $tmppp/
rmdir "$MAILDIRS/outbox"
maildirmake "$MAILDIRS/outbox"
- mkdir -p "$MAILDIRS/outbox/send"
# here we devince two useful arrays:
# bodies: the list of mail bodies to send
# corresponding to files with same name and extension .msmtp
@@ -139,7 +138,7 @@ queue() {
else
# recipients are set in the email envelope
- mv "$TMPDIR/$queue_body.mail" "$MAILDIRS/outbox/new/$queue_body.mail"
+ cat "$TMPDIR/$queue_body.mail" | deliver "outbox"
fi
unlock "$MAILDIRS/outbox"
@@ -271,7 +270,7 @@ send() {
# list mails to send
- queue_outbox=(`${=find} "${MAILDIRS}/outbox" -type f -name '*.mail'`)
+ queue_outbox=(`${=find} "${MAILDIRS}/outbox" -type f`)
{ test ${#queue_outbox} = 0 } && {
act "Outbox is empty, no mails to send."
return 0 }
@@ -323,7 +322,7 @@ EOF
for qbody in ${(f)queue_outbox}; do
# check if this is an anonymous mail
- head -n 20 "$qbody" | grep -i '^from: anon' > /dev/null
+ hdr "$qbody" | grep -i '^from: anon' > /dev/null
if [ $? = 0 ]; then
anoncfg="${TMPDIR}/${host}.anon.$RANDOM"
cat <<EOF > "$anoncfg"
@@ -351,7 +350,7 @@ EOF
act "Sending to: ${r}"
# parse subject line
- anonsubj=`head -n 20 "$qbody" | awk '
+ anonsubj=`hdr "$qbody" | awk '
/^Subject: / { for(i=2;i<=NF;i++) printf "%s ", $i }'`
act "Subject: $anonsubj"
@@ -381,7 +380,7 @@ BEGIN { head=1 }
else # normal send with msmtp
act "Sending out email"
- head -n 10 "$qbody" | awk '
+ hdr "$qbody" | awk '
/^From:/ { print " . " $0 }
/^To:/ { print " . " $0 }
/^Cc:/ { print " . " $0 }
diff --git a/src/zlibs/filters b/src/zlibs/filters
@@ -169,7 +169,10 @@ EOF
return 0
}
+
filter_maildir() {
+ typeset -h mdinput
+ mdinput="$1"
# for safety we bail out in case the final fallback
# maildir is not existing. unsorted should always
@@ -185,27 +188,22 @@ filter_maildir() {
source $MAILDIRS/cache/filters
ownfilters=1 }
- if [ "$1" = "" ]; then
- input="incoming"
- else
- input="$1"
- fi
+ { test "$1" = "" } && { mdinput=incoming }
- maildircheck "$MAILDIRS/$input"
+ maildircheck "$MAILDIRS/$mdinput"
{ test $? = 0 } || {
- error "Invalid maildir to filter: $input"
+ error "Invalid maildir to filter: $mdinput"
return 1; }
- numm=`${=find} "$MAILDIRS/$input" -maxdepth 2 -type f|wc -l`
- mails=`${=find} "$MAILDIRS/$input" -maxdepth 2 -type f`
+ numm=`${=find} "$MAILDIRS/$mdinput" -maxdepth 2 -type f|wc -l`
+ mails=`${=find} "$MAILDIRS/$mdinput" -maxdepth 2 -type f`
{ test "$numm" = "0" } && {
- error "Nothing to filter inside maildir $input"
+ error "Nothing to filter inside maildir $mdinput"
return 1 }
- notice "Filtering maildir: $input ($numm mails}"
+ notice "Filtering maildir: $mdinput ($numm mails}"
c=0
- typeset -alU ftos
for m in ${(f)mails}; do
match=0
@@ -226,10 +224,6 @@ filter_maildir() {
{ test $? = 0 } && { rm "$m" }
continue }
- # recompile the array of destination addresses
- ftos=`hdr "$m" | ${WORKDIR}/bin/fetchaddr -x Cc -a | cut -d, -f1`
- ftos+=`hdr "$m" | ${WORKDIR}/bin/fetchaddr -x To -a | cut -d, -f1`
-
{ test "$ownfilters" = "1" } && {
func "processing through own filters"
@@ -241,12 +235,15 @@ filter_maildir() {
for exp in ${(k)filter_from}; do
# special zsh parsing in PCRE (=~)
if [[ "$femail" =~ "$exp" ]]; then
+ # if destination maildir is same as input, skip
+ { test "${filter_from[$exp]}" = "$mdinput" } && {
+ act "$c\t\t/ $numm"
+ match=1; continue }
act "$c\t\t/ $numm\t\t-> ${filter_from[$exp]}"
cat "$m" | deliver ${filter_from[$exp]}
if [ $? = 0 ]; then
func "from filter match: $exp"
- rm $m
- match=1
+ match=1; rm "$m"; continue
else
error "Error filtering to maildir ${filter_from[$exp]}"
error "File: $m"
@@ -256,18 +253,26 @@ filter_maildir() {
}
{ test "$match" = "1" } && { continue }
+ typeset -alU ftos
+ # recompile the array of destination addresses
+ ftos=(`hdr "$m" | ${WORKDIR}/bin/fetchaddr -x cc -a`)
+ ftos+=(`hdr "$m" | ${WORKDIR}/bin/fetchaddr -x to -a`)
+
# run all filter regexps on the to: and cc: fields
{ test "$ftos" = "" } || {
for ft in ${(f)ftos}; do
for exp in ${(k)filter_to}; do
# special zsh parsing in PCRE (=~)
if [[ "$ft" =~ "$exp" ]]; then
+ # if destination maildir is same as input, skip
+ { test "${filter_to[$exp]}" = "$mdinput" } && {
+ act "$c\t\t/ $numm"
+ match=1; continue }
act "$c\t\t/ $numm\t\t-> ${filter_to[$exp]}"
cat "$m" | deliver ${filter_to[$exp]}
if [ $? = 0 ]; then
func "to filter match: $exp"
- rm "$m"
- match=1
+ match=1; rm "$m"; continue
else
error "Error filtering to maildir ${filter_to[$exp]}"
error "File: $m"
@@ -276,7 +281,8 @@ filter_maildir() {
done
done
}
- { test "$match" = "1" } && { continue }
+
+ { test "$match" = "1" } && { func "own filter match"; continue }
} # own filters
@@ -297,24 +303,23 @@ filter_maildir() {
# parse own email and aliases
for f in $ftos; do
-
# check if destination address is in filter_own array
if [[ ${filter_own[(i)"$ftos"]} -le ${#filter_own} ]] ; then
act "$c\t\t/ $numm\t\t-> priv"
cat "$m" | deliver priv
{ test $? = 0 } && { rm "$m" }
-
- else
-
- # if here then file to unsorted
- act "$c\t\t/ $numm\t\t-> unsorted"
- cat "$m" | deliver unsorted
- { test $? = 0 } && { rm "$m" }
-
fi
-
done
+ # if here then file to unsorted
+ if [ "$mdinput" = "unsorted" ]; then
+ act "$c\t\t/ $numm"
+ else
+ act "$c\t\t/ $numm\t\t-> unsorted"
+ cat "$m" | deliver unsorted
+ { test $? = 0 } && { rm "$m" }
+ fi
+
done
return 0
diff --git a/src/zlibs/maildirs b/src/zlibs/maildirs
@@ -235,6 +235,10 @@ deliver() {
dest="$MAILDIRS/incoming"
else
dest="$MAILDIRS/$1"
+ { test -d "$dest" } || { dest="$1"
+ { test -d "$dest" } || {
+ error "delivery destination path invalid: $1"
+ return 1; } }
fi
# create destination maildir if not existing
@@ -263,7 +267,7 @@ deliver() {
BEGIN { print "Delivery to maildir: '"$1"'" }
{ print $0 }
/^$/ { exit }
-' "$1/new/$base" >> "$MAILDIRS/logs/jaro-deliver.log"
+' "$MAILDIRS/$1/new/$base" >> "$MAILDIRS/logs/jaro-deliver.log"
}
return 0