jaromail

a commandline tool to easily and privately handle your e-mail
git clone git://parazyd.org/jaromail.git
Log | Files | Refs | Submodules | README

commit 149c566e66b21c2a27bc520c054291e87deafb53
parent 3243ea23ffd66c59d65a1c4c40ee59487cfd19df
Author: Jaromil <jaromil@dyne.org>
Date:   Wed, 12 Dec 2012 12:53:38 +0100

refactoring of the whitelisting and addressbook functionality

now multiple addresses get correctly imported with capital A
to remove addresses the use of hotkeys is removed and abook is recommended
parsed names get quotes removed automatically

Diffstat:
Mdoc/jaromail-manual.org | 50+++++++++++++++++++++++++++-----------------------
Msrc/zlibs/addressbook | 43++++++++++++++++++++++++++++++++-----------
Msrc/zlibs/filters | 4++--
3 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/doc/jaromail-manual.org b/doc/jaromail-manual.org @@ -245,15 +245,14 @@ This we call implicit whitelisting. To explicitly whitelist an address from inside the mail reader index press [ *a* ] while selecting an email, this will add in the whitelist -all addresses mentioned in To: and Cc:. To remove an address from the -whitelist, press [ *A* ] (shift-a) while selecting a mail and its -sender (only the From: field) will lose the privilege of ending up in -your *known/* folder. +the sender address (From: header). If you want to add all addresses +reached by the mail (From: To: and Cc: fields) use the same letter +capitalized pressing shift [ *A* ]. -There is one more privilege for people that have their address -whitelisted: their name and e-mail will be completed automatically -when composing a new email, pressing the *Tab* key while indicating -them among the recipients. +All addresses selected this way will have the privilege of ending up +in your *known/* folder, plus their name and e-mail will be completed +automatically when composing a new email, pressing the *Tab* key while +indicating them among the recipients. ** Blacklist @@ -262,11 +261,6 @@ e-mail is selected on the index: the sender indicated in the From: field will be downgraded to the very bottom of your priorities, closes to spam than the rest, the most infamous *zz.blacklist/* folder. -Similarly, to remove addresses from the blacklist the [ *Z* ] (shift-z) -key can be pressed and all addresses mentioned in the currently -selected e-mail (including those in Cc:) will be redeemed, but not -whitelisted unless you do it explicitly with 'a'. - ** Addressbook What we call addressbook here basically consists of both the whitelist @@ -279,7 +273,12 @@ Evolution etc.)[fn:appleaddr] [fn:appleaddr] On Apple/OSX systems Jaro Mail has access to the Mail.app addressbook, so all contacts known in your Mac will be automatically whitelisted -To edit the addressbook in Jaro Mail the *abook* command is available +Both the white and blacklist can be edited using a text interface, +this way you can delete entries for instance (removing them from the +whitelist or blacklist), or add entries by hand (for instance manually +from visit cards), as well you can change details directly (name and +email). To edit the addressbook in Jaro Mail the *abook* command is +available : $ jaro abook This will open the current whitelist for edit, but one can append "blacklist" to this commandline to open that one instead. @@ -287,9 +286,14 @@ This will open the current whitelist for edit, but one can append To quickly dump to the console all names and addresses in the Jaro Mail addressbook, one can use the *list* command : $ jaro list -Even more useful to interface with other addressbook software and -mobile phones, you can use the *export* and *import* functions to -transport your addressbook formatted as a series of +To search a string across the addressbook, simply use the command +search followed by a string, for instance: +: $ jaro search autistici +will list all addresses @autistici in your addressbook. + +Even more useful to interface with other addressbook +software and mobile phones, you can use the *export* and *import* +functions to transport your addressbook formatted as a series of VCards[fn:vcard]. : $ jaro export Will create or update the file in *Mail/jaro/addressbook.vcf*. On the @@ -313,12 +317,11 @@ Below a recapitulation of keys related to the white and blacklisting functionality, to be used in the e-mail index or when an e-mail is open inside the mail user agent: -| List | Key | Function | Fields | -|-------+-------------+----------------------------+-----------| -| White | *a* | Add all addresses found | From: Cc: | -| White | *A* (shift) | Remove sender address | From: | -| Black | *z* | Add sender address | From: | -| Black | *Z* (shift) | Remove all addresses found | From: Cc: | +| List | Key | Function | Fields | +|-------+-------------+----------------------------+---------------| +| White | *a* | Add the sender address | From: | +| White | *A* (shift) | Add all addresses | From: To: Cc: | +| Black | *z* | Blacklist the sender | From: | And here the addressbook commands that are available from the commandline: @@ -327,6 +330,7 @@ commandline: |----------+--------------------------| | *abook* | edit the addressbook | | *list* | list the addressbook | +| *search* | search a name or address | | *export* | export to a VCard file | | *import* | import from a VCard file | diff --git a/src/zlibs/addressbook b/src/zlibs/addressbook @@ -50,10 +50,11 @@ EOF return 0 } insert_address() { - func "insert address: $1, $2" + _email="$1"; _name="$2"; + func "insert address: $_name <$_email>" cat <<EOF | ${SQL} -batch ${addressbook} 2> /dev/null INSERT INTO $list (email, name) -VALUES ("${1}", "${2}"); +VALUES ("${_email}", "${_name}"); EOF { test $? != 0 } && { func "address already present in $list" @@ -146,29 +147,49 @@ learn() { what=sender { test -z ${PARAM[1]} } || { what=${PARAM[1]} } + buffer=`cat` case ${PARAM[1]} in + sender) # simple: one address only on From: - head="`cat | ${WORKDIR}/bin/fetchaddr -x From: -a`" - email="${head[(ws:,:)1]}" - name="${head[(ws:,:)2]}" + head="`print $buffer | ${WORKDIR}/bin/fetchaddr -x From: -a`" + # (Q) eliminates quotes, then word split + email="${(Q)head[(ws:,:)1]}" + name="${(Q)head[(ws:,:)2]}" insert_address "$email" "$name" return 0 ;; + + all) + head="`print $buffer | ${WORKDIR}/bin/fetchaddr -a`" + for h in ${(f)head}; do + # (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}>" } + done + return 0 + ;; + recipient) # complex: more addresses in To: and Cc: - head="`cat | ${WORKDIR}/bin/fetchaddr -x To: -a`" + head="`print $buffer | ${WORKDIR}/bin/fetchaddr -x To: -a`" for h in ${(f)head}; do - email="${h[(ws:,:)1]}" - name="${h[(ws:,:)2]}" + # (Q) eliminates quotes, then word split + email="${(Q)h[(ws:,:)1]}" + name="${(Q)h[(ws:,:)2]}" insert_address "$email" "$name" done - head="`cat | ${WORKDIR}/bin/fetchaddr -x Cc: -a`" + + head="`print $buffer | ${WORKDIR}/bin/fetchaddr -x Cc: -a`" for h in ${(f)head}; do - email="${h[(ws:,:)1]}" - name="${h[(ws:,:)2]}" + # (Q) eliminates quotes, then word split + email="${(Q)h[(ws:,:)1]}" + name="${(Q)h[(ws:,:)2]}" insert_address "$email" "$name" done return 0 ;; + *) error "Unknown learning function: $what" ;; esac diff --git a/src/zlibs/filters b/src/zlibs/filters @@ -66,9 +66,9 @@ set mailcap_path = "$WORKDIR/.mutt/mailcap:$WORKDIR/mailcap:$HOME/.mailcap:/etc/ # Little Brother Database set query_command = "$WORKDIR/bin/jaro -q complete '%s'" macro index,pager a "<pipe-message>$WORKDIR/bin/jaro -l whitelist -q learn sender<enter>" "add to whitelist everyone in the message" -macro index,pager A "<pipe-message>$WORKDIR/bin/jaro -l whitelist -q forget sender<enter>" "remove sender from whitelist +macro index,pager A "<pipe-message>$WORKDIR/bin/jaro -l whitelist -q learn all<enter>" "add all addresses in whitelist" macro index,pager z "<pipe-message>$WORKDIR/bin/jaro -l blacklist -q learn sender<enter>" "add sender to blacklist" -macro index,pager Z "<pipe-message>$WORKDIR/bin/jaro -l blacklist -q forget sender<enter>" "remove sender from blacklist +macro index,pager Z "<pipe-message>$WORKDIR/bin/jaro -l blacklist -q forget sender<enter>" "remove sender from blacklist" # mailboxes in order of priority source $MUTTDIR/mboxes