begin switch to mbsync
This commit is contained in:
parent
96e582a817
commit
83029cfee0
20
README.md
20
README.md
@ -3,7 +3,7 @@
|
|||||||
The mutt-wizard is a simple interface gives you:
|
The mutt-wizard is a simple interface gives you:
|
||||||
|
|
||||||
- a fully-functioning neomutt-based terminal email workflow with vim bindings, vibrant display.
|
- a fully-functioning neomutt-based terminal email workflow with vim bindings, vibrant display.
|
||||||
- email backed up offline with offlineIMAP, allowing mobile and offline access of all your mail.
|
- email backed up offline with isync/mbsync, allowing mobile and offline access of all your mail.
|
||||||
- automatically generated shortcuts for jumping between different accounts or mailboxes within an account.
|
- automatically generated shortcuts for jumping between different accounts or mailboxes within an account.
|
||||||
- sensible binds that make managing, moving and reading mail quicker and easier than ever.
|
- sensible binds that make managing, moving and reading mail quicker and easier than ever.
|
||||||
- your passwords safely encrypted on your machine so you (and only you) can access your account easily (uses GPG).
|
- your passwords safely encrypted on your machine so you (and only you) can access your account easily (uses GPG).
|
||||||
@ -12,12 +12,12 @@ I maintain mutt-wizard for GNU/Linux, but individual contributors have also made
|
|||||||
|
|
||||||
## Use mutt-wizard
|
## Use mutt-wizard
|
||||||
|
|
||||||
Clone the repo to `~/.config/mutt`. Either move to backup or delete your old `~/.config/mutt` directory if you have one. Remove/backup your old offlineimap and msmtp configs if you have them as well.
|
Clone the repo to `~/.config/mutt`. Either move to backup or delete your old `~/.config/mutt` directory if you have one. Remove/backup your old isync/mbsync and msmtp configs if you have them as well.
|
||||||
|
|
||||||
Be sure to install the following programs:
|
Be sure to install the following programs:
|
||||||
|
|
||||||
- `neomutt` - the email client. If you delete a lot of the neomutt-specific settings in the muttrc, you can run vanilla mutt if you want.
|
- `neomutt` - the email client. If you delete a lot of the neomutt-specific settings in the muttrc, you can run vanilla mutt if you want.
|
||||||
- `offlineimap` - downloads the email. Required for installation.
|
- `isync` - for the `mbsync` command. Downloads the email. Required for installation.
|
||||||
- `msmtp` - sends your email.
|
- `msmtp` - sends your email.
|
||||||
|
|
||||||
**You must have a GPG public/private key pair as well.** This is what will safely encrypt your passwords. Run `gpg --full-gen-key` (or `gpg2 --full-gen-key`) to get one.
|
**You must have a GPG public/private key pair as well.** This is what will safely encrypt your passwords. Run `gpg --full-gen-key` (or `gpg2 --full-gen-key`) to get one.
|
||||||
@ -26,9 +26,9 @@ Be sure to install the following programs:
|
|||||||
|
|
||||||
Once the repository is in place in `~/.config/mutt/`:
|
Once the repository is in place in `~/.config/mutt/`:
|
||||||
|
|
||||||
- Select to add an account. This will autogenerate your config files for mutt, offlineimap and msmtp.
|
- Select to add an account. This will autogenerate your config files for mutt, mbsync and msmtp.
|
||||||
- Run `offlineimap` once (at least a partial sync). This will create all the directories you need to finalize installation and will start downloading your mail.
|
- Run `mbsync -a` once (at least a partial sync). This will create all the directories you need to finalize installation and will start downloading your mail.
|
||||||
- Select the option to autodetect mailboxes. This will use the directories offlineimap creates to detect your mailboxes and make your mail readable by mutt.
|
- Select the option to autodetect mailboxes. This will use the directories mbsync creates to detect your mailboxes and make your mail readable by mutt.
|
||||||
|
|
||||||
### Optional dependencies
|
### Optional dependencies
|
||||||
|
|
||||||
@ -46,16 +46,16 @@ mutt-wizard is configured by default for you to use other useful tools, but thes
|
|||||||
- More elegant attachment handling. Image/video/pdf attachments without relying on the neomutt instance.
|
- More elegant attachment handling. Image/video/pdf attachments without relying on the neomutt instance.
|
||||||
- abook integration by default.
|
- abook integration by default.
|
||||||
- The messy template files have been removed and are now a part of the script itself.
|
- The messy template files have been removed and are now a part of the script itself.
|
||||||
- Optimal XDG standards compliance, moving offlineimap and msmtp configs to `~/.config/` and moving mail to `~/.local/share/mail/`. offlineimap still uses home for its cache though.
|
- Optimal XDG standards compliance, moving msmtp configs to `~/.config/`, moving mail to `~/.local/share/mail/` and moving mutt-wizard files to `~/.local/share/muttwizard/`. isync/mbsync still uses home for default though as XDG compliance is not built into them.
|
||||||
- `accounts/` hold account data and `bin/` holds script run by or for mutt. All other directories have been disintegrated.
|
- `accounts/` hold account data and `bin/` holds script run by or for mutt. All other directories have been disintegrated.
|
||||||
- Better handling of different gpg versions.
|
- Better handling of different gpg versions.
|
||||||
- Script is POSIX sh compliance.
|
- Script is POSIX sh compliance.
|
||||||
|
|
||||||
## Known issues (not my fault!)
|
## Known issues (not my fault!)
|
||||||
|
|
||||||
- If you're using a Gmail account, check the pinned issue on the Github. Gmail accounts haven't been working properly with offlineimap recently, but there's an easy fix. Remember also to enable third-party ("""less secure""") applications.
|
- For Gmail accounts, remember also to enable third-party ("""less secure""") applications before attempting installation.
|
||||||
- Check the ProtonMail issue as well. ProtonMail recently allows IMAP usage with their Bridge program for paid users. I don't have this, so I can't bugtest on it, but many users have gotten it working. Either way, it requires a little more work than just using the wizard.
|
- Check the ProtonMail issue on Github if you are a Protonmail user. ProtonMail recently allows IMAP usage with their Bridge program for paid users. I don't have this, so I can't bugtest on it, but many users have gotten it working. Either way, it requires a little more work than just using the wizard.
|
||||||
- Don't expect mutt-wizard to work out the box on a university email. Universities often have special IMAP policies and server settings. You might be lucky, but you might have to changes some settings in the offlineimap config file to get it to work properly with a university email.
|
- Don't expect mutt-wizard to work out the box on a university email. Universities often have special IMAP policies and server settings. You might be lucky, but you might have to changes some settings in the mbsyncrc config file to get it to work properly with a university email.
|
||||||
- If you use an email server whose mailboxes are not in English, mutt-wizard might not be able to guess which is which, so you may have to manually set your Inbox, Sent, Trash, Drafts, etc. in your mutt config file.
|
- If you use an email server whose mailboxes are not in English, mutt-wizard might not be able to guess which is which, so you may have to manually set your Inbox, Sent, Trash, Drafts, etc. in your mutt config file.
|
||||||
|
|
||||||
## Help!
|
## Help!
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
# This script will run offlineimap and check
|
# This script will run mbsync and check
|
||||||
# for new email if there is an internet connection.
|
# for new email if there is an internet connection.
|
||||||
#
|
#
|
||||||
# If it detects new mail, it uses mpv to play a
|
# If it detects new mail, it uses mpv to play a
|
||||||
@ -22,8 +22,8 @@ fi
|
|||||||
echo " 🔃" > /tmp/imapsyncicon
|
echo " 🔃" > /tmp/imapsyncicon
|
||||||
pkill -RTMIN+12 i3blocks
|
pkill -RTMIN+12 i3blocks
|
||||||
|
|
||||||
# Run offlineimap. You can feed this script different settings.
|
# Run mbsync. You can feed this script different settings.
|
||||||
offlineimap -o "$@"
|
mbsync -a "$@"
|
||||||
rm -f /tmp/imapsyncicon
|
rm -f /tmp/imapsyncicon
|
||||||
pkill -RTMIN+12 i3blocks
|
pkill -RTMIN+12 i3blocks
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ do
|
|||||||
newcount=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" -type f -newer "$HOME/.config/mutt/bin/.mailsynclastrun" 2> /dev/null | wc -l)
|
newcount=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" -type f -newer "$HOME/.config/mutt/bin/.mailsynclastrun" 2> /dev/null | wc -l)
|
||||||
[ "$newcount" -gt "0" ] && notify "$acc" "$newcount" &
|
[ "$newcount" -gt "0" ] && notify "$acc" "$newcount" &
|
||||||
done
|
done
|
||||||
notmuch new
|
notmuch new 2>/dev/null
|
||||||
|
|
||||||
#Create a touch file that indicates the time of the last run of mailsync
|
#Create a touch file that indicates the time of the last run of mailsync
|
||||||
touch "$HOME/.config/mutt/bin/.mailsynclastrun"
|
touch "$HOME/.config/mutt/bin/.mailsynclastrun"
|
||||||
|
79
mw
79
mw
@ -1,5 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
muttdir="$HOME/.config/mutt" # Main mutt config location
|
muttdir="$HOME/.config/mutt" # Main mutt config location
|
||||||
accdir="$muttdir/accounts" # Directory for account settings
|
accdir="$muttdir/accounts" # Directory for account settings
|
||||||
maildir="$HOME/.local/share/mail" # Location of mail storage
|
maildir="$HOME/.local/share/mail" # Location of mail storage
|
||||||
@ -7,6 +6,7 @@ creddir="$HOME/.local/share/muttwizard" # Location of encrypted credentials
|
|||||||
bindir="$HOME/.config/mutt/bin" # Location of scripts run by mutt or the wizard
|
bindir="$HOME/.config/mutt/bin" # Location of scripts run by mutt or the wizard
|
||||||
namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username
|
namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username
|
||||||
emailre=".\+@.\+\\..\+" # Regex to confirm valid email address
|
emailre=".\+@.\+\\..\+" # Regex to confirm valid email address
|
||||||
|
mbsyncrc="$HOME/.mbsyncrc"
|
||||||
[ ! -f "$muttdir/domains.csv" ] || [ ! -d "$bindir" ] && printf "Read the README. Be sure to put the repo in the right place before running.\\n" && exit 1
|
[ ! -f "$muttdir/domains.csv" ] || [ ! -d "$bindir" ] && printf "Read the README. Be sure to put the repo in the right place before running.\\n" && exit 1
|
||||||
gpgemail="$(grep "$emailre" "$creddir/gpgemail")" # Get previously set gpg email address
|
gpgemail="$(grep "$emailre" "$creddir/gpgemail")" # Get previously set gpg email address
|
||||||
tmpdir="$(mktemp -d)"
|
tmpdir="$(mktemp -d)"
|
||||||
@ -19,7 +19,7 @@ case "$(uname)" in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
getprofiles() { \
|
getprofiles() { \
|
||||||
unset msmtp_header msmtp_profile mutt_profile offlineimap_header offlineimap_profile
|
unset msmtp_header msmtp_profile mutt_profile mbsync_profile
|
||||||
printf "Creating profiles for \`%s\`..." "$title"
|
printf "Creating profiles for \`%s\`..." "$title"
|
||||||
msmtp_header="defaults
|
msmtp_header="defaults
|
||||||
auth on
|
auth on
|
||||||
@ -63,32 +63,29 @@ bind index gg first-entry
|
|||||||
unmailboxes *
|
unmailboxes *
|
||||||
set imap_check_subscribed
|
set imap_check_subscribed
|
||||||
"
|
"
|
||||||
offlineimap_header="[general]
|
mbsync_profile="IMAPAccount $title
|
||||||
accounts =
|
Host $imap
|
||||||
starttls = yes
|
Port $iport
|
||||||
ssl = true
|
PassCmd \"gpg -q --for-your-eyes-only --no-tty -d ~/.local/share/muttwizard/$title.gpg\"
|
||||||
pythonfile = $bindir/imappwd.py
|
SSLType IMAPS
|
||||||
|
CertificateFile /etc/ssl/certs/ca-certificates.crt
|
||||||
|
|
||||||
"
|
IMAPStore $title-remote
|
||||||
offlineimap_profile="
|
Account $title
|
||||||
[Account $title]
|
|
||||||
localrepository = $title-local
|
|
||||||
remoterepository = $title-remote
|
|
||||||
|
|
||||||
[Repository $title-remote]
|
MaildirStore $title-local
|
||||||
auth_mechanisms = LOGIN
|
Subfolder Verbatim
|
||||||
type = $type
|
Path ~/.local/share/mail/$title/
|
||||||
remoteuser = $login
|
Inbox ~/.local/share/mail/$title/INBOX
|
||||||
remotepasseval = mailpasswd(\"$title\")
|
|
||||||
remoteport = $iport
|
|
||||||
sslcacertfile = $sslcert
|
|
||||||
$ifgoogleline
|
|
||||||
|
|
||||||
[Repository $title-local]
|
Channel $title
|
||||||
type = Maildir
|
Master $title-remote
|
||||||
localfolders = $maildir/$title
|
Slave $title-local
|
||||||
"
|
Patterns * !\"[Gmail]/All Mail\"
|
||||||
|
|
||||||
|
Create Both
|
||||||
|
SyncState *
|
||||||
|
# End profile"
|
||||||
else
|
else
|
||||||
mutt_profile="# vim: filetype=neomuttrc
|
mutt_profile="# vim: filetype=neomuttrc
|
||||||
# muttrc file for account $title
|
# muttrc file for account $title
|
||||||
@ -120,7 +117,7 @@ fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
addaccount() { \
|
addaccount() { \
|
||||||
printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/offlineIMAP\\n\\nEmail: "
|
printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\\nEmail: "
|
||||||
printf "\033[36m\t"
|
printf "\033[36m\t"
|
||||||
read -r fulladdr
|
read -r fulladdr
|
||||||
printf "\033[0m"
|
printf "\033[0m"
|
||||||
@ -190,15 +187,9 @@ ssl_version = tls1_2"
|
|||||||
[ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config"
|
[ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config"
|
||||||
echo "$msmtp_profile" >> "$HOME/.config/msmtp/config"
|
echo "$msmtp_profile" >> "$HOME/.config/msmtp/config"
|
||||||
echo "$mutt_profile" > "$accdir/$title.muttrc"
|
echo "$mutt_profile" > "$accdir/$title.muttrc"
|
||||||
if [ "$accounttype" = "offline" ]; then
|
|
||||||
mkdir -p "$HOME/.config/offlineimap/"
|
|
||||||
[ ! -f "$HOME/.config/offlineimap/config" ] && echo "$offlineimap_header" > "$HOME/.config/offlineimap/config"
|
|
||||||
echo "$offlineimap_profile" >> "$HOME/.config/offlineimap/config"
|
|
||||||
sed -i "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =\\s*$/accounts = $title/g" "$HOME/.config/offlineimap/config"
|
|
||||||
fi
|
|
||||||
echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$title.muttrc<enter><change-folder>!<enter>;<check-stats>'" >> "$muttdir/personal.muttrc"
|
echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$title.muttrc<enter><change-folder>!<enter>;<check-stats>'" >> "$muttdir/personal.muttrc"
|
||||||
! grep "^source.*.muttrc" "$muttdir/personal.muttrc" >/dev/null && echo "source $accdir/$title.muttrc" >> "$muttdir/personal.muttrc"
|
! grep "^source.*.muttrc" "$muttdir/personal.muttrc" >/dev/null && echo "source $accdir/$title.muttrc" >> "$muttdir/personal.muttrc"
|
||||||
trysync && finalize
|
[ ! "$accounttype" = "offline" ] && trysync && finalize
|
||||||
}
|
}
|
||||||
|
|
||||||
getpass() { \
|
getpass() { \
|
||||||
@ -244,22 +235,22 @@ formatShortcut() { \
|
|||||||
done ;}
|
done ;}
|
||||||
|
|
||||||
trysync() { \
|
trysync() { \
|
||||||
! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning offlineimap manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" && return 1
|
! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning \`mbsync $title\` manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" && return 1
|
||||||
printf "\033[32mYou must have an internet connection to continue.\033[0m\\nmutt-wizard will run offlineimap briefly to (1) ensure that login details are functional and (2) allow offlineimap to tell us what mailboxes your email account has.\\nAfter around 15 seconds, mutt-wizard will kill the process and continue.\\nYou can run offlineimap manually to finish the mail sync later.\\n"
|
printf "\033[32mYou must have an internet connection to continue.\033[0m\\nmutt-wizard will run mbsync briefly to (1) ensure that login details are functional and (2) allow mbsync to tell us what mailboxes your email account has.\\nAfter around 15 seconds, mutt-wizard will kill the process and continue.\\nYou can run mbsync manually to finish the mail sync later.\\n"
|
||||||
cont
|
cont
|
||||||
(sleep 15; killall offlineimap; killall offlineimap; killall offlineimap)>/dev/null 2>&1 &
|
(sleep 15; killall mbsync)>/dev/null 2>&1 &
|
||||||
mkdir -p "$maildir"
|
mkdir -p "$maildir"
|
||||||
offlineimap -qoa "$title"
|
mbsync "$title"
|
||||||
if ls -d "$maildir/$title/"* >/dev/null 2>&1; then
|
if ls -d "$maildir/$title/"* >/dev/null 2>&1; then
|
||||||
printf "\033[32mSync successful.\033[0m\\n"; return
|
printf "\033[32mSync successful.\033[0m\\n"; return
|
||||||
else
|
else
|
||||||
printf "\033[31m\033[31mSync not successful.\033[0m Try running offlineimap manually after double-checking your password and server settings.\\nThen select to finalize the account.\\n"; return 1
|
printf "\033[31m\033[31mSync not successful.\033[0m Try running \`mbsync $title\` manually after double-checking your password and server settings.\\nThen select to finalize the account.\\n"; return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize() { \
|
finalize() { \
|
||||||
boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")"
|
boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")"
|
||||||
[ -z "$boxes" ] && printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that offlineimap has not been successfully run.\\nRun offlineimap, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$title" && return
|
[ -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
|
||||||
echo "$boxes" > "$tmpdir/title_boxes"
|
echo "$boxes" > "$tmpdir/title_boxes"
|
||||||
printf "Setting up the mutt sidebar...\\n"
|
printf "Setting up the mutt sidebar...\\n"
|
||||||
sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')"
|
sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')"
|
||||||
@ -289,7 +280,7 @@ finalize() { \
|
|||||||
wipe () { \
|
wipe () { \
|
||||||
printf "Are you \033[31;1mreally\033[0m sure you want to delete all email accounts?\\n" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
|
printf "Are you \033[31;1mreally\033[0m sure you want to delete all email accounts?\\n" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
|
||||||
printf "Are you really, really sure?" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
|
printf "Are you really, really sure?" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
|
||||||
#rm -rf "$HOME/.config/offlineimap/config" "$accdir" "$creddir" "$muttdir/personal.muttrc"
|
#rm -rf "$mbsyncrc" "$accdir" "$creddir" "$muttdir/personal.muttrc"
|
||||||
echo deleted
|
echo deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,13 +298,7 @@ pick() { \
|
|||||||
[ -n "$2" ] && printf "Are you sure you want to %s the \`%s\` account?\\n" "$1" "$title" && read -r input && echo "$input" | grep -i "y\(es\)*" >/dev/null
|
[ -n "$2" ] && printf "Are you sure you want to %s the \`%s\` account?\\n" "$1" "$title" && read -r input && echo "$input" | grep -i "y\(es\)*" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
delete() { sed -i "
|
delete() { sed -i "/IMAPAccount $title/,/# End profile/d" "$mbsyncrc"
|
||||||
/Account $title]/,/Account/{//!d}
|
|
||||||
/Account $title]/d
|
|
||||||
s/ $title\(,\|$\)//g
|
|
||||||
s/=$title\(,\|$\)/=/g
|
|
||||||
s/,$//g
|
|
||||||
" "$HOME/.config/offlineimap/config"
|
|
||||||
rm -rf "${accdir:?}/${title:?}" "$creddir/$title.gpg" "$accdir/$title.muttrc"
|
rm -rf "${accdir:?}/${title:?}" "$creddir/$title.gpg" "$accdir/$title.muttrc"
|
||||||
sed -i "/$title.muttrc/d" "$muttdir/personal.muttrc"
|
sed -i "/$title.muttrc/d" "$muttdir/personal.muttrc"
|
||||||
# Delete from the line matching the account name, until the next account or empty line
|
# Delete from the line matching the account name, until the next account or empty line
|
||||||
@ -351,7 +336,7 @@ cont() { [ -n "$1" ] && printf "%s\\n" "$1"
|
|||||||
|
|
||||||
addtype() { \
|
addtype() { \
|
||||||
while : ; do
|
while : ; do
|
||||||
echo "Do you want to keep your mail for this account offline with offlineimap? [yes/no]"
|
echo "Do you want to keep your mail for this account offline with mbsync? [yes/no]"
|
||||||
read -r offnot
|
read -r offnot
|
||||||
case "$offnot" in
|
case "$offnot" in
|
||||||
[Yy]es) accounttype="offline" && break ;;
|
[Yy]es) accounttype="offline" && break ;;
|
||||||
|
Loading…
Reference in New Issue
Block a user