* lib/tests: support X-Label and X-Keywords, update unit test

This commit is contained in:
djcb
2012-08-09 10:01:06 +03:00
parent abfcc4a2f3
commit cb17e22d48
3 changed files with 83 additions and 80 deletions

View File

@ -527,91 +527,91 @@ mu_msg_mime_get_body_part (GMimeMessage *msg, gboolean decrypt,
static char* /* static char* */
get_body (MuMsgFile *self, gboolean decrypt, gboolean want_html) /* get_body (MuMsgFile *self, gboolean decrypt, gboolean want_html) */
{ /* { */
GMimePart *part; /* GMimePart *part; */
gboolean err; /* gboolean err; */
gchar *str; /* gchar *str; */
g_return_val_if_fail (self, NULL); /* g_return_val_if_fail (self, NULL); */
g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); /* g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); */
part = mu_msg_mime_get_body_part (self->_mime_msg, /* part = mu_msg_mime_get_body_part (self->_mime_msg, */
decrypt, want_html); /* decrypt, want_html); */
if (!GMIME_IS_PART(part)) /* if (!GMIME_IS_PART(part)) */
return NULL; /* return NULL; */
err = FALSE; /* err = FALSE; */
str = mu_msg_mime_part_to_string (part, &err); /* str = mu_msg_mime_part_to_string (part, &err); */
/* note, str may be NULL (no body), but that's not necessarily /* /\* note, str may be NULL (no body), but that's not necessarily */
* an error; we only warn when an actual error occured */ /* * an error; we only warn when an actual error occured *\/ */
if (err) /* if (err) */
g_warning ("error occured while retrieving %s body " /* g_warning ("error occured while retrieving %s body " */
"for message %s", /* "for message %s", */
want_html ? "html" : "text", self->_path); /* want_html ? "html" : "text", self->_path); */
return str; /* return str; */
} /* } */
static void /* static void */
append_text (GMimeObject *parent, GMimeObject *part, gchar **txt) /* append_text (GMimeObject *parent, GMimeObject *part, gchar **txt) */
{ /* { */
GMimeContentType *ct; /* GMimeContentType *ct; */
GMimeContentDisposition *disp; /* GMimeContentDisposition *disp; */
gchar *parttxt, *tmp; /* gchar *parttxt, *tmp; */
gboolean err; /* gboolean err; */
if (!GMIME_IS_PART(part)) /* if (!GMIME_IS_PART(part)) */
return; /* return; */
ct = g_mime_object_get_content_type (part); /* ct = g_mime_object_get_content_type (part); */
if (!GMIME_IS_CONTENT_TYPE(ct) || /* if (!GMIME_IS_CONTENT_TYPE(ct) || */
!g_mime_content_type_is_type (ct, "text", "plain")) /* !g_mime_content_type_is_type (ct, "text", "plain")) */
return; /* not a text-plain part */ /* return; /\* not a text-plain part *\/ */
disp = g_mime_object_get_content_disposition (part); /* disp = g_mime_object_get_content_disposition (part); */
if (GMIME_IS_CONTENT_DISPOSITION(disp) && /* if (GMIME_IS_CONTENT_DISPOSITION(disp) && */
g_strcmp0 (g_mime_content_disposition_get_disposition (disp), /* g_strcmp0 (g_mime_content_disposition_get_disposition (disp), */
GMIME_DISPOSITION_ATTACHMENT) == 0) /* GMIME_DISPOSITION_ATTACHMENT) == 0) */
return; /* it's an attachment, don't include */ /* return; /\* it's an attachment, don't include *\/ */
parttxt = mu_msg_mime_part_to_string (GMIME_PART(part), &err); /* parttxt = mu_msg_mime_part_to_string (GMIME_PART(part), &err); */
if (err) { /* if (err) { */
/* this happens for broken messages */ /* /\* this happens for broken messages *\/ */
g_debug ("%s: could not get text for part", __FUNCTION__); /* g_debug ("%s: could not get text for part", __FUNCTION__); */
return; /* return; */
} /* } */
/* it's a text part -- append it! */ /* /\* it's a text part -- append it! *\/ */
tmp = *txt; /* tmp = *txt; */
if (*txt) { /* if (*txt) { */
*txt = g_strconcat (*txt, parttxt, NULL); /* *txt = g_strconcat (*txt, parttxt, NULL); */
g_free (parttxt); /* g_free (parttxt); */
} else /* } else */
*txt = parttxt; /* *txt = parttxt; */
g_free (tmp); /* g_free (tmp); */
} /* } */
/* instead of just the body, this function returns a concatenation of /* instead of just the body, this function returns a concatenation of
* all text/plain parts with inline disposition * all text/plain parts with inline disposition
*/ */
static char* /* static char* */
get_concatenated_text (MuMsgFile *self, gboolean decrypt) /* get_concatenated_text (MuMsgFile *self, gboolean decrypt) */
{ /* { */
char *txt; /* char *txt; */
g_return_val_if_fail (self, NULL); /* g_return_val_if_fail (self, NULL); */
g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); /* g_return_val_if_fail (GMIME_IS_MESSAGE(self->_mime_msg), NULL); */
txt = NULL; /* txt = NULL; */
mu_mime_message_foreach (self->_mime_msg, decrypt, /* mu_mime_message_foreach (self->_mime_msg, decrypt, */
(GMimeObjectForeachFunc)append_text, /* (GMimeObjectForeachFunc)append_text, */
&txt); /* &txt); */
return txt; /* return txt; */
} /* } */
static gboolean static gboolean
@ -651,7 +651,8 @@ get_references (MuMsgFile *self)
if (msgid && !contains (msgids, msgid)) if (msgid && !contains (msgids, msgid))
/* explicitly ensure it's utf8-safe, as GMime /* explicitly ensure it's utf8-safe, as GMime
* does not ensure that */ * 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); g_mime_references_free (mime_refs);
} }
@ -687,7 +688,7 @@ get_tags (MuMsgFile *self)
last = g_slist_last (lst1); last = g_slist_last (lst1);
last->next = lst2; 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; case MU_MSG_FIELD_ID_TO: *do_free = TRUE;
return get_recipient (self, recipient_type(mfid)); 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: case MU_MSG_FIELD_ID_FROM:
return (char*)maybe_cleanup return (char*)maybe_cleanup
(g_mime_message_get_sender (self->_mime_msg), (g_mime_message_get_sender (self->_mime_msg),

View File

@ -255,13 +255,15 @@ test_mu_msg_flags (void)
MuMsg *msg; MuMsg *msg;
MuFlags flags; 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); flags = mu_msg_get_flags (msg);
if (g_test_verbose()) if (g_test_verbose())
g_print ("=> %s [ %s, %u] <=> [ %s, %u]\n", g_print ("=> %s [ %s, %u] <=> [ %s, %u]\n",
msgflags[u].path, 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, (unsigned)msgflags[u].flags,
mu_flags_to_str_s(flags, MU_FLAG_TYPE_ANY), mu_flags_to_str_s(flags, MU_FLAG_TYPE_ANY),
(unsigned)flags); (unsigned)flags);
@ -381,7 +383,10 @@ test_mu_msg_tags (void)
tags = mu_msg_get_tags (msg); tags = mu_msg_get_tags (msg);
g_assert_cmpstr ((char*)tags->data,==,"Paradise"); g_assert_cmpstr ((char*)tags->data,==,"Paradise");
g_assert_cmpstr ((char*)tags->next->data,==,"losT"); 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); mu_msg_unref (msg);
} }
@ -463,7 +468,8 @@ main (int argc, char *argv[])
test_mu_msg_comp_unix_programmer); test_mu_msg_comp_unix_programmer);
g_log_set_handler (NULL, 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); (GLogFunc)black_hole, NULL);
rv = g_test_run (); rv = g_test_run ();

View File

@ -4,7 +4,8 @@ Subject: Fere libenter homines id quod volunt credunt
To: "Julius Caesar" <jc@example.com> To: "Julius Caesar" <jc@example.com>
Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com> Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com>
MIME-version: 1.0 MIME-version: 1.0
x-label: Paradise, losT x-label: Paradise losT
X-keywords: john, milton
Content-type: text/plain; charset=us-ascii Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT Content-transfer-encoding: 7BIT
Precedence: high Precedence: high
@ -34,4 +35,4 @@ And mad'st it pregnant: What in me is dark
Illumin, what is low raise and support; Illumin, what is low raise and support;
That to the highth of this great Argument That to the highth of this great Argument
I may assert Eternal Providence, [ 25 ] I may assert Eternal Providence, [ 25 ]
And justifie the wayes of God to men. And justifie the wayes of God to men.