mirror of https://github.com/djcb/mu.git
* add some mu-msg-gmime unit tests
This commit is contained in:
parent
537dd1b3a1
commit
52e6fa5f32
1
TODO
1
TODO
|
@ -24,6 +24,7 @@
|
||||||
- [X] fix rhel5 installation issue
|
- [X] fix rhel5 installation issue
|
||||||
- [X] don't require gio
|
- [X] don't require gio
|
||||||
- [X] summary
|
- [X] summary
|
||||||
|
- [ ] attachment handling
|
||||||
- [ ] review docs
|
- [ ] review docs
|
||||||
- [ ] xml,json,sexp output
|
- [ ] xml,json,sexp output
|
||||||
|
|
||||||
|
|
4
gtest.mk
4
gtest.mk
|
@ -23,4 +23,6 @@ test: all $(TEST_PROGS)
|
||||||
test "$$subdir" = "." || \
|
test "$$subdir" = "." || \
|
||||||
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $$? ; \
|
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $$? ; \
|
||||||
done
|
done
|
||||||
.PHONY: test
|
|
||||||
|
.PHONY: test gprof
|
||||||
|
|
||||||
|
|
|
@ -772,6 +772,24 @@ mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
mu_msg_gmime_attach_foreach (MuMsgGMime* msg, MuMsgGMimeAttachForeachFunc func,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
/* FIXME */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
mu_msg_gmime_save_attachment (MuMsgGMime *msg, unsigned num,
|
||||||
|
const char *targetdir)
|
||||||
|
{
|
||||||
|
return TRUE; /* FIXME */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_gmime_get_field_string (MuMsgGMime *msg, const MuMsgField* field)
|
mu_msg_gmime_get_field_string (MuMsgGMime *msg, const MuMsgField* field)
|
||||||
{
|
{
|
||||||
|
@ -844,8 +862,8 @@ fill_contact (MuMsgContact *contact, InternetAddress *addr,
|
||||||
static int
|
static int
|
||||||
address_list_foreach (InternetAddressList *addrlist,
|
address_list_foreach (InternetAddressList *addrlist,
|
||||||
MuMsgContactType ctype,
|
MuMsgContactType ctype,
|
||||||
MuMsgGMimeContactsCallback cb,
|
MuMsgGMimeContactsForeachFunc func,
|
||||||
void *ptr)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
int i,rv;
|
int i,rv;
|
||||||
|
|
||||||
|
@ -862,7 +880,7 @@ address_list_foreach (InternetAddressList *addrlist,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = (cb)(&contact, ptr);
|
rv = (func)(&contact, user_data);
|
||||||
if (rv != 0)
|
if (rv != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -872,8 +890,8 @@ address_list_foreach (InternetAddressList *addrlist,
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mu_msg_gmime_get_contacts_from (MuMsgGMime *msg, MuMsgGMimeContactsCallback cb,
|
mu_msg_gmime_get_contacts_from (MuMsgGMime *msg, MuMsgGMimeContactsForeachFunc func,
|
||||||
void *ptr)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
InternetAddressList *list;
|
InternetAddressList *list;
|
||||||
int rv;
|
int rv;
|
||||||
|
@ -886,7 +904,7 @@ mu_msg_gmime_get_contacts_from (MuMsgGMime *msg, MuMsgGMimeContactsCallback cb,
|
||||||
list = internet_address_list_parse_string (
|
list = internet_address_list_parse_string (
|
||||||
g_mime_message_get_sender (msg->_mime_msg));
|
g_mime_message_get_sender (msg->_mime_msg));
|
||||||
|
|
||||||
rv = address_list_foreach (list, MU_MSG_CONTACT_TYPE_FROM, cb, ptr);
|
rv = address_list_foreach (list, MU_MSG_CONTACT_TYPE_FROM, func, user_data);
|
||||||
|
|
||||||
if (list)
|
if (list)
|
||||||
g_object_unref (G_OBJECT(list));
|
g_object_unref (G_OBJECT(list));
|
||||||
|
@ -895,9 +913,9 @@ mu_msg_gmime_get_contacts_from (MuMsgGMime *msg, MuMsgGMimeContactsCallback cb,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
void
|
||||||
mu_msg_gmime_get_contacts_foreach (MuMsgGMime *msg, MuMsgGMimeContactsCallback cb,
|
mu_msg_gmime_contacts_foreach (MuMsgGMime *msg, MuMsgGMimeContactsForeachFunc func,
|
||||||
void *ptr)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
int i, rv;
|
int i, rv;
|
||||||
struct {
|
struct {
|
||||||
|
@ -909,23 +927,21 @@ mu_msg_gmime_get_contacts_foreach (MuMsgGMime *msg, MuMsgGMimeContactsCallback c
|
||||||
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
||||||
};
|
};
|
||||||
|
|
||||||
g_return_val_if_fail (cb && msg, -1);
|
g_return_if_fail (func && msg);
|
||||||
|
|
||||||
/* first, get the from address */
|
/* first, get the from address */
|
||||||
rv = mu_msg_gmime_get_contacts_from (msg, cb, ptr);
|
rv = mu_msg_gmime_get_contacts_from (msg, func, user_data);
|
||||||
if (rv != 0)
|
if (rv != 0)
|
||||||
return rv; /* callback told us to stop */
|
return; /* callback told us to stop */
|
||||||
|
|
||||||
for (i = 0, rv = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
for (i = 0, rv = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
||||||
InternetAddressList *addrlist;
|
InternetAddressList *addrlist;
|
||||||
addrlist = g_mime_message_get_recipients (msg->_mime_msg,
|
addrlist = g_mime_message_get_recipients (msg->_mime_msg,
|
||||||
ctypes[i]._gmime_type);
|
ctypes[i]._gmime_type);
|
||||||
rv = address_list_foreach (addrlist, ctypes[i]._type,cb, ptr);
|
rv = address_list_foreach (addrlist, ctypes[i]._type, func, user_data);
|
||||||
if (rv != 0)
|
if (rv != 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,46 @@ const char* mu_msg_gmime_get_body_html (MuMsgGMime *msg);
|
||||||
*/
|
*/
|
||||||
const char* mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines);
|
const char* mu_msg_gmime_get_summary (MuMsgGMime *msg, size_t max_lines);
|
||||||
|
|
||||||
|
|
||||||
|
struct _MuMsgGMimeAttach {
|
||||||
|
unsigned index; /* index of the attachment (names may not be unique) */
|
||||||
|
const char* name; /* name of the attachment */
|
||||||
|
size_t size; /* size in bytes, or 0 if not available */
|
||||||
|
const char* mime_type; /* the mime type */
|
||||||
|
};
|
||||||
|
typedef struct _MuMsgGMimeAttach MuMsgGMimeAttach;
|
||||||
|
|
||||||
|
typedef gboolean (*MuMsgGMimeAttachForeachFunc) (MuMsgGMimeAttach *att, gpointer data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call a user function for each attachment found in the message. the
|
||||||
|
* function will be calle d for each attachment and as long a the
|
||||||
|
* user-function returns TRUE
|
||||||
|
*
|
||||||
|
* @param msg a valid MuMsgGMime
|
||||||
|
* @param the function to call (callback)
|
||||||
|
* @param user_data a user pointer which will be passed to the callback function
|
||||||
|
*
|
||||||
|
* @return a list of attachment
|
||||||
|
*/
|
||||||
|
void mu_msg_gmime_attach_foreach (MuMsgGMime* msg,
|
||||||
|
MuMsgGMimeAttachForeachFunc func,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save a specific attachment to some targetdir
|
||||||
|
*
|
||||||
|
* @param msg a valid MuMsgGMime instance
|
||||||
|
* @param index index of the attachment you want to save
|
||||||
|
* @param targetdir filesystem directory to save the attachment
|
||||||
|
*
|
||||||
|
* @return TRUE if saving succeeded, FALSE otherwise
|
||||||
|
*/
|
||||||
|
gboolean mu_msg_gmime_save_attachment (MuMsgGMime *msg, unsigned num,
|
||||||
|
const char *targetdir);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the sender (From:) of this message
|
* get the sender (From:) of this message
|
||||||
*
|
*
|
||||||
|
@ -199,9 +239,7 @@ const char* mu_msg_gmime_get_msgid (MuMsgGMime *msg);
|
||||||
* is no such header. the returned string should *not* be modified or freed.
|
* is no such header. the returned string should *not* be modified or freed.
|
||||||
*/
|
*/
|
||||||
const char* mu_msg_gmime_get_header (MuMsgGMime *msg,
|
const char* mu_msg_gmime_get_header (MuMsgGMime *msg,
|
||||||
const char* header);
|
const char* header);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the message date/time (the Date: field) as time_t, using UTC
|
* get the message date/time (the Date: field) as time_t, using UTC
|
||||||
|
@ -278,25 +316,21 @@ MuMsgPriority mu_msg_gmime_get_priority (MuMsgGMime *msg);
|
||||||
*/
|
*/
|
||||||
time_t mu_msg_gmime_get_timestamp (MuMsgGMime *msg);
|
time_t mu_msg_gmime_get_timestamp (MuMsgGMime *msg);
|
||||||
|
|
||||||
|
typedef gboolean (*MuMsgGMimeContactsForeachFunc) (MuMsgContact* contact,
|
||||||
typedef int (*MuMsgGMimeContactsCallback) (MuMsgContact*, void *ptr);
|
gpointer user_data);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* call a function for each of the contacts in a message
|
* call a function for each of the contacts in a message
|
||||||
*
|
*
|
||||||
* @param msg a valid MuMsgGMime* instance
|
* @param msg a valid MuMsgGMime* instance
|
||||||
* @param cb a callback function to call for each contact; when
|
* @param func a callback function to call for each contact; when
|
||||||
* the callback returns non-0, the function stops, and this last
|
* the callback does not return TRUE, it won't be called again
|
||||||
* callback return value is returned
|
* @param user_data a user-provide pointer that will be passed to the callback
|
||||||
* @param ptr a user-provide pointer that will be passed to the callback
|
|
||||||
*
|
*
|
||||||
* @return 0 if the callback was called for each recipient, -1 if there
|
|
||||||
* was an error and any other != 0 number the callback returned
|
|
||||||
*/
|
*/
|
||||||
int mu_msg_gmime_get_contacts_foreach (MuMsgGMime *msg,
|
void mu_msg_gmime_contacts_foreach (MuMsgGMime *msg,
|
||||||
MuMsgGMimeContactsCallback cb,
|
MuMsgGMimeContactsForeachFunc func,
|
||||||
void *ptr);
|
gpointer user_data);
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /*__MU_MSG_GIME_H__*/
|
#endif /*__MU_MSG_GIME_H__*/
|
||||||
|
|
|
@ -44,6 +44,11 @@ TEST_PROGS += test-mu-query
|
||||||
test_mu_query_SOURCES= test-mu-query.c dummy.cc
|
test_mu_query_SOURCES= test-mu-query.c dummy.cc
|
||||||
test_mu_query_LDADD= libtestmucommon.la
|
test_mu_query_LDADD= libtestmucommon.la
|
||||||
|
|
||||||
|
TEST_PROGS += test-mu-msg-gmime
|
||||||
|
test_mu_msg_gmime_SOURCES= test-mu-msg-gmime.c
|
||||||
|
test_mu_msg_gmime_LDADD= libtestmucommon.la
|
||||||
|
|
||||||
|
|
||||||
libtestmucommon_la_SOURCES= \
|
libtestmucommon_la_SOURCES= \
|
||||||
test-mu-common.c \
|
test-mu-common.c \
|
||||||
test-mu-common.h
|
test-mu-common.h
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
|
**
|
||||||
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
** Free Software Foundation; either version 3, or (at your option) any
|
||||||
|
** later version.
|
||||||
|
**
|
||||||
|
** This program is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with this program; if not, write to the Free Software Foundation,
|
||||||
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif /*HAVE_CONFIG_H*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
#include "test-mu-common.h"
|
||||||
|
#include "src/mu-msg-gmime.h"
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
get_mailpath (unsigned idx)
|
||||||
|
{
|
||||||
|
const char* mailfile;
|
||||||
|
|
||||||
|
switch (idx) {
|
||||||
|
case 1: mailfile = "cur/1220863042.12663_1.mindcrime!2,S"; break;
|
||||||
|
case 2: mailfile = "cur/1220863087.12663_19.mindcrime!2,S"; break;
|
||||||
|
default: mailfile = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mailfile)
|
||||||
|
return g_strdup_printf ("%s/%s", MU_TESTMAILDIR, mailfile);
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_msg_gmime_01 (void)
|
||||||
|
{
|
||||||
|
char *mfile;
|
||||||
|
MuMsgGMime *msg;
|
||||||
|
|
||||||
|
mu_msg_gmime_init ();
|
||||||
|
mfile = get_mailpath (1);
|
||||||
|
|
||||||
|
msg = mu_msg_gmime_new (mfile, NULL);
|
||||||
|
|
||||||
|
g_assert_cmpstr (mu_msg_gmime_get_to(msg),
|
||||||
|
==, "gcc-help@gcc.gnu.org");
|
||||||
|
g_assert_cmpstr (mu_msg_gmime_get_subject(msg),
|
||||||
|
==, "gcc include search order");
|
||||||
|
g_assert_cmpstr (mu_msg_gmime_get_from(msg),
|
||||||
|
==, "anon@example.com");
|
||||||
|
g_assert_cmpstr (mu_msg_gmime_get_msgid(msg),
|
||||||
|
==, "3BE9E6535E3029448670913581E7A1A20D852173@"
|
||||||
|
"emss35m06.us.lmco.com");
|
||||||
|
g_assert_cmpuint (mu_msg_gmime_get_priority(msg), /* 'klub' */
|
||||||
|
==, MU_MSG_PRIORITY_NORMAL);
|
||||||
|
g_assert_cmpuint (mu_msg_gmime_get_date(msg),
|
||||||
|
==, 1217530645);
|
||||||
|
|
||||||
|
mu_msg_gmime_destroy (msg);
|
||||||
|
|
||||||
|
g_free (mfile);
|
||||||
|
mu_msg_gmime_uninit ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
ignore_error (const char* log_domain, GLogLevelFlags log_level, const gchar* msg,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
return FALSE; /* don't abort */
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
shutup (void) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
/* mu_msg_str_date */
|
||||||
|
g_test_add_func ("/mu-msg-gmime/mu-msg-gmime",
|
||||||
|
test_mu_msg_gmime_01);
|
||||||
|
|
||||||
|
g_log_set_handler (NULL,
|
||||||
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||||
|
(GLogFunc)shutup, NULL);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
|
}
|
Loading…
Reference in New Issue