mu4e_update_mail for mac osx using terminal-notifier

This commit is contained in:
Ivan Malison 2014-12-19 15:23:10 -08:00
parent b70181b71e
commit 17babb027e
3 changed files with 41 additions and 22 deletions

View File

@ -60,6 +60,10 @@ function emacs_make_frame_if_none_exists {
focus_emacs focus_emacs
} }
function execute_elisp {
emacs_get_running_instances | xargs -I svr-filename emacsclient --server-file=svr-filename -e "$1"
}
function focus_emacs { function focus_emacs {
is_osx && osascript -e 'tell application "Emacs" to activate' is_osx && osascript -e 'tell application "Emacs" to activate'
} }

View File

@ -1,32 +1,47 @@
MAILDIR="$HOME/Mail" MAILDIR="$HOME/Mail"
DBUS_COOKIE="$HOME/.sauron-dbus"
SYNC_STAMP="$HOME/.mail-sync" SYNC_STAMP="$HOME/.mail-sync"
function sauron_msg { function mu4e_alert_for_filename {
if test -z "$DBUS_SESSION_BUS_ADDRESS"; then local message="$(mu view $1 | grep -B 10 Date)"
echo "DBUS session not found." local title="$(echo $message | grep From | sed 's/From: //')"
if test -e $DBUS_COOKIE; then local subject="$(echo $message | grep Subject | sed 's/Subject: //')"
export DBUS_SESSION_BUS_ADDRESS="`cat $DBUS_COOKIE`" local view_file_command="$(which zsh) -c \"refresh_config && mu4e_view_message_from_file $1\""
else reattach-to-user-namespace $(which terminal-notifier) \
echo "DBUS cookie not found, unable to send message" -title "$title" \
fi -message "$subject" \
fi -execute "$view_file_command" \
if test -n "$DBUS_SESSION_BUS_ADDRESS"; then -activate "org.gnu.Emacs" \
dbus-send --session \ -appIcon "$(dotfiles_directory)/resources/gmail_logo.png"
--dest="org.gnu.Emacs" \
--type=method_call \
"/org/gnu/Emacs/Sauron" \
"org.gnu.Emacs.Sauron.AddMsgEvent" \
string:"$1" uint32:3 string:"$2"
fi
} }
function update_mail { function mu4e_update_mail {
offlineimap 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" touch "${SYNC_STAMP}.in-progress"
for f in `find "$MAILDIR" -cnewer $SYNC_STAMP -a -type f`; do for f in $(find "$MAILDIR/INBOX" -cnewer "$SYNC_STAMP" -a -type f); do
local message="$(mu view $f | grep -B 10 Date)" mu4e_alert_for_filename $f
test -n "$message" && sauron_msg "Gmail" "$message"
done done
mv "${SYNC_STAMP}.in-progress" $SYNC_STAMP 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB