Skip to content

Commit fc246f7

Browse files
authored
Merge pull request #2801 from bauermann/fix-msg-body
guile: Fix the mu:body message method
2 parents 8c0f136 + 5113799 commit fc246f7

File tree

7 files changed

+46
-21
lines changed

7 files changed

+46
-21
lines changed

guile/examples/org2mu4e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exec guile -e main -s $0 $@
4343
(org-mu4e-link msg)
4444
(if tag (string-concatenate `(":" ,tag "::")) "")
4545
(or (mu:from msg) "?")
46-
(let ((body (mu:body-txt msg)))
46+
(let ((body (mu:body msg)))
4747
(if (not body) ;; get a 'summary' of the body text
4848
"<no plain-text body>"
4949
(string-map

guile/mu-guile.texi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ properties, please refer to the @t{mu-find} man-page.
391391

392392
@itemize
393393
@item @code{(mu:bcc msg)}: the @t{Bcc} field of the message, or @t{#f} if there is none
394-
@item @code{(mu:body-html msg)}: : the html body of the message, or @t{#f} if there is none
395-
@item @code{(mu:body-txt msg)}: the plain-text body of the message, or @t{#f} if there is none
394+
@item @code{(mu:body msg)}: the body of the message, or @t{#f} if there is none
396395
@item @code{(mu:cc msg)}: the @t{Bcc} field of the message, or @t{#f} if there is none
397396
@item @code{(mu:date msg)}: the @t{Date} field of the message, or 0 if there is none
398397
@item @code{(mu:flags msg)}: list of message-flags for this message

guile/mu.scm

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
mu:header
3939
;; message accessors
4040
mu:field:bcc
41-
mu:field:body-html
42-
mu:field:body-txt
41+
mu:field:body
4342
mu:field:cc
4443
mu:field:date
4544
mu:field:flags
@@ -54,6 +53,9 @@
5453
mu:field:tags
5554
mu:field:timestamp
5655
mu:field:to
56+
;; deprecated message accessors
57+
mu:body-html
58+
mu:body-txt
5759
;; contact funcs
5860
mu:name
5961
mu:email
@@ -125,8 +127,7 @@
125127
(export method-name)))))
126128

127129
(define-getter mu:bcc mu:field:bcc)
128-
(define-getter mu:body-html mu:field:body-html)
129-
(define-getter mu:body-txt mu:field:body-txt)
130+
(define-getter mu:body mu:field:body)
130131
(define-getter mu:cc mu:field:cc)
131132
(define-getter mu:date mu:field:date)
132133
(define-getter mu:flags mu:field:flags)
@@ -142,6 +143,16 @@
142143
(define-getter mu:timestamp mu:field:timestamp)
143144
(define-getter mu:to mu:field:to)
144145

146+
(define-method (mu:body-html (msg <mu:message>))
147+
"The HTML body isn't stored separately anymore, so this method can't return
148+
anything useful. We keep it for backwards compatibility."
149+
#f)
150+
151+
(define-method (mu:body-txt (msg <mu:message>))
152+
"The text body isn't stored separately anymore. This method is now a synonym
153+
for mu:body."
154+
(mu:body msg))
155+
145156
(define-method (mu:header (msg <mu:message>) (hdr <string>))
146157
"Get an arbitrary header HDR from message MSG; return #f if it does
147158
not exist."

guile/tests/test-mu-guile.scm

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@ exec guile -e main -s $0 $@
8383
(str-equal-or-exit (mu:subject msg) "atoms")
8484
(str-equal-or-exit (mu:to msg) "Democritus <[email protected]>")
8585
(str-equal-or-exit (mu:from msg) "Richard P. Feynman <[email protected]>")
86-
;;(str-equal-or-exit (mu:header msg "Content-transfer-encoding") "7BIT")
86+
;;(str-equal-or-exit (mu:header msg "Content-Transfer-Encoding") "8bit")
87+
(str-equal-or-exit (mu:body msg)
88+
(string-join
89+
'("If, in some cataclysm, all scientific knowledge were to be destroyed,"
90+
"and only one sentence passed on to the next generation of creatures,"
91+
"what statement would contain the most information in the fewest words?"
92+
"I believe it is the atomic hypothesis (or atomic fact, or whatever you"
93+
"wish to call it) that all things are made of atoms — little particles"
94+
"that move around in perpetual motion, attracting each other when they"
95+
"are a little distance apart, but repelling upon being squeezed into"
96+
"one another. In that one sentence you will see an enormous amount of"
97+
"information about the world, if just a little imagination and thinking"
98+
"are applied.\n") "\n"))
99+
(str-equal-or-exit (mu:body-txt msg) (mu:body msg))
100+
(let ((got (mu:body-html msg)))
101+
(if got
102+
(error-exit "Expected #f, got ~a" got)))
87103
88104
(if (not (equal? (mu:priority msg) mu:prio:high))
89105
(error-exit "Expected ~a, got ~a" (mu:priority msg) mu:prio:high))))
@@ -97,7 +113,7 @@ exec guile -e main -s $0 $@
97113
(define (test-stats)
98114
"Test statistical functions."
99115
;; average
100-
(num-equal-or-exit (mu:average mu:size) 82601/14)
116+
(num-equal-or-exit (mu:average mu:size) 41299/7)
101117
(num-equal-or-exit (floor (mu:stddev mu:size)) 12637.0)
102118
(num-equal-or-exit (mu:max mu:size) 46308)
103119
(num-equal-or-exit (mu:min mu:size) 111))

mu4e/mu4e-message.el

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Some notes on the format:
7171
the MIME-part), :name (the file name, if any), :mime-type (the
7272
MIME-type, if any) and :size (the size in bytes, if any).
7373
- Messages in the Headers view come from the database and do not have
74-
:attachments, :body-txt or :body-html fields. Message in the
75-
Message view use the actual message file, and do include these fields."
74+
:attachments or :body fields. Message in the Message view use the
75+
actual message file, and do include these fields."
7676
;; after all this documentation, the spectacular implementation
7777
(if msg
7878
(plist-get msg field)
@@ -81,18 +81,17 @@ Some notes on the format:
8181
(defsubst mu4e-message-field (msg field)
8282
"Retrieve FIELD from message plist MSG.
8383
Like `mu4e-message-field-nil', but will sanitize nil values:
84-
- all string field except body-txt/body-html: nil -> \"\"
85-
- numeric fields + dates : nil -> 0
86-
- all others : return the value
87-
Thus, function will return nil for empty lists, non-existing body-txt
88-
or body-html."
84+
- all string field except body: nil -> \"\"
85+
- numeric fields + dates : nil -> 0
86+
- all others : return the value
87+
Thus, function will return nil for empty lists, or non-existing body."
8988
(let ((val (mu4e-message-field-raw msg field)))
9089
(cond
9190
(val
9291
val) ;; non-nil -> just return it
9392
((member field '(:subject :message-id :path :maildir :in-reply-to))
94-
"") ;; string fields except body-txt, body-html: nil -> ""
95-
((member field '(:body-html :body-txt))
93+
"") ;; string fields except body: nil -> ""
94+
((member field '(:body))
9695
val)
9796
((member field '(:docid :size))
9897
0) ;; numeric type: nil -> 0

mu4e/mu4e-server.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ The server output is as follows:
323323
3. a view looks like:
324324
(:view <msg-sexp>)
325325
=> the <msg-sexp> (see 2.) will be passed to `mu4e-view-func'.
326-
the <msg-sexp> also contains :body-txt and/or :body-html
326+
the <msg-sexp> also contains :body
327327
328328
4. a database update looks like:
329329
(:update <msg-sexp> :move <nil-or-t>)

testdata/testdir2/wom_bat/cur/atomic

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Subject: atoms
44
To: "Democritus" <[email protected]>
55
Message-id: <[email protected]>
66
MIME-version: 1.0
7-
Content-type: text/plain; charset=us-ascii
8-
Content-transfer-encoding: 7BIT
7+
Content-Type: text/plain; charset=UTF-8
8+
Content-Transfer-Encoding: 8bit
99
Precedence: high
1010

1111
If, in some cataclysm, all scientific knowledge were to be destroyed,

0 commit comments

Comments
 (0)