mirror of https://github.com/djcb/mu.git
* lib/tests: support X-Label and X-Keywords, update unit test
This commit is contained in:
parent
abfcc4a2f3
commit
cb17e22d48
|
@ -527,91 +527,91 @@ mu_msg_mime_get_body_part (GMimeMessage *msg, gboolean decrypt,
|
|||
|
||||
|
||||
|
||||
static char*
|
||||
get_body (MuMsgFile *self, gboolean decrypt, gboolean want_html)
|
||||
{
|
||||
GMimePart *part;
|
||||
gboolean err;
|
||||
gchar *str;
|
||||
/* static char* */
|
||||
/* get_body (MuMsgFile *self, gboolean decrypt, gboolean want_html) */
|
||||
/* { */
|
||||
/* GMimePart *part; */
|
||||
/* gboolean err; */
|
||||
/* gchar *str; */
|
||||
|
||||
g_return_val_if_fail (self, NULL);
|
||||
g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL);
|
||||
/* g_return_val_if_fail (self, NULL); */
|
||||
/* g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); */
|
||||
|
||||
part = mu_msg_mime_get_body_part (self->_mime_msg,
|
||||
decrypt, want_html);
|
||||
if (!GMIME_IS_PART(part))
|
||||
return NULL;
|
||||
/* part = mu_msg_mime_get_body_part (self->_mime_msg, */
|
||||
/* decrypt, want_html); */
|
||||
/* if (!GMIME_IS_PART(part)) */
|
||||
/* return NULL; */
|
||||
|
||||
err = FALSE;
|
||||
str = mu_msg_mime_part_to_string (part, &err);
|
||||
/* err = FALSE; */
|
||||
/* str = mu_msg_mime_part_to_string (part, &err); */
|
||||
|
||||
/* note, str may be NULL (no body), but that's not necessarily
|
||||
* an error; we only warn when an actual error occured */
|
||||
if (err)
|
||||
g_warning ("error occured while retrieving %s body "
|
||||
"for message %s",
|
||||
want_html ? "html" : "text", self->_path);
|
||||
return str;
|
||||
}
|
||||
/* /\* note, str may be NULL (no body), but that's not necessarily */
|
||||
/* * an error; we only warn when an actual error occured *\/ */
|
||||
/* if (err) */
|
||||
/* g_warning ("error occured while retrieving %s body " */
|
||||
/* "for message %s", */
|
||||
/* want_html ? "html" : "text", self->_path); */
|
||||
/* return str; */
|
||||
/* } */
|
||||
|
||||
|
||||
static void
|
||||
append_text (GMimeObject *parent, GMimeObject *part, gchar **txt)
|
||||
{
|
||||
GMimeContentType *ct;
|
||||
GMimeContentDisposition *disp;
|
||||
gchar *parttxt, *tmp;
|
||||
gboolean err;
|
||||
/* static void */
|
||||
/* append_text (GMimeObject *parent, GMimeObject *part, gchar **txt) */
|
||||
/* { */
|
||||
/* GMimeContentType *ct; */
|
||||
/* GMimeContentDisposition *disp; */
|
||||
/* gchar *parttxt, *tmp; */
|
||||
/* gboolean err; */
|
||||
|
||||
if (!GMIME_IS_PART(part))
|
||||
return;
|
||||
/* if (!GMIME_IS_PART(part)) */
|
||||
/* return; */
|
||||
|
||||
ct = g_mime_object_get_content_type (part);
|
||||
if (!GMIME_IS_CONTENT_TYPE(ct) ||
|
||||
!g_mime_content_type_is_type (ct, "text", "plain"))
|
||||
return; /* not a text-plain part */
|
||||
/* ct = g_mime_object_get_content_type (part); */
|
||||
/* if (!GMIME_IS_CONTENT_TYPE(ct) || */
|
||||
/* !g_mime_content_type_is_type (ct, "text", "plain")) */
|
||||
/* return; /\* not a text-plain part *\/ */
|
||||
|
||||
disp = g_mime_object_get_content_disposition (part);
|
||||
if (GMIME_IS_CONTENT_DISPOSITION(disp) &&
|
||||
g_strcmp0 (g_mime_content_disposition_get_disposition (disp),
|
||||
GMIME_DISPOSITION_ATTACHMENT) == 0)
|
||||
return; /* it's an attachment, don't include */
|
||||
/* disp = g_mime_object_get_content_disposition (part); */
|
||||
/* if (GMIME_IS_CONTENT_DISPOSITION(disp) && */
|
||||
/* g_strcmp0 (g_mime_content_disposition_get_disposition (disp), */
|
||||
/* GMIME_DISPOSITION_ATTACHMENT) == 0) */
|
||||
/* return; /\* it's an attachment, don't include *\/ */
|
||||
|
||||
parttxt = mu_msg_mime_part_to_string (GMIME_PART(part), &err);
|
||||
if (err) {
|
||||
/* this happens for broken messages */
|
||||
g_debug ("%s: could not get text for part", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
/* parttxt = mu_msg_mime_part_to_string (GMIME_PART(part), &err); */
|
||||
/* if (err) { */
|
||||
/* /\* this happens for broken messages *\/ */
|
||||
/* g_debug ("%s: could not get text for part", __FUNCTION__); */
|
||||
/* return; */
|
||||
/* } */
|
||||
|
||||
/* it's a text part -- append it! */
|
||||
tmp = *txt;
|
||||
if (*txt) {
|
||||
*txt = g_strconcat (*txt, parttxt, NULL);
|
||||
g_free (parttxt);
|
||||
} else
|
||||
*txt = parttxt;
|
||||
/* /\* it's a text part -- append it! *\/ */
|
||||
/* tmp = *txt; */
|
||||
/* if (*txt) { */
|
||||
/* *txt = g_strconcat (*txt, parttxt, NULL); */
|
||||
/* g_free (parttxt); */
|
||||
/* } else */
|
||||
/* *txt = parttxt; */
|
||||
|
||||
g_free (tmp);
|
||||
}
|
||||
/* g_free (tmp); */
|
||||
/* } */
|
||||
|
||||
/* instead of just the body, this function returns a concatenation of
|
||||
* all text/plain parts with inline disposition
|
||||
*/
|
||||
static char*
|
||||
get_concatenated_text (MuMsgFile *self, gboolean decrypt)
|
||||
{
|
||||
char *txt;
|
||||
/* static char* */
|
||||
/* get_concatenated_text (MuMsgFile *self, gboolean decrypt) */
|
||||
/* { */
|
||||
/* char *txt; */
|
||||
|
||||
g_return_val_if_fail (self, NULL);
|
||||
g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL);
|
||||
/* g_return_val_if_fail (self, NULL); */
|
||||
/* g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); */
|
||||
|
||||
txt = NULL;
|
||||
mu_mime_message_foreach (self->_mime_msg, decrypt,
|
||||
(GMimeObjectForeachFunc)append_text,
|
||||
&txt);
|
||||
return txt;
|
||||
}
|
||||
/* txt = NULL; */
|
||||
/* mu_mime_message_foreach (self->_mime_msg, decrypt, */
|
||||
/* (GMimeObjectForeachFunc)append_text, */
|
||||
/* &txt); */
|
||||
/* return txt; */
|
||||
/* } */
|
||||
|
||||
|
||||
static gboolean
|
||||
|
@ -651,7 +651,8 @@ get_references (MuMsgFile *self)
|
|||
if (msgid && !contains (msgids, msgid))
|
||||
/* explicitly ensure it's utf8-safe, as GMime
|
||||
* does not ensure that */
|
||||
msgids = g_slist_prepend (msgids, g_strdup((msgid)));
|
||||
msgids = g_slist_prepend (msgids,
|
||||
g_strdup((msgid)));
|
||||
}
|
||||
g_mime_references_free (mime_refs);
|
||||
}
|
||||
|
@ -687,7 +688,7 @@ get_tags (MuMsgFile *self)
|
|||
last = g_slist_last (lst1);
|
||||
last->next = lst2;
|
||||
|
||||
return last;
|
||||
return lst1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -741,11 +742,6 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid,
|
|||
case MU_MSG_FIELD_ID_TO: *do_free = TRUE;
|
||||
return get_recipient (self, recipient_type(mfid));
|
||||
|
||||
/* case MU_MSG_FIELD_ID_BODY_TEXT: *do_free = TRUE; */
|
||||
/* return get_concatenated_text (self, TRUE); /\* FIXME: decrypt ? *\/ */
|
||||
/* case MU_MSG_FIELD_ID_BODY_HTML: *do_free = TRUE; */
|
||||
/* return get_body (self, TRUE, TRUE); /\* FIXME: decrypt ? *\/ */
|
||||
|
||||
case MU_MSG_FIELD_ID_FROM:
|
||||
return (char*)maybe_cleanup
|
||||
(g_mime_message_get_sender (self->_mime_msg),
|
||||
|
|
|
@ -255,13 +255,15 @@ test_mu_msg_flags (void)
|
|||
MuMsg *msg;
|
||||
MuFlags flags;
|
||||
|
||||
g_assert ((msg = mu_msg_new_from_file (msgflags[u].path, NULL, NULL)));
|
||||
g_assert ((msg = mu_msg_new_from_file
|
||||
(msgflags[u].path, NULL, NULL)));
|
||||
flags = mu_msg_get_flags (msg);
|
||||
|
||||
if (g_test_verbose())
|
||||
g_print ("=> %s [ %s, %u] <=> [ %s, %u]\n",
|
||||
msgflags[u].path,
|
||||
mu_flags_to_str_s(msgflags[u].flags, MU_FLAG_TYPE_ANY),
|
||||
mu_flags_to_str_s(msgflags[u].flags,
|
||||
MU_FLAG_TYPE_ANY),
|
||||
(unsigned)msgflags[u].flags,
|
||||
mu_flags_to_str_s(flags, MU_FLAG_TYPE_ANY),
|
||||
(unsigned)flags);
|
||||
|
@ -381,7 +383,10 @@ test_mu_msg_tags (void)
|
|||
tags = mu_msg_get_tags (msg);
|
||||
g_assert_cmpstr ((char*)tags->data,==,"Paradise");
|
||||
g_assert_cmpstr ((char*)tags->next->data,==,"losT");
|
||||
g_assert (tags->next->next == NULL);
|
||||
g_assert_cmpstr ((char*)tags->next->next->data,==,"john");
|
||||
g_assert_cmpstr ((char*)tags->next->next->next->data,==,"milton");
|
||||
|
||||
g_assert (!tags->next->next->next->next);
|
||||
|
||||
mu_msg_unref (msg);
|
||||
}
|
||||
|
@ -463,7 +468,8 @@ main (int argc, char *argv[])
|
|||
test_mu_msg_comp_unix_programmer);
|
||||
|
||||
g_log_set_handler (NULL,
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL|
|
||||
G_LOG_FLAG_RECURSION,
|
||||
(GLogFunc)black_hole, NULL);
|
||||
|
||||
rv = g_test_run ();
|
||||
|
|
|
@ -4,7 +4,8 @@ Subject: Fere libenter homines id quod volunt credunt
|
|||
To: "Julius Caesar" <jc@example.com>
|
||||
Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com>
|
||||
MIME-version: 1.0
|
||||
x-label: Paradise, losT
|
||||
x-label: Paradise losT
|
||||
X-keywords: john, milton
|
||||
Content-type: text/plain; charset=us-ascii
|
||||
Content-transfer-encoding: 7BIT
|
||||
Precedence: high
|
||||
|
@ -34,4 +35,4 @@ And mad'st it pregnant: What in me is dark
|
|||
Illumin, what is low raise and support;
|
||||
That to the highth of this great Argument
|
||||
I may assert Eternal Providence, [ 25 ]
|
||||
And justifie the wayes of God to men.
|
||||
And justifie the wayes of God to men.
|
||||
|
|
Loading…
Reference in New Issue