From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ricardo Wurmus Newsgroups: gmane.emacs.devel Subject: [PATCH] [debbugs] Add mu4e support. Date: Sun, 23 Apr 2017 12:05:17 +0200 Message-ID: <87y3ursale.fsf@elephly.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1492941974 25137 195.159.176.226 (23 Apr 2017 10:06:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Apr 2017 10:06:14 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 25.1.1 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 23 12:06:10 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d2EPA-0006PH-6N for ged-emacs-devel@m.gmane.org; Sun, 23 Apr 2017 12:06:08 +0200 Original-Received: from localhost ([::1]:38559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2EPF-0002DU-Ub for ged-emacs-devel@m.gmane.org; Sun, 23 Apr 2017 06:06:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2EOa-0002Cy-RS for emacs-devel@gnu.org; Sun, 23 Apr 2017 06:05:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2EOX-0000iN-MM for emacs-devel@gnu.org; Sun, 23 Apr 2017 06:05:32 -0400 Original-Received: from sender-of-o51.zoho.com ([135.84.80.216]:21107) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d2EOX-0000ei-Da for emacs-devel@gnu.org; Sun, 23 Apr 2017 06:05:29 -0400 Original-Received: from localhost (x4d0c8edb.dyn.telefonica.de [77.12.142.219]) by mx.zohomail.com with SMTPS id 1492941924118130.68033027064246; Sun, 23 Apr 2017 03:05:24 -0700 (PDT) X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC X-Zoho-Virus-Status: 1 X-ZohoMailClient: External X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 135.84.80.216 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214235 Archived-At: --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, this patch is for the debbugs.el EPLA package. It adds the mail client =E2=80=9Cmu4e=E2=80=9D as a debbugs-gnu mail backend. When =E2=80=9Cdebbugs-gnu-mail-backend=E2=80=9D is set to =E2=80=9C'mu4e=E2= =80=9D, visiting a bug will download the bug=E2=80=99s mbox file, turn it into a separate Maildir tree = under =E2=80=9Cmu4e-maildir=E2=80=9D called =E2=80=9Cemacs-debbugs.1234=E2=80=9D = where =E2=80=9C1234=E2=80=9D is the bug id, runs =E2=80=9Cmu index=E2=80=9D (synchronously) to update the mail database= , and then shows the emails as usual with mu4e. I=E2=80=99ve been using this patch for a while with satisfactory results. =2D- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEvKaJtjZVOAHDxiFQGXpYiCNfrKwFAlj8fF0ACgkQGXpYiCNf rKzTGAf+MHlQhL5bmiuTWoSvGanvmc4Jcc5ZUxFG+gZ3KMRKZ3dxMLULkVifNGvX TgLaGPILmTeEPDJHz8wg3t/RdP3/otCMa6wekiAxzofZFZhCkHd4TuDhXSaseMaA r0mrZDsKeBs2rz/n9AgYHG673/Vj9y9MwE7WvDsu8IgElxpURKpd/dbYvlybMoHk Je4zxv6b8pSvWJqsJOiF5VgteDzzWqGtNTp3i0JGP+D9APZZyLyr+I7+08L8TSuw mLjlJDXCS7M2Svku3ObFn5diJX+Emc2x2bTk26UYJQVueNs7T4xUVCcwgw/TvR8S SBfbpoUI3DX1ml2rLGMFysaS/seKeg== =Mos2 -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-debbugs-Add-mu4e-support.patch >From c841c4ad0b77aad0b06a31915d46a7cefafc2058 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus 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 --=-=-=--