commit 4c1c5c111be369a8121e0f2acc5c6210cbc22052
parent 9348b680cd14d1c08274da417b8556c0df727dfc
Author: parazyd <parazyd@dyne.org>
Date: Tue, 27 Feb 2018 23:27:13 +0100
Add initial scripts.
Diffstat:
A | bin/rpabook | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
A | bin/rpinit | | | 152 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | bin/rppeek | | | 39 | +++++++++++++++++++++++++++++++++++++++ |
A | bin/rpqueue | | | 12 | ++++++++++++ |
A | bin/rpsend | | | 102 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | bin/rpsync | | | 59 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 files changed, 406 insertions(+), 0 deletions(-)
diff --git a/bin/rpabook b/bin/rpabook
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+profile="${RPPROFILE:-$HOME/.rp/default}"
+. "$HOME"/.rp/rplib/common.sh
+
+usage() {
+ einfo "usage: $(basename $0) [-a] [-c]"
+ einfo " -a: add to abook"
+ einfo " -c: completion (used from mutt)"
+ exit 1
+}
+
+comp() {
+ ebegin "searching for $1 in addressbook"
+ abook --datafile "$profile/whitelist.abook" --mutt-query "$1"
+ return $?
+}
+
+insert() {
+ ebegin "adding $1 to addressbook whitelist"
+ abook --datafile "$profile/whitelist.abook" \
+ --add-email-quiet > /dev/null
+ return $?
+}
+
+for i in $@; do
+ case "$i" in
+ -a)
+ comp "$2" > /dev/null || insert "$2"
+ exit $?
+ ;;
+ -c)
+ comp "$2"
+ exit $?
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+abook --datafile "$profile/whitelist.abook"
diff --git a/bin/rpinit b/bin/rpinit
@@ -0,0 +1,152 @@
+#!/bin/sh
+
+shareprefix="SHAREPREFIX"
+
+. "$shareprefix"/rplib/common.sh
+
+setupmutt() {
+ ebegin "copying mutt files"
+ mkdir -p "$HOME/.rp/$1/mutt"
+ touch "$HOME/.rp/$1/mutt/muttpass"
+ for i in $(ls -1 $shareprefix/mutt); do
+ cp -f "$shareprefix/mutt/$i" "$HOME/.rp/$1/mutt/"
+ done
+}
+
+usage() {
+ einfo "usage: $(basename $0) [-u profilename]"
+ einfo " -u: update"
+ exit 1
+}
+
+[ -n "$1" ] && {
+ case "$1" in
+ -u)
+ [ -n "$2" ] || prof="$(readlink $HOME/.rp/default)"
+ setupmutt "$prof"
+ exit 0
+ ;;
+ *)
+ usage
+ ;;
+ esac
+}
+
+einfo "Welcome to rp!"
+einfo "Let's start initializing your rp setup."
+
+mkdir -p ~/.rp && cd ~/.rp || exit 1
+
+printf " * What should be the name of your profile? > "
+read -r profile || exit 1
+mkdir -p "$profile" || exit 1
+echo
+
+[ -L default ] || ln -s "$profile" default
+
+einfo "Now the configuration begins."
+echo
+
+einfo "Enter the string value that should appear in your From: headers."
+einfo " An example is: Luther Blisset <luther@bliss.et>"
+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
+echo
+
+
+einfo "Please enter the port of your remote imap server (993)."
+printf " * remote imap port = "
+read -r remoteimapport || exit 1
+echo
+
+
+einfo "Please enter your remote imap username."
+printf " * remote imap username = "
+read -r remoteimapuser || exit 1
+echo
+
+einfo "Please enter your remote imap password."
+pass insert .rp/$profile/imapremote
+echo
+
+
+einfo "Please enter the address of your other imap server."
+printf " * local imap server = "
+read -r localimapserv || exit 1
+echo
+
+
+einfo "Please enter the port of your other imap server (143)."
+printf " * local imap port = "
+read -r localimapport || exit 1
+echo
+
+
+einfo "Please enter the username for your other imap server."
+printf " * local imap username = "
+read -r localimapuser || exit 1
+echo
+
+
+einfo "Please enter the password for your other imap server."
+pass insert .rp/$profile/imaplocal
+echo
+
+
+cat <<EOF > $profile/muttrc
+# muttrc for $profile
+source ~/.rp/$profile/mutt/general
+source ~/.rp/$profile/mutt/headers
+source ~/.rp/$profile/mutt/keybindings
+source ~/.rp/$profile/mutt/colors
+source ~/.rp/$profile/mutt/sidebar
+source ~/.rp/$profile/mutt/gpg
+source ~/.rp/$profile/mutt/muttpass
+
+auto_view text/html
+set mailcap_path = ~/.rp/$profile/mutt/mailcap
+
+set record = ~/.rp/$profile/tmp/Sent
+set postponed = ~/.rp/$profile/tmp/Drafts
+
+set from = "$from"
+set realname = "$(echo $from | awk -F' <' '{print $1}')"
+
+set folder = "imap://$localimapuser@$localimapserv:$localimapport"
+set spoolfile = "imap://$localimapuser@$localimapserv:$localimapport/INBOX"
+
+# add your customizations in the following file
+source ~/.rp/$profile/muttrc-custom
+EOF
+touch $profile/muttrc-custom
+
+cat <<EOF > $profile/config
+imap1host="$remoteimapserv"
+imap1port="$remoteimapport"
+imap1user="$remoteimapuser"
+
+imap2host="$localimapserv"
+imap2port="$localimapport"
+imap2user="$localimapuser"
+EOF
+
+setupmutt "$profile"
+
+touch "$profile/whitelist.abook"
+chmod 600 "$profile/whitelist.abook"
+
+ln -snf "$shareprefix/rplib" "./rplib"
+
+git init
+git add .
+git commit -m "rpinit"
+
+einfo "All done setting up rp!"
+einfo "Your profile files are in ~/.rp/$profile"
+einfo "Have fun!"
diff --git a/bin/rppeek b/bin/rppeek
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+profile="${RPPROFILE:-$HOME/.rp/default}"
+. "$HOME"/.rp/rplib/common.sh
+. "$HOME"/.rp/rplib/pass.sh
+
+. "$profile"/config
+
+usage() {
+ einfo "usage: $(basename $0) [folder]"
+ exit 1
+}
+
+for i in $@; do
+ case "$i" in
+ -h)
+ usage
+ ;;
+ *)
+ folder="$i"
+ einfo "requested folder '$i'"
+ shift 1 ;continue
+ ;;
+ esac
+done
+
+ebegin "asking imap password from pass"
+askmuttpass .rp/$(readlink $profile)/imaplocal
+
+( sleep 2; printf "imap_pass = a\n" > $profile/mutt/muttpass ) &
+
+ebegin "starting up mutt"
+mutt -F $profile/muttrc \
+ -f imap://${imap2user}@${imap2host}:${imap2port}/${folder}
+
+case $? in
+ 0) einfo "mutt exited successfully";;
+ *) edie "mutt didn't exit with 0 status";;
+esac
diff --git a/bin/rpqueue b/bin/rpqueue
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+profile="${RPPROFILE:-$HOME/.rp/default}"
+. "$HOME"/.rp/rplib/common.sh
+
+
+mkdir -p "$profile/tmp/outbox"
+
+email="$(cat)"
+fname="$(printf "$email" | grep -i '^message-id' | cut -d' ' -f2 | tr -d '<>')"
+
+printf "%s\n" "$email" > "$profile/tmp/outbox/$fname"
diff --git a/bin/rpsend b/bin/rpsend
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+profile="${RPPROFILE:-$HOME/.rp/default}"
+. "$HOME"/.rp/rplib/common.sh
+. "$HOME"/.rp/rplib/pass.sh
+. "$HOME"/.rp/rplib/tls.sh
+
+. "$profile"/config
+
+usage() {
+ einfo "usage: $(basename $0) [-n] [-l] [-a]"
+ einfo " -n: dry run"
+ einfo " -l: list outbox"
+ einfo " -a: send all"
+ exit 1
+}
+
+listoutbox() {
+ find "$profile"/tmp/outbox -type f
+}
+
+
+for i in $@; do
+ case "$i" in
+ -n)
+ dryrun="--pretend"
+ shift 1
+ continue
+ ;;
+ -l)
+ listoutbox
+ exit 0
+ ;;
+ -a)
+ ebegin "sending all available emails"
+ for i in $(rpsend -l); do
+ rpsend < "$i" && rm -f "$i"
+ done
+ exit $?
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+email="$(cat)"
+
+echo >&2
+ebegin "smtp send via $imap1host"
+
+if ! [ -f "$profile/smtp-fingerprint" ]; then
+ ebegin "no saved tls certificate fingerprint found. going tofu"
+ getfingerprint $imap1host 587 > "$profile"/smtp-fingerprint
+fi
+
+known="$(cat $profile/smtp-fingerprint)"
+served="$(getfingerprint $imap1host 587)"
+
+einfo "known fingerprint: $known"
+einfo "served fingerprint: $served"
+
+if [ "$known" != "$served" ]; then
+ ewarn "server fingerprint mismatch!"
+ ewarn "the known one is different, this may be mitm"
+ edie "to trust the new one, edit or delete $profile/smtp-fingerprint"
+fi
+
+
+msmtpcfg="$(mktemp)"
+cat <<EOF > "$msmtpcfg"
+account default
+from $imap1user
+user $imap1user
+host $imap1host
+password $(pass show .rp/$(readlink $profile)/imapremote)
+port 587
+auth plain
+tls on
+tls_starttls on
+tls_certcheck off
+EOF
+
+
+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
+
+
+printf "$email\n" | msmtp "$dryrun" \
+ -C "$msmtpcfg" \
+ -t -X "$profile/tmp/msmtp.log"
+
+_e=$?
+
+rm -f "$msmtpcfg"
+
+case "$_e" in
+ 0) einfo "email sent successfully";;
+ *) edie "msmtp failed";;
+esac
diff --git a/bin/rpsync b/bin/rpsync
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+profile="${RPPROFILE:-$HOME/.rp/default}"
+. "$HOME"/.rp/rplib/common.sh
+. "$HOME"/.rp/rplib/pass.sh
+
+. "$profile"/config
+
+usage() {
+ einfo "usage: $(basename $0) [-n] [-d]"
+ einfo " -n: dry run"
+ einfo " -d: delete remote emails"
+ exit 1
+}
+
+for i in $@; do
+ case "$i" in
+ -n)
+ dryrun="--dry"
+ shift 1
+ continue
+ ;;
+ -d)
+ delete="--delete1"
+ shift 1
+ continue
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+
+ebegin "starting imapsync"
+[ -n "$delete" ] && ewarn "remote deletion enabled"
+[ -n "$dryrun" ] && ewarn "dry run enabled"
+imapsync \
+ --tmpdir "$profile/tmp" \
+ --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)" \
+ --automap ${dryrun} ${delete} \
+ --no-modulesversion
+
+_e=$?
+
+rm -f "$profile/tmp/imaplocal" "$profile/tmp/imapremote"
+
+case "$_e" in
+ 0) einfo "synced successfully";;
+ *) edie "error while syncing";;
+esac