rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

commit 8249877f42642e5d5ef115cea40b541cb474dd82
parent 31d4287b8276e3661fb97bd1573eab1cc6a424a3
Author: parazyd <parazyd@dyne.org>
Date:   Fri,  2 Mar 2018 23:42:00 +0100

Cleanup and improvenents.

Diffstat:
Mbin/rpabook | 3+--
Dbin/rpcfg | 34----------------------------------
Mbin/rpcomp | 21++++++++++++++++++---
Mbin/rpinit | 106++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mbin/rppeek | 9+++------
Mbin/rpqueue | 2+-
Mbin/rpsend | 34++++++++++++++++------------------
Mbin/rpsync | 33++++++++++++++++++++++-----------
Mmutt/general | 4++++
9 files changed, 129 insertions(+), 117 deletions(-)

diff --git a/bin/rpabook b/bin/rpabook @@ -11,8 +11,7 @@ usage() { comp() { einfo "searching for $1 in addressbook" - abook --datafile "$profile/whitelist.abook" --mutt-query "$1" - return $? + abook --datafile "$profile/whitelist.abook" --mutt-query "$1" || return 1 } add() { diff --git a/bin/rpcfg b/bin/rpcfg @@ -1,34 +0,0 @@ -#!/bin/sh - -profile="${RPPROFILE:-$HOME/.rp/default}" -. "$HOME"/.rp/rplib/common.sh - -usage() { - edie "usage: $(basename $0) [-v value] [-l] - -v: view specified config value - -l: list all values" -} - -viewcfg() { - grep "$1" "$profile"/config | cut -d= -f2 | tr -d '"' -} - - -[ $# -gt 0 ] || usage -for i in $@; do - case "$i" in - -v) - shift 1 - [ -n "$1" ] || usage - viewcfg "$1" - exit $? - ;; - -l) - cat "$profile"/config - exit $? - ;; - *) - usage - ;; - esac -done diff --git a/bin/rpcomp b/bin/rpcomp @@ -1,7 +1,21 @@ #!/bin/sh +profile="${RPPROFILE:-$HOME/.rp/default}" + +content_head="Content-Type: text/plain; charset=\"utf-8\"" + to="" [ $# -gt 0 ] && to="$1" +[ $# -gt 1 ] && { + + exit 1 + + # added attachments + shift 1 + for i in $@; do + attach="$i,$attach" + done +} printf "Date: %s From: %s @@ -12,11 +26,12 @@ Bcc: Message-ID: %s User-Agent: rp MIME-Version: 1.0 -Content-Type: text/plain; charset=\"utf-8\"\n" \ +%s\n" \ "$(LANG=C date "+%a, %d %b %Y %T %Z")" \ - "$(rpcfg -v defaultfrom)" \ + "$(rpheaders defaultfrom < $profile/config)" \ "$to" \ - "$(rputil genmsgid)" + "$(rputil genmsgid)" \ + "$content_head" printf "\n\nText\n\n" diff --git a/bin/rpinit b/bin/rpinit @@ -53,52 +53,70 @@ printf " * from = " read -r from || exit 1 echo - -einfo "Please enter the hostname of your imap remote server." -printf " * remote imap server = " -read -r remoteimapserv || exit 1 +einfo "Please enter the network spec of your remote imap server." echo - - -einfo "Please enter the port of your remote imap server (993)." -printf " * remote imap port = " -read -r remoteimapport || exit 1 +einfo "Network specifications are for example:" +einfo " tcp!mail.example.com!imap" +einfo " tcp!mail.example.com!143" +echo +einfo "For a direct TLS connection:" +einfo " tcps!mail.example.com!imaps" +einfo " tcps!mail.example.com!993" +printf " * remote imap netspec = " +read -r rnet || exit 1 echo - einfo "Please enter your remote imap username." printf " * remote imap username = " -read -r remoteimapuser || exit 1 +read -r ruser || exit 1 echo einfo "Please enter your remote imap password." -pass insert .rp/$profile/imapremote +pass insert .rp/$profile/rimap echo -einfo "Please enter the address of your other imap server." -printf " * local imap server = " -read -r localimapserv || exit 1 +einfo "Please enter the network spec of your local imap server." echo - - -einfo "Please enter the port of your other imap server (143)." -printf " * local imap port = " -read -r localimapport || exit 1 +einfo "Network specifications are for example:" +einfo " tcp!localhost!imap" +einfo " tcp!localhost!143" +echo +einfo "For a direct TLS connection:" +einfo " tcps!localhost!imaps" +einfo " tcps!localhost!993" +printf " * local imap netspec = " +read -r lnet || exit 1 echo - -einfo "Please enter the username for your other imap server." +einfo "Please enter the username for your local imap server." printf " * local imap username = " -read -r localimapuser || exit 1 +read -r luser || exit 1 echo - -einfo "Please enter the password for your other imap server." -pass insert .rp/$profile/imaplocal +einfo "Please enter the password for your local imap server." +pass insert .rp/$profile/limap echo +lproto="$(echo $lnet | cut -d'!' -f1)" +lserv="$(echo $lnet | cut -d'!' -f2)" +lport="$(echo $lnet | cut -d'!' -f3)" + +case "$lproto" in + tcp) + lproto=imap;; + tcps) + lproto=imaps;; +esac + +case "$lport" in + imap) + lport=143;; + imaps) + lport=993;; +esac + cat <<EOF > $profile/muttrc # muttrc for $profile source ~/.rp/$profile/mutt/general @@ -109,14 +127,18 @@ source ~/.rp/$profile/mutt/sidebar source ~/.rp/$profile/mutt/gpg source ~/.rp/$profile/mutt/muttpass -set record = ~/.rp/$profile/tmp/Sent -set postponed = ~/.rp/$profile/tmp/Drafts - set from = "$from" -set realname = "$(echo $from | awk -F' <' '{print $1}')" +set realname = "$(echo $from | cut -d'<' -f1)" + +set folder = "${lproto}://${luser}@${lserv}:${lport}" +set spoolfile = "${lproto}://${luser}@${lserv}:${lport}/INBOX" -set folder = "imap://$localimapuser@$localimapserv:$localimapport" -set spoolfile = "imap://$localimapuser@$localimapserv:$localimapport/INBOX" +set record = "=Sent" +set postponed = "=Drafts" + +set mailcap_path = ~/.rp/$profile/mutt/mailcap +set header_cache = ~/.rp/$profile/tmp/mutt_hcache +set header_cache_backend = lmdb # add your customizations in the following file source ~/.rp/$profile/muttrc-custom @@ -124,15 +146,11 @@ EOF touch $profile/muttrc-custom cat <<EOF > $profile/config -defaultfrom="$from" - -imap1host="$remoteimapserv" -imap1port="$remoteimapport" -imap1user="$remoteimapuser" - -imap2host="$localimapserv" -imap2port="$localimapport" -imap2user="$localimapuser" +defaultfrom: $from +rnet: $rnet +ruser: $ruser +lnet: $lnet +luser: $luser EOF setupmutt "$profile" @@ -140,7 +158,11 @@ setupmutt "$profile" touch "$profile/whitelist.abook" chmod 600 "$profile/whitelist.abook" -cp "$shareprefix/misc/filters.txt" "$profile" +[ -f "$profile/filters.txt" ] || { + cp "$shareprefix/misc/filters.txt" "$profile" +} + +mkdir -p "$profile/tmp/mutt_hcache" ln -snf "$shareprefix/rplib" "./rplib" diff --git a/bin/rppeek b/bin/rppeek @@ -4,8 +4,6 @@ profile="${RPPROFILE:-$HOME/.rp/default}" . "$HOME"/.rp/rplib/common.sh . "$HOME"/.rp/rplib/pass.sh -. "$profile"/config - usage() { edie "usage: $(basename $0) [folder]" } @@ -16,7 +14,7 @@ for i in $@; do usage ;; *) - folder="$i" + folder="-f =${i}" einfo "requested folder '$i'" shift 1 ;continue ;; @@ -24,13 +22,12 @@ for i in $@; do done einfo "asking imap password from pass" -askmuttpass .rp/$(readlink $profile)/imaplocal +askmuttpass .rp/$(readlink $profile)/limap ( sleep 2; printf "set imap_pass = a\n" > $profile/mutt/muttpass ) & einfo "starting up mutt" -mutt -F $profile/muttrc \ - -f imap://${imap2user}@${imap2host}:${imap2port}/${folder} +neomutt -F $profile/muttrc $folder case $? in 0) einfo "mutt exited successfully";; diff --git a/bin/rpqueue b/bin/rpqueue @@ -5,6 +5,6 @@ profile="${RPPROFILE:-$HOME/.rp/default}" mkdir -p "$profile/tmp/outbox" email="$(cat)" -fname="$(printf "$email" | grep -i '^message-id' | cut -d' ' -f2 | tr -d '<>')" +fname="$(printf "$email" | rpheaders Message-ID | tr -d '<>')" printf "%s\n" "$email" > "$profile/tmp/outbox/$fname" diff --git a/bin/rpsend b/bin/rpsend @@ -4,8 +4,6 @@ profile="${RPPROFILE:-$HOME/.rp/default}" . "$HOME"/.rp/rplib/common.sh . "$HOME"/.rp/rplib/pass.sh -. "$profile"/config - usage() { edie "usage: $(basename $0) [-n] [-l] [-a] < email -n: dry run @@ -13,10 +11,7 @@ usage() { -a: send all" } -listoutbox() { - find "$profile"/tmp/outbox -type f -} - +listoutbox() { find "$profile"/tmp/outbox -type f ; } for i in $@; do case "$i" in @@ -32,7 +27,7 @@ for i in $@; do -a) einfo "sending all available emails" for i in $(rpsend -l); do - rpsend < "$i" && rm -f "$i" + rpsend < "$i" && { [ -z "$dryrun" ] && rm -f "$i" ; } done exit $? ;; @@ -44,16 +39,20 @@ done email="$(cat)" +rnet="$(rpheaders rnet < $profile/config)" +rimap="$(echo $rnet | cut -d'!' -f2)" +ruser="$(rpheaders ruser < $profile/config)" + echo >&2 -einfo "smtp send via $imap1host" +einfo "smtp send via $rimap" if ! [ -f "$profile/smtp-fingerprint" ]; then - einfo "no saved tls certificate fingerprint found. going tofu" - getfingerprint $imap1host 587 > "$profile"/smtp-fingerprint + einfo "no saved tls certificate fingerprint found. going with tofu." + rpnet -f "$(echo $rnet | sed 's/imaps/smtps/')" > "$profile"/smtp-fingerprint fi known="$(cat $profile/smtp-fingerprint)" -served="$(rpnet -f "tcps!$imap1host!imaps")" +served="$(rpnet -f "$rnet")" einfo "known fingerprint: $known" einfo "served fingerprint: $served" @@ -68,10 +67,10 @@ fi msmtpcfg="$(mktemp)" cat <<EOF > "$msmtpcfg" account default -from $imap1user -user $imap1user -host $imap1host -password $(pass show .rp/$(readlink $profile)/imapremote) +from $ruser +user $ruser +host $rimap +password $(pass show .rp/$(readlink $profile)/rimap) port 587 auth plain tls on @@ -88,9 +87,8 @@ einfo "to: $_dest" einfo "sending $(humansize $(printf "$email\n" | wc -c)) over the network" -printf "$email\n" | msmtp "$dryrun" \ - -C "$msmtpcfg" \ - -t -X "$profile/tmp/msmtp.log" +printf "$email\n" | \ + msmtp $dryrun -C "$msmtpcfg" -t -X "$profile/tmp/msmtp.log" _e=$? diff --git a/bin/rpsync b/bin/rpsync @@ -4,8 +4,6 @@ profile="${RPPROFILE:-$HOME/.rp/default}" . "$HOME"/.rp/rplib/common.sh . "$HOME"/.rp/rplib/pass.sh -. "$profile"/config - usage() { edie "usage: $(basename $0) [-n] [-d] -n: dry run @@ -30,28 +28,41 @@ for i in $@; do esac done -ping -c 1 "$imap1host" || edie "$imap1host unreachable" +rhost="$(rpheaders rnet < $profile/config | cut -d'!' -f2)" +case "$(rpheaders rnet < $profile/config | cut -d'!' -f1)" in + tcps) tls1="--tls1" +esac + +lhost="$(rpheaders lnet < $profile/config | cut -d'!' -f2)" +case "$(rpheaders lnet < $profile/config | cut -d'!' -f1)" in + tcps) tls2="--tls2" +esac + +ruser="$(rpheaders ruser < $profile/config | cut -d' ' -f2)" +luser="$(rpheaders luser < $profile/config | cut -d' ' -f2)" + +ping -c 1 "$rhost" || edie "$rhost unreachable" einfo "starting imapsync" [ -n "$delete" ] && ewarn "remote deletion enabled" [ -n "$dryrun" ] && ewarn "dry run enabled" + imapsync \ --tmpdir "$profile/tmp" \ --nolog \ #--logdir "$profile/tmp/rpsync_log" \ --usecache \ - --host1 "$imap1host" \ - --user1 "$imap1user" \ - --passfile1 "$(askpass -v .rp/$(readlink $profile)/imapremote $profile/tmp/imapremote)" \ - --tls1 \ - --host2 "$imap2host" \ - --user2 "$imap2user" \ - --passfile2 "$(askpass -v .rp/$(readlink $profile)/imaplocal $profile/tmp/imaplocal)" \ + --host1 "$rhost" $tls1 \ + --user1 "$ruser" \ + --passfile1 "$(askpass -v .rp/$(readlink $profile)/rimap $profile/tmp/rimap)" \ + --host2 "$lhost" $tls2 \ + --user2 "$luser" \ + --passfile2 "$(askpass -v .rp/$(readlink $profile)/limap $profile/tmp/limap)" \ --automap ${dryrun} ${delete} \ --no-modulesversion _e=$? -rm -f "$profile/tmp/imaplocal" "$profile/tmp/imapremote" +rm -f "$profile/tmp/rimap" "$profile/tmp/limap" case "$_e" in 0) einfo "synced successfully";; diff --git a/mutt/general b/mutt/general @@ -34,3 +34,7 @@ set fcc_clear = yes set forward_decrypt = yes set forward_decode = no set mime_forward = yes + +set sleep_time = 0 +set pager_stop = yes +set pager_context = 3