summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/mailsync35
-rwxr-xr-xbin/muttimage11
-rwxr-xr-xbin/mw44
-rwxr-xr-xbin/openfile5
4 files changed, 52 insertions, 43 deletions
diff --git a/bin/mailsync b/bin/mailsync
index 2cec271..93ec35d 100755
--- a/bin/mailsync
+++ b/bin/mailsync
@@ -1,11 +1,6 @@
-#!/usr/bin/env sh
-# Sync mail and give notification if there is new mail.
+#!/bin/sh
-export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
-export DBUS_SESSION_BUS_ADDRESS
-export DISPLAY=:0.0
-[ -d "$HOME/.local/share/password-store" ] && export PASSWORD_STORE_DIR="$HOME/.local/share/password-store"
+# Sync mail and give notification if there is new mail.
# Run only if user logged in (prevent cron errors)
pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;}
@@ -13,20 +8,29 @@ pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync wil
pgrep -x mbsync >/dev/null && { echo "mbsync is already running." ; exit ;}
# Checks for internet connection and set notification script.
-ping -q -c 1 1.1.1.1 > /dev/null || { echo "No internet connection detected."; exit ;}
+ping -q -c 1 1.1.1.1 > /dev/null || ping -q -c 1 1.0.0.1 > /dev/null || ping -q -c 1 example.org || { echo "No internet connection detected."; exit ;}
command -v notify-send >/dev/null || echo "Note that \`libnotify\` or \`libnotify-send\` should be installed for pop-up mail notifications with this script."
+# Required to display notifications if run as a cronjob:
+export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
+export DISPLAY=:0.0
+
+# For individual configurations:
+[ -d "$HOME/.local/share/password-store" ] && export PASSWORD_STORE_DIR="$HOME/.local/share/password-store"
+
# Settings are different for MacOS (Darwin) systems.
if [ "$(uname)" = "Darwin" ]; then
notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;}
+ messageinfo() { osascript -e "display notification with title \"📧 $from\" subtitle \"$subject\"" ;}
else
notify() { notify-send --app-name="mutt-wizard" "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." ;}
+ messageinfo() { notify-send --app-name="mutt-wizard" "📧$from:" "$subject" ;}
fi
# Check account for new mail. Notify if there is new content.
syncandnotify() {
acc="$(echo "$account" | sed "s/.*\///")"
- mbsync "$acc"
+ if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi
new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then
@@ -34,8 +38,8 @@ syncandnotify() {
for file in $new; do
# Extract subject and sender from mail.
from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//')
- subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n-1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
- notify-send --app-name="mutt-wizard" "📧$from:" "$subject" &
+ subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
+ messageinfo &
done
fi
}
@@ -44,11 +48,13 @@ syncandnotify() {
if [ "$#" -eq "0" ]; then
accounts="$(awk '/^Channel/ {print $2}' "$HOME/.mbsyncrc")"
else
+ for arg in "$@"; do
+ [ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1
+ done
accounts=$*
fi
-echo " 🔃" > /tmp/imapsyncicon_"$USER"
-pkill -RTMIN+12 "${STATUSBAR:?}" >/dev/null 2>&1
+( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null
# Parallelize multiple accounts
for account in $accounts
@@ -57,8 +63,7 @@ do
done
wait
-rm -f /tmp/imapsyncicon_"$USER"
-pkill -RTMIN+12 "${STATUSBAR:?}" >/dev/null 2>&1
+( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null
notmuch new 2>/dev/null
diff --git a/bin/muttimage b/bin/muttimage
deleted file mode 100755
index a846bea..0000000
--- a/bin/muttimage
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-
-#get image resolution
-resolution=$(identify $1 | awk '{print $3}')
-IFS='x' # x is set as delimiter
-read -ra ADDR <<< "$resolution"
-width=${ADDR[0]}
-height=${ADDR[1]}
-
-### Display Image / offset with mutt bar
-echo -e "2;3;\n0;1;0;42;$((width));$((height));0;0;0;0;$1\n4;\n3;" | /usr/lib/w3m/w3mimgdisplay &
diff --git a/bin/mw b/bin/mw
index e2939ec..9bf00c3 100755
--- a/bin/mw
+++ b/bin/mw
@@ -1,12 +1,13 @@
-#!/usr/bin/env sh
+#!/bin/sh
+
command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2"
[ -z ${PASSWORD_STORE_DIR+x} ] && PASSWORD_STORE_DIR="$HOME/.password-store"
[ -r "$PASSWORD_STORE_DIR/.gpg-id" ] &&
"$GPG" --list-secret-keys $(cat "$PASSWORD_STORE_DIR/.gpg-id") >/dev/null 2>&1 || {
- printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`$GPG --full-gen-key\` first.\\n"
+ printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`%s --full-gen-key\` first.\\n" "$GPG"
exit
}
-! command -v mbsync >/dev/null && printf "\`mbsync\` must be installed to run mutt-wizard.\\n" && exit
+! command -v mbsync >/dev/null && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit
prefix="/usr/local"
muttdir="$HOME/.config/mutt" # Main mutt config location
@@ -49,9 +50,10 @@ $starttlsoff
"
mbsync_profile="IMAPStore $title-remote
Host $imap
-Port $iport
+Port $iport
User $login
PassCmd \"pass mutt-wizard-$title\"
+AuthMechs LOGIN
SSLType $ssltype
CertificateFile $sslcert
@@ -85,6 +87,11 @@ set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies
set mbox_type = Maildir
+set crypt_autosign = yes
+set crypt_opportunistic_encrypt = yes
+set pgp_self_encrypt = yes
+set pgp_default_key = $keyid
+
bind index,pager gg noop
bind index,pager g noop
bind index,pager M noop
@@ -98,14 +105,20 @@ mutt_profile="# vim: filetype=neomuttrc
# muttrc file for account $title
set realname = \"$realname\"
set from = \"$fulladdr\"
-set sendmail = \"$prefix/bin/msmtp -a $title\"
+set sendmail = \"msmtp -a $title\"
alias me $realname <$fulladdr>
-set folder = \"imaps://$fulladdr@$imap:$iport\"
+set folder = \"imaps://$login@$imap:$iport\"
set imap_user = \"$login\"
set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies
set imap_pass = \"\`pass mutt-wizard-$title\`\"
+set crypt_autosign = yes
+set crypt_opportunistic_encrypt = yes
+set pgp_self_encrypt = yes
+set pgp_default_key = $keyid
+
+
set mbox_type = Maildir
set ssl_starttls = yes
set ssl_force_tls = yes
@@ -124,6 +137,7 @@ fi
askinfo() { \
printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\tEmail: \033[36m"
read -r fulladdr
+ keyid=$("$GPG" --list-keys --with-colons "$fulladdr" | awk -F: '/^pub:/ { print $5 }')
printf "\033[0m"
while ! echo "$fulladdr" | grep "$emailre" >/dev/null; do
printf "That is not a valid \033[31memail address\033[0m, please retype the desired email.\\n\\nEmail: \033[36m\t"
@@ -134,7 +148,7 @@ askinfo() { \
search_query=$domain
case "$domain" in
protonmail.com|protonmail.ch|pm.me)
- search_query='protonmail.com' && break;;
+ search_query='protonmail.com' ;;
*)
while : ; do
printf "\nIs your email hosted with Protonmail? [yes/no] "
@@ -214,8 +228,8 @@ getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1
formatShortcut() { \
while read -r data; do { echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"go to $2\" # mw-autogenerated"
- echo "macro index,pager M$1 \"<save-message>$data<enter>\" \"move mail to $2\" # mw-autogenerated"
- echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"copy mail to $2\" # mw-autogenerated"; } >> "$accdir/$idnum-$title.muttrc"
+ echo "macro index,pager M$1 \";<save-message>$data<enter>\" \"move mail to $2\" # mw-autogenerated"
+ echo "macro index,pager C$1 \";<copy-message>$data<enter>\" \"copy mail to $2\" # mw-autogenerated"; } >> "$accdir/$idnum-$title.muttrc"
done ;}
tryconnect() { mkdir -p "$maildir/$title"
@@ -230,7 +244,7 @@ tryconnect() { mkdir -p "$maildir/$title"
fi ;}
finalize() { \
- boxes="$(find "$maildir/$title/" -mindepth 1 -maxdepth 1 | sed "s/\ /\\\ /g;s/^.*\//=/")"
+ boxes="$(find "$maildir/$title/" -mindepth 1 -type d | sed "s/\ /\\\ /g;s/^.*\//=/;/=\(cur\|new\|tmp\)$/d")"
[ -z "$boxes" ] && printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that mbsync has not been successfully run.\\nRun mbsync, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$title" && return
printf "Setting default mailboxes for your Inbox, Sent, Drafts and Trash in mutt...\\n"
spoolfile=$(echo "$boxes" | grep -i -m 1 inbox | sed 's/=/+/g')
@@ -254,8 +268,8 @@ finalize() { \
return 0
}
-confirm() { printf "Do you want to %s? [y/N]\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
- printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
+confirm() { printf "Do you want to %s? [yes/N]\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
+ printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
return 0 ;}
pick() { printf "Select an accounts to %s:\\n" "$1"
@@ -289,7 +303,7 @@ choosecron() { ! pgrep cron >/dev/null && echo "No cron manager running. Install
read -r minnum
printf "\033[0m"
done
- (crontab -l; echo "*/$minnum * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus; export DISPLAY=:0; . \$HOME/.profile; $(type mailsync | cut -d' ' -f3)") | crontab - &&
+ (crontab -l; echo "*/$minnum * * * * $(type mailsync | cut -d' ' -f3) >/dev/null 2>&1") | crontab - >/dev/null &&
echo "Cronjob added. Mail will sync every $minnum minutes. Be sure you have your cron manager running."
fi ;}
@@ -319,7 +333,7 @@ name=$realname
primary_email=$fulladdr
[new]
tags=unread;inbox;
-ignore=
+ignore=.mbsyncstate;.uidvalidity
[search]
exclude_tags=deleted;spam;
[maildir]
@@ -328,7 +342,7 @@ synchronize_flags=true
gpg_path=$GPG"
echo "$nmbasic" > "$NOTMUCH_CONFIG" ;}
-trap 'echo -e "\033[0m\n"; exit' STOP INT ABRT KILL
+trap 'echo -e "\033[0m\n"; exit' INT ABRT
case "$1" in
ls) list ;;
diff --git a/bin/openfile b/bin/openfile
index b16483b..f6668dc 100755
--- a/bin/openfile
+++ b/bin/openfile
@@ -1,6 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
+
# Helps open a file with xdg-open from mutt in a external program without weird side effects.
-[ $(uname) = "Darwin" ] && opener="open" || opener="setsid xdg-open"
+[ "$(uname)" = "Darwin" ] && opener="open" || opener="setsid xdg-open"
mkdir -p "/tmp/$USER-mutt-tmp"
file="/tmp/$USER-mutt-tmp/$(basename "$1")"
rm -f "$file"