summaryrefslogtreecommitdiff
path: root/guile
diff options
context:
space:
mode:
authorThiago Jung Bauermann <bauermann@kolabnow.com>2025-01-02 14:01:35 -0300
committerThiago Jung Bauermann <bauermann@kolabnow.com>2025-01-04 20:51:14 -0300
commit606f4be74b1a1f5de74752fdcc7b33872c38b1fb (patch)
tree2b66728c7052b788d3b1e742b2123f75769388ec /guile
parenta703f002143b7167beb4fb10c71a497c8ed5b2f9 (diff)
guile: Fix the mu:body message method
Somewhere along the way, the body-txt and body-html fields were merged into a single body field. Later, commit 8eac3922215c ("guile: re-enable the guile support") finally removed support for Field::Id::BodyHtml from mu:c:get-field. Unfortunately mu.scm and the documentation are still stuck in the past, so update them. mu:body-txt is now a synonym for mu:body, and mu:body-html always returns #f. I wanted to add a mu:body test also for the rfc822.1 message, but there's currently a bug where its body text is is duplicated (issue #2802), so the test would fail.
Diffstat (limited to 'guile')
-rwxr-xr-xguile/examples/org2mu4e2
-rw-r--r--guile/mu-guile.texi3
-rw-r--r--guile/mu.scm19
-rwxr-xr-xguile/tests/test-mu-guile.scm16
4 files changed, 33 insertions, 7 deletions
diff --git a/guile/examples/org2mu4e b/guile/examples/org2mu4e
index 3556b9a..e7f10ad 100755
--- a/guile/examples/org2mu4e
+++ b/guile/examples/org2mu4e
@@ -43,7 +43,7 @@ exec guile -e main -s $0 $@
(org-mu4e-link msg)
(if tag (string-concatenate `(":" ,tag "::")) "")
(or (mu:from msg) "?")
- (let ((body (mu:body-txt msg)))
+ (let ((body (mu:body msg)))
(if (not body) ;; get a 'summary' of the body text
"<no plain-text body>"
(string-map
diff --git a/guile/mu-guile.texi b/guile/mu-guile.texi
index 9eae2fe..a5c24b9 100644
--- a/guile/mu-guile.texi
+++ b/guile/mu-guile.texi
@@ -391,8 +391,7 @@ properties, please refer to the @t{mu-find} man-page.
@itemize
@item @code{(mu:bcc msg)}: the @t{Bcc} field of the message, or @t{#f} if there is none
-@item @code{(mu:body-html msg)}: : the html body of the message, or @t{#f} if there is none
-@item @code{(mu:body-txt msg)}: the plain-text body of the message, or @t{#f} if there is none
+@item @code{(mu:body msg)}: the body of the message, or @t{#f} if there is none
@item @code{(mu:cc msg)}: the @t{Bcc} field of the message, or @t{#f} if there is none
@item @code{(mu:date msg)}: the @t{Date} field of the message, or 0 if there is none
@item @code{(mu:flags msg)}: list of message-flags for this message
diff --git a/guile/mu.scm b/guile/mu.scm
index 08eae1f..31eca41 100644
--- a/guile/mu.scm
+++ b/guile/mu.scm
@@ -38,8 +38,7 @@
mu:header
;; message accessors
mu:field:bcc
- mu:field:body-html
- mu:field:body-txt
+ mu:field:body
mu:field:cc
mu:field:date
mu:field:flags
@@ -54,6 +53,9 @@
mu:field:tags
mu:field:timestamp
mu:field:to
+ ;; deprecated message accessors
+ mu:body-html
+ mu:body-txt
;; contact funcs
mu:name
mu:email
@@ -125,8 +127,7 @@
(export method-name)))))
(define-getter mu:bcc mu:field:bcc)
-(define-getter mu:body-html mu:field:body-html)
-(define-getter mu:body-txt mu:field:body-txt)
+(define-getter mu:body mu:field:body)
(define-getter mu:cc mu:field:cc)
(define-getter mu:date mu:field:date)
(define-getter mu:flags mu:field:flags)
@@ -142,6 +143,16 @@
(define-getter mu:timestamp mu:field:timestamp)
(define-getter mu:to mu:field:to)
+(define-method (mu:body-html (msg <mu:message>))
+ "The HTML body isn't stored separately anymore, so this method can't return
+anything useful. We keep it for backwards compatibility."
+ #f)
+
+(define-method (mu:body-txt (msg <mu:message>))
+ "The text body isn't stored separately anymore. This method is now a synonym
+for mu:body."
+ (mu:body msg))
+
(define-method (mu:header (msg <mu:message>) (hdr <string>))
"Get an arbitrary header HDR from message MSG; return #f if it does
not exist."
diff --git a/guile/tests/test-mu-guile.scm b/guile/tests/test-mu-guile.scm
index 975d3d7..ed00f1e 100755
--- a/guile/tests/test-mu-guile.scm
+++ b/guile/tests/test-mu-guile.scm
@@ -84,6 +84,22 @@ exec guile -e main -s $0 $@
(str-equal-or-exit (mu:to msg) "Democritus <demo@example.com>")
(str-equal-or-exit (mu:from msg) "Richard P. Feynman <rpf@example.com>")
;;(str-equal-or-exit (mu:header msg "Content-Transfer-Encoding") "8bit")
+ (str-equal-or-exit (mu:body msg)
+ (string-join
+ '("If, in some cataclysm, all scientific knowledge were to be destroyed,"
+ "and only one sentence passed on to the next generation of creatures,"
+ "what statement would contain the most information in the fewest words?"
+ "I believe it is the atomic hypothesis (or atomic fact, or whatever you"
+ "wish to call it) that all things are made of atoms — little particles"
+ "that move around in perpetual motion, attracting each other when they"
+ "are a little distance apart, but repelling upon being squeezed into"
+ "one another. In that one sentence you will see an enormous amount of"
+ "information about the world, if just a little imagination and thinking"
+ "are applied.\n") "\n"))
+ (str-equal-or-exit (mu:body-txt msg) (mu:body msg))
+ (let ((got (mu:body-html msg)))
+ (if got
+ (error-exit "Expected #f, got ~a" got)))
(if (not (equal? (mu:priority msg) mu:prio:high))
(error-exit "Expected ~a, got ~a" (mu:priority msg) mu:prio:high))))