From 68280cc53bcef81ea684ee01276b091b93eb8a71 Mon Sep 17 00:00:00 2001
From: jao <jao@gnu.org>
Date: Thu, 4 Aug 2022 18:16:10 +0100
Subject: better consult-recoll open functions

---
 custom/jao-custom-gnus.el |  2 +-
 init.el                   | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/custom/jao-custom-gnus.el b/custom/jao-custom-gnus.el
index ddc2606..cf50ed3 100644
--- a/custom/jao-custom-gnus.el
+++ b/custom/jao-custom-gnus.el
@@ -421,7 +421,7 @@
   (with-temp-buffer
     (insert-file filename)
     (goto-char (point-min))
-    (when (re-search-forward "[Mm]essage-[Ii][Dd]: <?\\([^><]+\\)>?" nil t)
+    (when (re-search-forward "^[Mm]essage-[Ii][Dd]: <?\\([^><]+\\)>?" nil t)
       (match-string 1))))
 
 (defun jao-gnus-goto-file (filename &optional _page)
diff --git a/init.el b/init.el
index b1771a4..604ef71 100644
--- a/init.el
+++ b/init.el
@@ -961,8 +961,18 @@
             (propertize mtype 'face 'jao-themes-f01))))
 
 (defun jao-recoll-open-html (file &optional page)
-  (jao-afio--goto-www)
-  (eww-open-file file))
+  (if (string-match-p "\.epub\\'" file)
+      (find-file file)
+    (jao-afio--goto-www)
+    (eww-open-file file)))
+
+(defun jao-recoll-open-pdf (file &optional page)
+  (if (string-match-p "/gnus/Mail/" file)
+      (funcall (or (cdr (assoc-string "message/rfc822" consult-recoll-open-fns))
+                   'find-file)
+               file
+               page)
+    (jao-open-doc file page)))
 
 (defun jao-recoll-consult-messages ()
   (interactive)
@@ -979,7 +989,7 @@
 
 (use-package consult-recoll
   :init (setq consult-recoll-open-fns
-              '(("application/pdf" . jao-open-doc)
+              '(("application/pdf" . jao-recoll-open-pdf)
                 ("text/html" . jao-recoll-open-html))
               consult-recoll-search-flags nil
               consult-recoll-inline-snippets t
-- 
cgit v1.2.3