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 11de21e3c9c327c91de29bf2505ec1e821ff0d51
parent d5ca332ad5f6fc0216b1dc3611debbe59a4305d7
Author: Jaromil <jaromil@dyne.org>
Date:   Sun, 19 Mar 2017 23:12:23 +0100

several fixes to new parameter handling

still need to clean up use of ${PARAM} everywhere, but almost done

Diffstat:
Msrc/jaro | 134+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/zlibs/addressbook | 35++++++++++++++++++++---------------
Msrc/zlibs/email | 12++++++------
Msrc/zlibs/maildirs | 6++++++
4 files changed, 101 insertions(+), 86 deletions(-)

diff --git a/src/jaro b/src/jaro @@ -345,7 +345,6 @@ check_bin() { fi func "Mutt binary: `command -v mutt`" func "Notmuch binary: `command -v notmuch`" - func "Alot binary: `command -v alot`" func "Keyring set: $JARO_KEYRING" if [[ "$JARO_KEYRING" == "" ]]; then # check for pass, else fallback @@ -552,10 +551,12 @@ main() { option.parse $* || return 1 func "subcommand: $subcommand" + # print out version if option.is_set -v; then - cat $JAROMAILEXEC | awk '/^#/ {print $0 } !/^#/ {exit}' - echo + cat $JAROMAILEXEC | awk '/^#/ {print $0 } !/^#/ {exit}' + echo fi + { option.is_set -a } && { account=`option.value -a` } { option.is_set -l } && { if [[ "`option.value -l`" =~ "black" ]]; then @@ -581,11 +582,11 @@ main() { { option.is_set -f } && { FORCE=1 } # clean up options from param - PARAM=(${PARAM// -? /}) + # PARAM=(${PARAM// -? /}) case "$subcommand" in - compose) compose ${PARAM} + compose) compose ${option_params} exitcode=$? ;; @@ -595,17 +596,17 @@ main() { fetch) account=${account:-default} - fetch ${PARAM} && \ + fetch ${option_params} && \ update_filters && \ filter_maildir incoming && \ update_notmuch ;; - send) send ${PARAM} + send) send ${option_params} exitcode=$? ;; - peek) peek ${PARAM} + peek) peek ${option_params} exitcode=$? ;; @@ -615,13 +616,13 @@ main() { ;; replay) - replay ${PARAM} + replay ${option_params} exitcode=$? ;; update|init) [[ "$PARAM" = "" ]] || { - for p in $PARAM; do + for p in $option_params; do [[ "$p" = "." ]] && p=$PWD [[ -d $p ]] && MAILDIRS=$p done @@ -642,7 +643,7 @@ main() { ;; # notmuch search with file output - search) search ${PARAM} + search) search ${option_params} [[ $DRYRUN = 1 ]] || { for i in ${search_results=}; do print - "$i" @@ -650,7 +651,7 @@ main() { } | save_replay $subcommand ;; - alot) alot_search ${PARAM} ;; + alot) alot_search ${option_params} ;; notmuch) notice "Command: notmuch ${PARAM}" @@ -658,76 +659,76 @@ main() { exitcode=$? ;; - addr|list) search_addressbook ${PARAM} + addr|list) search_addressbook ${option_params} ;; - complete) complete ${PARAM} + complete) complete ${option_params} exitcode=$? ;; - isknown) sender_isknown ${PARAM} + isknown) sender_isknown ${option_params} exitcode=$? ;; - learn) learn ${PARAM} + learn) learn ${option_params} exitcode=$? ;; - import) import ${PARAM} + import) import ${option_params} exitcode=$? ;; "export") - export_vcard ${PARAM} + export_vcard ${option_params} ;; - abook) edit_abook ${PARAM} + abook) edit_abook ${option_params} exitcode=$? ;; - stat*) stats ${PARAM} | sort -n + stat*) stats ${option_params} | sort -n exitcode=$? ;; edit|vim) edit_file ${option_params} ;; - open) x_mutt -f ${PARAM} ;; - preview) preview_file ${PARAM} ;; + open) x_mutt -f ${option_params} ;; + preview) preview_file ${option_params} ;; mkdir) - DEBUG=1 maildirmake ${PARAM} + DEBUG=1 maildirmake ${option_params} exitcode=$? ;; copy) - maildir_shift ${PARAM} cp + maildir_shift ${option_params} cp exitcode=$? ;; move) - maildir_shift ${PARAM} mv + maildir_shift ${option_params} mv exitcode=$? ;; link) - maildir_shift ${PARAM} ln + maildir_shift ${option_params} ln exitcode=$? ;; - rmdupes) rmdupes ${PARAM} ;; - merge) merge ${PARAM} ;; + rmdupes) rmdupes ${option_params} ;; + merge) merge ${option_params} ;; filter) - update_filters ${PARAM} + update_filters ${option_params} [[ $? = 0 ]] || { error "error updating filters, operation aborted." break } - filter_maildir ${PARAM} | save_replay $subcommand + filter_maildir ${option_params} | save_replay $subcommand exitcode=$? ;; deliver) - deliver ${PARAM} + deliver ${option_params} exitcode=$? ;; @@ -735,7 +736,7 @@ main() { host=${PARAM:-$imap} new_password ;; - # cert) cert ${PARAM} ;; # was checking is_online + # cert) cert ${option_params} ;; # was checking is_online isonline) is_online ${=PARAM}; exitcode=$? ;; @@ -813,23 +814,23 @@ EOF ;; # list) - # list_abook ${PARAM} + # list_abook ${option_params} # exitcode=$? # ;; extract|parse) - extract_addresses ${PARAM} \ + extract_addresses ${option_params} \ | save_replay $subcommand exitcode=$? ;; header|headers) - extract_headers ${PARAM} + extract_headers ${option_params} exitcode=$? ;; smtp) - smtp_send ${PARAM} + smtp_send ${option_params} exitcode=$? ;; @@ -841,13 +842,13 @@ EOF ;; ismd) - maildircheck ${PARAM} + maildircheck ${option_params} [[ $? = 0 ]] && \ - notice "Directory is a maildir: ${PARAM}" + notice "Directory is a maildir: ${option_params}" exitcode=$? ;; - __unknown:*) # unknown command, pass it to autostart + __empty) # unknown command, pass it to autostart func "no command, autostart" func "subcommand: $subcommand" if [[ "$subcommand" = "__empty" ]]; then @@ -857,34 +858,37 @@ EOF else x_mutt -f "$PARAM" fi - exitcode=$? + fi + exitcode=$? + ;; + __unknown:*) # argument passed: determine if an email - elif [[ "$subcommand" = "__unknown" ]]; then - if isemail "$subcommand"; then - notice "Composing message to: ${@}" - # its an email, TODO see if we have it in our addressbook - x_mutt ${=@} - exitcode=0 - # or a directory of file - elif maildircheck "$subcommand"; then - # is it a maildir? then open - x_mutt -f "$subcommand" - exitcode=$? - elif maildircheck "$MAILDIRS/$subcommand"; then - x_mutt -f "$MAILDIRS/$subcommand" - exitcode=$? - elif [[ -f "$subcommand" ]]; then - # is it a regular file? then ;attach it - x_mutt -a ${=@} - exitcode=0 - else - # just open; mutt on first unread folder - x_mutt - exitcode=$? - - fi - fi + subcommand=${subcommand[(ws@:@)2]} + func "subcommand: $subcommand" + if isemail "$subcommand"; then + notice "Composing message to: ${@}" + # its an email, TODO see if we have it in our addressbook + x_mutt ${=@} + exitcode=0 + # or a directory of file + elif maildircheck "$subcommand"; then + # is it a maildir? then open + x_mutt -f "$subcommand" + exitcode=$? + elif maildircheck "$MAILDIRS/$subcommand"; then + x_mutt -f "$MAILDIRS/$subcommand" + exitcode=$? + elif [[ -f "$subcommand" ]]; then + # is it a regular file? then ;attach it + x_mutt -a ${=@} + exitcode=0 + else + # just open; mutt on first unread folder + x_mutt + exitcode=$? + + fi ;; esac diff --git a/src/zlibs/addressbook b/src/zlibs/addressbook @@ -89,7 +89,9 @@ lookup_email() { } complete() { - func "complete: $1 (list $list)" + fn complete $* + req=(list) + ckreq || return 1 # completion on configured groups { test -r "$MAILDIRS/Groups" } && { @@ -120,6 +122,7 @@ complete() { } sender_isknown() { + fn sender_isknown $* # extract only headers from stdin head="`awk ' { print $0 } @@ -135,11 +138,10 @@ sender_isknown() { } learn() { - func "learning ${PARAM[1]} in stdin piped mails" + fn learn $* [[ $DRYRUN == 1 ]] && func "running in dryrun mode, no entries added to addressbook" - what=sender - [[ "$1" = "" ]] || { what="$1" } + what=${1:-sender} func "learning from $what" # zero e_addr map before using e_parse @@ -207,14 +209,12 @@ learn() { # import emails from VCard into abook # checks if the emails are already known import_vcard() { - act "import VCard from file: $1" - - [[ -r "$1" ]] || { - error "File not found: $1" - return 1 - } - + fn import_vcard $* vcard="$1" + req=(vcard ADDRESSBOOK) + freq=($vcard) + ckreq || return 1 + head -n1 $vcard | grep '^BEGIN:VCARD' > /dev/null [[ $? = 0 ]] || { @@ -289,14 +289,11 @@ BEGIN { newcard=0; c=0; name=""; email=""; } # import address lists from stdin import() { + fn import $* # case insensitive match unsetopt CASE_MATCH - _arg=${PARAM[1]} - - func "import() arg: $_arg (param: $PARAM)" - notice "Import address list from stdin into addressbook $list" _new=0 @@ -343,6 +340,7 @@ import() { # export old addressbook format to abook export_old_to_abook() { + fn export_old_to_abook $* [[ -r $MAILDIRS/Addressbook ]] || { notice "Old addressbook format not found" @@ -424,6 +422,9 @@ convert_addresses() { } edit_abook() { + fn edit_abook $* + req=(ADDRESSBOOK) + ckreq || return 1 abook --config <(cat <<EOF set autosave=true @@ -435,6 +436,10 @@ EOF # print out all addresses into the selected addressbook list_abook() { + fn list_abook $* + req=(list ADDRESSBOOK) + ckreq || return 1 + notice "Extracting all addresses in $list" awk -F'=' ' /^name/ { printf("%s ",$2) } diff --git a/src/zlibs/email b/src/zlibs/email @@ -22,12 +22,12 @@ # extract all emails found in stdin, one per line compose() { - fn compose + fn compose $* # among the args parse recipient emails and files to attach local _files=() local _addrs=() - for p in ${PARAM}; do + for p in $*; do if [[ -r $p ]]; then func "attach: $p" _files+=(-a $p) @@ -70,7 +70,7 @@ queue() { notice "Adding mail to the outbox queue" base="`hostname`-queue-`date +%Y-%m-%d-%H.%M.%S`" - queue_to=($@) + queue_to=($*) # set it ready for saving in outbux queue_body="$base" @@ -186,7 +186,7 @@ fetchall() { } fetch() { - fn fetch + fn fetch $* [[ "$account" = "" ]] && { fetchall; return $? } @@ -429,7 +429,7 @@ EOF # SEND # this function should send all mails in outbox send() { - fn send + fn send * # list mails to send queue_outbox=`${=find} "${MAILDIRS}/outbox" -type f` @@ -539,7 +539,7 @@ BEGIN { body=0 } # PEEK # this function will open the MTA to the imap server without fetching mails locally peek() { - fn peek + fn peek $* read_account ${account} [[ $? = 0 ]] || { diff --git a/src/zlibs/maildirs b/src/zlibs/maildirs @@ -28,6 +28,8 @@ typeset -h formail_cache # returns 0 (success) if yes # no in all other cases maildircheck() { + maildircheck $* + { test -r "$1" } || { func "Maildir not existing: $1" return 1 } @@ -44,6 +46,7 @@ maildircheck() { } maildirmake() { + fn maildirmake $* { test -z "$1" } && { error "internal error: missing argument for maildirmake" @@ -73,6 +76,8 @@ maildirmake() { # fills up all maildirs array list_maildirs() { + fn list_maildirs $* + maildirs=`${=find} "$MAILDIRS" -maxdepth 1 -type d` for m in ${(f)maildirs}; do func "$m" @@ -89,6 +94,7 @@ list_maildirs() { rmdupes() { + fn rmdupes $* ## special argument lastlog { test "$1" = "lastlog" } && {