rp

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

commit 7a87c115d40a720f1f9a99514f6f9f05acd8c0e9
parent 4c1c5c111be369a8121e0f2acc5c6210cbc22052
Author: parazyd <parazyd@dyne.org>
Date:   Tue, 27 Feb 2018 23:55:32 +0100

Add humansize and fix rpabook bug.

Diffstat:
Mbin/rpabook | 11+++++++++--
Mbin/rpsend | 9++++++---
Mrplib/common.sh | 20++++++++++++++++++++
3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/bin/rpabook b/bin/rpabook @@ -26,11 +26,18 @@ insert() { for i in $@; do case "$i" in -a) - comp "$2" > /dev/null || insert "$2" + shift 1 + rpabook -c "$1" > /dev/null || rpabook -i "$1" + exit $? + ;; + -i) + shift 1 + insert "$1" exit $? ;; -c) - comp "$2" + shift 1 + comp "$1" exit $? ;; *) diff --git a/bin/rpsend b/bin/rpsend @@ -81,11 +81,14 @@ tls_starttls on tls_certcheck off EOF +_subj="$(printf "$email" | grep -i '^subject: ' | cut -d: -f2 | cut -c2-)" +_dest="$(printf "$email" | grep -i '^to: ' | cut -d: -f2 | cut -c2-)" ebegin "sending using msmtp" -einfo "subject:$(printf "$email" | grep -i '^subject: ' | cut -d: -f2)" -einfo "to: $(printf "$email" | grep -i '^to: ' | cut -d: -f2)" -printf "$email" | rpabook -a +einfo "subject: $_subj" +einfo "to: $_dest" +rpabook -a "${_dest}" +ebegin "sending $(humansize $(printf "$email\n" | wc -c)) over the network" printf "$email\n" | msmtp "$dryrun" \ diff --git a/rplib/common.sh b/rplib/common.sh @@ -32,3 +32,23 @@ edie() { printf "${boldred} * ${reset}%s\n" "$*" >&2 exit 1 } + +humansize() { + [ "$1" -gt 1073741824 ] && { + printf "$(( $1 >> 30 )) GiB" + return 0 + } + + [ "$1" -gt 1048576 ] && { + printf "$(( $1 >> 20 )) MiB" + return 0 + } + + [ "$1" -gt 1024 ] && { + printf "$(( $1 >> 10 )) KiB" + return 0 + } + + printf "$1 Bytes" + return 0 +}