diff options
author | Basil L. Contovounesios <contovob@tcd.ie> | 2017-01-04 19:29:55 +0000 |
---|---|---|
committer | Basil L. Contovounesios <contovob@tcd.ie> | 2017-01-04 19:29:55 +0000 |
commit | 02b990c134eef159ff051e7297a232fe0cff8ec4 (patch) | |
tree | a0b9e7e211356c2a06ae73ec79656b0d1a535da6 | |
parent | c363af85f341cc878d6c0be53fd32efa8ca9423b (diff) |
Refactor notify-send invocation and shell quoting
* Replace carriage returns with newline characters in multi-line
notifications.
D-Bus (via the notifications library) throws an error on input
containing carriage returns, and notify-send seems to silently
ignore anything past them.
* Split the notify-send executable and its switches into separate
configuration variables.
* Concatenate the executable and all its arguments before passing
them to call-process-shell-command, as per the function's
preferred calling convention.
-rw-r--r-- | gnus-desktop-notify.el | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/gnus-desktop-notify.el b/gnus-desktop-notify.el index b9668c1..1179d21 100644 --- a/gnus-desktop-notify.el +++ b/gnus-desktop-notify.el @@ -144,12 +144,17 @@ function. Each argument will be formatted according to `gnus-desktop-notify-format'" :type 'file) -(defcustom gnus-desktop-notify-send-program - "notify-send -i /usr/share/icons/gnome/32x32/actions/mail_new.png" - "Path and default arguments to the 'notify-send' program (part -of libnotify's utilities)." +(defcustom gnus-desktop-notify-send-program "notify-send" + "Path to the `notify-send' executable. +This is usually bundled as part of libnotify's utilities." :type 'file) +(defcustom gnus-desktop-notify-send-switches + '("-i" "/usr/share/icons/gnome/32x32/actions/mail_new.png") + "List of strings to pass as extra options to `notify-send'. +See `gnus-desktop-notify-send-program'." + :type '(repeat (string :tag "Argument"))) + (defcustom gnus-desktop-notify-behavior 'gnus-desktop-notify-multi "Desktop notification behavior. Can be either: @@ -235,18 +240,26 @@ with each argument being a group formatted according to (mapconcat 'shell-quote-argument groups " ")))))) (defun gnus-desktop-notify-send (groups) - "Call 'notify-send' (as defined by `gnus-desktop-notify-send-program'), -with the behavior defined by `gnus-desktop-notify-behavior'." - (let ((groups (mapcar 'gnus-desktop-notify-arg groups)) - (subject (shell-quote-argument gnus-desktop-notify-send-subject))) - (case gnus-desktop-notify-behavior - ('gnus-desktop-notify-single - (dolist (g groups) - (call-process-shell-command gnus-desktop-notify-send-program nil 0 nil "--" - subject (shell-quote-argument g)))) - ('gnus-desktop-notify-multi - (call-process-shell-command gnus-desktop-notify-send-program nil 0 nil "--" - subject (mapconcat 'shell-quote-argument groups "\C-m")))))) + "Invoke the configured `notify-send' program. +See `gnus-desktop-notify-send-program', +`gnus-desktop-notify-send-switches' and +`gnus-desktop-notify-behavior' for configuration options." + (let ((args `(,gnus-desktop-notify-send-program + ,@gnus-desktop-notify-send-switches + "--" + ,gnus-desktop-notify-send-subject)) + (groups (mapcar #'gnus-desktop-notify-arg groups))) + ;; Iterate over the groups either individually or as a whole + (dolist (group (case gnus-desktop-notify-behavior + (gnus-desktop-notify-single groups) + (gnus-desktop-notify-multi `(,groups)))) + ;; Join the groups when viewing as a whole + (let* ((lines (if (listp group) group `(,group))) + (body (mapconcat #'identity lines "\n"))) + ;; Actually perform the work + (call-process-shell-command + (mapconcat #'shell-quote-argument `(,@args ,body) " ") + nil 0 nil))))) (defun gnus-desktop-notify-dbus (groups) "Generate a notification directly using `notifications' with @@ -258,7 +271,7 @@ the behavior defined by `gnus-desktop-notify-behavior'." (notifications-notify :title gnus-desktop-notify-send-subject :body g))) ('gnus-desktop-notify-multi (notifications-notify :title gnus-desktop-notify-send-subject - :body (mapconcat 'identity groups "\C-m")))))) + :body (mapconcat 'identity groups "\n")))))) (defun gnus-desktop-notify-alert (groups) "Generate a notification directly using `alert' with |