summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/mailsync10
-rwxr-xr-xbin/mw19
-rwxr-xr-xbin/openfile3
3 files changed, 25 insertions, 7 deletions
diff --git a/bin/mailsync b/bin/mailsync
index 620557c..8ae8758 100755
--- a/bin/mailsync
+++ b/bin/mailsync
@@ -1,6 +1,9 @@
#!/usr/bin/env sh
# Sync mail and give notification if there is new mail.
+# Run only if user logged in (prevent cron errors)
+w | grep "^$USER\W" >/dev/null || exit
+
# Checks for internet connection and set notification script.
ping -q -c 1 1.1.1.1 > /dev/null || 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."
@@ -18,7 +21,12 @@ echo " 🔃" > /tmp/imapsyncicon_$USER
pkill -RTMIN+12 i3blocks
# Run mbsync. You can feed this script different settings.
-mbsync -a "$@"
+if [ $# -eq 0 ]; then
+ mbsync -a
+else
+ mbsync "$@"
+fi
+
rm -f /tmp/imapsyncicon_$USER
pkill -RTMIN+12 i3blocks
diff --git a/bin/mw b/bin/mw
index 6f3cd95..aacc081 100755
--- a/bin/mw
+++ b/bin/mw
@@ -11,6 +11,7 @@ mbsyncrc="$HOME/.mbsyncrc"
mwconfig="$muttshare/mutt-wizard.muttrc"
cachedir="$HOME/.cache/mutt-wizard"
muttrc="$muttdir/muttrc"
+msmtprc="$HOME/.config/msmtp/config"
ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail
for x in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
@@ -140,7 +141,7 @@ EOF
printf "\\n\033[3;33mCongrats!\033[0m Server info has automatically been found, so you won't have to look anything up!\\n\t\033[1mIMAP server\033[0m: %s\\n\t\033[1mIMAP port\033[0m: %s\\n\t\033[1mSMTP server\033[0m: %s\\n\t\033[1mSMTP port\033[0m: %s\\nThis data will be used by the wizard.\\n" "$imap" "$iport" "$smtp" "$sport"
case "$service" in
gmail.com) printf "\033[31mREMEMBER: Gmail users must enable \"less secure\" (third-party) applications first for the sync to work:\\nhttps://support.google.com/accounts/answer/6010255\\n\033[0m" ;;
- protonmail.*) printf "\033[31mREMEMBER: Protonmail users must install and configure Protonmail Bridge first for the sync to work:\\nhttps://protonmail.com/bridge/\\n\033[0m" && ssltype="None" ;;
+ protonmail.ch|protonmail.com|pm.me) printf "\033[31mREMEMBER: Protonmail users must install and configure Protonmail Bridge first for the sync to work:\\nhttps://protonmail.com/bridge/\\n\033[0m" && ssltype="None" ;;
esac
fi
printf "Enter the \033[35mfull name\033[0m you want to be identified by on this account.\\n\tReal name: "
@@ -163,8 +164,11 @@ EOF
mkdir -p "$muttdir" "$accdir" "$cachedir/$title/bodies" "$HOME/.config/msmtp"
getaccounts
for x in $(seq 1 9); do echo "$accounts" | grep "$x" >/dev/null 2>&1 || { export idnum="$x"; break ;}; done
- [ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config"
- echo "$msmtp_profile" >> "$HOME/.config/msmtp/config"
+ [ ! -f "$msmtprc" ] && echo "$msmtp_header" > "$msmtprc"
+ echo "$msmtp_profile" >> "$msmtprc"
+ case "$service" in
+ protonmail.ch|protonmail.com|pm.me) protonfinger || return 1 ;;
+ esac
echo "$mutt_profile" > "$accdir/$idnum-$title.muttrc"
echo "$mbsync_profile" >> "$mbsyncrc"
notmuchauto
@@ -174,6 +178,11 @@ EOF
echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$idnum-$title.muttrc<enter><change-folder>!<enter>;<check-stats>' \"switch to $fulladdr\" # mw-autogenerated" >> "$muttrc"
}
+protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n"
+ fingerprint="$(msmtp --serverinfo --tls --tls-certcheck=off -a "$title")" || return 1
+ sed -ibu "s/account $title/&\ntls_fingerprint $fingerprint/" "$msmtprc" ; rm -f "$msmtprc"bu
+}
+
getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1
pass insert "mutt-wizard-$title" && break; done ;}
@@ -233,10 +242,10 @@ pick() { printf "Select an accounts to %s:\\n" "$1"
delete() { sed -ibu "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" ; rm -rf "$mbsyncrc"bu
rm -rf "${cachedir:?}/${title:?}" "$accdir/"[1-9]"-$title.muttrc"
sed -ibu "/[0-9]-$title.muttrc/d" "$muttrc" ; rm -f "$muttrc"bu
- sed -ibu "/account $title/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config"; rm -f "$HOME/.config/msmtp/configbu"
+ sed -ibu "/account $title/,/^\(\s*$\|account\)/d" "$msmtprc"; rm -f "$msmtprc"bu
}
-choosecron() { ! pgrep -x cron\|crond >/dev/null && echo "No cron manager running. Install/enable one and then select this option again." && return 1
+choosecron() { ! pgrep cron >/dev/null && echo "No cron manager running. Install/enable one and then select this option again." && return 1
if crontab -l | grep mailsync >/dev/null; then
echo "Active mail sync cronjob detected. Do you want to remove it?"
printf "\033[36m\t"
diff --git a/bin/openfile b/bin/openfile
index 19cb077..a3163f3 100755
--- a/bin/openfile
+++ b/bin/openfile
@@ -1,8 +1,9 @@
#!/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"
base=$(basename "$1")
ext="${base##*.}"
file=$(mktemp -u --suffix=".$ext")
rm -f "$file"
cp "$1" "$file"
-setsid xdg-open "$file" >/dev/null 2>&1 &
+$opener "$file" >/dev/null 2>&1 &