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 106d017855f3c3e271ba7d64b8dcc64b8aaa9aee
parent 204da1ac6acf3119e07cd9cace8818357d6f0e21
Author: Jaromil <jaromil@dyne.org>
Date:   Tue,  3 Jul 2012 11:36:45 +0200

replaced echo with print

Diffstat:
Msrc/zlibs/accounts | 14+++++++-------
Msrc/zlibs/addressbook | 6+++---
Msrc/zlibs/email | 40+++++++++++++++-------------------------
Msrc/zlibs/filters | 12++++++------
Msrc/zlibs/helpers | 2+-
Msrc/zlibs/imap | 8+++++---
Msrc/zlibs/stats | 16++++++++--------
7 files changed, 45 insertions(+), 53 deletions(-)

diff --git a/src/zlibs/accounts b/src/zlibs/accounts @@ -45,7 +45,7 @@ list_accounts() { /^email/ { printf "<%s>", $2 } /^host/ { printf " on %s", $2 } {next}' $a.txt - echo " (`basename $a | cut -d. -f1`)" + print " (`basename $a | cut -d. -f1`)" done } @@ -59,8 +59,8 @@ read_account() { { test "$1" != "" } && { account=$1 } account=".${account}" - type=`echo ${account} | cut -d. -f2` - account=`echo ${account} | cut -d. -f3` + type=`print ${account} | cut -d. -f2` + account=`print ${account} | cut -d. -f3` { test "$2" != "" } && { account=$2 } @@ -87,8 +87,8 @@ read_account() { elif [ ${#all} != 1 ]; then error "Too many $type accounts named $account" act -n "" - for i in ${=all}; do echo -n "`basename ${i}` "; done - echo; error "Refine your account keyword using -a option" + for i in ${=all}; do print -n "`basename ${i}` "; done + print; error "Refine your account keyword using -a option" return 1 fi @@ -191,7 +191,7 @@ ask_password() { ################### # USE GNOME KEYRING { test $GNOMEKEY = 1 } && { - echo "protocol=${type}\npath=jaromail/${email}\nusername=${login}\nhost=${host}\n\n" \ + print "protocol=${type}\npath=jaromail/${email}\nusername=${login}\nhost=${host}\n\n" \ | $WORKDIR/bin/jaro-gnome-keyring check if [ $? != 0 ]; then # its a new password new_password @@ -200,7 +200,7 @@ ask_password() { return 1 } else # password found into gnome keyring act "Using saved password for $1 @ $2" - password=`echo "protocol=${type}\npath=jaromail/${email}\nusername=${login}\nhost=${host}\n\n" | $WORKDIR/bin/jaro-gnome-keyring get` + password=`print "protocol=${type}\npath=jaromail/${email}\nusername=${login}\nhost=${host}\n\n" | $WORKDIR/bin/jaro-gnome-keyring get` fi return 0 } diff --git a/src/zlibs/addressbook b/src/zlibs/addressbook @@ -90,8 +90,8 @@ address() { matches="${matches}\n`search_name ${PARAM[1]}`" # mutt query requires something like this - echo "jaro: `echo $matches | wc -l` matches" - echo "$matches" | awk ' + print "jaro: `print $matches | wc -l` matches" + print "$matches" | awk ' { printf "%s\t", $1 for(i=2;i<=NF;i++) { sub("<","",$i) @@ -144,7 +144,7 @@ list_addresses() { SELECT * FROM $list; EOF - echo ".dump" | ${SQL} -batch $WORKDIR/addressbook \ + print ".dump" | ${SQL} -batch $WORKDIR/addressbook \ | bzip2 > $WORKDIR/addressbook.bz2 notice "Backup of all addressbook created" act -n ""; ls -lh $WORKDIR/addressbook.bz2 diff --git a/src/zlibs/email b/src/zlibs/email @@ -49,7 +49,7 @@ queue() { mailfile="$base.mail" msmtpfile="$base.msmtp" # Write command line to $MSMTPFILE - echo "$@" > "$msmtpfile" + print "$@" > "$msmtpfile" lock $msmtpfile # Write the mail to $MAILFILE cat > "$mailfile" @@ -65,8 +65,8 @@ fetchall() { res=0 for i in `find $WORKDIR/Accounts -type f | grep -v README`; do account=`basename $i` - type=`echo $account | cut -d. -f1` - account=`echo $account | cut -d. -f2` + type=`print $account | cut -d. -f1` + account=`print $account | cut -d. -f2` fetch $type $account if [ $? != 0 ]; then res=1; fi # returns an error if just one of the accounts did @@ -108,28 +108,18 @@ fetch() { ask_password $login $host - - # skip getting size if Gmail - # (imap there lacks support for RFC822.SIZE) -# { test "$host" != "imap.gmail.com" } && { + # this puts total size in $imap_info get_imap_info - { test ${imap_info[${#imap_info}]} = 0 } && { - # imap account is empty + + # return here if the imap folders are all empty + { test ${imap_info[${#imap_info}]} = 0 } && { + act "Mailbox is empty, nothing to fetch." return 0 } + notice "Total occupation is `human_size ${imap_info[${#imap_info}]}`" -# } - # this puts total size in $imap_info { test $DRYRUN != 1 } && { - { test ${imap_info[${#imap_info}]} -eq 0 } && { return 0 } - - ask_password $login $host - { test $? != 0 } && { - error "Error retrieving password for $login on $host" - unset password all; return 1 - } - tmp=$TMPDIR/$host.fetch.$RANDOM newlock $tmp cat <<EOF > $tmp @@ -138,10 +128,10 @@ EOF unset password if ! [ -z $accountopt ]; then # add option configuration - echo "${accountopt}" >> $tmp; fi + print "${accountopt}" >> $tmp; fi if ! [ -z $folders ]; then # add folder configuration - echo "folder ${folders}" >> $tmp; fi + print "folder ${folders}" >> $tmp; fi cat <<EOF >> $tmp ssl warnings 3600 and wants mda "procmail -m $PROCMAILDIR/rc" @@ -196,7 +186,7 @@ EOF total=`mailstat -k $WORKDIR/log/procmail.log | tail -n1 | awk '{print $2}'` briefing=`mailstat -kt $WORKDIR/log/procmail.log |awk '!/procmail/ { print " " $2 "\t" $3 }'|sort -nr` notice "$total emails fetched" - echo "${briefing}" + print "${briefing}" } # DRYRUN @@ -256,7 +246,7 @@ EOF unset password for mail in `find $MAILDIRS/outbox -name "*.mail"`; do - smtp=`echo ${mail} | sed -e 's/mail/msmtp/'` + smtp=`print ${mail} | sed -e 's/mail/msmtp/'` lock ${smtp} recipients="`cat ${smtp}`" act "To: ${recipients}" @@ -303,7 +293,7 @@ peek() { iproto="imap" ;; esac # escape at sign in login - ilogin=`echo $login | sed 's/@/\\@/'` + ilogin=`print $login | sed 's/@/\\@/'` { test $DRYRUN != 1 } && { @@ -319,7 +309,7 @@ set imap_pass = "${password}" # set imap_peek = yes EOF unset password - echo "source $tmp" >> $MUTTDIR/password + print "source $tmp" >> $MUTTDIR/password (sleep 1; cp /dev/null $MUTTDIR/password cp /dev/null $tmp diff --git a/src/zlibs/filters b/src/zlibs/filters @@ -105,7 +105,7 @@ EOF # just the header, will be completed later in procmail loop rm -f $MUTTDIR/mboxes - echo -n "mailboxes +priv" > $MUTTDIR/mboxes + print -n "mailboxes +priv" > $MUTTDIR/mboxes # update identity with default read_account imap @@ -202,7 +202,7 @@ zz.bounces/ EOF ####### - echo "# filters generated from Filters.txt" >> $PROCMAILDIR/rc + print "# filters generated from Filters.txt" >> $PROCMAILDIR/rc typeset -alU filter_from typeset -alU filter_to @@ -234,8 +234,8 @@ EOF ;; esac # MUTT (generate mailboxes priority this parser) - echo " \\" >> $MUTTDIR/mboxes - echo -n " +${destination} " >> $MUTTDIR/mboxes + print " \\" >> $MUTTDIR/mboxes + print -n " +${destination} " >> $MUTTDIR/mboxes done # now do the sieve @@ -388,8 +388,8 @@ unsorted.ml/ EOF # MUTT (generate mailboxes priority this parser) - echo " \\" >> $MUTTDIR/mboxes - echo " +unsorted.ml +unsorted" >> $MUTTDIR/mboxes + print " \\" >> $MUTTDIR/mboxes + print " +unsorted.ml +unsorted" >> $MUTTDIR/mboxes uniq $MUTTDIR/mboxes > $TMPDIR/mboxes mv $TMPDIR/mboxes $MUTTDIR/mboxes diff --git a/src/zlibs/helpers b/src/zlibs/helpers @@ -36,7 +36,7 @@ autostart() { } # argument passed: determine if an email - echo "${1}" \ + print "${1}" \ | tr 'A-Z' 'a-z' \ | grep '^[a-zA-Z0-9._%+-]*@[a-zA-Z0-9]*[\.[a-zA-Z0-9]*]*[a-zA-Z0-9]$' \ > /dev/null diff --git a/src/zlibs/imap b/src/zlibs/imap @@ -27,6 +27,8 @@ get_imap_info() { { test "$type" != "imap" } && { error "get_imap_info() called on a non-imap account: $type.$host" return 1 } + # skip getting size if Gmail + # (imap there lacks support for RFC822.SIZE) { test "$host" = "imap.gmail.com" } && { act "skipping IMAP examination on GMail account" return 1 } @@ -56,10 +58,10 @@ B00001 LOGIN "${login}" "${password}" EOF c=$(( $c + 1 )) - echo "B0000$c SELECT \"${f}\"" >> $query + print "B0000$c SELECT \"${f}\"" >> $query c=$(( $c + 1 )) - echo "B0000$c FETCH 1:* (FLAGS RFC822.SIZE)" >> $query - echo >> $query + print "B0000$c FETCH 1:* (FLAGS RFC822.SIZE)" >> $query + print >> $query typeset -al res for i in `timeout 5 openssl s_client -starttls imap -quiet \ diff --git a/src/zlibs/stats b/src/zlibs/stats @@ -40,7 +40,7 @@ stats() { grandtot=0 for i in ${maildirs}; do # find maildir prefixes - pfx=`echo $i | cut -d. -f1` + pfx=`print $i | cut -d. -f1` # is it a new prefix? { test "$pfx" = "$oldpfx" } && { continue } oldpfx=$pfx @@ -98,7 +98,7 @@ EOF for m in ${maildirs}; do for f in `find $MAILDIRS/${m} -type f`; do timestamp=`fetchdate "%Y-%U" ${f}` - mdir=`echo $m|cut -d. -f1` + mdir=`print $m|cut -d. -f1` cat <<EOF | ${SQL} -batch $db > $sql SELECT * FROM stats WHERE ml IS "${mdir}" AND date IS "${timestamp}"; @@ -135,7 +135,7 @@ SELECT date FROM stats ORDER BY date; EOF for w in `cat $sql | uniq`; do week+=($w) - echo "<th scope=\"col\">${w}</th>" >> $table + print "<th scope=\"col\">${w}</th>" >> $table done cat <<EOF >> $table </tr> @@ -145,12 +145,12 @@ EOF EOF prevmdir="" for m in ${maildirs}; do - mdir=`echo $m|cut -d. -f1` + mdir=`print $m|cut -d. -f1` # skip duplicates if [ "$prevmdir" = "$mdir" ]; then continue else prevmdir=$mdir; fi - echo -n "<tr><th scopre=\"row\">$mdir</th>" >> $table + print -n "<tr><th scopre=\"row\">$mdir</th>" >> $table for w in ${week}; do cat <<EOF | ${SQL} -batch $db > $sql SELECT hits FROM stats @@ -160,9 +160,9 @@ EOF for h in `cat $sql`; do sum=$(( $sum + $h )) done - echo -n "<td>$sum</td>" >> $table + print -n "<td>$sum</td>" >> $table done - echo "</tr>" >> $table + print "</tr>" >> $table done cat <<EOF >> $table @@ -172,7 +172,7 @@ EOF cp $WORKDIR/.stats/visualize/header.html \ $WORKDIR/.stats/index.html cat $table >> $WORKDIR/.stats/index.html - echo "</body>\n</html>\n" >> $WORKDIR/.stats/index.html + print "</body>\n</html>\n" >> $WORKDIR/.stats/index.html } timecloud() {