guile: avoid body duplication
In message, don't re-fill when unneeded. Add tests. Fixes #2802.
This commit is contained in:
@ -333,7 +333,7 @@ SCM_DEFINE(get_parts,
|
|||||||
attlist = scm_cons(elm, attlist);
|
attlist = scm_cons(elm, attlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* explicitly close the file backend, so we won't run of fds */
|
/* explicitly close the file backend, so we won't run out of fds */
|
||||||
msg->unload_mime_message();
|
msg->unload_mime_message();
|
||||||
|
|
||||||
return attlist;
|
return attlist;
|
||||||
|
|||||||
@ -74,10 +74,13 @@ exec guile -e main -s $0 $@
|
|||||||
(str-equal-or-exit (mu:subject msg) "Fwd: rfc822")
|
(str-equal-or-exit (mu:subject msg) "Fwd: rfc822")
|
||||||
(str-equal-or-exit (mu:to msg) "martin")
|
(str-equal-or-exit (mu:to msg) "martin")
|
||||||
(str-equal-or-exit (mu:from msg) "foobar <foo@example.com>")
|
(str-equal-or-exit (mu:from msg) "foobar <foo@example.com>")
|
||||||
|
(str-equal-or-exit (mu:body msg) "Hello world, forwarding some RFC822 message\n")
|
||||||
(str-equal-or-exit (mu:header msg "X-Mailer") "Ximian Evolution 1.4.5")
|
(str-equal-or-exit (mu:header msg "X-Mailer") "Ximian Evolution 1.4.5")
|
||||||
|
;; issue #2802
|
||||||
|
(str-equal-or-exit (mu:body msg) "Hello world, forwarding some RFC822 message\n")
|
||||||
|
|
||||||
(if (not (equal? (mu:priority msg) mu:prio:normal))
|
(if (not (equal? (mu:priority msg) mu:prio:normal))
|
||||||
(error-exit "Expected ~A, got ~A" (mu:priority msg) mu:prio:normal)))
|
(error-exit "Expected ~A, got ~A" (mu:priority msg) mu:prio:normal)))
|
||||||
|
|
||||||
(let ((msg (car (mu:message-list "atoms"))))
|
(let ((msg (car (mu:message-list "atoms"))))
|
||||||
(str-equal-or-exit (mu:subject msg) "atoms")
|
(str-equal-or-exit (mu:subject msg) "atoms")
|
||||||
@ -85,21 +88,21 @@ exec guile -e main -s $0 $@
|
|||||||
(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") "8bit")
|
;;(str-equal-or-exit (mu:header msg "Content-Transfer-Encoding") "8bit")
|
||||||
(str-equal-or-exit (mu:body msg)
|
(str-equal-or-exit (mu:body msg)
|
||||||
(string-join
|
(string-join
|
||||||
'("If, in some cataclysm, all scientific knowledge were to be destroyed,"
|
'("If, in some cataclysm, all scientific knowledge were to be destroyed,"
|
||||||
"and only one sentence passed on to the next generation of creatures,"
|
"and only one sentence passed on to the next generation of creatures,"
|
||||||
"what statement would contain the most information in the fewest words?"
|
"what statement would contain the most information in the fewest words?"
|
||||||
"I believe it is the atomic hypothesis (or atomic fact, or whatever you"
|
"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"
|
"wish to call it) that all things are made of atoms — little particles"
|
||||||
"that move around in perpetual motion, attracting each other when they"
|
"that move around in perpetual motion, attracting each other when they"
|
||||||
"are a little distance apart, but repelling upon being squeezed into"
|
"are a little distance apart, but repelling upon being squeezed into"
|
||||||
"one another. In that one sentence you will see an enormous amount of"
|
"one another. In that one sentence you will see an enormous amount of"
|
||||||
"information about the world, if just a little imagination and thinking"
|
"information about the world, if just a little imagination and thinking"
|
||||||
"are applied.\n") "\n"))
|
"are applied.\n") "\n"))
|
||||||
(str-equal-or-exit (mu:body-txt msg) (mu:body msg))
|
(str-equal-or-exit (mu:body-txt msg) (mu:body msg))
|
||||||
(let ((got (mu:body-html msg)))
|
(let ((got (mu:body-html msg)))
|
||||||
(if got
|
(if got
|
||||||
(error-exit "Expected #f, got ~a" 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))))
|
||||||
|
|||||||
@ -72,6 +72,10 @@ struct Message::Private {
|
|||||||
|
|
||||||
Option<std::string> language; /* body ISO language code */
|
Option<std::string> language; /* body ISO language code */
|
||||||
|
|
||||||
|
// after unload_mime_message, we don't need to re-parse the message.
|
||||||
|
// issue #2802.
|
||||||
|
bool document_filled{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Document::Options doc_opts(Message::Options mopts) {
|
Document::Options doc_opts(Message::Options mopts) {
|
||||||
return any_of(opts & Message::Options::SupportNgrams) ?
|
return any_of(opts & Message::Options::SupportNgrams) ?
|
||||||
@ -675,6 +679,10 @@ doc_add_reply_to(Document& doc, const MimeMessage& mime_msg)
|
|||||||
static void
|
static void
|
||||||
fill_document(Message::Private& priv)
|
fill_document(Message::Private& priv)
|
||||||
{
|
{
|
||||||
|
if (priv.document_filled) {
|
||||||
|
return; // nothing to do.
|
||||||
|
}
|
||||||
|
|
||||||
/* hunt & gather info from message tree */
|
/* hunt & gather info from message tree */
|
||||||
Document& doc{priv.doc};
|
Document& doc{priv.doc};
|
||||||
MimeMessage& mime_msg{priv.mime_msg.value()};
|
MimeMessage& mime_msg{priv.mime_msg.value()};
|
||||||
@ -691,7 +699,7 @@ fill_document(Message::Private& priv)
|
|||||||
doc_add_list_post(doc, mime_msg); /* only in sexp */
|
doc_add_list_post(doc, mime_msg); /* only in sexp */
|
||||||
doc_add_reply_to(doc, mime_msg); /* only in sexp */
|
doc_add_reply_to(doc, mime_msg); /* only in sexp */
|
||||||
|
|
||||||
field_for_each([&](auto&& field) {
|
field_for_each([&](const auto& field) {
|
||||||
/* insist on explicitly handling each */
|
/* insist on explicitly handling each */
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic error "-Wswitch"
|
#pragma GCC diagnostic error "-Wswitch"
|
||||||
@ -775,6 +783,8 @@ fill_document(Message::Private& priv)
|
|||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
priv.document_filled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Option<std::string>
|
Option<std::string>
|
||||||
|
|||||||
Reference in New Issue
Block a user