forked from colonelpanic/dotfiles
mu4e_update_mail for mac osx using terminal-notifier
This commit is contained in:
parent
b70181b71e
commit
17babb027e
@ -60,6 +60,10 @@ function emacs_make_frame_if_none_exists {
|
||||
focus_emacs
|
||||
}
|
||||
|
||||
function execute_elisp {
|
||||
emacs_get_running_instances | xargs -I svr-filename emacsclient --server-file=svr-filename -e "$1"
|
||||
}
|
||||
|
||||
function focus_emacs {
|
||||
is_osx && osascript -e 'tell application "Emacs" to activate'
|
||||
}
|
||||
|
@ -1,32 +1,47 @@
|
||||
MAILDIR="$HOME/Mail"
|
||||
DBUS_COOKIE="$HOME/.sauron-dbus"
|
||||
SYNC_STAMP="$HOME/.mail-sync"
|
||||
|
||||
function sauron_msg {
|
||||
if test -z "$DBUS_SESSION_BUS_ADDRESS"; then
|
||||
echo "DBUS session not found."
|
||||
if test -e $DBUS_COOKIE; then
|
||||
export DBUS_SESSION_BUS_ADDRESS="`cat $DBUS_COOKIE`"
|
||||
else
|
||||
echo "DBUS cookie not found, unable to send message"
|
||||
fi
|
||||
fi
|
||||
if test -n "$DBUS_SESSION_BUS_ADDRESS"; then
|
||||
dbus-send --session \
|
||||
--dest="org.gnu.Emacs" \
|
||||
--type=method_call \
|
||||
"/org/gnu/Emacs/Sauron" \
|
||||
"org.gnu.Emacs.Sauron.AddMsgEvent" \
|
||||
string:"$1" uint32:3 string:"$2"
|
||||
fi
|
||||
function mu4e_alert_for_filename {
|
||||
local message="$(mu view $1 | grep -B 10 Date)"
|
||||
local title="$(echo $message | grep From | sed 's/From: //')"
|
||||
local subject="$(echo $message | grep Subject | sed 's/Subject: //')"
|
||||
local view_file_command="$(which zsh) -c \"refresh_config && mu4e_view_message_from_file $1\""
|
||||
reattach-to-user-namespace $(which terminal-notifier) \
|
||||
-title "$title" \
|
||||
-message "$subject" \
|
||||
-execute "$view_file_command" \
|
||||
-activate "org.gnu.Emacs" \
|
||||
-appIcon "$(dotfiles_directory)/resources/gmail_logo.png"
|
||||
}
|
||||
|
||||
function update_mail {
|
||||
function mu4e_update_mail {
|
||||
offlineimap
|
||||
mu4e_update_index
|
||||
mu4e_alerts
|
||||
}
|
||||
|
||||
function mu4e_update_index {
|
||||
execute_elisp "(mu4e-update-index)"
|
||||
}
|
||||
|
||||
function mu4e_alerts {
|
||||
test -e $SYNC_STAMP || touch $SYNC_STAMP
|
||||
touch "${SYNC_STAMP}.in-progress"
|
||||
for f in `find "$MAILDIR" -cnewer $SYNC_STAMP -a -type f`; do
|
||||
local message="$(mu view $f | grep -B 10 Date)"
|
||||
test -n "$message" && sauron_msg "Gmail" "$message"
|
||||
for f in $(find "$MAILDIR/INBOX" -cnewer "$SYNC_STAMP" -a -type f); do
|
||||
mu4e_alert_for_filename $f
|
||||
done
|
||||
mv "${SYNC_STAMP}.in-progress" $SYNC_STAMP
|
||||
}
|
||||
|
||||
function mu4e_get_msg_id_from_file {
|
||||
mu view $1 -o sexp | grep "message-id" | get_cols ' -1'
|
||||
}
|
||||
|
||||
function mu4e_view_message_from_file {
|
||||
mu4e_view_message "$(mu4e_get_msg_id_from_file $1)"
|
||||
}
|
||||
|
||||
function mu4e_view_message {
|
||||
local elisp="(mu4e-view-message-with-msgid "$1")"
|
||||
execute_elisp "$elisp"
|
||||
}
|
||||
|
BIN
resources/gmail_logo.png
Normal file
BIN
resources/gmail_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
Loading…
Reference in New Issue
Block a user