commit 429b71eef4ff09198fbd477d226a592573525d60
parent 36629e64aa7b94c2b47a3576b6ff19ec3b0d9392
Author: Jaromil <jaromil@dyne.org>
Date: Fri, 26 Dec 2014 20:15:02 +0100
compacted list and extract commands into one
Diffstat:
5 files changed, 74 insertions(+), 69 deletions(-)
diff --git a/src/jaro b/src/jaro
@@ -4,7 +4,7 @@
#
# a tool to easily and privately handle your e-mail communication
#
-# Copyleft (C) 2010-2014 Denis Roio <jaromil@dyne.org>
+# Copyleft (C) 2010-2015 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
@@ -694,7 +694,6 @@ main()
isknown) CLEANEXIT=0; sender_isknown ${PARAM} ;;
learn) CLEANEXIT=0; learn ${PARAM} ;;
forget) CLEANEXIT=0; forget ${PARAM} ;;
- list) CLEANEXIT=0; list_addresses ${PARAM} ;;
import) import_addressbook "${PARAM}" ;;
"export")
@@ -783,8 +782,8 @@ main()
esac
;;
- extract)
- md_extract ${=@}
+ list|extract)
+ extract ${=PARAM}
exitcode=$?
;;
diff --git a/src/zlibs/addressbook b/src/zlibs/addressbook
@@ -221,9 +221,10 @@ forget() {
# remove_address "${head[(ws:,:)1]}"
}
-# list all entries in addressbook or a file
-list_addresses() {
-
+# extract all entries in addressbook or all addresses in a pgp keyring
+# or all signatures on a pgp key (even without importing it)
+extract() {
+ func "extract() $@"
# without arguments just list all entries in the active list
# default is whitelist
[[ "$1" = "" ]] && {
@@ -237,6 +238,68 @@ list_addresses() {
# a map to eliminate duplicates
typeset -AU result
+ [[ -r "$1" ]] || {
+ error "file not found: $1"
+ error "nothing to extract."
+ return 1
+ }
+
+ ## arg is a directory
+ [[ -d "$1" ]] && {
+ func "extract maildir: $1"
+ ## extract from a maildir
+ maildircheck "$1" && {
+ _action="$2"
+ case $_action in
+ all) ;;
+ recipient) ;;
+ sender) ;;
+ *) _action="all" ;;
+ esac
+ _mails=`find $1 -type f`
+ # TODO ismailfile() to check if file is a mail?
+
+ # we switch dryrun temporarily off to use learn()
+ # without modifying the addressbook
+ _dryrun=$DRYRUN
+ DRYRUN=1
+
+ notice "Extracting and listing $_action in maildir: $2"
+ act "please wait while scanning ${#_mails} mail files..."
+ typeset -a learned
+
+ for i in ${(f)_mails}; do
+ _l=`hdr $i | learn $_action`
+ # handles results on multiple lines (recipients, all)
+ for i in ${(f)_l}; do
+ learned+=("$i")
+ done
+ done
+
+ DRYRUN=$_dryrun
+ # eliminates duplicates
+ typeset -A result
+ for i in ${learned}; do
+ _e=${i[(ws:,:)1]}
+ [[ "${result[$_e]}" = "" ]] && {
+ _n=${i[(ws:,:)2]}
+ result+=("$_e" "$_n")
+ print - "$_n <$_e>"
+ }
+ done
+ notice "Unique $_action found: ${#result}"
+ # counts which addresses are known to us
+ _known=0
+ for i in ${(k)result}; do
+ lookup_email ${i}
+ [[ $? = 0 ]] && {
+ _known=$(( $_known + 1 )) }
+ done
+ act "addresses known: $_known"
+ return 0
+ }
+ }
+
######### GPG
[[ `file "$1"` =~ "GPG key public ring" ]] && {
@@ -264,6 +327,7 @@ list_addresses() {
_known=$(( $_known + 1 )) }
done
act "new addresses: $_known"
+ return 0
}
[[ `file "$1"` =~ "PGP public key" ]] && {
@@ -302,6 +366,7 @@ list_addresses() {
_known=$(( $_known + 1 )) }
done
act "new addresses: $_known"
+ return 0
}
}
diff --git a/src/zlibs/helpers b/src/zlibs/helpers
@@ -4,7 +4,7 @@
#
# a tool to easily and privately handle your e-mail communication
#
-# Copyleft (C) 2010-2014 Denis Roio <jaromil@dyne.org>
+# Copyleft (C) 2010-2015 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
diff --git a/src/zlibs/maildirs b/src/zlibs/maildirs
@@ -4,7 +4,7 @@
#
# a tool to easily and privately handle your e-mail communication
#
-# Copyleft (C) 2010-2014 Denis Roio <jaromil@dyne.org>
+# Copyleft (C) 2010-2015 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
@@ -276,62 +276,3 @@ BEGIN { print "Delivery to maildir: '"$1"'" }
return 0
}
-
-# extract and list all recipients in a maildir
-md_extract() {
- func "md_extract()"
- _action="$1"
- case $_action in
- all) ;;
- recipient) ;;
- sender) ;;
- *) error "unknown extract action: $_action"; return 1 ;;
- esac
-
- maildircheck "$2"
- [[ $? = 0 ]] || {
- error "Cannot extract $_action from maildir: $2"
- return 1 }
- _mails=`find $2 -type f`
- # TODO ismail() to check if file is a mail
-
- # we switch dryrun temporarily off to use learn()
- # without modifying the addressbook
- _dryrun=$DRYRUN
- DRYRUN=1
-
- notice "Extracting and listing $_action in maildir: $2"
- act "please wait while scanning ${#_mails} mail files..."
- typeset -a learned
-
- for i in ${(f)_mails}; do
- _l=`hdr $i | learn $_action`
- # handles results on multiple lines (recipients, all)
- for i in ${(f)_l}; do
- learned+=("$i")
- done
- done
-
- DRYRUN=$_dryrun
-
- # eliminates duplicates
- typeset -A result
- for i in ${learned}; do
- _e=${i[(ws:,:)1]}
- [[ "${result[$_e]}" = "" ]] && {
- _n=${i[(ws:,:)2]}
- result+=("$_e" "$_n")
- print - "$_n <$_e>"
- }
- done
- notice "Unique $_action found: ${#result}"
-
- # counts which addresses are known to us
- _known=0
- for i in ${(k)result}; do
- lookup_email ${i}
- [[ $? = 0 ]] && {
- _known=$(( $_known + 1 )) }
- done
- act "addresses known: $_known"
-}
diff --git a/src/zlibs/search b/src/zlibs/search
@@ -4,7 +4,7 @@
#
# a tool to easily and privately handle your e-mail communication
#
-# Copyleft (C) 2010-2014 Denis Roio <jaromil@dyne.org>
+# Copyleft (C) 2010-2015 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by