~pkal/public-inbox

Add MUA support for notmuch v1 PROPOSED

Sandra Snan: 5
 Add MUA support for notmuch
 Add MUA support for notmuch
 Grab message id before switching to temp buffer
 Update the declaration
 Fix flickering in mu4e

 9 files changed, 119 insertions(+), 11 deletions(-)
Philip Kaludercic <philipk@posteo.net> writes:
Next
(It seems my first message was not sent out, so I'll try it again.)

Two points I forgot to mention in my last message:

1. I intend to publish autocrypt.el on GNU ELPA, if I am ever to finish
   the implementation (see the README for what is missing).  Have you
   signed the copyright agreement for Emacs?

2. Are you familiar with the previous attempt to add autocrypt.el
   support to Notmuch?

   https://www.mail-archive.com/notmuch@notmuchmail.org/msg50795.html

   If ELPA should turn out to be an issue, I would consider if
   implementing the necessary functions directly in notmuch would be a
   possible alternative.  More on that below.

Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Next
Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Btw, this shouldn't be an issue, you can just have to replace the

     (lambda () (and (derived-mode-p 'notmuch-show-mode) 'notmuch-show))

entry in autocrypt-backends with

     (lambda () (and (derived-mode-p 'notmuch-show-mode) 'notmuch))
Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Next
By "adds a header" I meant a Do-Discouraged-Autocrypt: no" header.



          
          
          
        
      

      
      
      
      

      

      
      
      
      

      
      
        
          






It doesn't correctly set my friend's preference in the autocrypt-peers val 
to mutual even though looking at his headers, that's what he wants.



          
          
          
        
      

      
      
      
      

      
      
        
          






(That explains the recommendation.)
Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Next
Just to clarify, I don't think the issues are related to this particular 
Notmuch commit/patch. It does seem to receive the header correctly, as far 
as I can tell.
ping?

Philip Kaludercic <philipk@posteo.net> writes:
Just trying to find a free weekend to work on this ♥



          
          
          
        
      

      
      
      
      

      
      
        
          






Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Next
It stopped working after I put in the "no-flickering" change and today I 
finally had a moment to see why, and patch it. So that was an issue on my 
end, fixed with this patch ♥
Additionally, I've found that autoload, I don't really know how that works 
but I've had to require the stuff in .emacs after all. That's also on my 
end but not sure what autoload annotations to put in, and where.
Third, the other issue, which as far as I can tell (I might be wrong) isn't 
related to this patch or notmuch specific, but what it is is that in autocrypt 
peers, my friend isn't getting recorded as "mutual" even though, when I 
look at their most recent headers, they have that setting on in k9.



          
          
          
        
      

      
      
      
      

      
      
        
          






Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Next
Philip Kaludercic <philipk@posteo.net> writes:
Next
I also wonder what and when the header-processing is gonna get triggered? 
In notmuch, the buffer usually shows several messages (from different senders) 
at once. The peers I have saved currently, I have from evaluating autocrypt-process-header



          
          
          
        
      

      
      
      
      

      
      
        
          






Sandra Snan <sandra.snan@idiomdrottning.org> writes:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~pkal/public-inbox/patches/26879/mbox | git am -3
Learn more about email & git

[PATCH] Add MUA support for notmuch Export this patch

---
 README.md                 |  1 +
 autocrypt-notmuch-show.el | 53 +++++++++++++++++++++++++++++++++++++++
 autocrypt.el              |  1 +
 3 files changed, 55 insertions(+)
 create mode 100644 autocrypt-notmuch-show.el

diff --git a/README.md b/README.md
index ae59f06..35d110e 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Currently, it supports:
- Rmail, as a viewer
- Gnus, as a viewer
- mu4e, as a viewer
- notmuch, as a viewer
- message, as a composer

As of writing, this package doesn't fully implement the autocrypt
diff --git a/autocrypt-notmuch-show.el b/autocrypt-notmuch-show.el
new file mode 100644
index 0000000..ee1e385
--- /dev/null
+++ b/autocrypt-notmuch-show.el
@@ -0,0 +1,53 @@
;;; autocrypt-notmuch-show.el --- Autocrypt for notmuch -*- lexical-binding:t -*-

;; Author: Idiomdrottning <sandra.snan@idiomdrottning.org>
;; Based on autocrypt MUA extensions by Philip Kaludercic

;; This file is NOT part of Emacs.
;;
;; This file is in the public domain, to the extent possible under law,
;; published under the CC0 1.0 Universal license.
;;
;; For a full copy of the CC0 license see
;; https://creativecommons.org/publicdomain/zero/1.0/legalcode

;;; Commentary:

;; MUA specific functions for notmuch-show

;; Setup example:
;; (setup (:package autocrypt)
;;   (:hook-into notmuch-show-mode message-mode))

;; Or, old school:
;; (require 'autocrypt)
;; (require 'autocrypt-message)
;; (add-hook 'message-mode-hook #'autocrypt-mode)
;; (require 'autocrypt-notmuch-show)
;; (add-hook 'notmuch-show-hook #'autocrypt-mode)

;;; Code:

(require 'autocrypt)

(declare-function notmuch-show-view-raw-message "notmuch-show" ())

;;;###autocrypt
(defun autocrypt-notmuch-show--install ()
  "Install autocrypt hooks for notmuch."
  (add-hook 'notmuch-show-hook #'autocrypt-process-header nil t))

(defun autocrypt-notmuch-show--uninstall ()
  "Remove autocrypt hooks for notmuch."
  (remove-hook 'notmuch-show-hook #'autocrypt-process-header t))

(defun autocrypt-notmuch-show--get-header (header)
  "Ask notmuch to return HEADER."
  (save-window-excursion
    (notmuch-show-view-raw-message)
    (prog1 (mail-fetch-field header)
      (kill-buffer (current-buffer)))))

(provide 'autocrypt-notmuch-show)

;;; autocrypt-notmuch.el ends here
diff --git a/autocrypt.el b/autocrypt.el
index 0fe2ba0..bf0a699 100644
--- a/autocrypt.el
+++ b/autocrypt.el
@@ -109,6 +109,7 @@ Every member of this list has to be an instance of the

(defvar autocrypt-backends
  (list (lambda () (and (derived-mode-p 'mu4e-main-mode 'mu4e-view-mode) 'mu4e))
        (lambda () (and (derived-mode-p 'notmuch-show-mode) 'notmuch-show))
        (lambda () (and (derived-mode-p 'gnus-mode) 'gnus))
        (lambda () (and (derived-mode-p 'rmail-mode) 'rmail))
        (lambda () (and (derived-mode-p 'message-mode) 'message))
-- 
2.30.2
Thank you for your patch, I assume everything works as intended? I don't
use notmuch, so I cannot test it right now.

I'll insert my questions inline:

Sandra Snan <sandra.snan@idiomdrottning.org> writes:

[PATCH v2 1/2] Add MUA support for notmuch Export this patch

---
 README.md                 |  1 +
 autocrypt-notmuch-show.el | 48 +++++++++++++++++++++++++++++++++++++++
 autocrypt.el              |  1 +
 3 files changed, 50 insertions(+)
 create mode 100644 autocrypt-notmuch-show.el

diff --git a/README.md b/README.md
index ae59f06..35d110e 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Currently, it supports:
- Rmail, as a viewer
- Gnus, as a viewer
- mu4e, as a viewer
- notmuch, as a viewer
- message, as a composer

As of writing, this package doesn't fully implement the autocrypt
diff --git a/autocrypt-notmuch-show.el b/autocrypt-notmuch-show.el
new file mode 100644
index 0000000..392c922
--- /dev/null
+++ b/autocrypt-notmuch-show.el
@@ -0,0 +1,48 @@
;;; autocrypt-notmuch-show.el --- Autocrypt for notmuch -*- lexical-binding:nil -*-

;; Author: Idiomdrottning <sandra.snan@idiomdrottning.org>
;; Based on autocrypt MUA extensions by Philip Kaludercic

;; This file is NOT part of Emacs.
;;
;; This file is in the public domain, to the extent possible under law,
;; published under the CC0 1.0 Universal license.
;;
;; For a full copy of the CC0 license see
;; https://creativecommons.org/publicdomain/zero/1.0/legalcode

;;; Commentary:

;; MUA specific functions for notmuch-show

;; Setup example:
;; (add-hook 'message-mode-hook #'autocrypt-mode)
;; (add-hook 'notmuch-show-hook #'autocrypt-mode)

;;; Code:

(require 'autocrypt)

(declare-function notmuch-show-view-raw-message "notmuch-show" ())

;;;###autocrypt
(defun autocrypt-notmuch-show--install ()
  "Install autocrypt hooks for notmuch."
  (add-hook 'notmuch-show-hook #'autocrypt-process-header nil t))

(defun autocrypt-notmuch-show--uninstall ()
  "Remove autocrypt hooks for notmuch."
  (remove-hook 'notmuch-show-hook #'autocrypt-process-header t))

(defun autocrypt-notmuch-show--get-header (header)
  "Ask notmuch to return HEADER."
  (with-temp-buffer
    (let ((coding-system-for-read 'no-conversion))
      (call-process notmuch-command
                    nil t nil "show" "--format=raw"
                    (notmuch-show-get-message-id)))
    (mail-fetch-field header)))

(provide 'autocrypt-notmuch-show)

;;; autocrypt-notmuch.el ends here
diff --git a/autocrypt.el b/autocrypt.el
index 0fe2ba0..bf0a699 100644
--- a/autocrypt.el
+++ b/autocrypt.el
@@ -109,6 +109,7 @@ Every member of this list has to be an instance of the

(defvar autocrypt-backends
  (list (lambda () (and (derived-mode-p 'mu4e-main-mode 'mu4e-view-mode) 'mu4e))
        (lambda () (and (derived-mode-p 'notmuch-show-mode) 'notmuch-show))
        (lambda () (and (derived-mode-p 'gnus-mode) 'gnus))
        (lambda () (and (derived-mode-p 'rmail-mode) 'rmail))
        (lambda () (and (derived-mode-p 'message-mode) 'message))
-- 
2.30.2
Sandra Snan <sandra.snan@idiomdrottning.org> writes:

[PATCH] Grab message id before switching to temp buffer Export this patch

---
 autocrypt-notmuch-show.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/autocrypt-notmuch-show.el b/autocrypt-notmuch-show.el
index 392c922..b19f748 100644
--- a/autocrypt-notmuch-show.el
+++ b/autocrypt-notmuch-show.el
@@ -36,12 +36,13 @@

(defun autocrypt-notmuch-show--get-header (header)
  "Ask notmuch to return HEADER."
  (with-temp-buffer
    (let ((coding-system-for-read 'no-conversion))
      (call-process notmuch-command
                    nil t nil "show" "--format=raw"
                    (notmuch-show-get-message-id)))
    (mail-fetch-field header)))
  (let ((message-id (notmuch-show-get-message-id)))
    (with-temp-buffer
      (let ((coding-system-for-read 'no-conversion))
        (call-process notmuch-command
                      nil t nil "show" "--format=raw" "--body=false"
                      message-id))
      (mail-fetch-field header))))

(provide 'autocrypt-notmuch-show)

-- 
2.30.2
It stopped working after I put in the "no-flickering" change and today I 
finally had a moment to see why, and patch it. So that was an issue on my 
end, fixed with this patch ♥

Additionally, I've found that autoload, I don't really know how that works 
but I've had to require the stuff in .emacs after all. That's also on my 
end but not sure what autoload annotations to put in, and where.

Third, the other issue, which as far as I can tell (I might be wrong) isn't 
related to this patch or notmuch specific, but what it is is that in autocrypt 
peers, my friend isn't getting recorded as "mutual" even though, when I 
look at their most recent headers, they have that setting on in k9.

[PATCH] Update the declaration Export this patch

---
 autocrypt-notmuch-show.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/autocrypt-notmuch-show.el b/autocrypt-notmuch-show.el
index b19f748..e36b44b 100644
--- a/autocrypt-notmuch-show.el
+++ b/autocrypt-notmuch-show.el
@@ -23,7 +23,7 @@

(require 'autocrypt)

(declare-function notmuch-show-view-raw-message "notmuch-show" ())
(declare-function notmuch-show-get-message-id "notmuch-show" ())

;;;###autocrypt
(defun autocrypt-notmuch-show--install ()
-- 
2.30.2
I also wonder what and when the header-processing is gonna get triggered? 
In notmuch, the buffer usually shows several messages (from different senders) 
at once. The peers I have saved currently, I have from evaluating autocrypt-process-header

[PATCH v2 2/2] Fix flickering in mu4e Export this patch

---
 autocrypt-mu4e.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/autocrypt-mu4e.el b/autocrypt-mu4e.el
index cfa4e42..4f3546b 100644
--- a/autocrypt-mu4e.el
+++ b/autocrypt-mu4e.el
@@ -35,10 +35,12 @@

(defun autocrypt-mu4e--get-header (header)
  "Ask mu4e to return HEADER."
  (save-window-excursion
    (with-current-buffer (mu4e-view-raw-message)
      (prog1 (mail-fetch-field header)
        (kill-buffer (current-buffer))))))
  (let ((path (mu4e-message-field-at-point :path)))
    (unless (and path (file-readable-p path))
      (mu4e-error "Not a readable file: %S" path))
    (with-temp-buffer
      (insert-file-contents path)
      (mail-fetch-field header))))

(provide 'autocrypt-mu4e)

-- 
2.30.2
By "adds a header" I meant a Do-Discouraged-Autocrypt: no" header.