discussion and development of piem
 help / color / mirror / code / Atom feed
* [PATCH] Add basic integration for Rmail
@ 2021-05-27 21:30 Kyle Meyer
  2021-05-27 23:23 ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2021-05-27 21:30 UTC (permalink / raw)
  To: piem

Teach piem how to get the associated inbox and message ID for the
current Rmail message.
---

   I'm not an Rmail user, but I've been playing around with it a bit
   while thinking about the lei interface.

 Documentation/piem.texi   |  2 ++
 Makefile                  |  6 ++--
 piem-rmail.el             | 72 +++++++++++++++++++++++++++++++++++++++
 tests/piem-rmail-tests.el | 69 +++++++++++++++++++++++++++++++++++++
 tests/piem-tests.el       |  1 +
 5 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100644 piem-rmail.el
 create mode 100644 tests/piem-rmail-tests.el

diff --git a/Documentation/piem.texi b/Documentation/piem.texi
index f4bbabc..c3208a7 100644
--- a/Documentation/piem.texi
+++ b/Documentation/piem.texi
@@ -172,6 +172,7 @@ Enabling integration libraries
 @findex piem-eww-mode
 @findex piem-gnus-mode
 @findex piem-notmuch-mode
+@findex piem-rmail-mode
 
 With inboxes defined, the next step is to enable minor modes that teach
 particular Emacs modes to link a buffer with a registered inbox.  piem
@@ -182,6 +183,7 @@ Enabling integration libraries
 @item Elfeed
 @item Gnus
 @item Notmuch
+@item Rmail
 @end itemize
 
 For example, if you use notmuch.el to read your mail, you can add
diff --git a/Makefile b/Makefile
index 5c65ed9..4d88b34 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ EMACS   = emacs
 BATCH   = $(EMACS) --batch -Q -L . -L tests
 
 EL = piem.el piem-b4.el piem-elfeed.el piem-eww.el piem-gnus.el \
-     piem-maildir.el piem-notmuch.el \
-     tests/piem-tests.el
+     piem-maildir.el piem-notmuch.el piem-rmail.el \
+     tests/piem-rmail-tests.el tests/piem-tests.el
 ELC = $(EL:.el=.elc)
 
 all: compile Documentation/piem.info piem-autoloads.el
@@ -37,7 +37,9 @@ piem-eww.elc: piem-eww.el piem.elc
 piem-gnus.elc: piem-gnus.el piem.elc
 piem-maildir.elc: piem-maildir.el
 piem-notmuch.elc: piem-notmuch.el piem.elc
+piem-rmail.elc: piem-rmail.el piem.elc
 piem.elc: piem.el piem-maildir.elc
+tests/piem-rmail-tests.elc: tests/piem-rmail-tests.el piem-rmail.elc
 tests/piem-tests.elc: tests/piem-tests.el piem.elc
 
 .SUFFIXES: .el .elc .texi .info .html
diff --git a/piem-rmail.el b/piem-rmail.el
new file mode 100644
index 0000000..ccb9432
--- /dev/null
+++ b/piem-rmail.el
@@ -0,0 +1,72 @@
+;;; piem-rmail.el --- Rmail integration for piem  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020-2021  all contributors <piem@inbox.kyleam.com>
+
+;; Author: Kyle Meyer <kyle@kyleam.com>
+;; Keywords: vc, tools
+;; Package-Requires: ((emacs "26.3"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides a minor mode, `piem-rmail-mode', that
+;; modifies `piem' variables to teach functions like `piem-inbox' how
+;; to extract information from Rmail mode buffers.
+
+;;; Code:
+
+(require 'piem)
+(require 'rmail)
+
+(defgroup piem-rmail nil
+  "Rmail integration for piem."
+  :group 'piem)
+
+(defun piem-rmail--call-with-message (fn)
+  (when (derived-mode-p 'rmail-mode 'rmail-summary-mode)
+    (rmail-apply-in-message
+     rmail-current-message
+     (lambda ()
+       (search-forward "\n\n" nil 'move)
+       (narrow-to-region (point-min) (point))
+       (funcall fn)))))
+
+(defun piem-rmail-get-inbox ()
+  "Return inbox name from an Rmail buffer."
+  (piem-rmail--call-with-message #'piem-inbox-by-header-match))
+
+(defun piem-rmail-get-mid ()
+  "Return the message ID of an Rmail buffer."
+  (when-let ((mid (piem-rmail--call-with-message
+                   (lambda () (mail-fetch-field "message-id")))))
+    (replace-regexp-in-string "\\`<\\(.*\\)>\\'" "\\1" mid)))
+
+;;;###autoload
+(define-minor-mode piem-rmail-mode
+  "Toggle Rmail support for piem.
+With a prefix argument ARG, enable piem-rmail mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil."
+  :global t
+  :init-value nil
+  (if piem-rmail-mode
+      (progn
+        (add-hook 'piem-get-inbox-functions #'piem-rmail-get-inbox)
+        (add-hook 'piem-get-mid-functions #'piem-rmail-get-mid))
+    (remove-hook 'piem-get-inbox-functions #'piem-rmail-get-inbox)
+    (remove-hook 'piem-get-mid-functions #'piem-rmail-get-mid)))
+
+;;; piem-rmail.el ends here
+(provide 'piem-rmail)
diff --git a/tests/piem-rmail-tests.el b/tests/piem-rmail-tests.el
new file mode 100644
index 0000000..f2340d3
--- /dev/null
+++ b/tests/piem-rmail-tests.el
@@ -0,0 +1,69 @@
+;;; piem-rmail-tests.el --- tests for piem-rmail  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021  all contributors <piem@inbox.kyleam.com>
+
+;; Author: Kyle Meyer <kyle@kyleam.com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'piem-rmail)
+
+(ert-deftest piem-rmail-get-inbox ()
+  (let ((piem-inboxes '(("foo" :address "i@inbox.example.com")))
+        (mbox-text "\
+From mboxrd@z Thu Jan  1 00:00:00 1970
+From: A <a@example.com>
+To: i@inbox.example.com
+Subject: test
+Date: Sun, 23 May 2021 02:26:01 -0400
+Message-ID: <123@example.com>
+
+test body
+
+From mboxrd@z Thu Jan  1 00:00:00 1970
+From: b <b@example.com>
+To: A <a@example.com>
+Cc: i@inbox.example.com
+Subject: Re: test
+Date: Sun, 23 May 2021 02:26:51 -0400
+Message-Id: <456@example.com>
+In-Reply-To: <123@example.com>
+References: <123@example.com>
+
+> test body
+
+no thanks
+"))
+    (should
+     (equal "foo"
+            (with-temp-buffer
+              (insert mbox-text)
+              (rmail-mode)
+              (piem-rmail-get-inbox))))
+    (should
+     (equal (list "123@example.com" "456@example.com")
+            (with-temp-buffer
+              (insert mbox-text)
+              (rmail-mode)
+              (rmail-first-message)
+              (list (piem-rmail-get-mid)
+                    (progn
+                      (rmail-next-message 1)
+                      (piem-rmail-get-mid))))))))
+
+(provide 'piem-rmail-tests)
+;;; piem-rmail-tests.el ends here
diff --git a/tests/piem-tests.el b/tests/piem-tests.el
index 969c9d0..5f01a5e 100644
--- a/tests/piem-tests.el
+++ b/tests/piem-tests.el
@@ -21,6 +21,7 @@
 
 (require 'ert)
 (require 'piem)
+(require 'piem-rmail-tests)
 
 (ert-deftest piem-message-link-re ()
   (should-not (string-match-p

base-commit: c99e806fd307ef69adc0d3a277385687edfd3454
-- 
2.31.1


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

* Re: [PATCH] Add basic integration for Rmail
  2021-05-27 21:30 [PATCH] Add basic integration for Rmail Kyle Meyer
@ 2021-05-27 23:23 ` Kyle Meyer
  2021-05-27 23:27   ` [PATCH v2] " Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2021-05-27 23:23 UTC (permalink / raw)
  To: piem

Kyle Meyer writes:

> diff --git a/tests/piem-rmail-tests.el b/tests/piem-rmail-tests.el
[...]
> +
> +(ert-deftest piem-rmail-get-inbox ()

Hmm, as the name indicates, I originally meant for this test to cover
just piem-rmail-get-inbox...

> +  (let ((piem-inboxes '(("foo" :address "i@inbox.example.com")))
> +        (mbox-text "\
> +From mboxrd@z Thu Jan  1 00:00:00 1970
[...]
> +"))
> +    (should
> +     (equal "foo"
> +            (with-temp-buffer
> +              (insert mbox-text)
> +              (rmail-mode)
> +              (piem-rmail-get-inbox))))
> +    (should
> +     (equal (list "123@example.com" "456@example.com")
> +            (with-temp-buffer
> +              (insert mbox-text)
> +              (rmail-mode)
> +              (rmail-first-message)
> +              (list (piem-rmail-get-mid)
> +                    (progn
> +                      (rmail-next-message 1)
> +                      (piem-rmail-get-mid))))))))

... but then I ended up testing piem-rmail-get-mid in the same test.
I'll move the piem-rmail-get-mid bits into a dedicated test.

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

* [PATCH v2] Add basic integration for Rmail
  2021-05-27 23:23 ` Kyle Meyer
@ 2021-05-27 23:27   ` Kyle Meyer
  2021-05-28  2:31     ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2021-05-27 23:27 UTC (permalink / raw)
  To: piem

Teach piem how to get the associated inbox and message ID for the
current Rmail message.
---

   Changes in v2: Split test into dedicated tests for
   piem-rmail-get-inbox and piem-rmail-get-mid.

 Documentation/piem.texi   |  2 ++
 Makefile                  |  6 ++--
 piem-rmail.el             | 72 ++++++++++++++++++++++++++++++++++++++
 tests/piem-rmail-tests.el | 73 +++++++++++++++++++++++++++++++++++++++
 tests/piem-tests.el       |  1 +
 5 files changed, 152 insertions(+), 2 deletions(-)
 create mode 100644 piem-rmail.el
 create mode 100644 tests/piem-rmail-tests.el

diff --git a/Documentation/piem.texi b/Documentation/piem.texi
index f4bbabc..c3208a7 100644
--- a/Documentation/piem.texi
+++ b/Documentation/piem.texi
@@ -172,6 +172,7 @@ Enabling integration libraries
 @findex piem-eww-mode
 @findex piem-gnus-mode
 @findex piem-notmuch-mode
+@findex piem-rmail-mode
 
 With inboxes defined, the next step is to enable minor modes that teach
 particular Emacs modes to link a buffer with a registered inbox.  piem
@@ -182,6 +183,7 @@ Enabling integration libraries
 @item Elfeed
 @item Gnus
 @item Notmuch
+@item Rmail
 @end itemize
 
 For example, if you use notmuch.el to read your mail, you can add
diff --git a/Makefile b/Makefile
index 5c65ed9..4d88b34 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ EMACS   = emacs
 BATCH   = $(EMACS) --batch -Q -L . -L tests
 
 EL = piem.el piem-b4.el piem-elfeed.el piem-eww.el piem-gnus.el \
-     piem-maildir.el piem-notmuch.el \
-     tests/piem-tests.el
+     piem-maildir.el piem-notmuch.el piem-rmail.el \
+     tests/piem-rmail-tests.el tests/piem-tests.el
 ELC = $(EL:.el=.elc)
 
 all: compile Documentation/piem.info piem-autoloads.el
@@ -37,7 +37,9 @@ piem-eww.elc: piem-eww.el piem.elc
 piem-gnus.elc: piem-gnus.el piem.elc
 piem-maildir.elc: piem-maildir.el
 piem-notmuch.elc: piem-notmuch.el piem.elc
+piem-rmail.elc: piem-rmail.el piem.elc
 piem.elc: piem.el piem-maildir.elc
+tests/piem-rmail-tests.elc: tests/piem-rmail-tests.el piem-rmail.elc
 tests/piem-tests.elc: tests/piem-tests.el piem.elc
 
 .SUFFIXES: .el .elc .texi .info .html
diff --git a/piem-rmail.el b/piem-rmail.el
new file mode 100644
index 0000000..ccb9432
--- /dev/null
+++ b/piem-rmail.el
@@ -0,0 +1,72 @@
+;;; piem-rmail.el --- Rmail integration for piem  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020-2021  all contributors <piem@inbox.kyleam.com>
+
+;; Author: Kyle Meyer <kyle@kyleam.com>
+;; Keywords: vc, tools
+;; Package-Requires: ((emacs "26.3"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides a minor mode, `piem-rmail-mode', that
+;; modifies `piem' variables to teach functions like `piem-inbox' how
+;; to extract information from Rmail mode buffers.
+
+;;; Code:
+
+(require 'piem)
+(require 'rmail)
+
+(defgroup piem-rmail nil
+  "Rmail integration for piem."
+  :group 'piem)
+
+(defun piem-rmail--call-with-message (fn)
+  (when (derived-mode-p 'rmail-mode 'rmail-summary-mode)
+    (rmail-apply-in-message
+     rmail-current-message
+     (lambda ()
+       (search-forward "\n\n" nil 'move)
+       (narrow-to-region (point-min) (point))
+       (funcall fn)))))
+
+(defun piem-rmail-get-inbox ()
+  "Return inbox name from an Rmail buffer."
+  (piem-rmail--call-with-message #'piem-inbox-by-header-match))
+
+(defun piem-rmail-get-mid ()
+  "Return the message ID of an Rmail buffer."
+  (when-let ((mid (piem-rmail--call-with-message
+                   (lambda () (mail-fetch-field "message-id")))))
+    (replace-regexp-in-string "\\`<\\(.*\\)>\\'" "\\1" mid)))
+
+;;;###autoload
+(define-minor-mode piem-rmail-mode
+  "Toggle Rmail support for piem.
+With a prefix argument ARG, enable piem-rmail mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil."
+  :global t
+  :init-value nil
+  (if piem-rmail-mode
+      (progn
+        (add-hook 'piem-get-inbox-functions #'piem-rmail-get-inbox)
+        (add-hook 'piem-get-mid-functions #'piem-rmail-get-mid))
+    (remove-hook 'piem-get-inbox-functions #'piem-rmail-get-inbox)
+    (remove-hook 'piem-get-mid-functions #'piem-rmail-get-mid)))
+
+;;; piem-rmail.el ends here
+(provide 'piem-rmail)
diff --git a/tests/piem-rmail-tests.el b/tests/piem-rmail-tests.el
new file mode 100644
index 0000000..b489594
--- /dev/null
+++ b/tests/piem-rmail-tests.el
@@ -0,0 +1,73 @@
+;;; piem-rmail-tests.el --- tests for piem-rmail  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021  all contributors <piem@inbox.kyleam.com>
+
+;; Author: Kyle Meyer <kyle@kyleam.com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'piem-rmail)
+
+(defvar piem-rmail-tests-mbox-text "\
+From mboxrd@z Thu Jan  1 00:00:00 1970
+From: A <a@example.com>
+To: i@inbox.example.com
+Subject: test
+Date: Sun, 23 May 2021 02:26:01 -0400
+Message-ID: <123@example.com>
+
+test body
+
+From mboxrd@z Thu Jan  1 00:00:00 1970
+From: b <b@example.com>
+To: A <a@example.com>
+Cc: i@inbox.example.com
+Subject: Re: test
+Date: Sun, 23 May 2021 02:26:51 -0400
+Message-Id: <456@example.com>
+In-Reply-To: <123@example.com>
+References: <123@example.com>
+
+> test body
+
+no thanks
+")
+
+(ert-deftest piem-rmail-get-inbox ()
+  (should
+   (equal "foo"
+          (with-temp-buffer
+            (insert piem-rmail-tests-mbox-text)
+            (rmail-mode)
+            (let ((piem-inboxes '(("foo" :address "i@inbox.example.com"))))
+              (piem-rmail-get-inbox))))))
+
+(ert-deftest piem-rmail-get-mid ()
+  (should
+   (equal (list "123@example.com" "456@example.com")
+          (with-temp-buffer
+            (insert piem-rmail-tests-mbox-text)
+            (rmail-mode)
+            (rmail-first-message)
+            (let ((piem-inboxes '(("foo" :address "i@inbox.example.com"))))
+              (list (piem-rmail-get-mid)
+                    (progn
+                      (rmail-next-message 1)
+                      (piem-rmail-get-mid))))))))
+
+(provide 'piem-rmail-tests)
+;;; piem-rmail-tests.el ends here
diff --git a/tests/piem-tests.el b/tests/piem-tests.el
index 969c9d0..5f01a5e 100644
--- a/tests/piem-tests.el
+++ b/tests/piem-tests.el
@@ -21,6 +21,7 @@
 
 (require 'ert)
 (require 'piem)
+(require 'piem-rmail-tests)
 
 (ert-deftest piem-message-link-re ()
   (should-not (string-match-p

base-commit: c99e806fd307ef69adc0d3a277385687edfd3454
-- 
2.31.1


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

* Re: [PATCH v2] Add basic integration for Rmail
  2021-05-27 23:27   ` [PATCH v2] " Kyle Meyer
@ 2021-05-28  2:31     ` Kyle Meyer
  0 siblings, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2021-05-28  2:31 UTC (permalink / raw)
  To: piem

Kyle Meyer writes:

> diff --git a/piem-rmail.el b/piem-rmail.el
> new file mode 100644
> index 0000000..ccb9432
> --- /dev/null
> +++ b/piem-rmail.el
> @@ -0,0 +1,72 @@
> +;;; piem-rmail.el --- Rmail integration for piem  -*- lexical-binding: t; -*-
> +
> +;; Copyright (C) 2020-2021  all contributors <piem@inbox.kyleam.com>

Will s/2020-// on apply.

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

end of thread, other threads:[~2021-05-28  2:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 21:30 [PATCH] Add basic integration for Rmail Kyle Meyer
2021-05-27 23:23 ` Kyle Meyer
2021-05-27 23:27   ` [PATCH v2] " Kyle Meyer
2021-05-28  2:31     ` Kyle Meyer

Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).