-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
235 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ Get this great stuff without effort: | |
* view and write emails while you're away from | ||
the internet | ||
* make backups | ||
- Provides a `mailsync` script that can be scheduled to run as often as you | ||
like, which downloads/syncs mail and notifies you when new mail has arrived. | ||
|
||
Specifically, this wizard: | ||
|
||
|
@@ -27,9 +29,10 @@ Specifically, this wizard: | |
#### Dependencies | ||
|
||
- `neomutt` - the email client. | ||
- `isync` - downloads and syncs the mail. (required at install) | ||
- `curl` - tests connections (required at install). | ||
- `isync` - downloads and syncs the mail (required if storing IMAP mail locally). | ||
- `msmtp` - sends the email. | ||
- `pass` - safely encrypts passwords (required at install) | ||
- `pass` - safely encrypts passwords (required at install). | ||
|
||
**Note**: There's a chance of errors if you use a slow-release distro like Ubuntu, Debian, | ||
or Mint. If you get errors in `neomutt`, install the most recent version | ||
|
@@ -45,6 +48,16 @@ sudo make install | |
A user of Arch-based distros can also install mutt-wizard from the AUR as | ||
[mutt-wizard-git](https://aur.archlinux.org/packages/mutt-wizard-git/). | ||
|
||
### Optional Dependencies | ||
|
||
- `pam-gnupg` - Automatically logs you into your GPG key on login so you will never need to input your password once logged on to your system. Check the repo and directions out [here](https://github.com/cruegge/pam-gnupg). | ||
- `lynx` - view HTML email in neomutt. | ||
- `notmuch` - index and search mail. Install it and run `notmuch setup`, tell it that your mail is in `~/.local/share/mail/` (although `mw` will do this automatically if you haven't set notmuch up before). You can run it in mutt with `ctrl-f`. Run `notmuch new` to process new mail. | ||
- `abook` - a terminal-based address book. Pressing tab while typing an address to send mail to will suggest contacts that are in your abook. | ||
- `urlview` - outputs urls in mail to browser. | ||
- `cronie` - (or any other major cronjob manager) to set up automatic mail syncing. | ||
|
||
|
||
## Usage | ||
|
||
The mutt-wizard runs via the command `mw`. Once setup is complete, you'll use | ||
|
@@ -56,6 +69,8 @@ The mutt-wizard runs via the command `mw`. Once setup is complete, you'll use | |
- `mw -Y` -- sync all configured email accounts | ||
- `mw -d` -- choose an account to delete | ||
- `mw -D [email protected]` -- delete account settings without confirmation | ||
- `mw -t 30` -- toggle automatic mailsync to every 30 minutes | ||
- `mw -T` -- toggle mailsync without specifying minutes (default is 10) | ||
- `pass edit [email protected]` -- revise an account's password | ||
|
||
### Options usable when adding an account | ||
|
@@ -64,7 +79,7 @@ The mutt-wizard runs via the command `mw`. Once setup is complete, you'll use | |
|
||
- `-u` -- Give an account username if different from the email address. | ||
- `-n` -- A real name to be used by the account. Put in quotations if multiple | ||
words | ||
words. | ||
- `-i` -- IMAP server address | ||
- `-I` -- IMAP server port (otherwise assumed to be 993) | ||
- `-s` -- SMTP server address | ||
|
@@ -126,8 +141,7 @@ To give you an example of the interface, here's an idea: | |
steps to install the system. | ||
- `mw` is now an installed program instead of just a script needed to be kept in | ||
your mutt folder. | ||
- `dialog` is no longer used (i.e. bloat) and the interface is simply text | ||
commands. | ||
- `dialog` is no longer used and the interface is simply text commands. | ||
- More autogenerated shortcuts that allow quickly moving and copying mail | ||
between boxes. | ||
- More elegant attachment handling. Image/video/pdf attachments without relying | ||
|
@@ -140,11 +154,12 @@ To give you an example of the interface, here's an idea: | |
- `pass` is used as a password manager instead of separately saving passwords. | ||
- Script is POSIX sh compliant. | ||
- Error handling for the many people who don't read or follow directions. Fewer | ||
errors, generally. | ||
errors generally. | ||
- Addition of a manual `man mw` | ||
|
||
## Help the Project! | ||
|
||
|
||
- 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/sh | ||
|
||
# - Syncs mail for all accounts, or a single account given as an argument. | ||
# - Displays a notification showing the number of new mails. | ||
# - Displays a notification for each new mail with its subject displayed. | ||
# - Runs notmuch to index new mail. | ||
# - This script can be set up as a cron job for automated mail syncing. | ||
|
||
# There are many arbitrary and ugly features in this script because it is | ||
# inherently difficult to pass environmental variables to cronjobs and other | ||
# issues. It also should at least be compatible with Linux (and maybe BSD) with | ||
# Xorg and MacOS as well. | ||
|
||
# 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 | ||
pgrep -x 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 | ||
# files for variable assignments. This is ugly, but there are few options that | ||
# will work on the maximum number of machines. | ||
eval "$(grep -h -- \ | ||
"^\s*\(export \)\?\(MBSYNCRC\|PASSWORD_STORE_DIR\|NOTMUCH_CONFIG\|GNUPGHOME\)=" \ | ||
"$HOME/.profile" "$HOME/.bash_profile" "$HOME/.zprofile" "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.pam_environment" 2>/dev/null)" | ||
# One alternative to this kind of command would be marking the script for | ||
# /bin/sh -l. That might cause other problems on other particular setups that | ||
# do more complicated things on login, or those people who assign environmental | ||
# variables in shell rc files. | ||
|
||
case "$(readlink -f /sbin/init)" in | ||
*systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; | ||
esac | ||
export GPG_TTY=$TTY | ||
|
||
[ -n "$MBSYNCRC" ] && alias mbsync="mbsync -c $MBSYNCRC" || MBSYNCRC="$HOME/.mbsyncrc" | ||
|
||
# Settings are different for MacOS (Darwin) systems. | ||
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\"" ;} | ||
;; | ||
*) | ||
displays="$(ps axo user,cmd | grep "^$USER\s\+.*Xorg" | grep -wo "[0-9]*:[0-9]\+")" | ||
notify() { for x in $displays; do | ||
export DISPLAY=$x | ||
notify-send --app-name="mutt-wizard" "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." | ||
done ;} | ||
messageinfo() { for x in $displays; do | ||
export DISPLAY=$x | ||
notify-send --app-name="mutt-wizard" "📧$from:" "$subject" | ||
done ;} | ||
;; | ||
esac | ||
|
||
# Check account for new mail. Notify if there is new content. | ||
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 "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null) | ||
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) | ||
if [ "$newcount" -gt "0" ]; then | ||
notify "$acc" "$newcount" & | ||
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 | ||
fi | ||
} | ||
|
||
# Sync accounts passed as argument or all. | ||
if [ "$#" -eq "0" ]; then | ||
accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC")" | ||
else | ||
for arg in "$@"; do | ||
[ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1 | ||
done | ||
accounts=$* | ||
fi | ||
|
||
# Parallelize multiple accounts | ||
for account in $accounts; do | ||
syncandnotify & | ||
done | ||
|
||
wait | ||
|
||
notmuch new 2>/dev/null | ||
|
||
#Create a touch file that indicates the time of the last run of mailsync | ||
touch "$HOME/.config/mutt/.mailsynclastrun" |
Oops, something went wrong.