Browse Source

Merge branch 'master' into master

tags/v3.3
Luke Smith 3 years ago
committed by GitHub
parent
commit
4e92252dc2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 46 deletions
  1. +2
    -2
      Makefile
  2. +14
    -18
      bin/mailsync
  3. +29
    -24
      bin/mw
  4. +13
    -2
      share/domains.csv
  5. +37
    -0
      share/unbind.muttrc

+ 2
- 2
Makefile View File

@@ -14,8 +14,8 @@ install:
chmod 755 $(DESTDIR)$(PREFIX)/bin/mw $(DESTDIR)$(PREFIX)/bin/mailsync $(DESTDIR)$(PREFIX)/bin/openfile
mkdir -p $(DESTDIR)$(PREFIX)/share/mutt-wizard
chmod 755 $(DESTDIR)$(PREFIX)/share/mutt-wizard
cp -f share/mailcap share/domains.csv share/mutt-wizard.muttrc $(DESTDIR)$(PREFIX)/share/mutt-wizard
chmod 644 $(DESTDIR)$(PREFIX)/share/mutt-wizard/mailcap $(DESTDIR)$(PREFIX)/share/mutt-wizard/domains.csv $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrc
cp -f share/mailcap share/domains.csv share/mutt-wizard.muttrc share/unbind.muttrc $(DESTDIR)$(PREFIX)/share/mutt-wizard
chmod 644 $(DESTDIR)$(PREFIX)/share/mutt-wizard/mailcap $(DESTDIR)$(PREFIX)/share/mutt-wizard/domains.csv $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrc $(DESTDIR)$(PREFIX)/share/mutt-wizard/unbind.muttrc
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
cp -f mw.1 $(DESTDIR)$(MANPREFIX)/man1/mw.1
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/mw.1


+ 14
- 18
bin/mailsync View File

@@ -14,7 +14,7 @@
# 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 ;}
# Run only if not already running in other instance
pidof -s mbsync >/dev/null && { echo "mbsync is already running." ; exit ;}
pidof mbsync >/dev/null && { echo "mbsync is already running."; exit ;}

# First, we have to get the right variables for the mbsync file, the pass
# archive, notmuch and the GPG home. This is done by searching common profile
@@ -25,10 +25,7 @@ eval "$(grep -h -- \
"$HOME/.profile" "$HOME/.bash_profile" "$HOME/.zprofile" "$HOME/.config/zsh/.zprofile" "$HOME/.zshenv" \
"$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/zsh/.zshrc" "$HOME/.pam_environment" 2>/dev/null)"

case "$(readlink -f /sbin/init)" in
*systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;;
esac
export GPG_TTY=$TTY
export GPG_TTY="$(tty)"

[ -n "$MBSYNCRC" ] && alias mbsync="mbsync -c $MBSYNCRC" || MBSYNCRC="$HOME/.mbsyncrc"

@@ -36,9 +33,11 @@ export GPG_TTY=$TTY
case "$(uname)" in
Darwin)
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\"" ;}
;;
*)
case "$(readlink -f /sbin/init)" in
*systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;;
esac
# remember if a display server is running since `ps` doesn't always contain a display
pgrepoutput="$(pgrep -a X\(org\|wayland\))"
displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)"
@@ -46,10 +45,6 @@ case "$(uname)" in
export DISPLAY=$x
notify-send --app-name="mutt-wizard" "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account."
done ;}
messageinfo() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do
export DISPLAY=$x
notify-send --app-name="mutt-wizard" "📧$from:" "$subject"
done ;}
;;
esac

@@ -57,16 +52,17 @@ esac
syncandnotify() {
acc="$(echo "$account" | sed "s/.*\///")"
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 "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null)
new=$(find\
"$HOME/.local/share/mail/$acc/INBOX/new/"\
"$HOME/.local/share/mail/$acc/Inbox/new/"\
"$HOME/.local/share/mail/$acc/inbox/new/"\
"$HOME/.local/share/mail/$acc/INBOX/cur/"\
"$HOME/.local/share/mail/$acc/Inbox/cur/"\
"$HOME/.local/share/mail/$acc/inbox/cur/"\
-type f -newer "${XDG_CONFIG_HOME:-$HOME/.config}/mutt/.mailsynclastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
case 1 in
$((newcount > 5)) ) notify "$acc" "$newcount" ;;
$((newcount > 0)) ) 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')
messageinfo &
done ;;
$((newcount > 0)) ) notify "$acc" "$newcount" ;;
esac
}



+ 29
- 24
bin/mw View File

@@ -12,14 +12,24 @@ mbsyncrc="${MBSYNCRC:-$HOME/.mbsyncrc}"
mpoprc="${XDG_CONFIG_HOME:-$HOME/.config}/mpop/config"
alias mbsync='mbsync -c "$mbsyncrc"'

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" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/"; do
# On Ubuntu/Debian, a link is needed since they use an older version.
if command -V apt-get >/dev/null 2>&1; then
ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null
master="Master"
slave="Slave"
fi

for x in "/etc/ssl/certs/ca-certificates.crt" \
"/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/cert.pem" \
"/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" \
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" \
"/usr/local/share/ca-certificates/"; do
[ -f "$x" ] && sslcert="$x" && break
done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && exit 1 ;}

checkbasics() { command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2"
PASSWORD_STORE_DIR="${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 || {
[ -r "$PASSWORD_STORE_DIR/.gpg-id" ] || {
echo "First run \`pass init <yourgpgemail>\` to set up a password archive."
echo "(If you don't already have a GPG key pair, first run \`$GPG --full-generate-key\`.)"
exit 1 ;} ;}
@@ -35,12 +45,11 @@ from $fulladdr
user $login
passwordeval \"pass $fulladdr\"
auth ${auth:-on}
${tlsline:-tls on}
tls on
tls_trust_file $sslcert
logfile $msmtplog
$tlsline
" >> "$msmtprc"
# On Ubuntu/Debian, a link is needed since they use an older version.
command -V apt-get >/dev/null 2>&1 && ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null
}

prepmbsync() { mkdir -p "${mbsyncrc%/*}"
@@ -61,8 +70,8 @@ Inbox ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$fulladdr/${inbox:-INBOX}

Channel $fulladdr
Expunge Both
Master :$fulladdr-remote:
Slave :$fulladdr-local:
${master:-Far} :$fulladdr-remote:
${slave:-Near} :$fulladdr-local:
Patterns * !\"[Gmail]/All Mail\"
Create Both
SyncState *
@@ -91,16 +100,9 @@ set folder = \"$folder\"
set header_cache = $cachedir/$fulladdr/headers
set message_cachedir = $cachedir/$fulladdr/bodies
set mbox_type = Maildir
set hostname = \"$hostname\"
source $muttshare/unbind.muttrc
$extra

bind index,pager gg noop
bind index,pager g noop
bind index,pager M noop
bind index,pager C noop
bind index gg first-entry
unmailboxes *
unalternates *
unset signature
$synccmd
" > "$accdir/$idnum-$fulladdr.muttrc"

@@ -111,7 +113,7 @@ $synccmd
}

getprofiles() { \
mkdir -p "${muttrc%/*}" "$accdir" "$cachedir/$fulladdr/bodies" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp"
mkdir -p "${muttrc%/*}" "$accdir" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp"
unset msmtp_header msmtp_profile mutt_profile mbsync_profile
case "$iport" in
1143) imapssl=None ;;
@@ -172,10 +174,8 @@ delete() { if [ -z "${fulladdr+x}" ]; then
pass rm -f "$fulladdr" >/dev/null 2>&1
[ -n "${purge+x}" ] && rm -rf "${maildir:?}/${fulladdr:?}"

# Get rid of those multiple newlines because I don't know awk well enough to do it by default lol.
for file in "$msmtprc" "$mbsyncrc" "$mpoprc"; do
tr '\n' '|' 2>/dev/null < "$file" | sed "s/||\+/||/g" | tr '|' '\n' >> "$file"bu
mv -f "$file"bu "$file"
sed -ibu 'N;/^\n$/D;P;D;' "$file" 2>/dev/null; rm -f "$file"bu
done
}

@@ -183,7 +183,7 @@ askinfo() { \
[ -z "$fulladdr" ] && echo "Give the full email address to add:" &&
read -r fulladdr
while ! echo "$fulladdr" | grep -qE "^.+@.+\.[A-Za-z]+$"; do
echo "\`$fulladdr\` is not a valid email address. Please retype the address:"
echo "$fulladdr is not a valid email address. Please retype the address:"
read -r fulladdr
done
getaccounts; echo "$accounts" | grep -q "\s$fulladdr$" 2>/dev/null &&
@@ -195,6 +195,7 @@ askinfo() { \
read -r smtp
[ "$sport" = 465 ] && tlsline="tls_starttls off"
[ -z "$realname" ] && realname="${fulladdr%%@*}"
hostname="$(echo "$fulladdr" | cut -d @ -f 2)"
login="${login:-$fulladdr}"
if [ -n "${password+x}" ]; then
createpass
@@ -204,7 +205,7 @@ askinfo() { \
}

createpass() { echo "$password" > "$PASSWORD_STORE_DIR/$fulladdr"
"$GPG" -qer "$(cat "$PASSWORD_STORE_DIR/.gpg-id")" "$PASSWORD_STORE_DIR/$fulladdr"
"$GPG" -qe $(printf -- " -r %s" $(cat "$PASSWORD_STORE_DIR/.gpg-id")) "$PASSWORD_STORE_DIR/$fulladdr"
rm -f "$PASSWORD_STORE_DIR/$fulladdr" ;}

getpass() { while : ; do pass rm -f "$fulladdr" >/dev/null 2>&1
@@ -223,11 +224,14 @@ getboxes() { if [ -n "${force+x}" ] ; then
else
info="$(curl --location-trusted -s -m 5 --user "$login:$(pass "$fulladdr")" --url "${protocol:-imaps}://$imap:${iport:-993}")"
[ -z "$info" ] && echo "Log-on not successful." && return 1
mailboxes="$(echo "$info" | grep -v HasChildren | sed "s/.*\" //;s/\"//g" | tr -d ' ')"
mailboxes="$(echo "$info" | grep -v HasChildren | sed "s/.*\" //;s/\"//g" | tr -d '
')"
fi
[ "$type" = "pop" ] && mailboxes="INBOX"
getaccounts; for x in $(seq 1 9); do echo "$accounts" | grep -q "^$x:" || { export idnum="$x"; break ;}; done
toappend="mailboxes \`mdir=$maildir/$fulladdr/; find \$mdir -mindepth 1 -type d -name cur | sed -e 's:/cur\$:\":' -e \"s:\$mdir:\\\"=:\" | sort | tr '\\\n' ' '\`"
IFS='
'
for x in $mailboxes; do
case "$x" in
*[Ss][Ee][Nn][Tt]*) setBox record "$x"; formatShortcut s sent "$x" ;;
@@ -239,6 +243,7 @@ getboxes() { if [ -n "${force+x}" ] ; then
*[Ii][Nn][Bb][Oo][Xx]) formatShortcut i inbox "$x"; setBox spoolfile "$x" inbox="$x" ;;
esac
done
unset IFS
}

finalize() { echo "$toappend" >> "$accdir/$idnum-$fulladdr.muttrc"


+ 13
- 2
share/domains.csv View File

@@ -1,6 +1,7 @@
ADDRESS,IMAP,imap port,SMTP,smtp port
126.com,imap.126.com,993,smtp.126.com,587
163.com,imap.163.com,993,smtp.163.com,587
3nt3.de,mail.3nt3.de,993,mail.3nt3.de,465
420blaze.it,mail.cock.li,993,mail.cock.li,587
8chan.co,mail.cock.li,993,mail.cock.li,587
aaathats3as.com,mail.cock.li,993,mail.cock.li,587
@@ -43,10 +44,13 @@ bocken.org,mail.bocken.org,993,mail.bocken.org,587
brew-meister.com,imap.mail.com,993,smtp.mail.com,587
bruttocarattere.org,mail.autistici.org,993,smtp.autistici.org,465
btinternet.com,mail.btinternet.com,993,mail.btinternet.com,587
calstatela.edu,outlook.office365.com,993,smtp.office365.com,587
campus.fct.unl.pt,imap.gmail.com,993,smtp.gmail.com,587
canaglie.net,mail.autistici.org,993,smtp.autistici.org,465
canaglie.org,mail.autistici.org,993,smtp.autistici.org,465
carleton.ca,imap-mail.outlook.com,993,smtp-mail.outlook.com,587
cash4u.com,imap.mail.com,993,smtp.mail.com,587
cedars.xyz,mail.cedars.xyz,993,mail.cedars.xyz,465
ceng.metu.edu.tr,imap.ceng.metu.edu.tr,993,mailhost.ceng.metu.edu.tr,587
cheerful.com,imap.mail.com,993,smtp.mail.com,587
chef.net,imap.mail.com,993,smtp.mail.com,587
@@ -98,6 +102,7 @@ europe.com,imap.mail.com,993,smtp.mail.com,587
ex-studenti.unitn.it,imap.gmail.com,993,smtp.gmail.com,587
fastmail.com,imap.fastmail.com,993,smtp.fastmail.com,465
fastmail.fm,imap.fastmail.com,993,smtp.fastmail.com,465
fct.unl.pt,imap.gmail.com,993,smtp.gmail.com,587
firemail.cc,mail.cock.li,993,mail.cock.li,587
forpsi.com,imap.forpsi.com,993,smtp.forpsi.com,465
forthnet.gr,mail.forthnet.gr,993,smtp-auth.forthnet.gr,465
@@ -111,6 +116,7 @@ gmx.*,imap.gmx.net,993,mail.gmx.net,587
go2.pl,poczta.o2.pl,993,poczta.o2.pl,465
goat.si,mail.cock.li,993,mail.cock.li,587
googlemail.com,imap.googlemail.com,993,smtp.googlemail.com,587
gordon.edu,outlook.office365.com,993,smtp.office365.com,587
grrlz.net,mail.autistici.org,993,smtp.autistici.org,465
hacari.*,mail.autistici.org,993,smtp.autistici.org,465
helsinki.fi,outlook.office365.com,993,smtp.helsinki.fi,587
@@ -156,6 +162,8 @@ loves.dicksinhisan.us,mail.cock.li,993,mail.cock.li,587
loves.dicksinmyan.us,mail.cock.li,993,mail.cock.li,587
lukesmith.xyz,mail.lukesmith.xyz,993,mail.lukesmith.xyz,587
luther.edu,imap.gmail.com,993,smtp.gmail.com,587
mac.com,imap.mail.me.com,993,smtp.mail.me.com,587
mace.ac.in,imap.gmail.com,993,smtp.gmail.com,587
mail.com,imap.mail.com,993,smtp.mail.com,587
mail.de,imap.mail.de,993,smtp.mail.de,465
mail.mcgill.ca,outlook.office365.com,993,smtp.office365.com,587
@@ -167,6 +175,7 @@ mailbox.tu-dresden.de,msx.tu-dresden.de,993,msx.tu-dresden.de,587
mailfence.com,imap.mailfence.com,993,smtp.mailfence.com,465
mailo.com,mail.mailo.com,993,mail.mailo.com,465
marquette.edu,outlook.office365.com,993,smtp.office365.com,587
me.com,imap.mail.me.com,993,smtp.mail.me.com,587
memeware.net,mail.cock.li,993,mail.cock.li,587
metu.edu.tr,imap.metu.edu.tr,993,smtp.metu.edu.tr,465
mit.edu,imap.exchange.mit.edu,993,outgoing.mit.edu,465
@@ -202,8 +211,8 @@ outlook.*,imap-mail.outlook.com,993,smtp-mail.outlook.com,587
outlook.es,outlook.office365.com,993,smtp.office365.com,587
parabolas.xyz,mail.parabolas.xyz,993,mail.parabolas.xyz,587
paranoici.org,mail.autistici.org,993,smtp.autistici.org,465
paranoid.network,imap.nixnet.email,143,smtp.nixnet.email,587
paranoid.email,imap.paranoid.email,993,smtp.paranoid.email,25
paranoid.network,imap.nixnet.email,143,smtp.nixnet.email,587
pm.me,127.0.0.1,1143,127.0.0.1,1025
poczta.fm,poczta.interia.pl,993,poczta.interia.pl,465
poczta.onet.pl,imap.poczta.onet.pl,993,smtp.poczta.onet.pl,465
@@ -275,10 +284,12 @@ txstate.edu,outlook.office365.com,993,smtp.office365.com,587
ua.pt,outlook.office365.com,993,mail.ua.pt,25
uach.mx,imap.gmail.com,993,smtp.gmail.com,587
ucdavis.edu,imap.gmail.com,993,smtp.gmail.com,587
uclive.ac.nz,outlook.office365.com,993,smtp.office365.com,587
ucsb.edu,imap.gmail.com,993,smtp.gmail.com,587
uni.strath.ac.uk,outlook.office365.com,993,smtp.office365.com,587
ucsc.edu,imap.gmail.com,993,smtp.gmail.com,587
uni-duesseldorf.de,mail.hhu.de,993,mail.hhu.de,465
uni-jena.de,imap.uni-jena.de,993,smtp.uni-jena.de,587
uni.strath.ac.uk,outlook.office365.com,993,smtp.office365.com,587
unilodz.eu,outlook.office365.com,993,smtp.office365.com,587
unitn.it,imap.gmail.com,993,smtp.gmail.com,587
unitybox.de,mail.unity-mail.de,993,mail.unity-mail.de,587


+ 37
- 0
share/unbind.muttrc View File

@@ -0,0 +1,37 @@
# vim: filetype=neomuttrc

# This is an embarrassing and hacky file that unbinds a bunch of binds between
# switching accounts. It is called each time an account is changed.

bind index,pager gi noop
bind index,pager gs noop
bind index,pager gd noop
bind index,pager ga noop
bind index,pager gS noop
bind index,pager gj noop
bind index,pager gt noop
bind index,pager Mi noop
bind index,pager Ms noop
bind index,pager Md noop
bind index,pager Ma noop
bind index,pager MS noop
bind index,pager Mj noop
bind index,pager Mt noop
bind index,pager Ci noop
bind index,pager Cs noop
bind index,pager Cd noop
bind index,pager Ca noop
bind index,pager CS noop
bind index,pager Cj noop
bind index,pager Ct noop
bind index,pager gg noop
bind index,pager g noop
bind index,pager M noop
bind index,pager C noop
unset hostname
unmy_hdr Organization
unmailboxes *
unalternates *
unset signature

bind index gg first-entry

Loading…
Cancel
Save