all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] [debbugs] Add mu4e support.
@ 2017-04-23 10:05 Ricardo Wurmus
  2017-04-23 17:53 ` Marcin Borkowski
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Ricardo Wurmus @ 2017-04-23 10:05 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 648 bytes --]

Hi,

this patch is for the debbugs.el EPLA package.  It adds the mail client
“mu4e” as a debbugs-gnu mail backend.

When “debbugs-gnu-mail-backend” is set to “'mu4e”, visiting a bug will
download the bug’s mbox file, turn it into a separate Maildir tree under
“mu4e-maildir” called “emacs-debbugs.1234” where “1234” is the bug id,
runs “mu index” (synchronously) to update the mail database, and then
shows the emails as usual with mu4e.

I’ve been using this patch for a while with satisfactory results.

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net



[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-debbugs-Add-mu4e-support.patch --]
[-- Type: text/x-patch, Size: 4773 bytes --]

From c841c4ad0b77aad0b06a31915d46a7cefafc2058 Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
Date: Mon, 10 Apr 2017 09:33:51 +0200
Subject: [PATCH] [debbugs] Add mu4e support.

* packages/debbugs/debbugs-gnu.el (debbugs-gnu-mail-backend,
debbugs-gnu-select-report): Handle "mu4e" option.
(debbugs--extract-mbox-to-maildir, debbugs-read-emacs-bug-with-mu4e):
New procedures.
---
 packages/debbugs/debbugs-gnu.el | 65 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 62 insertions(+), 3 deletions(-)

diff --git a/packages/debbugs/debbugs-gnu.el b/packages/debbugs/debbugs-gnu.el
index ebfa738a4..aea0ddd86 100644
--- a/packages/debbugs/debbugs-gnu.el
+++ b/packages/debbugs/debbugs-gnu.el
@@ -170,9 +170,13 @@
 (autoload 'mail-header-subject "nnheader")
 (autoload 'message-goto-body "message")
 (autoload 'message-make-from "message")
+(autoload 'message-fetch-field "message")
+(autoload 'nndoc-mbox-article-begin "nndoc")
+(autoload 'nnmail-write-region "nnmail")
 (autoload 'rmail-get-new-mail "rmail")
 (autoload 'rmail-show-message "rmail")
 (autoload 'rmail-summary "rmailsum")
+(autoload 'mu4e-headers-search "mu4e-headers")
 (autoload 'vc-dir-hide-up-to-date "vc-dir")
 (autoload 'vc-dir-mark "vc-dir")
 
@@ -293,11 +297,12 @@ suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
 
 (defcustom debbugs-gnu-mail-backend 'gnus
   "The email backend to use for reading bug report email exchange.
-If this is `gnus', the default, use Gnus.
-If this is `rmail', use Rmail instead."
+If this is `gnus', the default, use Gnus.  If this is `rmail',
+use Rmail.  If this is `mu4e', use Mu4e instead."
   :group 'debbugs-gnu
   :type '(radio (function-item :tag "Use Gnus" gnus)
-		(function-item :tag "Use Rmail" rmail))
+                (function-item :tag "Use Rmail" rmail)
+                (function-item :tag "Use Mu4e" mu4e))
   :version "25.1")
 
 (defface debbugs-gnu-archived '((t (:inverse-video t)))
@@ -1329,6 +1334,58 @@ MERGED is the list of bugs merged with this one."
     (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
     (rmail-show-message 1)))
 
+(defun debbugs--extract-mbox-to-maildir (bug-str maildir start end)
+  (let* ((msgid (save-restriction
+                  (narrow-to-region start end)
+                  (message-fetch-field "Message-ID")))
+         (file  (concat bug-str "-" (secure-hash 'md5 msgid) ":2,"))
+         (path  (concat maildir "/cur/" file)))
+    (when (not (file-exists-p path))
+      (nnmail-write-region start end path))))
+
+(defun debbugs-read-emacs-bug-with-mu4e (id status merged)
+  "Read email exchange for debbugs bug ID.
+STATUS is the bug's status list.
+MERGED is the list of bugs merged with this one."
+  (let* ((bug-str (number-to-string id))
+         (tmpdir  "/tmp")
+         (mbox    (concat tmpdir "/bug-" bug-str ".mbox"))
+         (subdir  (concat "/emacs-debbugs." bug-str))
+         (maildir (concat mu4e-maildir subdir)))
+    ;; Create temporary maildir structure
+    (dolist (dir '("cur" "new" "tmp"))
+      (make-directory (concat maildir "/" dir) t))
+
+    ;; Download mbox for the given bug
+    (debbugs-get-mbox id 'mboxmaint mbox)
+
+    ;; Split mbox into individual mail files
+    (with-temp-buffer
+      (insert-file-contents mbox)
+      (goto-char (point-min))
+      (setq start (point))
+      (forward-char)
+      (while (nndoc-mbox-article-begin)
+        (setq end (point))
+        (debbugs--extract-mbox-to-maildir bug-str maildir start end)
+        (setq start end)
+        (forward-char))
+      ;; Save last email
+      (debbugs--extract-mbox-to-maildir bug-str maildir start (point-max)))
+
+    ;; Clean up
+    (delete-file mbox)
+
+    ;; We cannot use mu4e-update-index because it runs
+    ;; asynchronously.
+    (call-process-shell-command
+     (concat "mu index -m " mu4e-maildir))
+    (with-current-buffer (window-buffer (selected-window))
+      (let ((msgid (substring (cdr (assq 'msgid status)) 1 -1)))
+        (message msgid)
+        (mu4e-headers-search (concat "maildir:" subdir)
+                             nil nil nil msgid nil)))))
+
 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
   "Read email exchange for debbugs bug ID.
 STATUS is the bug's status list.
@@ -1361,6 +1418,8 @@ MERGED is the list of bugs merged with this one."
       (message "No bug report on the current line"))
      ((eq debbugs-gnu-mail-backend 'rmail)
       (debbugs-read-emacs-bug-with-rmail id status merged))
+     ((eq debbugs-gnu-mail-backend 'mu4e)
+      (debbugs-read-emacs-bug-with-mu4e id status merged))
      ((eq debbugs-gnu-mail-backend 'gnus)
       (debbugs-read-emacs-bug-with-gnus id status merged))
      (t (error "No valid mail backend specified")))))
-- 
2.12.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH] [debbugs] Add mu4e support.
@ 2022-12-24 14:46 Felix
  2022-12-24 15:04 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Felix @ 2022-12-24 14:46 UTC (permalink / raw)
  To: rekado; +Cc: emacs-devel


This Thread is now more than 5 years old.
Is there any plan for finishing this?
Or is this obsolete because of another way to use mu4e
for debbugs that i didn't find?





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-25  9:33 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-23 10:05 [PATCH] [debbugs] Add mu4e support Ricardo Wurmus
2017-04-23 17:53 ` Marcin Borkowski
2017-04-23 18:26 ` Michael Albinus
2017-04-28 13:22 ` Michael Albinus
2017-04-28 14:44   ` Stefan Monnier
2017-05-07 11:45   ` Ricardo Wurmus
2017-05-09 13:19     ` Michael Albinus
  -- strict thread matches above, loose matches on Subject: below --
2022-12-24 14:46 Felix
2022-12-24 15:04 ` Eli Zaretskii
2022-12-24 15:28   ` Felix
2022-12-24 15:47     ` Eli Zaretskii
2022-12-24 15:45       ` Felix
2022-12-24 16:26         ` Eli Zaretskii
2022-12-25  9:33           ` Michael Albinus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.