* start of XML output support (WIP)

This commit is contained in:
Dirk-Jan C. Binnema 2011-01-05 22:46:10 +02:00
parent 2303bc4f59
commit 4409b565dc
6 changed files with 87 additions and 7 deletions

2
TODO
View File

@ -12,6 +12,8 @@
** release 0.9.2 [20%]
- [ ] xml,json,sexp output
- [ ] check all strings are really UTF8
- [ ] fix size value
- [ ] separate exit code for 'not found' vs other errors
- [ ] fix build for Solaris
- [X] clearer errors when /home/user does not exist

View File

@ -186,7 +186,7 @@ mu_msg_iter_get_field (MuMsgIter *iter, MuMsgFieldId mfid)
g_return_val_if_fail (mu_msg_field_id_is_valid(mfid), NULL);
try {
if (!iter->_str[mfid]) { /* cache the value */
if (!iter->_str[mfid]) { /* cache the value */
Xapian::Document doc (iter->_cursor.get_document());
iter->_str[mfid] =
g_strdup (doc.get_value(mfid).c_str());
@ -248,6 +248,13 @@ mu_msg_iter_get_maildir (MuMsgIter *iter)
return mu_msg_iter_get_field (iter, MU_MSG_FIELD_ID_MAILDIR);
}
const char*
mu_msg_iter_get_msgid (MuMsgIter *iter)
{
g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL);
return mu_msg_iter_get_field (iter, MU_MSG_FIELD_ID_MSGID);
}
const char*

View File

@ -109,8 +109,20 @@ const char* mu_msg_iter_get_path (MuMsgIter *iter);
const char* mu_msg_iter_get_maildir (MuMsgIter *iter);
/**
* get the size of the message
* get the msgid of the message
*
* @param iter a valid MuMsgIter iterator
*
* @return the msgid or NULL in case of error
*/
const char* mu_msg_iter_get_msgid (MuMsgIter *iter);
/**
* get the size of the message in Kb
*
* @param iter a valid MuMsgIter iterator
*

View File

@ -206,7 +206,6 @@ mu_output_plain (MuMsgIter *iter, const char *fields, size_t summary_len,
int len;
for (myfields = fields, len = 0; *myfields; ++myfields) {
MuMsgFieldId mfid;
mfid = mu_msg_field_id_from_shortcut (*myfields, FALSE);
@ -229,15 +228,55 @@ mu_output_plain (MuMsgIter *iter, const char *fields, size_t summary_len,
return TRUE;
}
static void
print_attr (const char* elm, const char *str)
{
gchar *esc;
if (!str || strlen(str) == 0)
return; /* empty: don't include */
esc = mu_str_escape_xml (str);
g_print ("\t\t<%s>%s</%s>\n", elm, esc, elm);
g_free (esc);
}
gboolean
mu_output_xml (MuMsgIter *iter, size_t *count)
{
g_print ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
g_print ("%s\n", __FUNCTION__);
return TRUE;
MuMsgIter *myiter;
size_t mycount;
g_return_val_if_fail (iter, FALSE);
g_print ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
g_print ("<messages>\n");
for (myiter = iter, mycount = 0; !mu_msg_iter_is_done (myiter);
mu_msg_iter_next (myiter), ++mycount) {
g_print ("\t<message>\n");
print_attr ("from", mu_msg_iter_get_from (iter));
print_attr ("to", mu_msg_iter_get_to (iter));
print_attr ("cc", mu_msg_iter_get_cc (iter));
print_attr ("subject", mu_msg_iter_get_subject (iter));
g_print ("\t\t<date>%u</date>\n",
(unsigned) mu_msg_iter_get_date (iter));
g_print ("\t\t<size>%u</size>\n",
(unsigned) mu_msg_iter_get_size (iter));
print_attr ("msgid", mu_msg_iter_get_msgid (iter));
print_attr ("path", mu_msg_iter_get_path (iter));
print_attr ("maildir", mu_msg_iter_get_maildir (iter));
g_print ("\t</message>\n");
}
g_print ("</messages>\n");
if (count)
*count = mycount;
return TRUE;
}
gboolean

View File

@ -368,3 +368,12 @@ mu_str_fullpath_s (const char* path, const char* name)
return buf;
}
char*
mu_str_escape_xml (const gchar* str)
{
if (!str)
return NULL;
return g_markup_escape_text (str, -1);
}

View File

@ -220,6 +220,17 @@ time_t mu_str_date_parse_hdwmy (const char* str);
*/
const char* mu_str_fullpath_s (const char* path, const char* name);
/**
* escape string for inclusion in XML-data
*
* @param str a str or NULL
*
* @return the escaped version of the string; g_free when you're done
* with it.
*/
char* mu_str_escape_xml (const gchar* str);
G_END_DECLS
#endif /*__MU_STR_H__*/