rewrite underway

This commit is contained in:
Luke Smith 2019-02-21 10:14:17 -05:00
parent f2dcd92c30
commit 03279ea318
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252
24 changed files with 324 additions and 533 deletions

10
.gitignore vendored
View File

@ -1,10 +1,6 @@
personal.muttrc
*.swp *.swp
*.gpg *.gpg
accounts/
*.pyc *.pyc
personal.muttrc accounts/
thunderbird/ *mailsynclastrun
autoconf/log
etc/mailsynclastrun
etc/.mailsynclastrun
.dl

161
README.md
View File

@ -1,138 +1,59 @@
# Luke's mutt Wizard for automatic Neomutt and OfflineIMAP configuration! # mutt-wizard
![mutt wizard preview](etc/mw.png) The mutt-wizard is a simple `dialog`-based interface gives you:
Mutt is one of the most rewarding programs one can use, but can be a pain in - a fully-functioning neomutt-based terminal email workflow with vim bindings, vibrant display.
the ass to configure. Since my job is making power-user tools available for the - email backed up offline with offlineIMAP, allowing mobile and offline access of all your mail.
masses I want to create a tool that automates most of mutt configuration so - automatically generated shortcuts for jumping between different accounts or mailboxes within an account.
that users can simply give their email address and get a /comfy/ setup. At - sensible binds that make managing, moving and reading mail quicker and easier than ever.
that, I don't just want a mutt wizard, but an offlineIMAP wizard, so users can - your passwords safely encrypted on your machine so you (and only you) can access your account easily (uses GPG).
easily access their mail offline as well, and a wizard that makes it easy to
store passwords securely using gpg.
The mutt-wizard is all of this in a simple ncurses menu. It's really just a I maintain mutt-wizard for GNU/Linux, but individual contributors have also made it compatible with Mac.
little bash script, but one that can save countless people thousands of
combined manhours of frustratingly trying to get all the moving pieces working
together.
## User interface ## Use mutt-wizard
The system takes an email and autodetect its server settings, generating a 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.
muttrc and offlineimaprc profile automatically. If it can't do so, it simply
prompts you for these (which you can easily look up) and will put them all in
the right places. You get:
+ Automatic configuration of mutt and offlineimap. Be sure to install the following programs:
+ Automatic encryption and safe storage of passwords which are used by mutt and
offlineimap when necessary.
+ Multiple account management in mutt: jump from account to account with the
`i` prefix in mutt: `i1`: first email account, `i5`: fifth, etc.
+ Easy movement to mail folders in mutt: `gi`: go to inbox, `gs` to sent mail,
`ga` to archive, `gS` to spam, `gd` to drafts, etc.
+ Some default controls and colors. This system is going to be integrated into
my [public auto-rice script](https://larbs.xyz) so I want it to look pretty
and be usable out the box.
+ An optional autosync script that will smartly run offlineimap when connected
to the internet at what interval you want and will notify you with a ding
when new mail arrives.
### Will it work on my email? (95% yes) - `neomutt` - the email client.
- `offlineimap` - downloads the email.
- `msmtp` - sends your email.
- `dialog` - is the mutt-wizard interface.
Yes! At this point, the only problems are the unexpected ones. Please try it, **You must have a GPG public/private key pair as well.** This is what will safely encrypt your passwords.
and if you do run into problems, email me at
[luke@lukesmith.xyz](mailto:luke@lukesmith.xyz)! I've tried the system
personally on Gmail, Teknik.io, cock.li and Yandex, while others have tried
other providers.
If you have a ProtonMail account, due to their secure setup, you must have ### Optional dependencies
[ProtonMail Bridge](https://protonmail.com/bridge/) installed and configured.
Compatibility with ProtonMail is still in testing, so be sure to open an issue
if you have problems as I do not have a paid account to test this with.
Note also that Gmail and some providers require you to enable sign-ins from mutt-wizard is configured by default for you to use other useful tools, but these are not strictly necessary.
third-party (or as they call it "less secure") applications to be able to load
mail with mutt and offlineimap. Be sure to enable that!
## Installation and Dependencies - `w3m` - You'll probably want this one at least. It will help you read HTML email from those terrible people who send it... if you want to. It will also enable viewing images in mutt.
- `notmuch` - can index your mail to be easily searched. Install it and run `notmuch setup`, tell it that your mail is in `~/.local/share/mail/`. You can run it in mutt with `ctrl-f`. Remember to run `notmuch new` to process new mail, although the included `mailsync` script does this for you.
- `abook` - a terminal-based address book. Pressing tab while typing an address to send mail to will suggest contacts that are in your abook.
- A cron manager - if you want to enable the auto-sync feature.
`dialog`, `neomutt`, `offlineimap` and `msmtp` should be installed. You also need to ## New stuff and improvements since the original release
have a GPG public/private key pair for the wizard to automatically store your
passwords. The whole repo should be cloned to `~/.config/mutt/`. (If you have a
previous mutt folder, you'll want to back it up or delete it first.)
``` - More autogenerated shortcuts that allow quickly moving and copying mail between boxes.
git clone https://github.com/LukeSmithxyz/mutt-wizard.git ~/.config/mutt - More elegant attachment handling. Image/video/pdf attachments without relying on the neomutt instance.
``` - abook integration by default.
- 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/`.
- `accounts/` hold account data and `bin/` holds script run by for for mutt. All other directories have been disintegrated.
- Better handling of different gpg versions.
- Narrow POSIX compliance because why not?
You will want to delete or rename your current `~/.offlineimaprc` and ## Known issues (not my fault!)
`~/.msmtprc` as well, as although you can later modify these files produced by
the script, you must have no file there the first time you add your first
account or the wizard will assume some settings are already set which aren't.
Just run `mutt-wizard.sh` and choose to add an account. After you do so, you - 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.
may run `offlineimap` to begin the mailsync, and you will be able to run - 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.
neomutt and see your mail. If mutt doesn't immediately work properly run the - 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.
`Redetect mailboxes` option, then open mutt. This may be necessary for some - 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.
accounts.
## Help!
### Installation on macOS - Try mutt-wizard out on weird machines and weird email addresses and report any errors.
- Open a PR to add new server information into `domains.csv` so their users can more easily use mutt-wizard.
- If nothing else, [Donate!](https://paypal.me/LukeMSmith)
You may need to install or symlink additional packages on macOS. Otherwise the generation of configuration files may fail, or worse. See Luke's website [here](https://lukesmith.xyz). Email him at [luke@lukesmith.xyz](mailto:luke@lukesmith.xyz).
```
ln -s /usr/local/bin/gpg /usr/local/bin/gpg2
brew install coreutils
ln -s /usr/local/bin/gshred /usr/local/bin/shred
```
### Non-essential dependencies for extra features
The automatically deployed configs will look for certain programs for certain
extra abilities. Consider installing the following for the extra functionality.
+ `notmuch` -- for mail searching and indexing set to `ctrl-f`. Be sure to run
`notmuch setup`. Remember your mail is in `~/.mail/` when you configure
notmuch.
+ `w3m` and/or `w3mimg` -- for HTML emails and viewing images. Like .pdfs, view in the attachments menu.
+ A cron manager if you want the autosync feature.
+ `iproute2mac` for Mac users who want the autosync feature.
+ `mpv` if you want the autosync feature to notify you with a ding on new mail.
## The autosync
If you activate the autosync at a significantly infrequent interval, by
default, your system might prompt you for your GPG password every time. To
prevent this, you can change the time a GPG unlock lasts by adding a time in
seconds as below into `~/.gnupg/gpg-agent.conf`:
```
default-cache-ttl <number-of-seconds>
max-cache-ttl <number-of-seconds>
```
You can also use [pam-gnupg](https://github.com/cruegge/pam-gnupg) if you want
to just log into your keyring immediately on log in. This is what I do, but
it's less secure if you leave you computer logged on.
## You can help!
If you use mutt with a particular host or domain, put your server information
in `domains.csv`! This will make everyone else who uses your email provider's
life much easier!
Or you can help monetarily via [Patreon](https://patreon.com/lukesmith) or
[Paypal](https://paypal.me/LukeMSmith)!
## Notes
Mail is stored in `~/.mail`. mutt configs and caches for each account are in
`~/.config/mutt/accounts/`. Encypted passwords are in
`~/.config/mutt/credentials`. A "personal" muttrc, with the macros for
switching accounts and the default config is in
`~/.config/mutt/personal.muttrc`.
## Todo
* Expand the list of server information in `domains.csv`, possibly porting the
Thunderbird autoconfigure settings.

View File

@ -1,10 +0,0 @@
#!/bin/bash
# Give this script the abstract name of an account and it will make it the default.
title=$1
muttdir="$HOME/.config/mutt/"
muttdirsed=$(echo $muttdir | sed -e 's/\//\\\//g')
grep "$muttdir"personal.muttrc -e "^source .*accounts.*" >/dev/null && \
sed -i "s/^source .*accounts.*/source ${muttdirsed}accounts\/$title.muttrc/g" "$muttdir"personal.muttrc

View File

@ -1,6 +0,0 @@
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log

View File

@ -1,7 +0,0 @@
account $title
host $smtp
port $sport
from $login
user $login
passwordeval "gpg -d --quiet --for-your-eyes-only --no-tty ~/.config/mutt/credentials/$title.gpg | sed -e '$a\'"

View File

@ -1,21 +0,0 @@
# vim: filetype=neomuttrc
# muttrc file for account $title
set realname = "$realname"
set from = "$fulladdr"
set sendmail = "/usr/bin/msmtp -a $title"
set folder = "~/.mail/$title"
set header_cache = ~/.config/mutt/accounts/$title/cache/headers
set message_cachedir = ~/.config/mutt/accounts/$title/cache/bodies
set certificate_file = ~/.config/mutt/accounts/$title/certificates
source "~/.config/mutt/credentials/getmuttpass $title |"
alias me $realname <$fulladdr>
set mbox_type = Maildir
set ssl_starttls = yes
set ssl_force_tls = yes
bind index,pager gg noop
bind index,pager g noop
bind index gg first-entry
unmailboxes *

View File

@ -1,6 +0,0 @@
[general]
accounts =
starttls = yes
ssl = yes
pythonfile = ~/.config/mutt/credentials/imappwd.py

View File

@ -1,6 +0,0 @@
[general]
accounts =
starttls = yes
ssl = true
pythonfile = ~/.config/mutt/credentials/imappwd.py

View File

@ -1,19 +0,0 @@
[Account $title]
localrepository = $title-local
remoterepository = $title-remote
[Repository $title-remote]
auth_mechanisms = LOGIN
type = $type
remoteuser = $login
remotepasseval = mailpasswd("$title")
remotehost = $imap
remoteport = $iport
folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
[Repository $title-local]
type = Maildir
localfolders = ~/.mail/$title

View File

@ -1,19 +0,0 @@
[Account $title]
localrepository = $title-local
remoterepository = $title-remote
[Repository $title-remote]
auth_mechanisms = LOGIN
type = $type
remoteuser = $login
sslcacertfile = /usr/local/etc/openssl/cert.pem
remotepasseval = mailpasswd("$title")
remotehost = $imap
remoteport = $iport
folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']
sslcacertfile = /usr/local/etc/openssl/cert.pem
[Repository $title-local]
type = Maildir
localfolders = ~/.mail/$title

View File

@ -1,9 +0,0 @@
SERVICE,IMAP,imap port,SMTP,smtp port,spoolfile,postponed,record
"Zoho",imap.zoho.com,993,smtp.zoho.com,465,,,
"iCloud",imap.mail.me.com,993,smtp.mail.me.com,587,,,
"Inbox.com",imap.inbox.com,993,smtp.inbox.com,465,,,
"Office 365",outlook.office365.com,993,smtp.office365.com,587,INBOX,Drafts,Sent Items
"Host Gator",gator4171.hostgator.com,993,gator4171.hostgator.com,587,INBOX,INBOX.Drafts,INBOX.Sent
"GoDaddy",imap.secureserver.net,993,smtpout.secureserver.net,465,,,
"Yandex",imap.yandex.com,993.00,smtp.yandex.com,465.00,,,
"Muny Mail",mail.muny.us,993,mail.muny.us,465,,,
1 SERVICE IMAP imap port SMTP smtp port spoolfile postponed record
2 Zoho imap.zoho.com 993 smtp.zoho.com 465
3 iCloud imap.mail.me.com 993 smtp.mail.me.com 587
4 Inbox.com imap.inbox.com 993 smtp.inbox.com 465
5 Office 365 outlook.office365.com 993 smtp.office365.com 587 INBOX Drafts Sent Items
6 Host Gator gator4171.hostgator.com 993 gator4171.hostgator.com 587 INBOX INBOX.Drafts INBOX.Sent
7 GoDaddy imap.secureserver.net 993 smtpout.secureserver.net 465
8 Yandex imap.yandex.com 993.00 smtp.yandex.com 465.00
9 Muny Mail mail.muny.us 993 mail.muny.us 465

View File

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
GPG="gpg"; command -v gpg >/dev/null || GPG="gpg2" GPG="gpg"; command -v gpg >/dev/null || GPG="gpg2"
pass=$(printf '%q' "$("$GPG" --decrypt --quiet ~/.config/mutt/credentials/$1.gpg)") pass=$(printf '%q' "$("$GPG" --decrypt --quiet ~/.local/share/muttwizard/$1.gpg)")
echo "set smtp_pass=\"$pass\"" echo "set smtp_pass=\"$pass\""
echo "set imap_pass=\"$pass\"" echo "set imap_pass=\"$pass\""

View File

@ -3,7 +3,7 @@ import subprocess
home = os.path.expanduser("~") home = os.path.expanduser("~")
def mailpasswd(acct): def mailpasswd(acct):
acct = os.path.basename(acct) acct = os.path.basename(acct)
path = "%s/.config/mutt/credentials/%s.gpg" % (home,acct) path = "%s/.local/share/muttwizard/%s.gpg" % (home,acct)
args = ["gpg2", "--use-agent", "--quiet", "--batch", "-d", path] args = ["gpg2", "--use-agent", "--quiet", "--batch", "-d", path]
try: try:
return subprocess.check_output(args).strip().decode('UTF-8') return subprocess.check_output(args).strip().decode('UTF-8')

View File

@ -1,7 +1,7 @@
text/plain; vim %s ; text/plain; vim %s ;
text/html; ~/.config/mutt/etc/openfile.sh %s ; text/html; ~/.config/mutt/bin/openfile %s ;
text/html; w3m -I %{charset} -T text/html; copiousoutput; text/html; w3m -I %{charset} -T text/html; copiousoutput;
image/*; ~/.config/mutt/etc/muttimage.sh %s ; copiousoutput image/*; ~/.config/mutt/bin/muttimage %s ; copiousoutput
video/*; setsid mpv --quiet %s &; copiousoutput video/*; setsid mpv --quiet %s &; copiousoutput
application/pdf; ~/.config/mutt/etc/openfile.sh %s ; application/pdf; ~/.config/mutt/bin/openfile %s ;
application/pgp-encrypted; gpg -d '%s'; copiousoutput; application/pgp-encrypted; gpg -d '%s'; copiousoutput;

View File

@ -16,7 +16,7 @@ if [ "$(uname)" = "Darwin" ]
then then
notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;} notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;}
else else
notify() { mpv --really-quiet ~/.config/mutt/etc/notify.opus & pgrep -x dunst && notify-send -i ~/.config/mutt/etc/email.gif "$2 new mail(s) in \`$1\` account." ;} notify() { mpv --really-quiet ~/.config/mutt/bin/notify.opus & pgrep -x dunst && notify-send -i ~/.config/mutt/bin/email.gif "$2 new mail(s) in \`$1\` account." ;}
fi fi
echo " 🔃" > /tmp/imapsyncicon echo " 🔃" > /tmp/imapsyncicon
@ -28,10 +28,10 @@ rm -f /tmp/imapsyncicon
pkill -RTMIN+12 i3blocks pkill -RTMIN+12 i3blocks
# Check all accounts/mailboxes for new mail. Notify if there is new content. # Check all accounts/mailboxes for new mail. Notify if there is new content.
for account in $(ls ~/.mail) for account in $(ls ~/.local/share/mail)
do do
#List unread messages newer than last mailsync and count them #List unread messages newer than last mailsync and count them
newcount=$(find ~/.mail/"$account"/INBOX/new/ -type f -newer ~/.config/mutt/etc/.mailsynclastrun 2> /dev/null | wc -l) newcount=$(find ~/.mail/"$account"/INBOX/new/ -type f -newer ~/.config/mutt/bin/.mailsynclastrun 2> /dev/null | wc -l)
if [ "$newcount" -gt "0" ] if [ "$newcount" -gt "0" ]
then then
notify "$account" "$newcount" & notify "$account" "$newcount" &
@ -40,4 +40,4 @@ done
notmuch new notmuch new
#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 ~/.config/mutt/etc/.mailsynclastrun touch ~/.config/mutt/bin/.mailsynclastrun

View File

@ -1,14 +1,9 @@
#!/bin/sh #!/bin/sh
# Helps open a file with xdg-open from mutt in a external program without weird side effects. # Helps open a file with xdg-open from mutt in a external program without weird side effects.
base=$(basename "$1") base=$(basename "$1")
ext="${base##*.}" ext="${base##*.}"
file=$(mktemp -u --suffix=".$ext") file=$(mktemp -u --suffix=".$ext")
rm -f "$file" rm -f "$file"
cp "$1" "$file" cp "$1" "$file"
setsid xdg-open "$file" >/dev/null 2>&1 & setsid xdg-open "$file" >/dev/null 2>&1 &

View File

@ -108,7 +108,7 @@ mortemale.org,mail.autistici.org,993,smtp.autistici.org,465
msn.com,imap-mail.outlook.com,993,smtp-mail.outlook.com,587 msn.com,imap-mail.outlook.com,993,smtp-mail.outlook.com,587
muny.us,mail.muny.us,993,mail.muny.us,465 muny.us,mail.muny.us,993,mail.muny.us,465
myself.com,imap.mail.com,995,smtp.mail.com,587 myself.com,imap.mail.com,995,smtp.mail.com,587
narod.ru,imap.yandex.com,993,smtp.yandex.com,465 narod.ru,imap.yandex.com,993,smtp.yandex.com,587
national.shitposting.agency,mail.cock.li,993,mail.cock.li,587 national.shitposting.agency,mail.cock.li,993,mail.cock.li,587
nigge.rs,mail.cock.li,993,mail.cock.li,587 nigge.rs,mail.cock.li,993,mail.cock.li,587
nuke.africa,mail.cock.li,993,mail.cock.li,587 nuke.africa,mail.cock.li,993,mail.cock.li,587
@ -142,14 +142,14 @@ wants.dicksinhisan.us,mail.cock.li,993,mail.cock.li,587
wants.dicksinmyan.us,mail.cock.li,993,mail.cock.li,587 wants.dicksinmyan.us,mail.cock.li,993,mail.cock.li,587
web.de,imap.web.de,993,smtp.web.de,587 web.de,imap.web.de,993,smtp.web.de,587
writeme.com,imap.mail.com,995,smtp.mail.com,587 writeme.com,imap.mail.com,995,smtp.mail.com,587
ya.ru,imap.yandex.com,993,smtp.yandex.com,465 ya.ru,imap.yandex.com,993,smtp.yandex.com,587
yahoo.com,imap.mail.yahoo.com,993,smtp.mail.yahoo.com,587 yahoo.com,imap.mail.yahoo.com,993,smtp.mail.yahoo.com,587
yandex.by,imap.yandex.com,993,smtp.yandex.com,465 yandex.by,imap.yandex.com,993,smtp.yandex.com,587
yandex.com,imap.yandex.com,993,smtp.yandex.com,465 yandex.com,imap.yandex.com,993,smtp.yandex.com,587
yandex.kz,imap.yandex.com,993,smtp.yandex.com,465 yandex.kz,imap.yandex.com,993,smtp.yandex.com,587
yandex.net,imap.yandex.com,993,smtp.yandex.com,465 yandex.net,imap.yandex.com,993,smtp.yandex.com,587
yandex.ru,imap.yandex.com,993,smtp.yandex.com,465 yandex.ru,imap.yandex.com,993,smtp.yandex.com,587
yandex.ua,imap.yandex.com,993,smtp.yandex.com,465 yandex.ua,imap.yandex.com,993,smtp.yandex.com,587
zoho.com,imap.zoho.com,993,smtp.zoho.com,465 zoho.com,imap.zoho.com,993,smtp.zoho.com,465
duke.edu,outlook.office365.com,993,smtp.office365.com,587 duke.edu,outlook.office365.com,993,smtp.office365.com,587
1 ADDRESS IMAP imap port SMTP smtp port
108 msn.com imap-mail.outlook.com 993 smtp-mail.outlook.com 587
109 muny.us mail.muny.us 993 mail.muny.us 465
110 myself.com imap.mail.com 995 smtp.mail.com 587
111 narod.ru imap.yandex.com 993 smtp.yandex.com 465 587
112 national.shitposting.agency mail.cock.li 993 mail.cock.li 587
113 nigge.rs mail.cock.li 993 mail.cock.li 587
114 nuke.africa mail.cock.li 993 mail.cock.li 587
142 wants.dicksinmyan.us mail.cock.li 993 mail.cock.li 587
143 web.de imap.web.de 993 smtp.web.de 587
144 writeme.com imap.mail.com 995 smtp.mail.com 587
145 ya.ru imap.yandex.com 993 smtp.yandex.com 465 587
146 yahoo.com imap.mail.yahoo.com 993 smtp.mail.yahoo.com 587
147 yandex.by imap.yandex.com 993 smtp.yandex.com 465 587
148 yandex.com imap.yandex.com 993 smtp.yandex.com 465 587
149 yandex.kz imap.yandex.com 993 smtp.yandex.com 465 587
150 yandex.net imap.yandex.com 993 smtp.yandex.com 465 587
151 yandex.ru imap.yandex.com 993 smtp.yandex.com 465 587
152 yandex.ua imap.yandex.com 993 smtp.yandex.com 465 587
153 zoho.com imap.zoho.com 993 smtp.zoho.com 465
154 duke.edu outlook.office365.com 993 smtp.office365.com 587
155

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,276 +0,0 @@
#!/usr/bin/env bash
[ "$(uname)" == "Darwin" ] && os=".macos"
muttdir="$HOME/.config/mutt"
namere="^[a-z_][a-z0-9_-]*$"
emailre=".+@.+\..+"
createMailboxes() { \
tmpdir=$(mktemp -d)
offlineimap --info -a "$1" 2&> "$tmpdir"/log
sed -n '/^Folderlist/,/^Folderlist/p' "$tmpdir"/log |
grep "^ " | sed -e "s/\//./g;s/(.*//g;s/^ //g" > "$tmpdir"/lognew
while read box; do mkdir -p "$HOME/.mail/$1/$box"; done <"$tmpdir"/lognew ;}
testSync() { (crontab -l | grep mailsync.sh && removeSync) || addSync ;}
addSync() { min=$(dialog --inputbox "How many minutes should be between mail syncs?" 8 60 3>&1 1>&2 2>&3 3>&-)
(crontab -l; echo "*/$min * * * * eval \"export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME -x i3)/environ)\"; "$muttdir"/etc/mailsync.sh") | crontab - &&
dialog --msgbox "Cronjob successfully added. Remember you may need to restart or tell systemd/etc. to start your cron manager for this to take effect." 7 60 ;}
removeSync() { ((crontab -l | sed -e '/mailsync.sh/d') | crontab - >/dev/null) && dialog --msgbox "Cronjob successfully removed. To reactivate, select this option again." 6 60 ;}
changePassword() { \
gpgemail=$( dialog --title "Luke's mutt/offlineIMAP password wizard" --inputbox "Insert the email address with which you originally created your GPG key pair. This is NOT necessarily the email you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- )
while ! [[ "${gpgemail}" =~ ${emailre} ]]; do
gpgemail=$(dialog --no-cancel --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "That's not a valid email address. Please input the entire address." 10 60 3>&1 1>&2 2>&3 3>&1)
done
dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the new password for the \"$1\" account." 10 60 2> /tmp/$1
gpg2 -r "$gpgemail" --encrypt /tmp/$1 || (dialog --title "GPG decryption failed." --msgbox "GPG decryption failed. This is either because you do not have a GPG key pair or because your distro uses GPG1 and you thus need to symlink /usr/bin/gpg2 to /usr/bin/gpg." 7 60 && break)
shred -u /tmp/$1
mv /tmp/$1.gpg "$muttdir"/credentials/
dialog --title "Finalizing your account." --infobox "The account \"$title\"'s password has been changed. Now attempting to configure mail directories...
This may take several seconds..." 10 70
createMailboxes "$title" || (clear && exit)
detectMailboxes "$title"
dialog --title "Password changed." --msgbox "Your \"$fulladdr\" password has been changed. To start the download of your mail, you can manually run \`offlineimap -a $title\` in a terminal. The first sync may take some time depending on the amount of your mail." 8 60 ;}
chooseDetect() { for x in $(grep "^accounts =" ~/.offlineimaprc | sed -e 's/accounts =\( \)//g;s/\(,\) /\n/g;'); do detectMailboxes $x; done && detectSuccess ;}
detectWarning() { \
dialog --title "Mailbox detect requirement" --yesno "In order for the mailbox detection system to work, you must have
1) already have added the email account with this wizard, and
2) already have run offlineimap at least once to synchronize your mail.
This detection system only works if you already have begun your first sync. If you have, press 'yes' to continue." 12 70 ;}
detectSuccess() { dialog --title "Mailbox detect complete." --msgbox "The script has now smartly detected your different mailboxes and has enabled them in the sidebar and given you keyboard shortcuts as below:
gi for move to the Inbox.
gs for move to Sent Mail.
gd for move to Drafts
gS for move to Spam
ga for move to the Archive.
gj for move to Junk
gt for move to Trash
These shortcuts will only work if your email system does have that particular folder (i.e. if your email system has a Junk folder, but not a Trash folder, 'gt' will not work, etc." 20 60 ;}
formatShortcut() { \
while read data; do
echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"Go to $2.\"" >> "$muttdir"/accounts/$3.muttrc
done ;}
gen_delim() { \
delim="="
for i in `seq $(( $1 - 1 ))`
do
delim="$delim-"
done
echo $delim ;}
detectMailboxes() { \
find ~/.mail/$1 -maxdepth 1 -mindepth 1 -type d | sed -e "s/.*\///g;s/^/=/g" > /tmp/$1_boxes
sidebar_width=$(sed -n -e '/^set sidebar_width/p' "$muttdir"/muttrc | awk -F'=' '{print $2}')
delim=$(gen_delim $sidebar_width)
oneline=$(sed -e "s/^\|$/\"/g" /tmp/$1_boxes | tr "\n" " ")
oneline="=$1 $delim $oneline"
sed -i "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$muttdir"/accounts/$1.muttrc
echo mailboxes $oneline >> "$muttdir"/accounts/$1.muttrc
sed -i "/^macro index,pager g/d" "$muttdir"/accounts/$1.muttrc
grep -i /tmp/$1_boxes -e inbox | sed 1q | formatShortcut i inbox $1
grep -i /tmp/$1_boxes -e sent | sed 1q | formatShortcut s sent $1
grep -i /tmp/$1_boxes -e draft | sed 1q | formatShortcut d drafts $1
grep -i /tmp/$1_boxes -e trash | sed 1q | formatShortcut t trash $1
grep -i /tmp/$1_boxes -e spam | sed 1q | formatShortcut S spam $1
grep -i /tmp/$1_boxes -e junk | sed 1q | formatShortcut j junk $1
grep -i /tmp/$1_boxes -e archive | sed 1q | formatShortcut a archive $1
spoolfile=$(grep -i /tmp/$1_boxes -e inbox | sed -e 's/=/+/g' | sed 1q)
record=$(grep -i /tmp/$1_boxes -e sent | sed -e 's/=/+/g' | sed 1q)
postponed=$(grep -i /tmp/$1_boxes -e draft | sed -e 's/=/+/g' | sed 1q)
trash=$(grep -i /tmp/$1_boxes -e trash | sed -e 's/=/+/g' | sed 1q)
echo "set spoolfile = \"$spoolfile\"" >> "$muttdir"/accounts/$1.muttrc
echo "set record = \"$record\"" >> "$muttdir"/accounts/$1.muttrc
echo "set postponed = \"$postponed\"" >> "$muttdir"/accounts/$1.muttrc
echo "set trash = \"$trash\"" >> "$muttdir"/accounts/$1.muttrc ;}
# Get all accounts in ~/.offlineimaprc and load into variable `accounts`.
getAccounts() { \
grep "^accounts =" ~/.offlineimaprc | sed -e 's/accounts =\( \)//g;s/\(,\) /\n/g;' | nl --number-format=ln > /tmp/numbered
accounts=()
while read n s ; do
accounts+=($n "$s" off)
done < /tmp/numbered ;}
# Yields a menu of available accounts.
inventory() { \
getAccounts
choices=$(dialog --separate-output --checklist "Select all desired email accounts with <SPACE>." 15 40 16 "${accounts[@]}" 2>&1 >/dev/tty)
if [ -z "$choices" ];
then
clear
else
userchoices=$(IFS="|"; keys="${choices[*]}"; keys="${keys//|/\\|}"; grep -w "${keys}" /tmp/numbered | awk '{print $2}')
fi ;}
removeAccount() { sed -ie "
/Account $1]/,/Account/{//!d}
/Account $1]/d
s/ $1\(,\|$\)//g
s/=$1\(,\|$\)/=/g
s/,$//g
" ~/.offlineimaprc
rm "$muttdir"/accounts/$1.muttrc
rm "$muttdir"/credentials/$1.gpg
rm -rf "$muttdir"/accounts/$1
sed -i "/$1.muttrc/d" "$muttdir"/personal.muttrc
# Delete from the line matching the account name, until the next account or empty line
sed -i "/account $1/,/^\(\s*$\|account\)/d" ~/.msmtprc ;}
manual() { \
imap=$( dialog --inputbox "Insert the IMAP server for your email provider (excluding the port number)" 10 60 3>&1 1>&2 2>&3 3>&- )
iport=$(dialog --inputbox "What is your server's IMAP port number? (Usually 993)" 10 60 3>&1 1>&2 2>&3 3>&-)
smtp=$( dialog --inputbox "Insert the SMTP server for your email provider (excluding the port number)" 10 60 3>&1 1>&2 2>&3 3>&- )
sport=$( dialog --inputbox "What is your server's SMTP port number? (Usually 587 or 465)" 10 60 3>&1 1>&2 2>&3 3>&- ) ;}
addloop() { fulladdr=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Insert the full email address for the account you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- )
while ! [[ "${fulladdr}" =~ ${emailre} ]]; do
fulladdr=$(dialog --no-cancel --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "That's not a valid email address. Please input the entire address." 10 60 3>&1 1>&2 2>&3 3>&1)
done
# Check to see if domain is in domain list
serverinfo=$(grep -w ^${fulladdr##*@} "$muttdir"/autoconf/domains.csv)
if [ -z "$serverinfo" ];
then
manual
else
# Read in server data as variables
IFS=, read service imap iport smtp sport <<EOF
$serverinfo
EOF
fi
realname=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Enter the full name you'd like to be identified by on this email account." 10 60 3>&1 1>&2 2>&3 3>&- )
title=$(dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Give a short, one-word name for this email account that will differentiate it from other email accounts." 10 60 3>&1 1>&2 2>&3 3>&1) || exit
while ! [[ "${title}" =~ ${namere} ]]; do
title=$(dialog --no-cancel --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Account title not valid. Give a username beginning with a letter, with only lowercase letters, - or _." 10 60 3>&1 1>&2 2>&3 3>&1)
done
login=$(dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "If you have a username for the \"$title\" account which is different from your email address, enter it here. Otherwise leave this prompt blank." 10 60 3>&1 1>&2 2>&3 3>&- )
# Sets the repo type and other variables for the sed regex.
if [[ "$service" == "gmail.com" ]];
then
type="Gmail"
delet="remotehost"
else
type="IMAP"
delet="Gmail]\/"
fi
if [[ -z "$login" ]];
then
login=$fulladdr
fi
# The replacements
replacement="
s/\$realname/$realname/g;
s/\$title/$title/g;
s/\$fulladdr/$fulladdr/g;
s/\$imap/$imap/g;
s/\$iport/$iport/g;
s/\$smtp/$smtp/g;
s/\$sport/$sport/g;
s/\$type/$type/g;
s/\$login/$login/g;
/$delet/d"
# Gets the first unused shortcut number in the muttrc and puts it in $idnum.
grep "i[0-9]" "$muttdir/personal.muttrc" | awk '{print $3}' | sed -e 's/i//g' > /tmp/mutt_used
echo -e "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9" > /tmp/mutt_all_possible
idnum=$(diff /tmp/mutt_all_possible /tmp/mutt_used | sed -n 2p | awk '{print $2}')
addAccount \
;}
addAccount() {
# First, adding the encrypted password.
dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the password for the \"$title\" account." 10 60 2> /tmp/$title
gpg2 -r $gpgemail --encrypt /tmp/$title || (dialog --title "GPG decryption failed." --msgbox "GPG decryption failed. This is either because you do not have a GPG key pair or because your distro uses GPG1 and you thus need to symlink /usr/bin/gpg2 to /usr/bin/gpg." 7 60 && break)
shred -u "/tmp/$title"
mv "/tmp/$title.gpg" "$muttdir"/credentials/
# Adding directory structure for cache.
mkdir -p "$muttdir/accounts/$title/cache/bodies"
# Creating the offlineimaprc if it doesn't exist already.
if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"/autoconf/offlineimap_header"$os" ~/.offlineimaprc; fi
sed -e "$replacement" "$muttdir"/autoconf/offlineimap_profile"$os" >> ~/.offlineimaprc
mkdir -p "$HOME/.mail/$title"
# Creating msmtprc if it doesn't exist already.
if [ ! -f ~/.msmtprc ]; then cp "$muttdir"/autoconf/msmtprc_header ~/.msmtprc; fi
sed -e "$replacement" "$muttdir"/autoconf/msmtprc_profile >> ~/.msmtprc
# Add the mutt profile.
sed -e "$replacement" "$muttdir"/autoconf/mutt_profile > "$muttdir/accounts/$title.muttrc"
# Add a numbered shortcut in the muttrc
echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source \"$muttdir\"/accounts/$title.muttrc<enter><change-folder>!<enter>;<check-stats>'" >> "$muttdir"/personal.muttrc
# Add to offlineimaprc sync list.
sed -i.bu "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =\\s*$/accounts = $title/g" ~/.offlineimaprc && rm ~/.offlineimaprc.bu
# Makes account default if there is no default account.
grep "$muttdir"/personal.muttrc -e "^source .*accounts.*" >/dev/null && echo there || \
echo "source ${muttdir}/accounts/$title.muttrc" >> "$muttdir"/personal.muttrc
dialog --title "Finalizing your account." --infobox "The account \"$title\" has been added. Now attempting to configure mail directories...
This may take several seconds..." 10 70
createMailboxes "$title" || (clear && exit)
detectMailboxes "$title"
dialog --title "Account added." --msgbox "Your \"$fulladdr\" account has been added. To start the download of your mail, you can manually run \`offlineimap -a $title\` in a terminal. The first sync may take some time depending on the amount of your mail." 8 60 ;}
# This is run when a user chooses to add an account.
chooseAdd() { \
mkdir -p "$muttdir"/credentials/ "$muttdir"/accounts/
gpgemail=$( dialog --title "Luke's mutt/offlineIMAP password wizard" --inputbox "Insert the email address with which you originally created your GPG key pair. This is NOT necessarily the email you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- )
addloop
while : ;
do
dialog --title "Luke's mutt/offlineIMAP password wizard" --yesno "Would you like to add another email account?" 5 60 || break
addloop
done ;}
wipe () { rm "$HOME/.offlineimaprc"
rm -rf "$muttdir"/accounts
rm -f "$muttdir"/credentials/*gpg
rm "$muttdir"/personal.muttrc ;}
while : ;
do
choice=$(dialog --title "Luke's mutt/offlineIMAP wizard" --nocancel \
--menu "What would you like to do?" 15 45 8 \
0 "List all email accounts configured." \
1 "Add an email account." \
2 "Enable/disable autosync." \
3 "Redetect mailboxes." \
4 "Change an account's password." \
5 "Remove an email account." \
6 "Remove all email accounts." \
7 "Exit this wizard." \
3>&1 1>&2 2>&3 3>&1 )
case $choice in
0) dialog --title "Accounts detected" --msgbox "The following accounts have been detected:
$(grep ~/.offlineimaprc -e "^accounts =" | sed 's/accounts =//g')
" 6 60;;
1) chooseAdd;;
2) testSync;;
3) detectWarning && chooseDetect;;
4) inventory && for i in $userchoices; do changePassword "$i" ; done;;
5) inventory && for i in $userchoices; do removeAccount "$i" ; done;;
6) (dialog --defaultno --title "Wipe all custom neomutt/offlineIMAP settings?" --yesno "Would you like to wipe all of the mutt/offlineIMAP settings generated by the system?" 6 60 && wipe) ;;
7) clear && break ;;
*) echo "Unable to read response from dialog. Exiting." >&2; exit 2
esac
done

6
muttrc
View File

@ -10,7 +10,7 @@ set editor = $EDITOR
#set copy = no #set copy = no
set timeout = "5" set timeout = "5"
set mail_check = "10" set mail_check = "10"
set mailcap_path = ~/.config/mutt/etc/mailcap set mailcap_path = ~/.config/mutt/bin/mailcap
set date_format="%y/%m/%d %I:%M" set date_format="%y/%m/%d %I:%M"
set index_format="%2C %zs %?X?A& ? %D %-15.15F %s (%-4.4c)" set index_format="%2C %zs %?X?A& ? %D %-15.15F %s (%-4.4c)"
set markers = no set markers = no
@ -65,10 +65,6 @@ macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "ma
macro index O "<shell-escape>$HOME/.config/mutt/etc/mailsync.sh<enter>" "run offlineimap to sync all mail" macro index O "<shell-escape>$HOME/.config/mutt/etc/mailsync.sh<enter>" "run offlineimap to sync all mail"
macro index o "<shell-escape>$HOME/.config/mutt/etc/mailsync.sh -qf INBOX<enter>" "run offlineimap to sync inbox" macro index o "<shell-escape>$HOME/.config/mutt/etc/mailsync.sh -qf INBOX<enter>" "run offlineimap to sync inbox"
#copy/move dialogs
macro index C "<copy-message>?<toggle-mailboxes>" "copy a message to a mailbox"
macro index M "<save-message>?<toggle-mailboxes>" "move a message to a mailbox"
# Notmuch searching # Notmuch searching
macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>read -p 'notmuch query: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;chomp@a;s/\^id:// for@a;$,=\"|\";print@a'\`\"<enter>" "show only messages matching a notmuch pattern" macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>read -p 'notmuch query: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;chomp@a;s/\^id:// for@a;$,=\"|\";print@a'\`\"<enter>" "show only messages matching a notmuch pattern"
macro index A "<limit>all\n" "show all messages (undo limit)" macro index A "<limit>all\n" "show all messages (undo limit)"

262
mw Executable file
View File

@ -0,0 +1,262 @@
#!/bin/sh
muttdir="$HOME/.config/mutt" # Main mutt config location
accdir="$muttdir/accounts" # Directory for account settings
maildir="$HOME/.local/share/mail" # Location of mail storage
creddir="$HOME/.local/share/muttwizard" # Location of encrypted credentials
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
emailre=".\+@.\+\\..\+" # Regex to confirm valid email address
gpgemail="$(cat "$creddir/gpgemail")" # Get previously set gpg email address
tmpdir="$(mktemp -d)"
GPG="gpg"; command -v gpg >/dev/null || GPG="gpg2" # Ensure proper gpg command
mkdir -p "$maildir" "$creddir" "$bindir"
# Get certificate location depending on OS. Linux is elsewhere condition.
case "$(uname)" in
"Darwin") sslcert="/usr/local/etc/openssl/cert.pem" ;;
*) sslcert="/etc/ssl/certs/ca-certificates.crt" ;;
esac
getprofiles() { \
offlineimap_header="[general]
accounts =
starttls = yes
ssl = true
pythonfile = $bindir/imappwd.py
"
offlineimap_profile="
[Account $title]
localrepository = $title-local
remoterepository = $title-remote
[Repository $title-remote]
auth_mechanisms = LOGIN
type = $type
remoteuser = $login
remotepasseval = mailpasswd(\"$title\")
remoteport = $iport
sslline = $sslcert
$ifgoogleline
[Repository $title-local]
type = Maildir
localfolders = $maildir/$title
"
msmtp_header="defaults
auth on
tls on
tls_trust_file $sslcert
logfile ~/.msmtp.log
"
msmtp_profile="
account $title
host $smtp
port $sport
from $login
user $login
passwordeval \"$GPG -d --quiet --for-your-eyes-only --no-tty $creddir/$title.gpg | sed -e '\$a\\'\"
"
mutt_profile="# vim: filetype=neomuttrc
# muttrc file for account $title
set realname = \"$realname\"
set from = \"$fulladdr\"
set sendmail = \"/usr/bin/msmtp -a $title\"
set folder = \"$maildir/$title\"
set header_cache = $accdir/$title/cache/headers
set message_cachedir = $accdir/$title/cache/bodies
set certificate_file = $accdir/$title/certificates
source \"$bindir/getmuttpass $title |\"
alias me $realname <$fulladdr>
set mbox_type = Maildir
set ssl_starttls = yes
set ssl_force_tls = yes
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 *
"
offlineimap_profile="
[Account $title]
localrepository = $title-local
remoterepository = $title-remote
[Repository $title-remote]
auth_mechanisms = LOGIN
type = $type
remoteuser = $login
remotepasseval = mailpasswd(\"$title\")
remotehost = $imap
remoteport = $iport
folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
[Repository $title-local]
type = Maildir
localfolders = $maildir/$title
"
}
userexit() { clear; exit ;}
inventory() { \
grep "^accounts =" "$HOME/.config/offlineimap/config" | sed 's/accounts =\( \)//g;s/\(,\) /\n/g;' | nl --number-format=ln > "$tmpdir/numbered"
accounts=()
while read n s ; do
accounts+=($n "$s" off)
done < "$tmpdir/numbered"
choices=$(dialog --separate-output --checklist "Select all desired email accounts with <SPACE>." 15 40 16 "${accounts[@]}" 2>&1 >/dev/tty)
if [ -z "$choices" ];
then
clear
else
userchoices=$(IFS="|"; keys="${choices[*]}"; keys="${keys//|/\\|}"; grep -w "${keys}" "$tmpdir/numbered" | awk '{print $2}')
fi ;}
chooseadd() { \
fulladdr=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Insert the full email address for the account you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- ) || userexit
while ! echo "$fulladdr" | grep "emailre" >/dev/null; do
fulladdr=$(dialog --no-cancel --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "That's not a valid email address. Please input the entire address." 10 60 3>&1 1>&2 2>&3 3>&1) || userexit
done
domain="$(echo "$fulladdr" | sed "s/.*@//")"
serverinfo="$(grep "$domain" "$muttdir/domains.csv")"
if [ -z "$serverinfo" ]; then
imap="$( dialog --inputbox "Insert the IMAP server for your email provider (excluding the port number)" 10 60 3>&1 1>&2 2>&3 3>&- )"
iport="$(dialog --inputbox "What is your server's IMAP port number? (Usually 993)" 10 60 3>&1 1>&2 2>&3 3>&-)"
smtp="$(dialog --inputbox "Insert the SMTP server for your email provider (excluding the port number)" 10 60 3>&1 1>&2 2>&3 3>&- )"
sport="$(dialog --inputbox "What is your server's SMTP port number? (Usually 587 or 465)" 10 60 3>&1 1>&2 2>&3 3>&- )"
else
IFS=, read service imap iport smtp sport <<EOF
$serverinfo
EOF
fi
realname=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Enter the full name you'd like to be identified by on this email account." 10 60 3>&1 1>&2 2>&3 3>&- ) || userexit
title=$(dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Give a short, one-word name for this email account that will differentiate it from other email accounts." 10 60 3>&1 1>&2 2>&3 3>&1) || userexit
while ! echo "$title" | grep "$namere" >/dev/null; do
title=$(dialog --no-cancel --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Account title not valid. Give a username beginning with a letter, with only lowercase letters, - or _." 10 60 3>&1 1>&2 2>&3 3>&1) || userexit
done
login=$(dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "If you have a username for the \"$title\" account which is different from your email address, enter it here. Otherwise leave this prompt blank." 10 60 3>&1 1>&2 2>&3 3>&- ) || userexit
[ -z "$login" ] && login="$fulladdr"
#ifgoogleline
grep "i[0-9]" "$muttdir/personal.muttrc" | awk '{print $3}' | sed -e 's/i//g' > "$tmpdir/mutt_used"
printf "1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9" > "$tmpdir/mutt_all_possible"
idnum=$(diff "$tmpdir/mutt_all_possible" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}')
getpass "$title" || userexit
addaccount
}
getpass() { \
dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the password for the \"$1\" account." 10 60 2> "$tmpdir/$1"
"$GPG" -r "$gpgemail" --encrypt "$tmpdir/$1"
shred -u "$tmpdir/$1"
mv "$tmpdir/$1.gpg" "$creddir"
}
addaccount() { \
getprofiles
mkdir -p "$HOME/.config/offlineimap/" "$HOME/.config/msmtp"
[ ! -f "$HOME/.config/offlineimap/config" ] && echo "$offlineimap_header" > "$HOME/.config/offlineimap/config"
[ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config"
echo "$offlineimap_profile" >> "$HOME/.config/offlineimap/config"
echo "$msmtp_profile" >> "$HOME/.config/msmtp/config"
echo "$mutt_profile" > "$accdir/$title.muttrc"
}
askgpg() { \
gpgemail=$(dialog --title "Luke's mutt/offlineIMAP wizard" --inputbox "To safely encrypt passwords, mutt-wizard requires that you have a GPG public/private key pair.\n\nPlease insert the email address for your key pair here, or generate one first with \`$GPG --full-gen-key\` and come back." 12 60 3>&1 1>&2 2>&3 3>&- ) || userexit
while ! echo "$gpgemail" | grep "$emailre"; do
gpgemail=$(dialog --title "Luke's mutt/offlineIMAP wizard" --inputbox "That's not a valid email address. Please input the entire address." 10 60 3>&1 1>&2 2>&3 3>&1) || userexit
done
if "$GPG" -K | grep "<$gpgemail>"; then
echo "$gpgemail" > "$creddir/gpgemail"
else
dialog --title "Luke's mutt/offlineIMAP wizard" --msgbox "You do not appear to have a private key with that email address.\n\nPlease be sure to create your key with \`$GPG --full-gen-key\` and come back." 8 70
clear; exit
fi
}
formatShortcut() { \
while read data; do { echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"Go to $2.\" # autogenerated"
echo "macro index,pager M$1 \"<save-message>$data<enter>\" \"Move mail to $2.\" # autogenerated"
echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"Copy mail to $2.\" # autogenerated"; } >> "$muttdir/accounts/$3.muttrc"
done ;}
gen_delim() { \
delim="="
for i in $(seq $(( $1 - 1 )))
do
delim="$delim-"
done
echo $delim ;}
detectMailboxes() { \
ls -d "$maildir/$1/"* | sed "s/.*\///;s/^/=/" > "$tmpdir/$1_boxes"
sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')"
delim="$(gen_delim "$sidebar_width")"
oneline="$(sed -e "s/^\|$/\"/g" "$tmpdir/$1_boxes" | tr "\n" " ")"
oneline="=$1 $delim $oneline"
sed -i "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$muttdir/accounts/$1.muttrc"
echo mailboxes "$oneline" >> "$muttdir/accounts/$1.muttrc"
sed -i "/# autogenerated/d" "$muttdir/accounts/$1.muttrc"
grep -i "$tmpdir/$1_boxes" -e inbox | sed 1q | formatShortcut i inbox "$1"
grep -i "$tmpdir/$1_boxes" -e sent | sed 1q | formatShortcut s sent "$1"
grep -i "$tmpdir/$1_boxes" -e draft | sed 1q | formatShortcut d drafts "$1"
grep -i "$tmpdir/$1_boxes" -e trash | sed 1q | formatShortcut t trash "$1"
grep -i "$tmpdir/$1_boxes" -e spam | sed 1q | formatShortcut S spam "$1"
grep -i "$tmpdir/$1_boxes" -e junk | sed 1q | formatShortcut j junk "$1"
grep -i "$tmpdir/$1_boxes" -e archive | sed 1q | formatShortcut a archive "$1"
spoolfile=$(grep -i "$tmpdir/$1_boxes" -e inbox | sed -e 's/=/+/g' | sed 1q)
record=$(grep -i "$tmpdir/$1_boxes" -e sent | sed -e 's/=/+/g' | sed 1q)
postponed=$(grep -i "$tmpdir/$1_boxes" -e draft | sed -e 's/=/+/g' | sed 1q)
trash=$(grep -i "$tmpdir/$1_boxes" -e trash | sed -e 's/=/+/g' | sed 1q)
{ echo "set spoolfile = \"$spoolfile\""; echo "set record = \"$record\""; echo "set postponed = \"$postponed\""; echo "set trash = \"$trash\""; } >> "$muttdir/accounts/$1.muttrc"
}
#wipe () { rm "$HOME/.config/offlineimap/config" "$accdir" "$creddir" "$muttdir/personal.muttrc" ;}
[ -z "$gpgemail" ] && askgpg
while : ;
do
choice=$(dialog --title "Luke's mutt/offlineIMAP wizard" --nocancel \
--menu "What would you like to do?" 15 50 8 \
0 "Add email account (Begin installtion)" \
1 "Autodetect mailboxes (Finalize installation)" \
2 "Enable/disable autosync." \
3 "Change an account's password" \
4 "Remove an account" \
5 "Remove all accounts" \
6 "Change your GPG email" \
7 "Exit this wizard." \
3>&1 1>&2 2>&3 3>&1 )
case $choice in
0) dialog --title "Accounts detected" --msgbox "The following accounts have been detected:
$(grep ~/.offlineimaprc -e "^accounts =" | sed 's/accounts =//g')
" 6 60;;
1) chooseadd ;;
2) detectWarning && chooseDetect;;
3) inventory && for i in $userchoices; do getpass "$i" ; done;;
4) inventory && for i in $userchoices; do removeAccount "$i" ; done;;
5) (dialog --defaultno --title "Wipe all custom neomutt/offlineIMAP settings?" --yesno "Would you like to wipe all of the mutt/offlineIMAP settings generated by the system?" 6 60 && wipe) ;;
6) askgpg ;;
7) clear && break ;;
*) echo "Error. Are you sure you have dialog installed?" >&2; exit 2
esac
done
rm -rf "$tmpdir"