From 0b32a63537871c1f2e2fd70987ab71c3a2ecc1dc Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 17 Sep 2012 11:13:37 +0300 Subject: [PATCH] * guile: fix getting message bodies --- guile/mu-guile-message.c | 37 ++++++++++++++++++++++++++++--------- lib/mu-msg-file.c | 11 +++++------ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/guile/mu-guile-message.c b/guile/mu-guile-message.c index c6684dd9..24902116 100644 --- a/guile/mu-guile-message.c +++ b/guile/mu-guile-message.c @@ -162,6 +162,32 @@ msg_string_list_field (MuMsg *msg, MuMsgFieldId mfid) } +static SCM +get_body (MuMsg *msg, gboolean html) +{ + SCM data; + const char* body; + MuMsgOptions opts; + + opts = MU_MSG_OPTION_NONE; + + if (html) + body = mu_msg_get_body_html (msg, opts); + else + body = mu_msg_get_body_text (msg, opts); + + if (body) + data = mu_guile_scm_from_str (body); + else + data = SCM_BOOL_F; + + /* explicitly close the file backend, so we won't run of fds */ + mu_msg_unload_msg_file (msg); + + return data; +} + + SCM_DEFINE (get_field, "mu:c:get-field", 2, 0, 0, (SCM MSG, SCM FIELD), "Get the field FIELD from message MSG.\n") @@ -186,21 +212,14 @@ SCM_DEFINE (get_field, "mu:c:get-field", 2, 0, 0, case MU_MSG_FIELD_ID_FLAGS: return get_flags_scm (msgwrap->_msg); case MU_MSG_FIELD_ID_BODY_HTML: + return get_body (msgwrap->_msg, TRUE); case MU_MSG_FIELD_ID_BODY_TEXT: - { - SCM data; - data = mu_guile_scm_from_str - (mu_msg_get_field_string (msgwrap->_msg, mfid)); - /* explicitly close the file backend, so we won't run of fds */ - mu_msg_unload_msg_file (msgwrap->_msg); - return data; - } + return get_body (msgwrap->_msg, FALSE); /* our pseudo-field; we get it from the message file */ case MU_GUILE_MSG_FIELD_ID_TIMESTAMP: return scm_from_uint ( (unsigned)mu_msg_get_timestamp(msgwrap->_msg)); - default: break; } diff --git a/lib/mu-msg-file.c b/lib/mu-msg-file.c index 6253322b..f7c3ca99 100644 --- a/lib/mu-msg-file.c +++ b/lib/mu-msg-file.c @@ -602,13 +602,12 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid, case MU_MSG_FIELD_ID_MAILDIR: return self->_maildir; - case MU_MSG_FIELD_ID_BODY_TEXT: - case MU_MSG_FIELD_ID_BODY_HTML: + case MU_MSG_FIELD_ID_BODY_TEXT: /* use mu_msg_get_body_text */ + case MU_MSG_FIELD_ID_BODY_HTML: /* use mu_msg_get_body_html */ case MU_MSG_FIELD_ID_EMBEDDED_TEXT: - g_warning ("not available here: %s", - mu_msg_field_name (mfid)); - g_return_val_if_reached (NULL); - return NULL; + g_warning ("%s is not retrievable through: %s", + mu_msg_field_name (mfid), __FUNCTION__); + return NULL; default: g_return_val_if_reached (NULL); }