commit 290ba973c78e6a88203859509f73782d345ee321
parent f730d9a11e98ec8415e25468507ca27e04dc0045
Author: Jaromil <jaromil@dyne.org>
Date: Thu, 30 Oct 2014 17:13:36 +0100
parse and print From: emails using learn (also in dryrun) for easy import in groups
Diffstat:
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/src/zlibs/addressbook b/src/zlibs/addressbook
@@ -170,11 +170,15 @@ sender_isknown() {
}
learn() {
- func "learn ${PARAM[1]} from mail in stdin"
+ func "learning ${PARAM[1]} in stdin piped mails"
+ [[ $DRYRUN == 1 ]] && {
+ func "dryrun parsing ${PARAM[1]} in stdin piped mails" }
what=sender
- { test -z ${PARAM[1]} } || { what=${PARAM[1]} }
+ [[ "${PARAM[1]}" != "" ]] && { what=${PARAM[1]} }
+
buffer=`cat`
+
case ${PARAM[1]} in
sender) # simple: one address only on From:
@@ -182,7 +186,11 @@ learn() {
# (Q) eliminates quotes, then word split
email="${(Q)head[(ws:,:)1]}"
name="${(Q)head[(ws:,:)2]}"
- insert_address "$email" "$name"
+ print "$name" "<$email>"
+ [[ $DRYRUN == 1 ]] || {
+ insert_address "$email" "$name"
+ { test $? = 0 } && { act "new: $_name <${_email}>" }
+ }
return 0
;;
@@ -192,8 +200,13 @@ learn() {
# (Q) eliminates quotes, then word split
email="${(Q)h[(ws:,:)1]}"
name="${(Q)h[(ws:,:)2]}"
- insert_address "$email" "$name"
- { test $? = 0 } && { act "new: $_name <${_email}>" }
+
+ print "$name" "<$email>"
+
+ [[ $DRYRUN == 1 ]] || {
+ insert_address "$email" "$name"
+ { test $? = 0 } && { act "new: $_name <${_email}>" }
+ }
done
return 0
;;
@@ -204,7 +217,12 @@ learn() {
# (Q) eliminates quotes, then word split
email="${(Q)h[(ws:,:)1]}"
name="${(Q)h[(ws:,:)2]}"
- insert_address "$email" "$name"
+ print "$name" "<$email>"
+
+ [[ $DRYRUN == 1 ]] || {
+ insert_address "$email" "$name"
+ { test $? = 0 } && { act "new: $_name <${_email}>" }
+ }
done
head="`print $buffer | ${WORKDIR}/bin/fetchaddr -x Cc -a`"
@@ -212,7 +230,12 @@ learn() {
# (Q) eliminates quotes, then word split
email="${(Q)h[(ws:,:)1]}"
name="${(Q)h[(ws:,:)2]}"
- insert_address "$email" "$name"
+ print "$name" "<$email>"
+
+ [[ $DRYRUN == 1 ]] || {
+ insert_address "$email" "$name"
+ { test $? = 0 } && { act "new: $_name <${_email}>" }
+ }
done
return 0
;;
@@ -221,6 +244,7 @@ learn() {
error "Unknown learning function: $what" ;;
esac
return 1
+
}
forget() {