diff options
| author | Philip K | 2020-03-17 15:29:53 +0100 |
|---|---|---|
| committer | Robert Pluim | 2020-03-24 17:56:01 +0100 |
| commit | 421eeff243af683bf0b7c6d9181650a1c6900f9b (patch) | |
| tree | ef5104ffe5ce488039a724fab0d0648761d100a1 /lisp | |
| parent | 82f8bee734b47e639a931048f9a6ccbfc85a8bb0 (diff) | |
| download | emacs-421eeff243af683bf0b7c6d9181650a1c6900f9b.tar.gz emacs-421eeff243af683bf0b7c6d9181650a1c6900f9b.zip | |
Add support for multiple Gravatar services
Now supports Libravatar and Unicornify, next to Gravatar (Bug#39965).
* lisp/image/gravatar.el (gravatar-base-url): Remove constant.
(gravatar-service-alist): List supported services.
(gravatar-service): Add user option to specify service, defaults to
Libravatar.
(gravatar--service-libravatar): New function, libravatar image host
resolver implementation.
(gravatar-build-url): Use alist gravatar-service-alist instead of
gravatar-base-url.
* etc/NEWS: Mention new gravatar service option.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/image/gravatar.el | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el index b8542bc3c35..e13f0075f3c 100644 --- a/lisp/image/gravatar.el +++ b/lisp/image/gravatar.el | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | 26 | ||
| 27 | (require 'url) | 27 | (require 'url) |
| 28 | (require 'url-cache) | 28 | (require 'url-cache) |
| 29 | (require 'dns) | ||
| 29 | (eval-when-compile | 30 | (eval-when-compile |
| 30 | (require 'subr-x)) | 31 | (require 'subr-x)) |
| 31 | 32 | ||
| @@ -118,9 +119,42 @@ a gravatar for a given email address." | |||
| 118 | :version "27.1" | 119 | :version "27.1" |
| 119 | :group 'gravatar) | 120 | :group 'gravatar) |
| 120 | 121 | ||
| 121 | (defconst gravatar-base-url | 122 | (defconst gravatar-service-alist |
| 122 | "https://www.gravatar.com/avatar" | 123 | `((gravatar . ,(lambda (_addr) "https://www.gravatar.com/avatar")) |
| 123 | "Base URL for getting gravatars.") | 124 | (unicornify . ,(lambda (_addr) "https://unicornify.pictures/avatar/")) |
| 125 | (libravatar . ,#'gravatar--service-libravatar)) | ||
| 126 | "Alist of supported gravatar services.") | ||
| 127 | |||
| 128 | (defcustom gravatar-service 'libravatar | ||
| 129 | "Symbol denoting gravatar-like service to use. | ||
| 130 | Note that certain services might ignore other options, such as | ||
| 131 | `gravatar-default-image' or certain values as with | ||
| 132 | `gravatar-rating'." | ||
| 133 | :type `(choice ,@(mapcar (lambda (s) `(const ,(car s))) | ||
| 134 | gravatar-service-alist)) | ||
| 135 | :version "28.1" | ||
| 136 | :link '(url-link "https://www.libravatar.org/") | ||
| 137 | :link '(url-link "https://unicornify.pictures/") | ||
| 138 | :link '(url-link "https://gravatar.com/") | ||
| 139 | :group 'gravatar) | ||
| 140 | |||
| 141 | (defun gravatar--service-libravatar (addr) | ||
| 142 | "Find domain that hosts avatars for email address ADDR." | ||
| 143 | ;; implements https://wiki.libravatar.org/api/ | ||
| 144 | (save-match-data | ||
| 145 | (unless (string-match ".+@\\(.+\\)" addr) | ||
| 146 | (error "%s is not an email address" addr)) | ||
| 147 | (let ((domain (match-string 1 addr))) | ||
| 148 | (catch 'found | ||
| 149 | (dolist (record '(("_avatars-sec" . "https") | ||
| 150 | ("_avatars" . "http"))) | ||
| 151 | (let* ((query (concat (car record) "._tcp." domain)) | ||
| 152 | (result (dns-query query 'SRV))) | ||
| 153 | (when result | ||
| 154 | (throw 'found (format "%s://%s/avatar" | ||
| 155 | (cdr record) | ||
| 156 | result))))) | ||
| 157 | "https://seccdn.libravatar.org/avatar")))) | ||
| 124 | 158 | ||
| 125 | (defun gravatar-hash (mail-address) | 159 | (defun gravatar-hash (mail-address) |
| 126 | "Return the Gravatar hash for MAIL-ADDRESS." | 160 | "Return the Gravatar hash for MAIL-ADDRESS." |
| @@ -142,7 +176,8 @@ a gravatar for a given email address." | |||
| 142 | "Return the URL of a gravatar for MAIL-ADDRESS." | 176 | "Return the URL of a gravatar for MAIL-ADDRESS." |
| 143 | ;; https://gravatar.com/site/implement/images/ | 177 | ;; https://gravatar.com/site/implement/images/ |
| 144 | (format "%s/%s?%s" | 178 | (format "%s/%s?%s" |
| 145 | gravatar-base-url | 179 | (funcall (alist-get gravatar-service gravatar-service-alist) |
| 180 | mail-address) | ||
| 146 | (gravatar-hash mail-address) | 181 | (gravatar-hash mail-address) |
| 147 | (gravatar--query-string))) | 182 | (gravatar--query-string))) |
| 148 | 183 | ||