Merge pull request #2801 from bauermann/fix-msg-body
guile: Fix the mu:body message method
This commit is contained in:
@ -43,7 +43,7 @@ exec guile -e main -s $0 $@
|
|||||||
(org-mu4e-link msg)
|
(org-mu4e-link msg)
|
||||||
(if tag (string-concatenate `(":" ,tag "::")) "")
|
(if tag (string-concatenate `(":" ,tag "::")) "")
|
||||||
(or (mu:from msg) "?")
|
(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
|
(if (not body) ;; get a 'summary' of the body text
|
||||||
"<no plain-text body>"
|
"<no plain-text body>"
|
||||||
(string-map
|
(string-map
|
||||||
|
|||||||
@ -391,8 +391,7 @@ properties, please refer to the @t{mu-find} man-page.
|
|||||||
|
|
||||||
@itemize
|
@itemize
|
||||||
@item @code{(mu:bcc msg)}: the @t{Bcc} field of the message, or @t{#f} if there is none
|
@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 msg)}: the 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:cc msg)}: the @t{Bcc} field 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: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
|
@item @code{(mu:flags msg)}: list of message-flags for this message
|
||||||
|
|||||||
19
guile/mu.scm
19
guile/mu.scm
@ -38,8 +38,7 @@
|
|||||||
mu:header
|
mu:header
|
||||||
;; message accessors
|
;; message accessors
|
||||||
mu:field:bcc
|
mu:field:bcc
|
||||||
mu:field:body-html
|
mu:field:body
|
||||||
mu:field:body-txt
|
|
||||||
mu:field:cc
|
mu:field:cc
|
||||||
mu:field:date
|
mu:field:date
|
||||||
mu:field:flags
|
mu:field:flags
|
||||||
@ -54,6 +53,9 @@
|
|||||||
mu:field:tags
|
mu:field:tags
|
||||||
mu:field:timestamp
|
mu:field:timestamp
|
||||||
mu:field:to
|
mu:field:to
|
||||||
|
;; deprecated message accessors
|
||||||
|
mu:body-html
|
||||||
|
mu:body-txt
|
||||||
;; contact funcs
|
;; contact funcs
|
||||||
mu:name
|
mu:name
|
||||||
mu:email
|
mu:email
|
||||||
@ -125,8 +127,7 @@
|
|||||||
(export method-name)))))
|
(export method-name)))))
|
||||||
|
|
||||||
(define-getter mu:bcc mu:field:bcc)
|
(define-getter mu:bcc mu:field:bcc)
|
||||||
(define-getter mu:body-html mu:field:body-html)
|
(define-getter mu:body mu:field:body)
|
||||||
(define-getter mu:body-txt mu:field:body-txt)
|
|
||||||
(define-getter mu:cc mu:field:cc)
|
(define-getter mu:cc mu:field:cc)
|
||||||
(define-getter mu:date mu:field:date)
|
(define-getter mu:date mu:field:date)
|
||||||
(define-getter mu:flags mu:field:flags)
|
(define-getter mu:flags mu:field:flags)
|
||||||
@ -142,6 +143,16 @@
|
|||||||
(define-getter mu:timestamp mu:field:timestamp)
|
(define-getter mu:timestamp mu:field:timestamp)
|
||||||
(define-getter mu:to mu:field:to)
|
(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>))
|
(define-method (mu:header (msg <mu:message>) (hdr <string>))
|
||||||
"Get an arbitrary header HDR from message MSG; return #f if it does
|
"Get an arbitrary header HDR from message MSG; return #f if it does
|
||||||
not exist."
|
not exist."
|
||||||
|
|||||||
@ -83,7 +83,23 @@ exec guile -e main -s $0 $@
|
|||||||
(str-equal-or-exit (mu:subject msg) "atoms")
|
(str-equal-or-exit (mu:subject msg) "atoms")
|
||||||
(str-equal-or-exit (mu:to msg) "Democritus <demo@example.com>")
|
(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:from msg) "Richard P. Feynman <rpf@example.com>")
|
||||||
;;(str-equal-or-exit (mu:header msg "Content-transfer-encoding") "7BIT")
|
;;(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))
|
(if (not (equal? (mu:priority msg) mu:prio:high))
|
||||||
(error-exit "Expected ~a, got ~a" (mu:priority msg) mu:prio:high))))
|
(error-exit "Expected ~a, got ~a" (mu:priority msg) mu:prio:high))))
|
||||||
@ -97,7 +113,7 @@ exec guile -e main -s $0 $@
|
|||||||
(define (test-stats)
|
(define (test-stats)
|
||||||
"Test statistical functions."
|
"Test statistical functions."
|
||||||
;; average
|
;; average
|
||||||
(num-equal-or-exit (mu:average mu:size) 82601/14)
|
(num-equal-or-exit (mu:average mu:size) 41299/7)
|
||||||
(num-equal-or-exit (floor (mu:stddev mu:size)) 12637.0)
|
(num-equal-or-exit (floor (mu:stddev mu:size)) 12637.0)
|
||||||
(num-equal-or-exit (mu:max mu:size) 46308)
|
(num-equal-or-exit (mu:max mu:size) 46308)
|
||||||
(num-equal-or-exit (mu:min mu:size) 111))
|
(num-equal-or-exit (mu:min mu:size) 111))
|
||||||
|
|||||||
@ -71,8 +71,8 @@ Some notes on the format:
|
|||||||
the MIME-part), :name (the file name, if any), :mime-type (the
|
the MIME-part), :name (the file name, if any), :mime-type (the
|
||||||
MIME-type, if any) and :size (the size in bytes, if any).
|
MIME-type, if any) and :size (the size in bytes, if any).
|
||||||
- Messages in the Headers view come from the database and do not have
|
- Messages in the Headers view come from the database and do not have
|
||||||
:attachments, :body-txt or :body-html fields. Message in the
|
:attachments or :body fields. Message in the Message view use the
|
||||||
Message view use the actual message file, and do include these fields."
|
actual message file, and do include these fields."
|
||||||
;; after all this documentation, the spectacular implementation
|
;; after all this documentation, the spectacular implementation
|
||||||
(if msg
|
(if msg
|
||||||
(plist-get msg field)
|
(plist-get msg field)
|
||||||
@ -81,18 +81,17 @@ Some notes on the format:
|
|||||||
(defsubst mu4e-message-field (msg field)
|
(defsubst mu4e-message-field (msg field)
|
||||||
"Retrieve FIELD from message plist MSG.
|
"Retrieve FIELD from message plist MSG.
|
||||||
Like `mu4e-message-field-nil', but will sanitize nil values:
|
Like `mu4e-message-field-nil', but will sanitize nil values:
|
||||||
- all string field except body-txt/body-html: nil -> \"\"
|
- all string field except body: nil -> \"\"
|
||||||
- numeric fields + dates : nil -> 0
|
- numeric fields + dates : nil -> 0
|
||||||
- all others : return the value
|
- all others : return the value
|
||||||
Thus, function will return nil for empty lists, non-existing body-txt
|
Thus, function will return nil for empty lists, or non-existing body."
|
||||||
or body-html."
|
|
||||||
(let ((val (mu4e-message-field-raw msg field)))
|
(let ((val (mu4e-message-field-raw msg field)))
|
||||||
(cond
|
(cond
|
||||||
(val
|
(val
|
||||||
val) ;; non-nil -> just return it
|
val) ;; non-nil -> just return it
|
||||||
((member field '(:subject :message-id :path :maildir :in-reply-to))
|
((member field '(:subject :message-id :path :maildir :in-reply-to))
|
||||||
"") ;; string fields except body-txt, body-html: nil -> ""
|
"") ;; string fields except body: nil -> ""
|
||||||
((member field '(:body-html :body-txt))
|
((member field '(:body))
|
||||||
val)
|
val)
|
||||||
((member field '(:docid :size))
|
((member field '(:docid :size))
|
||||||
0) ;; numeric type: nil -> 0
|
0) ;; numeric type: nil -> 0
|
||||||
|
|||||||
@ -323,7 +323,7 @@ The server output is as follows:
|
|||||||
3. a view looks like:
|
3. a view looks like:
|
||||||
(:view <msg-sexp>)
|
(:view <msg-sexp>)
|
||||||
=> the <msg-sexp> (see 2.) will be passed to `mu4e-view-func'.
|
=> the <msg-sexp> (see 2.) will be passed to `mu4e-view-func'.
|
||||||
the <msg-sexp> also contains :body-txt and/or :body-html
|
the <msg-sexp> also contains :body
|
||||||
|
|
||||||
4. a database update looks like:
|
4. a database update looks like:
|
||||||
(:update <msg-sexp> :move <nil-or-t>)
|
(:update <msg-sexp> :move <nil-or-t>)
|
||||||
|
|||||||
4
testdata/testdir2/wom_bat/cur/atomic
vendored
4
testdata/testdir2/wom_bat/cur/atomic
vendored
@ -4,8 +4,8 @@ Subject: atoms
|
|||||||
To: "Democritus" <demo@example.com>
|
To: "Democritus" <demo@example.com>
|
||||||
Message-id: <3BE9E6535E302944823E7A1A20D852173@msg.id>
|
Message-id: <3BE9E6535E302944823E7A1A20D852173@msg.id>
|
||||||
MIME-version: 1.0
|
MIME-version: 1.0
|
||||||
Content-type: text/plain; charset=us-ascii
|
Content-Type: text/plain; charset=UTF-8
|
||||||
Content-transfer-encoding: 7BIT
|
Content-Transfer-Encoding: 8bit
|
||||||
Precedence: high
|
Precedence: high
|
||||||
|
|
||||||
If, in some cataclysm, all scientific knowledge were to be destroyed,
|
If, in some cataclysm, all scientific knowledge were to be destroyed,
|
||||||
|
|||||||
Reference in New Issue
Block a user