Display images from gpg signatures
authorAdam Sjøgren <asjo@koldfront.dk>
Tue, 25 Dec 2012 22:49:35 +0000 (23:49 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 25 Dec 2012 22:49:35 +0000 (23:49 +0100)
* epg.el (epg-signature-to-string): Use new functions
epg-key-image, epg-key-image-to-string to find and display image
from key.

lisp/ChangeLog
lisp/epg.el

index 2181a6d..73379a9 100644 (file)
@@ -1,3 +1,9 @@
+2012-12-25  Adam Sjøgren  <asjo@koldfront.dk>
+
+       * epg.el (epg-signature-to-string): Use new functions
+       epg-key-image, epg-key-image-to-string to find and display image
+       from key.
+
 2012-12-24  Constantin Kulikov <zxnotdead@gmail.com>  (tiny change)
 
        * startup.el (initial-buffer-choice): Allow function as value
index 833a68d..b79c5df 100644 (file)
@@ -967,11 +967,34 @@ This function is for internal use only."
        (setcdr entry value)
       (epg-context-set-result context (cons (cons name value) result)))))
 
+(defun epg-key-image (key-id)
+  "Return the image of a key, if any"
+  (let ((filename
+        (replace-regexp-in-string
+         "\n" ""
+         (shell-command-to-string
+          (concat "/usr/bin/gpg --photo-viewer 'echo %I >&2' --list-keys "
+                  key-id " > /dev/null")))))
+    (when (and (not (string-equal filename ""))
+              (file-exists-p filename))
+      (create-image filename))))
+
+(defun epg-key-image-to-string (key-id)
+  "Return a string with the image of a key, if any"
+  (let* ((result "")
+         (key-image (epg-key-image key-id)))
+    (when key-image
+      (setq result "  ")
+      (put-text-property 1 2 'display key-image result))
+    result))
+
 (defun epg-signature-to-string (signature)
   "Convert SIGNATURE to a human readable string."
   (let* ((user-id (cdr (assoc (epg-signature-key-id signature)
                              epg-user-id-alist)))
-        (pubkey-algorithm (epg-signature-pubkey-algorithm signature)))
+        (pubkey-algorithm (epg-signature-pubkey-algorithm signature))
+        (key-id (epg-signature-key-id signature))
+        (key-image (epg-key-image-to-string key-id)))
     (concat
      (cond ((eq (epg-signature-status signature) 'good)
            "Good signature from ")
@@ -985,7 +1008,8 @@ This function is for internal use only."
            "Signature made by revoked key ")
           ((eq (epg-signature-status signature) 'no-pubkey)
            "No public key for "))
-     (epg-signature-key-id signature)
+     key-id
+     key-image
      (if user-id
         (concat " "
                 (if (stringp user-id)