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 39ddbf528a112388f06596a534dedd4eea821286
parent cbb50423108f1dd0a9f93904fc126c3c35991f19
Author: Jaromil <jaromil@dyne.org>
Date:   Sun,  5 Feb 2017 15:25:19 +0100

new way to call mutt

mboxes are now computed at each call with risible overhead
this fixes also change of known to INBOX for peek's sidebar

Diffstat:
Msrc/jaro | 21++-------------------
Msrc/zlibs/email | 66+++++++++++++++---------------------------------------------------
Msrc/zlibs/filters | 18------------------
Msrc/zlibs/helpers | 16++--------------
Asrc/zlibs/mutt | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 137 insertions(+), 102 deletions(-)

diff --git a/src/jaro b/src/jaro @@ -292,23 +292,6 @@ hostname=$(hostname) # gather the current hostname } # if not sourcing -_mutt() { - - [[ -r $MAILDIRS/.mutt/rc ]] || { - error "Jaro Mail is not yet configured." - error "To configure, edit the files in $MAILDIRS/Accounts" - error "Then run 'jaro update' at least once." - return 1 - } - - for i; do _fa+=" $i "; done - func "exec: mutt -F $MUTTDIR/rc ${=muttflags} ${_fa}" - [[ "$subcommand" = "peek" ]] || rm -f $MUTTDIR/muttpass - touch $MUTTDIR/muttpass - mutt -F $MUTTDIR/rc ${=muttflags} ${=_fa} - return $? -} - # binary programs recognition check_bin() { @@ -961,7 +944,7 @@ EOF elif isemail "$subcommand"; then notice "Composing message to: ${@}" # its an email, TODO see if we have it in our addressbook - _mutt ${=@} + x_mutt ${=@} exitcode=0 # or a directory of file elif maildircheck "$subcommand"; then @@ -973,7 +956,7 @@ EOF exitcode=$? elif [[ -f "$subcommand" ]]; then # is it a regular file? then ;attach it - _mutt -a ${=@} + x_mutt -a ${=@} exitcode=0 else # just open; mutt on first unread folder diff --git a/src/zlibs/email b/src/zlibs/email @@ -39,7 +39,7 @@ compose() { fi done - cat | _mutt ${=_files} -- ${=_addrs} + cat | x_mutt ${=_files} -- ${=_addrs} # _mutt -H <(print "To: ${PARAM[@]}") return $? } @@ -537,66 +537,30 @@ peek() { folder="" if ! [ -z ${1} ]; then - folder="${1}" - act "opening folder ${folder}" + folder="${1}" + act "opening folder ${folder}" fi case $transport in - SSL*|TLS*) act "using secure connection ($transport)" - iproto="imaps" ;; - plain) act "using clear text connection" - iproto="imap" ;; - *) - error "Unknown transport: $transport" - error "Configuration error in imap account ${account}" - return 1 ;; + SSL*|TLS*) act "using secure connection ($transport)" + iproto="imaps" ;; + plain) act "using clear text connection" + iproto="imap" ;; + *) + error "Unknown transport: $transport" + error "Configuration error in imap account ${account}" + return 1 ;; esac # escape at sign in login ilogin=`print $login | sed 's/@/\\@/'` { test $DRYRUN != 1 } && { - type=imap - host=$imap - port=$imap_port - - # when peeking and using mutt-kz use the sidebar - is_mutt_kz && { - cat <<EOF > "$MAILDIRS/.mutt/notmuch" -set sidebar_width = 25 -set sidebar_visible = yes - -color sidebar_new white default -color progress default magenta - -bind index p sidebar-prev -bind index n sidebar-next -bind index <space> sidebar-open - -macro pager S "<enter-command>toggle sidebar_visible<enter>" -macro index S "<enter-command>toggle sidebar_visible<enter>" - -EOF - } - - # when peeking don't mark unread messages as Old - # and sort date received with no threading (latest up) - # also set the spoolfile name to INBOX (imap's default) - rm -f "$MAILDIRS/.mutt/muttpass" - sysread -o 1 <<EOF > "$MAILDIRS/.mutt/muttpass" -set imap_pass = \`$WORKDIR/bin/jaro -a ${account} askpass\` -unset mark_old -set sort=reverse-date-received -set folder=${iproto}://${ilogin}@${imap}:${imap_port} -set spoolfile=${iproto}://${ilogin}@${imap}:${imap_port}/INBOX -EOF - - # schedule deletion of muttpass file after use - sched +3 " -rm -f $MAILDIRS/.mutt/muttpass -touch $MAILDIRS/.mutt/muttpass" + type=imap + host=$imap + port=$imap_port - _mutt -f ${iproto}://${ilogin}@${imap}:${imap_port}/${folder} + x_mutt -f ${iproto}://${ilogin}@${imap}:${imap_port}/${folder} } # DRYRUN return $? diff --git a/src/zlibs/filters b/src/zlibs/filters @@ -619,24 +619,6 @@ EOF touch "$MAILDIRS/.mutt/notmuch" - # just the header, will be completed later - rm -f $MAILDIRS/.mutt/mboxes - print -n "mailboxes +known +priv" > $MAILDIRS/.mutt/mboxes - - for f in `cat "$MAILDIRS/Filters.txt" | awk ' - /^#/ {next} - /^./ { print $4 }'`; do - # MUTT (generate mailboxes priority this parser) - print " \\" >> $MAILDIRS/.mutt/mboxes - print -n " +${f} " >> $MAILDIRS/.mutt/mboxes - done - print " \\" >> $MAILDIRS/.mutt/mboxes - print " +unsorted.ml +unsorted" >> $MAILDIRS/.mutt/mboxes - - ztmp - ttmp=$ztmpfile - uniq $MAILDIRS/.mutt/mboxes > $ttmp - mv $ttmp $MAILDIRS/.mutt/mboxes } diff --git a/src/zlibs/helpers b/src/zlibs/helpers @@ -220,18 +220,6 @@ edit_file() { return $? } -is_mutt_kz() { - rm -f "$MAILDIRS/.mutt/notmuch" - touch "$MAILDIRS/.mutt/notmuch" - kz=`mutt -v | awk '/Configure options.*enable-notmuch/ { print $0 }'` - if [[ "$kz" = "" ]]; then - return 1 - else - act "Notmuch powered mutt-kz detected, enabling extra features" - return 0 - fi -} - ##################### ## Open a mail folder open_folder() { @@ -280,9 +268,9 @@ EOF } if [[ "$1" = "" ]]; then - _mutt -Z + x_mutt -Z else - _mutt -f "$1" + x_mutt -f "$1" fi return $? } diff --git a/src/zlibs/mutt b/src/zlibs/mutt @@ -0,0 +1,118 @@ +#!/usr/bin/env zsh +# +# Jaro Mail, your humble and faithful electronic postman +# +# a tool to easily and privately handle your e-mail communication +# +# Copyright (C) 2017 Dyne.org Foundation +# +# JaroMail is designed, written and maintained by 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 +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This source code is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# Please refer to the GNU Public License for more details. +# +# You should have received a copy of the GNU Public License along with +# this source code; if not, write to: +# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +is_mutt_kz() { + rm -f "$MAILDIRS/.mutt/notmuch" + touch "$MAILDIRS/.mutt/notmuch" + kz=`mutt -v | awk '/Configure options.*enable-notmuch/ { print $0 }'` + if [[ "$kz" = "" ]]; then + return 1 + else + act "Notmuch powered mutt-kz detected, enabling extra features" + return 0 + fi +} + + +x_mutt() { + + [[ -r $MAILDIRS/.mutt/rc ]] || { + error "Jaro Mail is not yet configured." + error "To configure, edit the files in $MAILDIRS/Accounts" + error "Then run 'jaro update' at least once." + return 1 + } + + + # when peeking and using mutt-kz use the sidebar + is_mutt_kz && { + cat <<EOF > "$MAILDIRS/.mutt/notmuch" +set sidebar_width = 25 +set sidebar_visible = yes + +color sidebar_new white default +color progress default magenta + +bind index p sidebar-prev +bind index n sidebar-next +bind index <space> sidebar-open + +macro pager S "<enter-command>toggle sidebar_visible<enter>" +macro index S "<enter-command>toggle sidebar_visible<enter>" + +EOF + } + + rm -f $MAILDIRS/.mutt/mboxes + + for i; do _fa+=" $i "; done + func "exec: mutt -F $MUTTDIR/rc ${=muttflags} ${_fa}" + + ztmp + _mboxes=$ztmpfile + + if [[ "$subcommand" = "peek" ]]; then + # when peeking don't mark unread messages as Old + # and sort date received with no threading (latest up) + # also set the spoolfile name to INBOX (imap's default) + rm -f "$MAILDIRS/.mutt/muttpass" + sysread -o 1 <<EOF > "$MAILDIRS/.mutt/muttpass" +set imap_pass = \`$WORKDIR/bin/jaro -a ${account} askpass\` +unset mark_old +set sort=reverse-date-received +set folder=${iproto}://${ilogin}@${imap}:${imap_port} +set spoolfile=${iproto}://${ilogin}@${imap}:${imap_port}/INBOX +EOF + + print -n "mailboxes +INBOX +priv" > $_mboxes + else + print -n "mailboxes +known +priv" > $_mboxes + rm -f $MUTTDIR/muttpass + fi + + touch $MUTTDIR/muttpass + + # make the mailboxes according to filters and such + + for f in `cat "$MAILDIRS/Filters.txt" | awk ' + /^#/ {next} + /^./ { print $4 }'`; do + # MUTT (generate mailboxes priority this parser) + print " \\" >> $_mboxes + print -n " +${f} " >> $_mboxes + done + print " \\" >> $_mboxes + print " +unsorted.ml +unsorted" >> $_mboxes + + uniq $_mboxes > $MAILDIRS/.mutt/mboxes + + # schedule deletion of muttpass file after use + sched +3 " +rm -f $MAILDIRS/.mutt/muttpass +touch $MAILDIRS/.mutt/muttpass" + + mutt -F $MUTTDIR/rc ${=muttflags} ${=_fa} + return $? +}