diff --git a/src/mu-msg-doc.cc b/src/mu-msg-doc.cc index 15bc0eb0..59b5d9b9 100644 --- a/src/mu-msg-doc.cc +++ b/src/mu-msg-doc.cc @@ -26,6 +26,7 @@ #include "mu-util.h" #include "mu-msg-fields.h" #include "mu-msg-doc.h" +#include "mu-str.h" struct _MuMsgDoc { _MuMsgDoc (const Xapian::Document& doc) : _doc (doc) {} @@ -76,6 +77,27 @@ mu_msg_doc_get_str_field (MuMsgDoc *self, MuMsgFieldId mfid, gboolean *do_free) } +GSList* +mu_msg_doc_get_str_list_field (MuMsgDoc *self, MuMsgFieldId mfid, + gboolean *do_free) +{ + g_return_val_if_fail (self, NULL); + g_return_val_if_fail (mu_msg_field_id_is_valid(mfid), NULL); + g_return_val_if_fail (mu_msg_field_is_string_list(mfid), NULL); + + *do_free = TRUE; + + try { + /* return a comma-separated string as a GSList */ + const std::string s (self->doc().get_value(mfid)); + return s.empty() ? NULL : mu_str_to_list(s.c_str(),','); + + } MU_XAPIAN_CATCH_BLOCK_RETURN(NULL); +} + + + + gint64 mu_msg_doc_get_num_field (MuMsgDoc *self, MuMsgFieldId mfid) { diff --git a/src/mu-msg-doc.h b/src/mu-msg-doc.h index 6acd3a4d..f05df504 100644 --- a/src/mu-msg-doc.h +++ b/src/mu-msg-doc.h @@ -68,6 +68,23 @@ void mu_msg_doc_destroy (MuMsgDoc *self); gchar* mu_msg_doc_get_str_field (MuMsgDoc *self, MuMsgFieldId mfid, gboolean *do_free) G_GNUC_WARN_UNUSED_RESULT; +/** + * get a string-list parameter from the msgdoc + * + * @param self a MuMsgDoc instance + * @param mfid a MuMsgFieldId for a string-list field + * @param do_free receives either TRUE or FALSE, where TRUE means that + * the caller owns the string, and has to free it (mu_str_free_list) when done + * with it; FALSE means that the MuMsgDoc owns the list, and it is + * only valid as long as the MuMsgDoc is valid (ie., before + * mu_msg_doc_destroy). + * + * @return a list for the given field (see do_free), or NULL in case of error + */ +GSList* mu_msg_doc_get_str_list_field (MuMsgDoc *self, MuMsgFieldId mfid, + gboolean *do_free) G_GNUC_WARN_UNUSED_RESULT; + + /** * * get a numeric parameter from the msgdoc diff --git a/src/mu-msg-file.c b/src/mu-msg-file.c index 1fc504d9..5a212805 100644 --- a/src/mu-msg-file.c +++ b/src/mu-msg-file.c @@ -428,17 +428,6 @@ get_prio (MuMsgFile *self) } -/* static const char* */ -/* get_header (MuMsgFile *self, const char* header) */ -/* { */ -/* g_return_val_if_fail (msg, NULL); */ -/* g_return_val_if_fail (header, NULL); */ - -/* return g_mime_object_get_header (GMIME_OBJECT(self->_mime_msg), */ -/* header); */ -/* } */ - - struct _GetBodyData { GMimeObject *_txt_part, *_html_part; gboolean _want_html; @@ -701,7 +690,7 @@ get_msgids_from_header (MuMsgFile *self, const char* header) } -static GSList* +GSList* get_references (MuMsgFile *self) { GSList *refs, *inreply; @@ -723,34 +712,6 @@ get_references (MuMsgFile *self) return g_slist_reverse (refs); } -static char* -get_references_str (MuMsgFile *self) -{ - GSList *refs; - gchar *refsstr; - - g_return_val_if_fail (self, NULL); - - refsstr = NULL; - refs = get_references (self); - if (refs) { - const GSList *cur; - for (cur = refs; cur; cur = g_slist_next(cur)) { - char *tmp; - tmp = g_strdup_printf ("%s%s%s", - refsstr ? refsstr : "", - refsstr ? "," : "", - (gchar*)cur->data); - g_free (refsstr); - refsstr = tmp; - } - } - - g_slist_foreach (refs, (GFunc)g_free, NULL); - g_slist_free (refs); - - return refsstr; -} char* @@ -793,14 +754,36 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid, gboolean *do_free case MU_MSG_FIELD_ID_MAILDIR: return self->_maildir; - case MU_MSG_FIELD_ID_REFS: *do_free = TRUE; - return get_references_str (self); - default: g_return_val_if_reached (NULL); } } + + + +GSList* +mu_msg_file_get_str_list_field (MuMsgFile *self, MuMsgFieldId mfid, + gboolean *do_free) +{ + g_return_val_if_fail (self, NULL); + g_return_val_if_fail (mu_msg_field_is_string_list(mfid), NULL); + + switch (mfid) { + + case MU_MSG_FIELD_ID_REFS: + *do_free = TRUE; + return get_references (self); + + default: + g_return_val_if_reached (NULL); + } +} + + + + + gint64 mu_msg_file_get_num_field (MuMsgFile *self, const MuMsgFieldId mfid) { diff --git a/src/mu-msg-file.h b/src/mu-msg-file.h index 529e52a6..d04bc8a8 100644 --- a/src/mu-msg-file.h +++ b/src/mu-msg-file.h @@ -64,20 +64,42 @@ const char* mu_msg_file_get_header (MuMsgFile *self, const char *header); * get a string value for this message * * @param self a valid MuMsgFile - * @param msfid the message field id to get (must be string-based one) * + * @param msfid the message field id to get (must be of type string) * @param do_free receives TRUE or FALSE, conveying if this string * should be owned & freed (TRUE) or not by caller. In case 'FALSE', * this function should be treated as if it were returning a const * char*, and note that in that case the string is only valid as long * as the MuMsgFile is alive, ie. before mu_msg_file_destroy * - * @return a const string, or NULL + * @return a string, or NULL */ char* mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId msfid, gboolean *do_free) G_GNUC_WARN_UNUSED_RESULT; + +/** + * get a string-list value for this message + * + * @param self a valid MuMsgFile + * @param msfid the message field id to get (must be of type string-list) + * @param do_free receives TRUE or FALSE, conveying if this string + * should be owned & freed (TRUE) or not by caller. In case 'FALSE', + * this function should be treated as if it were returning a const + * GSList*, and note that in that case the string is only valid as long + * as the MuMsgFile is alive, ie. before mu_msg_file_destroy + * + * @return a GSList*, or NULL + */ +GSList* mu_msg_file_get_str_list_field (MuMsgFile *self, + MuMsgFieldId msfid, + gboolean *do_free) + G_GNUC_WARN_UNUSED_RESULT; + + + + /** * get a numeric value for this message -- the return value should be * cast into the actual type, e.g., time_t, MuMsgPrio etc.