From 7766d8db9ca42f25dafb872d1788052d29695027 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 9 May 2011 09:33:01 +0300 Subject: [PATCH 01/12] * mu-msg.c: fix indentation --- src/mu-msg.c | 1028 +++++++++++++++++++++++++------------------------- 1 file changed, 514 insertions(+), 514 deletions(-) diff --git a/src/mu-msg.c b/src/mu-msg.c index f8ce9122..17c5c14c 100644 --- a/src/mu-msg.c +++ b/src/mu-msg.c @@ -43,87 +43,87 @@ static gboolean _gmime_initialized = FALSE; void mu_msg_gmime_init (void) { - g_return_if_fail (!_gmime_initialized); + g_return_if_fail (!_gmime_initialized); #ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS - g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); + g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); #else - g_mime_init(0); + g_mime_init(0); #endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */ - _gmime_initialized = TRUE; + _gmime_initialized = TRUE; } void mu_msg_gmime_uninit (void) { - g_return_if_fail (_gmime_initialized); + g_return_if_fail (_gmime_initialized); - g_mime_shutdown(); - _gmime_initialized = FALSE; + g_mime_shutdown(); + _gmime_initialized = FALSE; } static void mu_msg_destroy (MuMsg *msg) { - int i; + int i; - if (!msg) - return; + if (!msg) + return; - if (G_IS_OBJECT(msg->_mime_msg)) { - g_object_unref (msg->_mime_msg); - msg->_mime_msg = NULL; - } + if (G_IS_OBJECT(msg->_mime_msg)) { + g_object_unref (msg->_mime_msg); + msg->_mime_msg = NULL; + } - for (i = 0; i != FIELD_NUM; ++i) - g_free (msg->_fields[i]); + for (i = 0; i != FIELD_NUM; ++i) + g_free (msg->_fields[i]); - g_slist_foreach (msg->_refs, (GFunc)g_free, NULL); - g_slist_free (msg->_refs); + g_slist_foreach (msg->_refs, (GFunc)g_free, NULL); + g_slist_free (msg->_refs); - g_slice_free (MuMsg, msg); + g_slice_free (MuMsg, msg); } static gboolean init_file_metadata (MuMsg* msg, const char* path, const gchar* mdir, - GError **err) + GError **err) { - struct stat statbuf; + struct stat statbuf; - if (access (path, R_OK) != 0) { - g_set_error (err, 0, MU_ERROR_FILE, - "cannot read file %s: %s", - path, strerror(errno)); - return FALSE; - } + if (access (path, R_OK) != 0) { + g_set_error (err, 0, MU_ERROR_FILE, + "cannot read file %s: %s", + path, strerror(errno)); + return FALSE; + } - if (stat (path, &statbuf) < 0) { - g_set_error (err, 0, MU_ERROR_FILE, - "cannot stat %s: %s", - path, strerror(errno)); - return FALSE; - } + if (stat (path, &statbuf) < 0) { + g_set_error (err, 0, MU_ERROR_FILE, + "cannot stat %s: %s", + path, strerror(errno)); + return FALSE; + } - if (!S_ISREG(statbuf.st_mode)) { - g_set_error (err, 0, MU_ERROR_FILE, - "not a regular file: %s", path); - return FALSE; - } + if (!S_ISREG(statbuf.st_mode)) { + g_set_error (err, 0, MU_ERROR_FILE, + "not a regular file: %s", path); + return FALSE; + } - msg->_timestamp = statbuf.st_mtime; - /* size_t should be enough for message size... */ - msg->_size = (size_t)statbuf.st_size; - msg->_fields[PATH_FIELD] = strdup (path); + msg->_timestamp = statbuf.st_mtime; + /* size_t should be enough for message size... */ + msg->_size = (size_t)statbuf.st_size; + msg->_fields[PATH_FIELD] = strdup (path); - /* FIXME: maybe try to derive it from the path? */ - if (mdir) - msg->_fields[MDIR_FIELD] = strdup (mdir); + /* FIXME: maybe try to derive it from the path? */ + if (mdir) + msg->_fields[MDIR_FIELD] = strdup (mdir); - return TRUE; + return TRUE; } @@ -131,140 +131,140 @@ init_file_metadata (MuMsg* msg, const char* path, const gchar* mdir, static GMimeStream* get_mime_stream (MuMsg *msg, GError **err) { - FILE *file; - GMimeStream *stream; + FILE *file; + GMimeStream *stream; - file = fopen (mu_msg_get_path(msg), "r"); - if (!file) { - g_set_error (err, 0, MU_ERROR_FILE, - "cannot open %s: %s", mu_msg_get_path(msg), - strerror (errno)); - return NULL; - } + file = fopen (mu_msg_get_path(msg), "r"); + if (!file) { + g_set_error (err, 0, MU_ERROR_FILE, + "cannot open %s: %s", mu_msg_get_path(msg), + strerror (errno)); + return NULL; + } - stream = g_mime_stream_file_new (file); - if (!stream) { - g_set_error (err, 0, MU_ERROR_GMIME, - "cannot create mime stream for %s", - mu_msg_get_path(msg)); - fclose (file); - return NULL; - } + stream = g_mime_stream_file_new (file); + if (!stream) { + g_set_error (err, 0, MU_ERROR_GMIME, + "cannot create mime stream for %s", + mu_msg_get_path(msg)); + fclose (file); + return NULL; + } - return stream; + return stream; } static gboolean init_mime_msg (MuMsg *msg, GError **err) { - GMimeStream *stream; - GMimeParser *parser; + GMimeStream *stream; + GMimeParser *parser; - stream = get_mime_stream (msg, err); - if (!stream) - return FALSE; + stream = get_mime_stream (msg, err); + if (!stream) + return FALSE; - parser = g_mime_parser_new_with_stream (stream); - g_object_unref (stream); - if (!parser) { - g_set_error (err, 0, MU_ERROR_GMIME, - "cannot create mime parser for %s", - mu_msg_get_path(msg)); - return FALSE; - } + parser = g_mime_parser_new_with_stream (stream); + g_object_unref (stream); + if (!parser) { + g_set_error (err, 0, MU_ERROR_GMIME, + "cannot create mime parser for %s", + mu_msg_get_path(msg)); + return FALSE; + } - msg->_mime_msg = g_mime_parser_construct_message (parser); - g_object_unref (parser); - if (!msg->_mime_msg) { - g_set_error (err, 0, MU_ERROR_GMIME, - "cannot construct mime message for %s", - mu_msg_get_path(msg)); - return FALSE; - } + msg->_mime_msg = g_mime_parser_construct_message (parser); + g_object_unref (parser); + if (!msg->_mime_msg) { + g_set_error (err, 0, MU_ERROR_GMIME, + "cannot construct mime message for %s", + mu_msg_get_path(msg)); + return FALSE; + } - return TRUE; + return TRUE; } MuMsg* mu_msg_ref (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - ++msg->_refcount; + ++msg->_refcount; - return msg; + return msg; } void mu_msg_unref (MuMsg *msg) { - g_return_if_fail (msg); - g_return_if_fail (msg->_refcount >= 1); + g_return_if_fail (msg); + g_return_if_fail (msg->_refcount >= 1); - if (--msg->_refcount == 0) - mu_msg_destroy (msg); + if (--msg->_refcount == 0) + mu_msg_destroy (msg); } MuMsg* mu_msg_new (const char* filepath, const gchar* mdir, GError **err) { - MuMsg *msg; + MuMsg *msg; - g_return_val_if_fail (filepath, NULL); - g_return_val_if_fail (_gmime_initialized, NULL); + g_return_val_if_fail (filepath, NULL); + g_return_val_if_fail (_gmime_initialized, NULL); - msg = g_slice_new0 (MuMsg); - msg->_prio = MU_MSG_PRIO_NONE; - msg->_refcount = 1; - msg->_refs = NULL; + msg = g_slice_new0 (MuMsg); + msg->_prio = MU_MSG_PRIO_NONE; + msg->_refcount = 1; + msg->_refs = NULL; - if (!init_file_metadata(msg, filepath, mdir, err)) { - mu_msg_unref (msg); - return NULL; - } + if (!init_file_metadata(msg, filepath, mdir, err)) { + mu_msg_unref (msg); + return NULL; + } - if (!init_mime_msg(msg, err)) { - mu_msg_unref (msg); - return NULL; - } + if (!init_mime_msg(msg, err)) { + mu_msg_unref (msg); + return NULL; + } - return msg; + return msg; } const char* mu_msg_get_path (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - return msg->_fields[PATH_FIELD]; + return msg->_fields[PATH_FIELD]; } const char* mu_msg_get_subject (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - return g_mime_message_get_subject (msg->_mime_msg); + return g_mime_message_get_subject (msg->_mime_msg); } const char* mu_msg_get_msgid (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - return g_mime_message_get_message_id (msg->_mime_msg); + return g_mime_message_get_message_id (msg->_mime_msg); } const char* mu_msg_get_maildir (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - return msg->_fields[MDIR_FIELD]; + return msg->_fields[MDIR_FIELD]; } @@ -272,113 +272,113 @@ mu_msg_get_maildir (MuMsg *msg) const char* mu_msg_get_from (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - return g_mime_message_get_sender (msg->_mime_msg); + return g_mime_message_get_sender (msg->_mime_msg); } static const char* get_recipient (MuMsg *msg, GMimeRecipientType rtype, StringFields field) { - /* can only be set once */ - if (!msg->_fields[field]) { + /* can only be set once */ + if (!msg->_fields[field]) { - char *recep; - InternetAddressList *receps; - receps = g_mime_message_get_recipients (msg->_mime_msg, - rtype); - /* FIXME: is there an internal leak in - * internet_address_list_to_string? */ - recep = (char*)internet_address_list_to_string (receps, - TRUE); - if (mu_str_is_empty(recep)) - g_free (recep); - else - msg->_fields[field] = recep; - } + char *recep; + InternetAddressList *receps; + receps = g_mime_message_get_recipients (msg->_mime_msg, + rtype); + /* FIXME: is there an internal leak in + * internet_address_list_to_string? */ + recep = (char*)internet_address_list_to_string (receps, + TRUE); + if (mu_str_is_empty(recep)) + g_free (recep); + else + msg->_fields[field] = recep; + } - return msg->_fields[field]; + return msg->_fields[field]; } const char* mu_msg_get_to (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); - return get_recipient (msg, GMIME_RECIPIENT_TYPE_TO, TO_FIELD); + g_return_val_if_fail (msg, NULL); + return get_recipient (msg, GMIME_RECIPIENT_TYPE_TO, TO_FIELD); } const char* mu_msg_get_cc (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); - return get_recipient (msg, GMIME_RECIPIENT_TYPE_CC, CC_FIELD); + g_return_val_if_fail (msg, NULL); + return get_recipient (msg, GMIME_RECIPIENT_TYPE_CC, CC_FIELD); } const char* mu_msg_get_bcc (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); - return get_recipient (msg, GMIME_RECIPIENT_TYPE_BCC, BCC_FIELD); + g_return_val_if_fail (msg, NULL); + return get_recipient (msg, GMIME_RECIPIENT_TYPE_BCC, BCC_FIELD); } time_t mu_msg_get_date (MuMsg *msg) { - time_t t; + time_t t; - g_return_val_if_fail (msg, 0); + g_return_val_if_fail (msg, 0); - /* TODO: check: is the GMT-offset relevant? */ - g_mime_message_get_date(msg->_mime_msg, &t, NULL); + /* TODO: check: is the GMT-offset relevant? */ + g_mime_message_get_date(msg->_mime_msg, &t, NULL); - return t; + return t; } static gboolean part_looks_like_attachment (GMimeObject *part) { - GMimeContentDisposition *disp; - const char *str; + GMimeContentDisposition *disp; + const char *str; - disp = g_mime_object_get_content_disposition (part); - if (!GMIME_IS_CONTENT_DISPOSITION(disp)) - return FALSE; /* no content disp? prob not - * an attachment. */ + disp = g_mime_object_get_content_disposition (part); + if (!GMIME_IS_CONTENT_DISPOSITION(disp)) + return FALSE; /* no content disp? prob not + * an attachment. */ - str = g_mime_content_disposition_get_disposition (disp); + str = g_mime_content_disposition_get_disposition (disp); - /* ok, it says it's an attachment, so it probably is... */ - if (!str) - return TRUE; - if (strcmp (str, GMIME_DISPOSITION_ATTACHMENT) == 0) - return TRUE; - else if (strcmp (str, GMIME_DISPOSITION_INLINE) == 0) { - /* inline-images are also considered attachments... */ - GMimeContentType *ct; - ct = g_mime_object_get_content_type (part); - if (ct) - return g_mime_content_type_is_type - (ct, "image", "*"); - } + /* ok, it says it's an attachment, so it probably is... */ + if (!str) + return TRUE; + if (strcmp (str, GMIME_DISPOSITION_ATTACHMENT) == 0) + return TRUE; + else if (strcmp (str, GMIME_DISPOSITION_INLINE) == 0) { + /* inline-images are also considered attachments... */ + GMimeContentType *ct; + ct = g_mime_object_get_content_type (part); + if (ct) + return g_mime_content_type_is_type + (ct, "image", "*"); + } - return FALSE; + return FALSE; } static void msg_cflags_cb (GMimeObject *parent, GMimeObject *part, MuMsgFlags *flags) { - if (*flags & MU_MSG_FLAG_HAS_ATTACH) - return; + if (*flags & MU_MSG_FLAG_HAS_ATTACH) + return; - if (!GMIME_IS_PART(part)) - return; + if (!GMIME_IS_PART(part)) + return; - if (part_looks_like_attachment(part)) - *flags |= MU_MSG_FLAG_HAS_ATTACH; + if (part_looks_like_attachment(part)) + *flags |= MU_MSG_FLAG_HAS_ATTACH; } @@ -386,175 +386,175 @@ msg_cflags_cb (GMimeObject *parent, GMimeObject *part, MuMsgFlags *flags) static MuMsgFlags get_content_flags (MuMsg *msg) { - GMimeContentType *ctype; - MuMsgFlags flags; - GMimeObject *part; + GMimeContentType *ctype; + MuMsgFlags flags; + GMimeObject *part; - if (!GMIME_IS_MESSAGE(msg->_mime_msg)) - return MU_MSG_FLAG_NONE; + if (!GMIME_IS_MESSAGE(msg->_mime_msg)) + return MU_MSG_FLAG_NONE; - flags = 0; - g_mime_message_foreach (msg->_mime_msg, - (GMimeObjectForeachFunc)msg_cflags_cb, - &flags); + flags = 0; + g_mime_message_foreach (msg->_mime_msg, + (GMimeObjectForeachFunc)msg_cflags_cb, + &flags); - /* note: signed or encrypted status for a message is determined by - * the top-level mime-part - */ - if ((part = g_mime_message_get_mime_part(msg->_mime_msg))) { - ctype = g_mime_object_get_content_type - (GMIME_OBJECT(part)); - if (!ctype) { - g_warning ("not a content type!"); - return 0; - } + /* note: signed or encrypted status for a message is determined by + * the top-level mime-part + */ + if ((part = g_mime_message_get_mime_part(msg->_mime_msg))) { + ctype = g_mime_object_get_content_type + (GMIME_OBJECT(part)); + if (!ctype) { + g_warning ("not a content type!"); + return 0; + } - if (ctype) { - if (g_mime_content_type_is_type - (ctype,"*", "signed")) - flags |= MU_MSG_FLAG_SIGNED; - if (g_mime_content_type_is_type - (ctype,"*", "encrypted")) - flags |= MU_MSG_FLAG_ENCRYPTED; - } - } else - g_warning ("no top level mime part found"); + if (ctype) { + if (g_mime_content_type_is_type + (ctype,"*", "signed")) + flags |= MU_MSG_FLAG_SIGNED; + if (g_mime_content_type_is_type + (ctype,"*", "encrypted")) + flags |= MU_MSG_FLAG_ENCRYPTED; + } + } else + g_warning ("no top level mime part found"); - return flags; + return flags; } MuMsgFlags mu_msg_get_flags (MuMsg *msg) { - g_return_val_if_fail (msg, MU_MSG_FLAG_NONE); + g_return_val_if_fail (msg, MU_MSG_FLAG_NONE); - if (msg->_flags == MU_MSG_FLAG_NONE) { - msg->_flags = mu_msg_file_get_flags_from_path (mu_msg_get_path(msg)); - msg->_flags |= get_content_flags (msg); - } + if (msg->_flags == MU_MSG_FLAG_NONE) { + msg->_flags = mu_msg_file_get_flags_from_path (mu_msg_get_path(msg)); + msg->_flags |= get_content_flags (msg); + } - return msg->_flags; + return msg->_flags; } size_t mu_msg_get_size (MuMsg *msg) { - g_return_val_if_fail (msg, 0); + g_return_val_if_fail (msg, 0); - return msg->_size; + return msg->_size; } static char* to_lower (char *s) { - char *t = s; - while (t&&*t) { - t[0] = g_ascii_tolower(t[0]); - ++t; - } - return s; + char *t = s; + while (t&&*t) { + t[0] = g_ascii_tolower(t[0]); + ++t; + } + return s; } static char* get_prio_header_field (MuMsg *msg) { - const char *str; - GMimeObject *obj; + const char *str; + GMimeObject *obj; - obj = GMIME_OBJECT(msg->_mime_msg); + obj = GMIME_OBJECT(msg->_mime_msg); - str = g_mime_object_get_header (obj, "X-Priority"); - if (!str) - str = g_mime_object_get_header (obj, "X-MSMail-Priority"); - if (!str) - str = g_mime_object_get_header (obj, "Importance"); - if (!str) - str = g_mime_object_get_header (obj, "Precedence"); - if (str) - return (to_lower(g_strdup(str))); - else - return NULL; + str = g_mime_object_get_header (obj, "X-Priority"); + if (!str) + str = g_mime_object_get_header (obj, "X-MSMail-Priority"); + if (!str) + str = g_mime_object_get_header (obj, "Importance"); + if (!str) + str = g_mime_object_get_header (obj, "Precedence"); + if (str) + return (to_lower(g_strdup(str))); + else + return NULL; } static MuMsgPrio parse_prio_str (const char* priostr) { - int i; - struct { - const char* _str; - MuMsgPrio _prio; - } str_prio[] = { - { "high", MU_MSG_PRIO_HIGH }, - { "1", MU_MSG_PRIO_HIGH }, - { "2", MU_MSG_PRIO_HIGH }, + int i; + struct { + const char* _str; + MuMsgPrio _prio; + } str_prio[] = { + { "high", MU_MSG_PRIO_HIGH }, + { "1", MU_MSG_PRIO_HIGH }, + { "2", MU_MSG_PRIO_HIGH }, - { "normal", MU_MSG_PRIO_NORMAL }, - { "3", MU_MSG_PRIO_NORMAL }, + { "normal", MU_MSG_PRIO_NORMAL }, + { "3", MU_MSG_PRIO_NORMAL }, - { "low", MU_MSG_PRIO_LOW }, - { "list", MU_MSG_PRIO_LOW }, - { "bulk", MU_MSG_PRIO_LOW }, - { "4", MU_MSG_PRIO_LOW }, - { "5", MU_MSG_PRIO_LOW } - }; + { "low", MU_MSG_PRIO_LOW }, + { "list", MU_MSG_PRIO_LOW }, + { "bulk", MU_MSG_PRIO_LOW }, + { "4", MU_MSG_PRIO_LOW }, + { "5", MU_MSG_PRIO_LOW } + }; - for (i = 0; i != G_N_ELEMENTS(str_prio); ++i) - if (g_strstr_len (priostr, -1, str_prio[i]._str) != NULL) - return str_prio[i]._prio; + for (i = 0; i != G_N_ELEMENTS(str_prio); ++i) + if (g_strstr_len (priostr, -1, str_prio[i]._str) != NULL) + return str_prio[i]._prio; - /* e.g., last-fm uses 'fm-user'... as precedence */ - return MU_MSG_PRIO_NORMAL; + /* e.g., last-fm uses 'fm-user'... as precedence */ + return MU_MSG_PRIO_NORMAL; } MuMsgPrio mu_msg_get_prio (MuMsg *msg) { - char* priostr; + char* priostr; - g_return_val_if_fail (msg, 0); + g_return_val_if_fail (msg, 0); - if (msg->_prio != MU_MSG_PRIO_NONE) - return msg->_prio; + if (msg->_prio != MU_MSG_PRIO_NONE) + return msg->_prio; - priostr = get_prio_header_field (msg); - if (!priostr) - return MU_MSG_PRIO_NORMAL; + priostr = get_prio_header_field (msg); + if (!priostr) + return MU_MSG_PRIO_NORMAL; - msg->_prio = parse_prio_str (priostr); - g_free (priostr); + msg->_prio = parse_prio_str (priostr); + g_free (priostr); - return msg->_prio; + return msg->_prio; } const char* mu_msg_get_header (MuMsg *msg, const char* header) { - g_return_val_if_fail (msg, NULL); - g_return_val_if_fail (header, NULL); + g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (header, NULL); - return g_mime_object_get_header (GMIME_OBJECT(msg->_mime_msg), - header); + return g_mime_object_get_header (GMIME_OBJECT(msg->_mime_msg), + header); } time_t mu_msg_get_timestamp (MuMsg *msg) { - g_return_val_if_fail (msg, 0); + g_return_val_if_fail (msg, 0); - return msg->_timestamp; + return msg->_timestamp; } struct _GetBodyData { - GMimeObject *_txt_part, *_html_part; - gboolean _want_html; + GMimeObject *_txt_part, *_html_part; + gboolean _want_html; }; typedef struct _GetBodyData GetBodyData; @@ -562,49 +562,49 @@ typedef struct _GetBodyData GetBodyData; static gboolean looks_like_attachment (GMimeObject *part) { - const char *str; - GMimeContentDisposition *disp; + const char *str; + GMimeContentDisposition *disp; - disp = g_mime_object_get_content_disposition (GMIME_OBJECT(part)); - if (!GMIME_IS_CONTENT_DISPOSITION(disp)) - return FALSE; + disp = g_mime_object_get_content_disposition (GMIME_OBJECT(part)); + if (!GMIME_IS_CONTENT_DISPOSITION(disp)) + return FALSE; - str = g_mime_content_disposition_get_disposition (disp); - if (!str) - return FALSE; + str = g_mime_content_disposition_get_disposition (disp); + if (!str) + return FALSE; - if (strcmp(str,GMIME_DISPOSITION_INLINE) == 0) - return FALSE; /* inline, so it's not an attachment */ + if (strcmp(str,GMIME_DISPOSITION_INLINE) == 0) + return FALSE; /* inline, so it's not an attachment */ - return TRUE; /* looks like an attachment */ + return TRUE; /* looks like an attachment */ } static void get_body_cb (GMimeObject *parent, GMimeObject *part, GetBodyData *data) { - GMimeContentType *ct; + GMimeContentType *ct; - /* already found what we're looking for? */ - if ((data->_want_html && data->_html_part != NULL) || - (!data->_want_html && data->_txt_part != NULL)) - return; + /* already found what we're looking for? */ + if ((data->_want_html && data->_html_part != NULL) || + (!data->_want_html && data->_txt_part != NULL)) + return; - ct = g_mime_object_get_content_type (part); - if (!GMIME_IS_CONTENT_TYPE(ct)) { - g_warning ("not a content type!"); - return; - } + ct = g_mime_object_get_content_type (part); + if (!GMIME_IS_CONTENT_TYPE(ct)) { + g_warning ("not a content type!"); + return; + } - if (looks_like_attachment (part)) - return; /* not the body */ + if (looks_like_attachment (part)) + return; /* not the body */ - /* is it right content type? */ - if (g_mime_content_type_is_type (ct, "text", "plain")) - data->_txt_part = part; - else if (g_mime_content_type_is_type (ct, "text", "html")) - data->_html_part = part; - else - return; /* wrong type */ + /* is it right content type? */ + if (g_mime_content_type_is_type (ct, "text", "plain")) + data->_txt_part = part; + else if (g_mime_content_type_is_type (ct, "text", "html")) + data->_html_part = part; + else + return; /* wrong type */ } @@ -614,10 +614,10 @@ get_body_cb (GMimeObject *parent, GMimeObject *part, GetBodyData *data) static void asciify (char *buf) { - char *c; - for (c = buf; c && *c; ++c) - if (!isascii(*c)) - c[0] = '.'; + char *c; + for (c = buf; c && *c; ++c) + if (!isascii(*c)) + c[0] = '.'; } @@ -625,22 +625,22 @@ asciify (char *buf) static gchar* text_to_utf8 (const char* buffer, const char *charset) { - GError *err; - gchar * utf8; + GError *err; + gchar * utf8; - err = NULL; - utf8 = g_convert_with_fallback (buffer, -1, "UTF-8", - charset, (gchar*)".", - NULL, NULL, &err); - if (!utf8) { - MU_WRITE_LOG ("%s: conversion failed from %s: %s", - __FUNCTION__, charset, - err ? err ->message : ""); - if (err) - g_error_free (err); - } + err = NULL; + utf8 = g_convert_with_fallback (buffer, -1, "UTF-8", + charset, (gchar*)".", + NULL, NULL, &err); + if (!utf8) { + MU_WRITE_LOG ("%s: conversion failed from %s: %s", + __FUNCTION__, charset, + err ? err ->message : ""); + if (err) + g_error_free (err); + } - return utf8; + return utf8; } @@ -648,272 +648,272 @@ text_to_utf8 (const char* buffer, const char *charset) static char* convert_to_utf8 (GMimePart *part, char *buffer) { - GMimeContentType *ctype; - const char* charset; - unsigned char *cur; + GMimeContentType *ctype; + const char* charset; + unsigned char *cur; - /* optimization: if the buffer is plain ascii, no conversion - * is done... */ - for (cur = (unsigned char*)buffer; *cur && *cur < 0x80; ++cur); - if (*cur == '\0') - return buffer; + /* optimization: if the buffer is plain ascii, no conversion + * is done... */ + for (cur = (unsigned char*)buffer; *cur && *cur < 0x80; ++cur); + if (*cur == '\0') + return buffer; - ctype = g_mime_object_get_content_type (GMIME_OBJECT(part)); - g_return_val_if_fail (GMIME_IS_CONTENT_TYPE(ctype), NULL); + ctype = g_mime_object_get_content_type (GMIME_OBJECT(part)); + g_return_val_if_fail (GMIME_IS_CONTENT_TYPE(ctype), NULL); - charset = g_mime_content_type_get_parameter (ctype, "charset"); - if (charset) - charset = g_mime_charset_iconv_name (charset); + charset = g_mime_content_type_get_parameter (ctype, "charset"); + if (charset) + charset = g_mime_charset_iconv_name (charset); - /* of course, the charset specified may be incorrect... */ - if (charset) { - char *utf8 = text_to_utf8 (buffer, charset); - if (utf8) { - g_free (buffer); - return utf8; + /* of course, the charset specified may be incorrect... */ + if (charset) { + char *utf8 = text_to_utf8 (buffer, charset); + if (utf8) { + g_free (buffer); + return utf8; + } } - } - /* hmmm.... no charset at all, or conversion failed; ugly - * hack: replace all non-ascii chars with '.' - * instead... TODO: come up with something better */ - asciify (buffer); - return buffer; + /* hmmm.... no charset at all, or conversion failed; ugly + * hack: replace all non-ascii chars with '.' + * instead... TODO: come up with something better */ + asciify (buffer); + return buffer; } static gchar* stream_to_string (GMimeStream *stream, size_t buflen) { - char *buffer; - ssize_t bytes; + char *buffer; + ssize_t bytes; - buffer = g_new(char, buflen + 1); - g_mime_stream_reset (stream); + buffer = g_new(char, buflen + 1); + g_mime_stream_reset (stream); - /* we read everything in one go */ - bytes = g_mime_stream_read (stream, buffer, buflen); - if (bytes < 0) { - g_warning ("%s: failed to read from stream", __FUNCTION__); - g_free (buffer); - return NULL; - } + /* we read everything in one go */ + bytes = g_mime_stream_read (stream, buffer, buflen); + if (bytes < 0) { + g_warning ("%s: failed to read from stream", __FUNCTION__); + g_free (buffer); + return NULL; + } - buffer[bytes]='\0'; + buffer[bytes]='\0'; - return buffer; + return buffer; } static gchar* part_to_string (GMimePart *part, gboolean *err) { - GMimeDataWrapper *wrapper; - GMimeStream *stream = NULL; - ssize_t buflen; - char *buffer = NULL; + GMimeDataWrapper *wrapper; + GMimeStream *stream = NULL; + ssize_t buflen; + char *buffer = NULL; - *err = TRUE; - g_return_val_if_fail (GMIME_IS_PART(part), NULL); + *err = TRUE; + g_return_val_if_fail (GMIME_IS_PART(part), NULL); - wrapper = g_mime_part_get_content_object (part); - if (!wrapper) { - /* this happens with invalid mails */ - g_debug ("failed to create data wrapper"); - goto cleanup; - } + wrapper = g_mime_part_get_content_object (part); + if (!wrapper) { + /* this happens with invalid mails */ + g_debug ("failed to create data wrapper"); + goto cleanup; + } - stream = g_mime_stream_mem_new (); - if (!stream) { - g_warning ("failed to create mem stream"); - goto cleanup; - } + stream = g_mime_stream_mem_new (); + if (!stream) { + g_warning ("failed to create mem stream"); + goto cleanup; + } - buflen = g_mime_data_wrapper_write_to_stream (wrapper, stream); - if (buflen <= 0) {/* empty buffer, not an error */ + buflen = g_mime_data_wrapper_write_to_stream (wrapper, stream); + if (buflen <= 0) {/* empty buffer, not an error */ + *err = FALSE; + goto cleanup; + } + + buffer = stream_to_string (stream, (size_t)buflen); + + /* convert_to_utf8 will free the old 'buffer' if needed */ + buffer = convert_to_utf8 (part, buffer); + *err = FALSE; - goto cleanup; - } - - buffer = stream_to_string (stream, (size_t)buflen); - - /* convert_to_utf8 will free the old 'buffer' if needed */ - buffer = convert_to_utf8 (part, buffer); - - *err = FALSE; cleanup: - if (stream) - g_object_unref (G_OBJECT(stream)); + if (stream) + g_object_unref (G_OBJECT(stream)); - return buffer; + return buffer; } static char* get_body (MuMsg *msg, gboolean want_html) { - GetBodyData data; - char *str; - gboolean err; + GetBodyData data; + char *str; + gboolean err; - g_return_val_if_fail (msg, NULL); - g_return_val_if_fail (GMIME_IS_MESSAGE(msg->_mime_msg), NULL); + g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (GMIME_IS_MESSAGE(msg->_mime_msg), NULL); - memset (&data, 0, sizeof(GetBodyData)); - data._want_html = want_html; + memset (&data, 0, sizeof(GetBodyData)); + data._want_html = want_html; - err = FALSE; - g_mime_message_foreach (msg->_mime_msg, - (GMimeObjectForeachFunc)get_body_cb, - &data); - if (want_html) - str = data._html_part ? - part_to_string (GMIME_PART(data._html_part), &err) : - NULL; - else - str = data._txt_part ? - part_to_string (GMIME_PART(data._txt_part), &err) : - NULL; + err = FALSE; + g_mime_message_foreach (msg->_mime_msg, + (GMimeObjectForeachFunc)get_body_cb, + &data); + if (want_html) + str = data._html_part ? + part_to_string (GMIME_PART(data._html_part), &err) : + NULL; + else + str = data._txt_part ? + part_to_string (GMIME_PART(data._txt_part), &err) : + NULL; - /* 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", - mu_msg_get_path(msg)); + /* 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", + mu_msg_get_path(msg)); - return str; + return str; } const char* mu_msg_get_body_html (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - if (msg->_fields[HTML_FIELD]) - return msg->_fields[HTML_FIELD]; - else - return msg->_fields[HTML_FIELD] = get_body (msg, TRUE); + if (msg->_fields[HTML_FIELD]) + return msg->_fields[HTML_FIELD]; + else + return msg->_fields[HTML_FIELD] = get_body (msg, TRUE); } const char* mu_msg_get_body_text (MuMsg *msg) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - if (msg->_fields[TEXT_FIELD]) - return msg->_fields[TEXT_FIELD]; - else - return msg->_fields[TEXT_FIELD] = get_body (msg, FALSE); + if (msg->_fields[TEXT_FIELD]) + return msg->_fields[TEXT_FIELD]; + else + return msg->_fields[TEXT_FIELD] = get_body (msg, FALSE); } const char* mu_msg_get_summary (MuMsg *msg, size_t max_lines) { - const char *body; + const char *body; - g_return_val_if_fail (msg, NULL); - g_return_val_if_fail (max_lines > 0, NULL); + g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (max_lines > 0, NULL); - /* do we have a summary cached already? */ - if (msg->_fields[SUMMARY_FIELD]) - return msg->_fields[SUMMARY_FIELD]; + /* do we have a summary cached already? */ + if (msg->_fields[SUMMARY_FIELD]) + return msg->_fields[SUMMARY_FIELD]; - /* nope; calculate it */ - body = mu_msg_get_body_text (msg); - if (!body) - return NULL; /* there was no text body */ + /* nope; calculate it */ + body = mu_msg_get_body_text (msg); + if (!body) + return NULL; /* there was no text body */ - return msg->_fields[SUMMARY_FIELD] = - mu_str_summarize (body, max_lines); + return msg->_fields[SUMMARY_FIELD] = + mu_str_summarize (body, max_lines); } static GSList* get_msgids_from_header (MuMsg *msg, const char* header) { - GSList *msgids; - const char *str; + GSList *msgids; + const char *str; - msgids = NULL; - str = g_mime_object_get_header (GMIME_OBJECT(msg->_mime_msg), - header); + msgids = NULL; + str = g_mime_object_get_header (GMIME_OBJECT(msg->_mime_msg), + header); - /* get stuff from the 'references' header */ - if (str) { - const GMimeReferences *cur; - GMimeReferences *mime_refs; - mime_refs = g_mime_references_decode (str); - for (cur = mime_refs; cur; cur = g_mime_references_get_next(cur)) { - const char* msgid; - msgid = g_mime_references_get_message_id (cur); - if (msgid) - msgids = g_slist_prepend (msgids, g_strdup (msgid)); + /* get stuff from the 'references' header */ + if (str) { + const GMimeReferences *cur; + GMimeReferences *mime_refs; + mime_refs = g_mime_references_decode (str); + for (cur = mime_refs; cur; cur = g_mime_references_get_next(cur)) { + const char* msgid; + msgid = g_mime_references_get_message_id (cur); + if (msgid) + msgids = g_slist_prepend (msgids, g_strdup (msgid)); + } + g_mime_references_free (mime_refs); } - g_mime_references_free (mime_refs); - } - return g_slist_reverse (msgids); + return g_slist_reverse (msgids); } const char* mu_msg_get_references_str (MuMsg *msg) { - const GSList *refs; - gchar *refsstr; + const GSList *refs; + gchar *refsstr; - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - if (msg->_fields[REFS_FIELD]) - return msg->_fields[REFS_FIELD]; + if (msg->_fields[REFS_FIELD]) + return msg->_fields[REFS_FIELD]; - refsstr = NULL; - refs = mu_msg_get_references (msg); - 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 ? "," : "", - g_strdup((gchar*)cur->data)); - g_free (refsstr); - refsstr = tmp; - } - } + refsstr = NULL; + refs = mu_msg_get_references (msg); + 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 ? "," : "", + g_strdup((gchar*)cur->data)); + g_free (refsstr); + refsstr = tmp; + } + } - return msg->_fields[REFS_FIELD] = refsstr; + return msg->_fields[REFS_FIELD] = refsstr; } const GSList* mu_msg_get_references (MuMsg *msg) { - GSList *refs, *inreply; + GSList *refs, *inreply; - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - if (msg->_refs) - return msg->_refs; + if (msg->_refs) + return msg->_refs; - refs = get_msgids_from_header (msg, "References"); + refs = get_msgids_from_header (msg, "References"); - /* now, add in-reply-to:, we only take the first one if there - * are more */ - inreply = get_msgids_from_header (msg, "In-reply-to"); - if (inreply) { - refs = g_slist_prepend (refs, g_strdup ((gchar*)inreply->data)); - g_slist_foreach (inreply, (GFunc)g_free, NULL); - g_slist_free (inreply); - } + /* now, add in-reply-to:, we only take the first one if there + * are more */ + inreply = get_msgids_from_header (msg, "In-reply-to"); + if (inreply) { + refs = g_slist_prepend (refs, g_strdup ((gchar*)inreply->data)); + g_slist_foreach (inreply, (GFunc)g_free, NULL); + g_slist_free (inreply); + } - /* put in proper order */ - msg->_refs = g_slist_reverse (refs); + /* put in proper order */ + msg->_refs = g_slist_reverse (refs); - return msg->_refs; + return msg->_refs; } @@ -921,36 +921,36 @@ mu_msg_get_references (MuMsg *msg) const char* mu_msg_get_field_string (MuMsg *msg, MuMsgFieldId mfid) { - g_return_val_if_fail (msg, NULL); + g_return_val_if_fail (msg, NULL); - switch (mfid) { - case MU_MSG_FIELD_ID_BCC: return mu_msg_get_bcc (msg); - case MU_MSG_FIELD_ID_BODY_TEXT: return mu_msg_get_body_text (msg); - case MU_MSG_FIELD_ID_BODY_HTML: return mu_msg_get_body_html (msg); - case MU_MSG_FIELD_ID_CC: return mu_msg_get_cc (msg); - case MU_MSG_FIELD_ID_FROM: return mu_msg_get_from (msg); - case MU_MSG_FIELD_ID_PATH: return mu_msg_get_path (msg); - case MU_MSG_FIELD_ID_SUBJECT: return mu_msg_get_subject (msg); - case MU_MSG_FIELD_ID_TO: return mu_msg_get_to (msg); - case MU_MSG_FIELD_ID_MSGID: return mu_msg_get_msgid (msg); - case MU_MSG_FIELD_ID_MAILDIR: return mu_msg_get_maildir (msg); - case MU_MSG_FIELD_ID_REFS: return mu_msg_get_references_str (msg); - default: - g_return_val_if_reached (NULL); - } + switch (mfid) { + case MU_MSG_FIELD_ID_BCC: return mu_msg_get_bcc (msg); + case MU_MSG_FIELD_ID_BODY_TEXT: return mu_msg_get_body_text (msg); + case MU_MSG_FIELD_ID_BODY_HTML: return mu_msg_get_body_html (msg); + case MU_MSG_FIELD_ID_CC: return mu_msg_get_cc (msg); + case MU_MSG_FIELD_ID_FROM: return mu_msg_get_from (msg); + case MU_MSG_FIELD_ID_PATH: return mu_msg_get_path (msg); + case MU_MSG_FIELD_ID_SUBJECT: return mu_msg_get_subject (msg); + case MU_MSG_FIELD_ID_TO: return mu_msg_get_to (msg); + case MU_MSG_FIELD_ID_MSGID: return mu_msg_get_msgid (msg); + case MU_MSG_FIELD_ID_MAILDIR: return mu_msg_get_maildir (msg); + case MU_MSG_FIELD_ID_REFS: return mu_msg_get_references_str (msg); + default: + g_return_val_if_reached (NULL); + } } gint64 mu_msg_get_field_numeric (MuMsg *msg, const MuMsgFieldId mfid) { - g_return_val_if_fail (msg, 0); + g_return_val_if_fail (msg, 0); - switch (mfid) { - case MU_MSG_FIELD_ID_DATE: return mu_msg_get_date(msg); - case MU_MSG_FIELD_ID_FLAGS: return mu_msg_get_flags(msg); - case MU_MSG_FIELD_ID_PRIO: return mu_msg_get_prio(msg); - case MU_MSG_FIELD_ID_SIZE: return mu_msg_get_size(msg); - default: g_return_val_if_reached (-1); - } + switch (mfid) { + case MU_MSG_FIELD_ID_DATE: return mu_msg_get_date(msg); + case MU_MSG_FIELD_ID_FLAGS: return mu_msg_get_flags(msg); + case MU_MSG_FIELD_ID_PRIO: return mu_msg_get_prio(msg); + case MU_MSG_FIELD_ID_SIZE: return mu_msg_get_size(msg); + default: g_return_val_if_reached (-1); + } } From f06d8b466e0e88db784d878d865de9a89f139fa1 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 9 May 2011 09:33:33 +0300 Subject: [PATCH 02/12] * mu-query.cc: enable wildcard queries (Xapian::QueryParser::FLAG_WILDCARD) --- src/mu-query.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mu-query.cc b/src/mu-query.cc index a5d158ad..55d7da04 100644 --- a/src/mu-query.cc +++ b/src/mu-query.cc @@ -212,6 +212,7 @@ set_query (MuQuery *mqx, Xapian::Query& q, const char* searchexpr, (searchexpr, Xapian::QueryParser::FLAG_BOOLEAN | Xapian::QueryParser::FLAG_PURE_NOT | + Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_AUTO_SYNONYMS | Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE); From 3d79ba8c130a9d9055d38fdfe24920d4373057d9 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 00:00:10 +0300 Subject: [PATCH 03/12] * tests/: add tests for issues mentioned in issue #38 (http://code.google.com/p/mu0/issues/detail?id=38). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cannot reproduce the issue though, except when searching for the 'From:' -- this seems to be due to limitation with GMime, if I do: mu view testdir/cur/1305664394.2171_402.cthulhu\!2, get: ------------------------------- From: Mü To: Helmut =?iso-8859-1?q?Kr=F6ger?= Subject: Motörhead Test for issue #38, where apparently searching for accented words in subject, to etc. fails. What about here? Queensrÿche. Mötley Crüe. ------------------------------- They decoding issues are of course very mail-client specific. --- src/tests/Makefile.am | 1 + src/tests/test-mu-maildir.c | 4 +-- src/tests/test-mu-query.c | 32 +++++++++++++++++-- .../cur/1305664394.2171_402.cthulhu!2, | 15 +++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 1a770cbf..46058a8d 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -100,6 +100,7 @@ EXTRA_DIST= \ testdir/cur/1220863042.12663_1.mindcrime!2,S \ testdir/cur/1220863060.12663_3.mindcrime!2,S \ testdir/cur/1283599333.1840_11.cthulhu!2, \ + testdir/cur/1305664394.2171_402.cthulhu!2, \ testdir2/bar/cur/mail1 \ testdir2/bar/cur/mail2 \ testdir2/bar/cur/mail3 \ diff --git a/src/tests/test-mu-maildir.c b/src/tests/test-mu-maildir.c index a7f30b4c..d99accd9 100644 --- a/src/tests/test-mu-maildir.c +++ b/src/tests/test-mu-maildir.c @@ -189,7 +189,7 @@ test_mu_maildir_walk_01 (void) &data); g_assert_cmpuint (MU_OK, ==, rv); - g_assert_cmpuint (data._file_count, ==, 11); + g_assert_cmpuint (data._file_count, ==, 12); g_assert_cmpuint (data._dir_entered,==, 5); g_assert_cmpuint (data._dir_left,==, 5); @@ -220,7 +220,7 @@ test_mu_maildir_walk_02 (void) &data); g_assert_cmpuint (MU_OK, ==, rv); - g_assert_cmpuint (data._file_count, ==, 7); + g_assert_cmpuint (data._file_count, ==, 8); g_assert_cmpuint (data._dir_entered,==, 4); g_assert_cmpuint (data._dir_left,==, 4); diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 077c975e..0a408c87 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -186,10 +186,10 @@ test_mu_query_04 (void) { "f:bilbo", 0}, { "baggins", 1}, { "prio:high", 1}, - { "prio:normal", 3}, + { "prio:normal", 4}, { "prio:h", 1}, { "prio:l", 7}, - { "not prio:l", 4} + { "not prio:l", 5}, }; xpath = fill_database (); @@ -238,6 +238,33 @@ test_mu_query_05 (void) } + +static void +test_mu_query_06 (void) +{ + gchar *xpath; + int i; + + QResults queries[] = { + { "f:mü", 1}, + { "s:motörhead", 1}, + { "s:MotorHeäD", 1}, + { "queensryche", 1}, + { "Queensrÿche", 1}, + }; + + xpath = fill_database (); + g_assert (xpath != NULL); + + for (i = 0; i != G_N_ELEMENTS(queries); ++i) + g_assert_cmpuint (run_and_count_matches (xpath, queries[i].query), + ==, queries[i].count); + g_free (xpath); + +} + + + int main (int argc, char *argv[]) { @@ -249,6 +276,7 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-query/test-mu-query-03", test_mu_query_03); g_test_add_func ("/mu-query/test-mu-query-04", test_mu_query_04); g_test_add_func ("/mu-query/test-mu-query-05", test_mu_query_05); + g_test_add_func ("/mu-query/test-mu-query-06", test_mu_query_06); g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, diff --git a/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, b/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, new file mode 100644 index 00000000..cea827fb --- /dev/null +++ b/src/tests/testdir/cur/1305664394.2171_402.cthulhu!2, @@ -0,0 +1,15 @@ +From: =?UTF-8?B?TcO8?= +To: Helmut =?UTF-8?B?S3LDtmdlcg==?= +Subject: =?UTF-8?B?TW90w7ZyaGVhZA==?= +User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/24.0 Mule/6.0 (HANACHIRUSATO) +MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + + +Test for issue #38, where apparently searching for accented words in subject, +to etc. fails. + +What about here? Queensrÿche. Mötley Crüe. + + From ca9dc6ee6bb96ac1b5db87ff738d225fce539d77 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 00:15:52 +0300 Subject: [PATCH 04/12] * test-mu-query.c: add specific tests for searching accented chars, as per #38 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this seems to work even for "Kröger", even though 'mu view' does not show the correct value. It could be some inconsistency in GMime, need to check. --- src/tests/test-mu-query.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 0a408c87..9b4ffb9a 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -248,6 +248,8 @@ test_mu_query_06 (void) QResults queries[] = { { "f:mü", 1}, { "s:motörhead", 1}, + { "t:Helmut", 1}, + { "t:Kröger", 1}, { "s:MotorHeäD", 1}, { "queensryche", 1}, { "Queensrÿche", 1}, @@ -264,7 +266,6 @@ test_mu_query_06 (void) } - int main (int argc, char *argv[]) { From f6c21aaadcc18bea987fee377fe785caf2849d6c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 00:22:19 +0300 Subject: [PATCH 05/12] * mu-util.c: Fix #39: use MU_WRITE_LOG instead of the (now something different) MU_LOG_FILE. Change suggested by patch, thanks! --- src/mu-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mu-util.c b/src/mu-util.c index e6146e83..ec5f0082 100644 --- a/src/mu-util.c +++ b/src/mu-util.c @@ -158,7 +158,7 @@ mu_util_init_system (void) g_critical ("cannot set G_SLICE"); return FALSE; } - MU_LOG_FILE("setting G_SLICE to always-malloc"); + MU_WRITE_LOG("setting G_SLICE to always-malloc"); #endif /*__FreeBSD__*/ g_type_init (); From 98b9b68aa08fc6dce3d0bd9fbeb024a1f36a1245 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 09:05:09 +0300 Subject: [PATCH 06/12] * contrib/gmime-test.c: add little test program to test plain GMime --- contrib/Makefile.am | 8 ++ contrib/gmime-test.c | 172 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 contrib/gmime-test.c diff --git a/contrib/Makefile.am b/contrib/Makefile.am index c30689dc..cee99cd9 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -16,5 +16,13 @@ include $(top_srcdir)/gtest.mk +INCLUDES=$(GMIME_CFLAGS) $(GLIB_CFLAGS) +AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement -pedantic + +noinst_PROGRAMS=gmime-test +gmime_test_SOURCES=gmime-test.c +gmime_test_LDADD=$(GMIME_LIBS) $(GLIB_LIBS) + + EXTRA_DIST= \ mu-completion.zsh diff --git a/contrib/gmime-test.c b/contrib/gmime-test.c new file mode 100644 index 00000000..60797ea3 --- /dev/null +++ b/contrib/gmime-test.c @@ -0,0 +1,172 @@ +/* +** Copyright (C) 2011 djcb +** +** 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. +** +*/ + + + +/* gmime-test; compile with: + gcc -o gmime-test gmime-test.c -Wall -O0 -ggdb3 \ + `pkg-config --cflags --libs gmime-2.4` + */ + +#include +#include +#include +#include + +gchar* +get_recip (GMimeMessage *msg, GMimeRecipientType rtype) +{ + char *recep; + InternetAddressList *receps; + + receps = g_mime_message_get_recipients (msg, rtype); + recep = (char*)internet_address_list_to_string (receps, FALSE); + + if (!recep || !*recep) { + g_free (recep); + return NULL; + } + + return recep; +} + + +static gboolean +test_message (GMimeMessage *msg) +{ + gchar *val; + const gchar *str; + + g_print ("From : %s\n", g_mime_message_get_sender (msg)); + + val = get_recip (msg, GMIME_RECIPIENT_TYPE_TO); + g_print ("To : %s\n", val ? val : "" ); + g_free (val); + + val = get_recip (msg, GMIME_RECIPIENT_TYPE_CC); + g_print ("Cc : %s\n", val ? val : "" ); + g_free (val); + + val = get_recip (msg, GMIME_RECIPIENT_TYPE_BCC); + g_print ("Bcc : %s\n", val ? val : "" ); + g_free (val); + + str = g_mime_message_get_subject (msg); + g_print ("Subject: %s\n", str ? str : ""); + + str = g_mime_message_get_message_id (msg); + g_print ("Msg-id : %s\n", str ? str : ""); + + return TRUE; +} + + + +static gboolean +test_stream (GMimeStream *stream) +{ + GMimeParser *parser; + GMimeMessage *msg; + gboolean rv; + + parser = NULL; + msg = NULL; + + parser = g_mime_parser_new_with_stream (stream); + if (!parser) { + g_warning ("failed to create parser"); + rv = FALSE; + goto leave; + } + + msg = g_mime_parser_construct_message (parser); + if (!msg) { + g_warning ("failed to construct message"); + rv = FALSE; + goto leave; + } + + rv = test_message (msg); + +leave: + if (parser) + g_object_unref (parser); + else + g_object_unref (stream); + + if (msg) + g_object_unref (msg); + + return rv; +} + + +static gboolean +test_file (const char *path) +{ + FILE *file; + GMimeStream *stream; + gboolean rv; + + stream = NULL; + file = NULL; + + file = fopen (path, "r"); + if (!file) { + g_warning ("cannot open file '%s': %s", path, + strerror(errno)); + rv = FALSE; + goto leave; + } + + stream = g_mime_stream_file_new (file); + if (!stream) { + g_warning ("cannot open stream for '%s'", path); + rv = FALSE; + goto leave; + } + + rv = test_stream (stream); /* test-stream will unref it */ + +leave: + if (file) + fclose (file); + + return rv; +} + + +int +main (int argc, char *argv[]) +{ + gboolean rv; + + if (argc != 2) { + g_printerr ("usage: %s \n", argv[0]); + return 1; + } + + g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS); + + rv = test_file (argv[1]); + + g_mime_shutdown (); + + return rv ? 0 : 1; +} From bb18f312d69a18a00049eae3b69868309b45cd58 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 09:06:23 +0300 Subject: [PATCH 07/12] * fix mu-msg for the 'mu view' issue found during checking for issue #38 -- don't encode the addresses you get --- src/mu-msg.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/mu-msg.c b/src/mu-msg.c index 17c5c14c..3d8f5909 100644 --- a/src/mu-msg.c +++ b/src/mu-msg.c @@ -284,18 +284,21 @@ get_recipient (MuMsg *msg, GMimeRecipientType rtype, StringFields field) /* can only be set once */ if (!msg->_fields[field]) { - char *recep; - InternetAddressList *receps; - receps = g_mime_message_get_recipients (msg->_mime_msg, + char *recip; + InternetAddressList *recips; + recips = g_mime_message_get_recipients (msg->_mime_msg, rtype); /* FIXME: is there an internal leak in * internet_address_list_to_string? */ - recep = (char*)internet_address_list_to_string (receps, - TRUE); - if (mu_str_is_empty(recep)) - g_free (recep); + + /* FALSE --> don't encode */ + recip = (char*)internet_address_list_to_string (recips, + FALSE); + + if (mu_str_is_empty(recip)) + g_free (recip); else - msg->_fields[field] = recep; + msg->_fields[field] = recip; } return msg->_fields[field]; From 75e7daac6585114498c75b9e9c0616a6188ac650 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 19:19:08 +0300 Subject: [PATCH 08/12] * mu-contacts: cosmetics --- src/mu-contacts.c | 36 ++++++++++++++++++++++-------------- src/mu-contacts.h | 8 ++++---- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/mu-contacts.c b/src/mu-contacts.c index afb3e323..9c4fb49b 100644 --- a/src/mu-contacts.c +++ b/src/mu-contacts.c @@ -45,7 +45,7 @@ struct _MuContacts { static gboolean -unserialize_cache (MuContacts *self) +deserialize_cache (MuContacts *self) { GError *err; gchar **groups; @@ -69,12 +69,16 @@ unserialize_cache (MuContacts *self) groups = g_key_file_get_groups (self->_ccache, &len); for (i = 0; i != len; ++i) { ContactInfo *cinfo; - cinfo = contact_info_new (/* note, contact_info_new will *own* the string param, - * and take care of freeing it */ + cinfo = contact_info_new (/* note, contact_info_new + * will *own* the string + * param, and take care of + * freeing it */ g_key_file_get_string (self->_ccache, groups[i], MU_CONTACTS_NAME_KEY, NULL), (time_t)g_key_file_get_integer (self->_ccache, groups[i], - MU_CONTACTS_TIMESTAMP_KEY, NULL)); + MU_CONTACTS_TIMESTAMP_KEY, + NULL)); + /* note, we're using the groups[i], so don't free with g_strfreev */ g_hash_table_insert (self->_hash, groups[i], cinfo); } @@ -103,7 +107,7 @@ mu_contacts_new (const gchar *ccachefile) (g_str_hash, g_str_equal, g_free, (GDestroyNotify)contact_info_destroy); - unserialize_cache (contacts); + deserialize_cache (contacts); MU_WRITE_LOG("unserialized contacts cache %s", ccachefile); contacts->_dirty = FALSE; @@ -126,7 +130,8 @@ mu_contacts_add (MuContacts *self, const char* name, const char *email, cinfo = (ContactInfo*) g_hash_table_lookup (self->_hash, email); if (!cinfo || (cinfo->_tstamp < tstamp && !mu_str_is_empty(name))) { - ContactInfo *ci; /* note ci will take care of freeing the first param */ + ContactInfo *ci; /* note ci will take care of freeing + * the first param */ ci = contact_info_new (name ? g_strdup(name) : NULL, tstamp); g_hash_table_insert (self->_hash, g_strdup(email), ci); return self->_dirty = TRUE; @@ -144,20 +149,20 @@ struct _EachContactData { typedef struct _EachContactData EachContactData; static void /* email will never be NULL, but ci->_name may be */ -each_contact (const char* email, ContactInfo *ci, EachContactData *ecdata) +each_contact (const char *email, ContactInfo *ci, EachContactData *ecdata) { /* ignore this contact if we have a regexp, and it matches - * neither email nor name (if we have a name) */ + * neither email nor name (if we have a name) */ while (ecdata->_rx) { /* note, only once */ if (g_regex_match (ecdata->_rx, email, 0, NULL)) break; /* email matches? continue! */ if (!ci->_name) return; /* email did not match, no name? ignore this one */ - if (g_regex_match (ecdata->_rx,ci->_name, 0, NULL)) + if (g_regex_match (ecdata->_rx, ci->_name, 0, NULL)) break; /* name matches? continue! */ return; /* nothing matched, ignore this one */ } - + ecdata->_func (email, ci->_name, ci->_tstamp, ecdata->_user_data); ++ecdata->_num; } @@ -190,7 +195,7 @@ mu_contacts_foreach (MuContacts *self, MuContactsForeachFunc func, ecdata._user_data = user_data; ecdata._num = 0; - g_hash_table_foreach (self->_hash, (GHFunc) each_contact, &ecdata); + g_hash_table_foreach (self->_hash, (GHFunc)each_contact, &ecdata); if (ecdata._rx) g_regex_unref (ecdata._rx); @@ -202,12 +207,15 @@ mu_contacts_foreach (MuContacts *self, MuContactsForeachFunc func, } - - - static void each_keyval (const char *email, ContactInfo *cinfo, MuContacts *self) { + /* TODO: we use 'email' as key here; however, this fails for + * technically valid e-mail addresses containing '=' + * ('smith=cool@domain.com') or '[]' (jones@[192.168.255.2]), + * because GKeyFile does not like '=' or '[]' in its group + * names. Maybe use a hash as the key, and 'email' as a + * value */ if (cinfo->_name) g_key_file_set_string (self->_ccache, email, "name", cinfo->_name); diff --git a/src/mu-contacts.h b/src/mu-contacts.h index 89246223..5a473e62 100644 --- a/src/mu-contacts.h +++ b/src/mu-contacts.h @@ -28,7 +28,6 @@ G_BEGIN_DECLS struct _MuContacts; typedef struct _MuContacts MuContacts; - /** * create a new MuContacts object; use mu_contacts_destroy when you no longer need it * @@ -52,7 +51,8 @@ MuContacts* mu_contacts_new (const gchar* ccachefile) * * @return TRUE if succeeded, FALSE otherwise */ -gboolean mu_contacts_add (MuContacts *contacts, const char* name, const char *email, +gboolean mu_contacts_add (MuContacts *contacts, const char* name, + const char *email, time_t tstamp); /** @@ -67,8 +67,8 @@ void mu_contacts_destroy (MuContacts *contacts); * name (which may be NULL) and the timestamp for the address * */ -typedef void (*MuContactsForeachFunc) (const char *email, const char *name, time_t tstamp, - gpointer user_data); +typedef void (*MuContactsForeachFunc) (const char *email, const char *name, + time_t tstamp, gpointer user_data); /** * call a function for either each contact, or each contact satisfying From 0f71852aea0c51eb6af2e0717f395501b3db7c6c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 21:20:17 +0300 Subject: [PATCH 09/12] * tests/Makefile.am, tests/test-mu-contacts.c: add mu_contacts unit tests --- src/tests/Makefile.am | 6 +- src/tests/test-mu-contacts.c | 183 +++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 src/tests/test-mu-contacts.c diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 46058a8d..53997e2d 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -1,4 +1,4 @@ -## Copyright (C) 2008-2010 Dirk-Jan C. Binnema +## Copyright (C) 2008-2011 Dirk-Jan C. Binnema ## ## 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 @@ -56,6 +56,10 @@ TEST_PROGS += test-mu-query test_mu_query_SOURCES= test-mu-query.c dummy.cc test_mu_query_LDADD= libtestmucommon.la +TEST_PROGS += test-mu-contacts +test_mu_contacts_SOURCES= test-mu-contacts.c dummy.cc +test_mu_contacts_LDADD= libtestmucommon.la + TEST_PROGS += test-mu-cmd test_mu_cmd_SOURCES= test-mu-cmd.c dummy.cc test_mu_cmd_LDADD= libtestmucommon.la diff --git a/src/tests/test-mu-contacts.c b/src/tests/test-mu-contacts.c new file mode 100644 index 00000000..d7ce3bda --- /dev/null +++ b/src/tests/test-mu-contacts.c @@ -0,0 +1,183 @@ +/* +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema +** +** 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 +#include + +#include +#include +#include + +#include "test-mu-common.h" +#include "src/mu-contacts.h" + +static gchar* +fill_database (void) +{ + gchar *cmdline, *tmpdir; + + tmpdir = test_mu_common_get_random_tmpdir(); + cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" + " --quiet", + MU_PROGRAM, tmpdir, MU_TESTMAILDIR); + + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, + NULL, NULL)); + g_free (cmdline); + + return tmpdir; +} + + +struct _Contact { + char *name, *email; + time_t tstamp; +}; +typedef struct _Contact Contact; + +static Contact* +contact_new (const char *email, const char *name, size_t tstamp) +{ + Contact *contact; + + contact = g_slice_new (Contact); + contact->name = name ? g_strdup (name) :NULL; + contact->email = email ? g_strdup (email) : NULL; + contact->tstamp = tstamp; + + return contact; + +} + +static void +contact_destroy (Contact *contact) +{ + if (contact) { + g_free (contact->name); + g_free (contact->email); + g_slice_free (Contact, contact); + } +} + + +static void +each_contact (const char *email, const char *name, time_t tstamp, + GSList **lst) +{ + Contact *contact; + + /* g_print ("[n:%s, e:%s]\n", name, email); */ + + contact = contact_new (email, name, tstamp); + *lst = g_slist_prepend (*lst, contact); +} + +static gboolean +has_contact (GSList *lst, const char* name_or_email, gboolean use_name) +{ + while (lst) { + Contact *c; + c = (Contact*)lst->data; + + /* g_print ("{n:%s,e:%s}\n", c->name, c->email); */ + + if (use_name && g_strcmp0(name_or_email, c->name) == 0) + return TRUE; + if (g_strcmp0 (name_or_email, c->email) == 0) + return TRUE; + + lst = g_slist_next (lst); + } + + return FALSE; +} + + + +static GSList* +accumulate_contacts (MuContacts *contacts, const gchar *pattern) +{ + GSList *lst; + + lst = NULL; + g_assert (mu_contacts_foreach (contacts, + (MuContactsForeachFunc)each_contact, + &lst, pattern, NULL)); + return lst; +} + + +static void +test_mu_contacts_01 (void) +{ + MuContacts *contacts; + gchar *muhome, *contactsfile; + GSList *clist; + + muhome = fill_database (); + g_assert (muhome != NULL); + contactsfile = g_strdup_printf ("%s%ccache%ccontacts", + muhome, G_DIR_SEPARATOR, G_DIR_SEPARATOR); + /* g_print ("[%s]\n", contactsfile); */ + + contacts = mu_contacts_new (contactsfile); + g_assert (contacts); + + clist = accumulate_contacts (contacts, "Mü"); + g_assert_cmpint (g_slist_length (clist), ==, 1); + g_assert (has_contact (clist, "Mü", TRUE)); + g_assert (has_contact (clist, "testmu@testmu.xx", FALSE)); + g_slist_foreach (clist, (GFunc)contact_destroy, NULL); + g_slist_free (clist); + + clist = accumulate_contacts (contacts, "testmu\\.xxx?"); + g_assert_cmpint (g_slist_length (clist), ==, 2); + g_assert (has_contact (clist, "Mü", TRUE)); + g_assert (has_contact (clist, "testmu@testmu.xx", FALSE)); + g_assert (has_contact (clist, "Helmut Kröger", TRUE)); + g_assert (has_contact (clist, "hk@testmu.xxx", FALSE)); + + g_slist_foreach (clist, (GFunc)contact_destroy, NULL); + g_slist_free (clist); + + g_free (contactsfile); + g_free (muhome); +} + + +int +main (int argc, char *argv[]) +{ + int rv; + + g_test_init (&argc, &argv, NULL); + g_test_add_func ("/mu-contact/test-mu-contacts-01", test_mu_contacts_01); + + g_log_set_handler (NULL, + G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, + (GLogFunc)black_hole, NULL); + rv = g_test_run (); + + return rv; +} + From fa0882ed90261ffd8ed9e2241269ab42abe6b497 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 21:21:10 +0300 Subject: [PATCH 10/12] * test-mu-{cmd,msg,query}.c: update (c) year --- src/tests/test-mu-cmd.c | 4 +++- src/tests/test-mu-msg.c | 34 ++++++++++++++++++++++++++++++++-- src/tests/test-mu-query.c | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/tests/test-mu-cmd.c b/src/tests/test-mu-cmd.c index 0e8d2f5e..a1ae2abb 100644 --- a/src/tests/test-mu-cmd.c +++ b/src/tests/test-mu-cmd.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2010 Dirk-Jan C. Binnema +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** 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 @@ -409,6 +409,8 @@ test_mu_view_01 (void) } + + static void test_mu_mkdir_01 (void) { diff --git a/src/tests/test-mu-msg.c b/src/tests/test-mu-msg.c index dabc9d7a..cbaedfca 100644 --- a/src/tests/test-mu-msg.c +++ b/src/tests/test-mu-msg.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2010 Dirk-Jan C. Binnema +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** 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 @@ -215,6 +215,31 @@ test_mu_msg_04 (void) } +static void +test_mu_msg_05 (void) +{ + MuMsg *msg; + + msg = mu_msg_new (MU_TESTMAILDIR + "cur/1305664394.2171_402.cthulhu!2,", + NULL, NULL); + + g_assert_cmpstr (mu_msg_get_to(msg), + ==, "Helmut Kröger "); + g_assert_cmpstr (mu_msg_get_subject(msg), + ==, "Motörhead"); + g_assert_cmpstr (mu_msg_get_from(msg), + ==, "Mü "); + g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */ + ==, MU_MSG_PRIO_NORMAL); + g_assert_cmpuint (mu_msg_get_date(msg), + ==, 0); + + mu_msg_unref (msg); +} + + + /* static gboolean */ /* ignore_error (const char* log_domain, GLogLevelFlags log_level, const gchar* msg, */ @@ -225,6 +250,9 @@ test_mu_msg_04 (void) + + + int main (int argc, char *argv[]) { @@ -240,7 +268,9 @@ main (int argc, char *argv[]) test_mu_msg_03); g_test_add_func ("/mu-msg/mu-msg-04", test_mu_msg_04); - + g_test_add_func ("/mu-msg/mu-msg-05", + test_mu_msg_05); + g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, (GLogFunc)black_hole, NULL); diff --git a/src/tests/test-mu-query.c b/src/tests/test-mu-query.c index 9b4ffb9a..90031ea3 100644 --- a/src/tests/test-mu-query.c +++ b/src/tests/test-mu-query.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2008-2010 Dirk-Jan C. Binnema +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** 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 From c692fdb3a27511062d06974c83bce1ea4e58a0d9 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 18 May 2011 21:21:36 +0300 Subject: [PATCH 11/12] * cosmetics --- ChangeLog | 1 + NEWS | 1 + TODO | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e69de29b..1ccf95ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1 @@ +Please us the 'git log' to see the ChangeLog diff --git a/NEWS b/NEWS index 3e5716a7..4a022fe6 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ * NEWS (user visible changes) + ** Release 0.9.5 <2011-04-25 Mon> - bug fix for infinite loop in Maildir detection diff --git a/TODO b/TODO index 57709ca9..500cfab3 100644 --- a/TODO +++ b/TODO @@ -11,12 +11,12 @@ - [ ] follow symlinks when indexing - [ ] better 'usage' info - + * Releases already done ** release 0.9.5 [100%] - + ** release 0.9.4 [100%] - [X] add 'mu cfind' to find contacts From f6ff982e921b60b7afcba19dd85f01d576057f42 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 19 May 2011 20:56:29 +0300 Subject: [PATCH 12/12] * tests: add unit-tests for 'mu cfind'; fix up merge --- src/tests/Makefile.am | 5 + src/tests/test-mu-cmd-cfind.c | 281 +++++++++++++++++ src/tests/test-mu-cmd.c | 560 +++++++++++++++++----------------- src/tests/test-mu-contacts.c | 2 +- 4 files changed, 572 insertions(+), 276 deletions(-) create mode 100644 src/tests/test-mu-cmd-cfind.c diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 53997e2d..6028626a 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -64,6 +64,11 @@ TEST_PROGS += test-mu-cmd test_mu_cmd_SOURCES= test-mu-cmd.c dummy.cc test_mu_cmd_LDADD= libtestmucommon.la +TEST_PROGS += test-mu-cmd-cfind +test_mu_cmd_cfind_SOURCES= test-mu-cmd-cfind.c dummy.cc +test_mu_cmd_cfind_LDADD= libtestmucommon.la + + TEST_PROGS += test-mu-msg test_mu_msg_SOURCES= test-mu-msg.c dummy.cc test_mu_msg_LDADD= libtestmucommon.la diff --git a/src/tests/test-mu-cmd-cfind.c b/src/tests/test-mu-cmd-cfind.c new file mode 100644 index 00000000..e41412f7 --- /dev/null +++ b/src/tests/test-mu-cmd-cfind.c @@ -0,0 +1,281 @@ +/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- +** +** Copyright (C) 2008-2011 Dirk-Jan C. Binnema +** +** 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. +** +*/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif /*HAVE_CONFIG_H*/ + +#include +#include + +#include "../mu-query.h" + +#include +#include +#include + +#include "test-mu-common.h" +#include "src/mu-store.h" + +static gchar* +fill_contacts_cache (void) +{ + gchar *cmdline, *tmpdir; + + tmpdir = test_mu_common_get_random_tmpdir(); + cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" + " --quiet", + MU_PROGRAM, tmpdir, MU_TESTMAILDIR); + + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, + NULL, NULL)); + g_free (cmdline); + + return tmpdir; +} + + +static void +test_mu_cfind_plain (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=plain " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "Helmut Kröger hk@testmu.xxx\n" + "Mü testmu@testmu.xx\n"); + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + +static void +test_mu_cfind_bbdb (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=bbdb " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + ";; -*-coding: utf-8-emacs;-*-\n" + ";;; file-version: 6\n" + + "[\"Helmut\" \"Kröger\" nil nil nil nil (\"hk@testmu.xxx\") " + "((creation-date . \"2011-05-19\") " + "(time-stamp . \"1970-01-01\")) nil]\n" + + "[\"Mü\" \"\" nil nil nil nil (\"testmu@testmu.xx\") " + "((creation-date . \"2011-05-19\") " + "(time-stamp . \"1970-01-01\")) nil]\n"); + + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + + +static void +test_mu_cfind_wl (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=wl " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "hk@testmu.xxx \"HelmutK\" \"Helmut Kröger\"\n" + "testmu@testmu.xx \"Mü\" \"Mü\"\n"); + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + + +static void +test_mu_cfind_mutt_alias (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-alias " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "alias HelmutK Helmut Kröger \n" + "alias Mü Mü \n"); + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + +static void +test_mu_cfind_mutt_ab (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=mutt-ab " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "hk@testmu.xxx\tHelmut Kröger\t\n" + "testmu@testmu.xx\tMü\t\n"); + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + + +static void +test_mu_cfind_org_contact (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=org-contact " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "* Helmut Kröger\n" + ":PROPERTIES:\n" + ":EMAIL: hk@testmu.xxx\n" + ":END:\n\n" + + "* Mü\n" + ":PROPERTIES:\n" + ":EMAIL: testmu@testmu.xx\n" + ":END:\n\n"); + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + + + +static void +test_mu_cfind_csv (void) +{ + gchar *muhome, *cmdline, *output, *erroutput; + + muhome = fill_contacts_cache (); + g_assert (muhome != NULL); + + cmdline = g_strdup_printf ("%s cfind --muhome=%s --format=csv " + "'testmu\\.xxx?'", + MU_PROGRAM, muhome); + + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "Helmut Kröger,hk@testmu.xxx\n" + "Mü,testmu@testmu.xx\n"); + g_free (cmdline); + g_free (muhome); + g_free (output); + g_free (erroutput); +} + + + + +int +main (int argc, char *argv[]) +{ + int rv; + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-plain", test_mu_cfind_plain); + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-bbdb", test_mu_cfind_bbdb); + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-wl", test_mu_cfind_wl); + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-mutt-alias", + test_mu_cfind_mutt_alias); + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-mutt-ab", + test_mu_cfind_mutt_ab); + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-org-contact", + test_mu_cfind_org_contact); + g_test_add_func ("/mu-cmd-cfind/test-mu-cfind-csv", + test_mu_cfind_csv); + + g_log_set_handler (NULL, + G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING| + G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, + (GLogFunc)black_hole, NULL); + + rv = g_test_run (); + + return rv; +} + diff --git a/src/tests/test-mu-cmd.c b/src/tests/test-mu-cmd.c index a1ae2abb..d24eb452 100644 --- a/src/tests/test-mu-cmd.c +++ b/src/tests/test-mu-cmd.c @@ -1,4 +1,5 @@ -/* +/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- +** ** Copyright (C) 2008-2011 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it @@ -39,34 +40,35 @@ static gchar* fill_database (void) { - gchar *cmdline, *tmpdir; + gchar *cmdline, *tmpdir; - tmpdir = test_mu_common_get_random_tmpdir(); - cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" - " --quiet", - MU_PROGRAM, tmpdir, MU_TESTMAILDIR2); + tmpdir = test_mu_common_get_random_tmpdir(); + cmdline = g_strdup_printf ("%s index --muhome=%s --maildir=%s" + " --quiet", + MU_PROGRAM, + tmpdir, MU_TESTMAILDIR2); - g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, - NULL, NULL)); - g_free (cmdline); + g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, + NULL, NULL)); + g_free (cmdline); - return tmpdir; + return tmpdir; } static unsigned newlines_in_output (const char* str) { - int count; + int count; - count = 0; + count = 0; - while (str && *str) { - if (*str == '\n') - ++count; - ++str; - } + while (str && *str) { + if (*str == '\n') + ++count; + ++str; + } - return count; + return count; } static void @@ -74,50 +76,50 @@ search (const char* query, unsigned expected) { gchar *muhome, *cmdline, *output, *erroutput; - muhome = fill_database (); - g_assert (muhome); + muhome = fill_database (); + g_assert (muhome); - cmdline = g_strdup_printf ("%s find --muhome=%s %s", - MU_PROGRAM, muhome, query); + cmdline = g_strdup_printf ("%s find --muhome=%s %s", + MU_PROGRAM, muhome, query); - /* g_printerr ("%s\n", cmdline); */ + /* g_printerr ("%s\n", cmdline); */ - g_assert (g_spawn_command_line_sync (cmdline, - &output, &erroutput, - NULL, NULL)); - g_assert_cmpuint (newlines_in_output(output),==,expected); + g_assert (g_spawn_command_line_sync (cmdline, + &output, &erroutput, + NULL, NULL)); + g_assert_cmpuint (newlines_in_output(output),==,expected); - /* we expect zero lines of error output if there is a match; - * otherwise there should be one line 'No matches found' */ - /* g_assert_cmpuint (newlines_in_output(erroutput),==, */ - /* expected == 0 ? 1 : 0); */ + /* we expect zero lines of error output if there is a match; + * otherwise there should be one line 'No matches found' */ + /* g_assert_cmpuint (newlines_in_output(erroutput),==, */ + /* expected == 0 ? 1 : 0); */ - g_free (output); - g_free (erroutput); - g_free (cmdline); - g_free (muhome); + g_free (output); + g_free (erroutput); + g_free (cmdline); + g_free (muhome); } /* index testdir2, and make sure it adds two documents */ static void test_mu_index (void) { - MuStore *store; - gchar *muhome, *xpath; + MuStore *store; + gchar *muhome, *xpath; - muhome = fill_database (); - g_assert (muhome != NULL); + muhome = fill_database (); + g_assert (muhome != NULL); - xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR, "xapian"); + xpath = g_strdup_printf ("%s%c%s", muhome, G_DIR_SEPARATOR, "xapian"); - store = mu_store_new (xpath, NULL, NULL); - g_assert (store); + store = mu_store_new (xpath, NULL, NULL); + g_assert (store); - g_assert_cmpuint (mu_store_count (store), ==, 5); - mu_store_destroy (store); + g_assert_cmpuint (mu_store_count (store), ==, 5); + mu_store_destroy (store); - g_free (muhome); - g_free (xpath); + g_free (muhome); + g_free (xpath); } @@ -125,15 +127,15 @@ test_mu_index (void) static void test_mu_find_01 (void) { - search ("f:john fruit", 1); - search ("f:soc@example.com", 1); - search ("t:alki@example.com", 1); - search ("t:alcibiades", 1); - search ("f:soc@example.com OR f:john", 2); - search ("f:soc@example.com OR f:john OR t:edmond", 3); - search ("t:julius", 1); - search ("s:dude", 1); - search ("t:dantès", 1); + search ("f:john fruit", 1); + search ("f:soc@example.com", 1); + search ("t:alki@example.com", 1); + search ("t:alcibiades", 1); + search ("f:soc@example.com OR f:john", 2); + search ("f:soc@example.com OR f:john OR t:edmond", 3); + search ("t:julius", 1); + search ("s:dude", 1); + search ("t:dantès", 1); } @@ -141,14 +143,14 @@ test_mu_find_01 (void) static void test_mu_find_02 (void) { - search ("bull", 1); - search ("bull m:foo", 0); - search ("bull m:/foo", 1); - search ("bull m:/Foo", 1); - search ("bull flag:a", 1); - search ("g:x", 0); - search ("flag:encrypted", 0); - search ("flag:attach", 1); + search ("bull", 1); + search ("bull m:foo", 0); + search ("bull m:/foo", 1); + search ("bull m:/Foo", 1); + search ("bull flag:a", 1); + search ("g:x", 0); + search ("flag:encrypted", 0); + search ("flag:attach", 1); } @@ -156,10 +158,10 @@ test_mu_find_02 (void) static void test_mu_find_03 (void) { - search ("bull", 1); - search ("bull m:foo", 0); - search ("bull m:/foo", 1); - search ("i:3BE9E6535E0D852173@emss35m06.us.lmco.com", 1); + search ("bull", 1); + search ("bull m:foo", 0); + search ("bull m:/foo", 1); + search ("i:3BE9E6535E0D852173@emss35m06.us.lmco.com", 1); } @@ -168,24 +170,25 @@ test_mu_find_04 (void) { gchar *muhome, *cmdline, *erroutput; - muhome = fill_database (); - g_assert (muhome); + muhome = fill_database (); + g_assert (muhome); - cmdline = g_strdup_printf ("%s --muhome=%cfoo%cbar%cnonexistent find f:socrates", - MU_PROGRAM, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR); + cmdline = g_strdup_printf ("%s --muhome=%cfoo%cbar%cnonexistent " + "find f:socrates", + MU_PROGRAM, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR); - g_assert (g_spawn_command_line_sync (cmdline, NULL, &erroutput, - NULL, NULL)); + g_assert (g_spawn_command_line_sync (cmdline, NULL, &erroutput, + NULL, NULL)); - /* we expect multiple lines of error output */ - g_assert_cmpuint (newlines_in_output(erroutput),>=,1); + /* we expect multiple lines of error output */ + g_assert_cmpuint (newlines_in_output(erroutput),>=,1); - g_free (erroutput); - g_free (cmdline); - g_free (muhome); + g_free (erroutput); + g_free (cmdline); + g_free (muhome); } @@ -194,49 +197,50 @@ test_mu_extract_01 (void) { gchar *cmdline, *output, *erroutput, *tmpdir; - tmpdir = test_mu_common_get_random_tmpdir(); - g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); + tmpdir = test_mu_common_get_random_tmpdir(); + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - cmdline = g_strdup_printf ("%s extract --muhome=%s %s%cFoo%ccur%cmail5", - MU_PROGRAM, - tmpdir, - MU_TESTMAILDIR2, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR); + cmdline = g_strdup_printf ("%s extract --muhome=%s %s%cFoo%ccur%cmail5", + MU_PROGRAM, + tmpdir, + MU_TESTMAILDIR2, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR); - /* g_print ("[%s]", cmdline); */ + /* g_print ("[%s]", cmdline); */ - output = erroutput = NULL; - g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL)); - g_assert_cmpstr (output, - ==, - "MIME-parts in this message:\n" - " 0 multipart/mixed []\n" - " 1 text/plain []\n" - " 2 sittingbull.jpg image/jpeg [inline]\n" - " 3 custer.jpg image/jpeg [inline]\n"); + output = erroutput = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, + ==, + "MIME-parts in this message:\n" + " 0 multipart/mixed []\n" + " 1 text/plain []\n" + " 2 sittingbull.jpg image/jpeg [inline]\n" + " 3 custer.jpg image/jpeg [inline]\n"); - /* we expect zero lines of error output */ - g_assert_cmpuint (newlines_in_output(erroutput),==,0); + /* we expect zero lines of error output */ + g_assert_cmpuint (newlines_in_output(erroutput),==,0); - g_free (output); - g_free (erroutput); - g_free (cmdline); - g_free (tmpdir); + g_free (output); + g_free (erroutput); + g_free (cmdline); + g_free (tmpdir); } static gint64 get_file_size (const char* path) { - int rv; - struct stat statbuf; + int rv; + struct stat statbuf; - rv = stat (path, &statbuf); - if (rv != 0) - return -1; + rv = stat (path, &statbuf); + if (rv != 0) + return -1; - return (gint64)statbuf.st_size; + return (gint64)statbuf.st_size; } @@ -244,36 +248,37 @@ static void test_mu_extract_02 (void) { gchar *cmdline, *output, *tmpdir; - gchar *att1, *att2; + gchar *att1, *att2; - tmpdir = test_mu_common_get_random_tmpdir(); + tmpdir = test_mu_common_get_random_tmpdir(); - g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - cmdline = g_strdup_printf ("%s extract --muhome=%s -a --target-dir=%s %s%cFoo%ccur%cmail5", - MU_PROGRAM, - tmpdir, - tmpdir, - MU_TESTMAILDIR2, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR); + cmdline = g_strdup_printf ("%s extract --muhome=%s -a " + "--target-dir=%s %s%cFoo%ccur%cmail5", + MU_PROGRAM, + tmpdir, + tmpdir, + MU_TESTMAILDIR2, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR); - output = NULL; - g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); - g_assert_cmpstr (output, ==, ""); + output = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); + g_assert_cmpstr (output, ==, ""); - att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR); - att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR); + att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR); + att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR); - g_assert_cmpint (get_file_size(att1),==,15960); - g_assert_cmpint (get_file_size(att2),==,17674); + g_assert_cmpint (get_file_size(att1),==,15960); + g_assert_cmpint (get_file_size(att2),==,17674); - g_free (output); - g_free (tmpdir); - g_free (cmdline); - g_free (att1); - g_free (att2); + g_free (output); + g_free (tmpdir); + g_free (cmdline); + g_free (att1); + g_free (att2); } @@ -281,36 +286,36 @@ static void test_mu_extract_03 (void) { gchar *cmdline, *output, *tmpdir; - gchar *att1, *att2; + gchar *att1, *att2; - tmpdir = test_mu_common_get_random_tmpdir(); + tmpdir = test_mu_common_get_random_tmpdir(); - g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - cmdline = g_strdup_printf ("%s extract --muhome=%s --parts 3 " - "--target-dir=%s %s%cFoo%ccur%cmail5", - MU_PROGRAM, - tmpdir, - tmpdir, - MU_TESTMAILDIR2, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR); - output = NULL; - g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); - g_assert_cmpstr (output, ==, ""); + cmdline = g_strdup_printf ("%s extract --muhome=%s --parts 3 " + "--target-dir=%s %s%cFoo%ccur%cmail5", + MU_PROGRAM, + tmpdir, + tmpdir, + MU_TESTMAILDIR2, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR); + output = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); + g_assert_cmpstr (output, ==, ""); - att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR); - att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR); + att1 = g_strdup_printf ("%s%ccuster.jpg", tmpdir, G_DIR_SEPARATOR); + att2 = g_strdup_printf ("%s%csittingbull.jpg", tmpdir, G_DIR_SEPARATOR); - g_assert_cmpint (get_file_size(att1),==,15960); /* should not exist */ - g_assert_cmpint (get_file_size(att2),==,-1); + g_assert_cmpint (get_file_size(att1),==,15960); /* should not exist */ + g_assert_cmpint (get_file_size(att2),==,-1); - g_free (output); - g_free (tmpdir); - g_free (cmdline); - g_free (att1); - g_free (att2); + g_free (output); + g_free (tmpdir); + g_free (cmdline); + g_free (att1); + g_free (att2); } @@ -319,42 +324,48 @@ test_mu_extract_04 (void) { gchar *cmdline, *output, *erroutput, *tmpdir; - tmpdir = test_mu_common_get_random_tmpdir(); + tmpdir = test_mu_common_get_random_tmpdir(); - g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - cmdline = g_strdup_printf ("%s extract --muhome=%s -a --target-dir=%s %s%cFoo%ccur%cmail5", - MU_PROGRAM, tmpdir, tmpdir, - MU_TESTMAILDIR2, G_DIR_SEPARATOR, - G_DIR_SEPARATOR, G_DIR_SEPARATOR); + cmdline = g_strdup_printf ("%s extract --muhome=%s -a " + "--target-dir=%s %s%cFoo%ccur%cmail5", + MU_PROGRAM, tmpdir, tmpdir, + MU_TESTMAILDIR2, G_DIR_SEPARATOR, + G_DIR_SEPARATOR, G_DIR_SEPARATOR); - g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL)); - g_assert_cmpstr (output, ==, ""); - g_assert_cmpstr (erroutput, ==, ""); - g_free (erroutput); - g_free (output); + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, ==, ""); + g_assert_cmpstr (erroutput, ==, ""); + g_free (erroutput); + g_free (output); - /* now, it should fail, because we don't allow overwrites without --overwrite */ - g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL)); - g_assert_cmpstr (output, ==, ""); - g_assert_cmpstr (erroutput, !=, ""); - g_free (erroutput); - g_free (output); + /* now, it should fail, because we don't allow overwrites + * without --overwrite */ + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, ==, ""); + g_assert_cmpstr (erroutput, !=, ""); + g_free (erroutput); + g_free (output); - g_free (cmdline); - /* this should work now, because we have specified --overwrite */ - cmdline = g_strdup_printf ("%s extract --muhome=%s -a --overwrite " - "--target-dir=%s %s%cFoo%ccur%cmail5", - MU_PROGRAM, tmpdir, tmpdir, MU_TESTMAILDIR2, G_DIR_SEPARATOR, - G_DIR_SEPARATOR, G_DIR_SEPARATOR); - g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL)); - g_assert_cmpstr (output, ==, ""); - g_assert_cmpstr (erroutput, ==, ""); - g_free (erroutput); - g_free (output); + g_free (cmdline); + /* this should work now, because we have specified --overwrite */ + cmdline = g_strdup_printf ("%s extract --muhome=%s -a --overwrite " + "--target-dir=%s %s%cFoo%ccur%cmail5", + MU_PROGRAM, tmpdir, tmpdir, + MU_TESTMAILDIR2, G_DIR_SEPARATOR, + G_DIR_SEPARATOR, G_DIR_SEPARATOR); + g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, + NULL, NULL)); + g_assert_cmpstr (output, ==, ""); + g_assert_cmpstr (erroutput, ==, ""); + g_free (erroutput); + g_free (output); - g_free (tmpdir); - g_free (cmdline); + g_free (tmpdir); + g_free (cmdline); } @@ -363,49 +374,49 @@ static void test_mu_view_01 (void) { gchar *cmdline, *output, *tmpdir; - int len; + int len; - tmpdir = test_mu_common_get_random_tmpdir(); - g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); + tmpdir = test_mu_common_get_random_tmpdir(); + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - cmdline = g_strdup_printf ("%s view --muhome=%s %s%cbar%ccur%cmail4", - MU_PROGRAM, - tmpdir, - MU_TESTMAILDIR2, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR, - G_DIR_SEPARATOR); - output = NULL; - g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); - g_assert_cmpstr (output, !=, NULL); + cmdline = g_strdup_printf ("%s view --muhome=%s %s%cbar%ccur%cmail4", + MU_PROGRAM, + tmpdir, + MU_TESTMAILDIR2, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR, + G_DIR_SEPARATOR); + output = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); + g_assert_cmpstr (output, !=, NULL); - /* - * note: there are two possibilities here; older versions of - * GMime will produce: - * - * From: "=?iso-8859-1?Q? =F6tzi ?=" - * - * while newer ones return something like: - * - * From: ?tzi - * - * or even - * - * From: \xc3\xb6tzi - * - * both are 'okay' from mu's perspective; it'd be even better - * to have some #ifdefs for the GMime versions, but this - * should work for now - * - * Added 350 as 'okay', which comes with gmime 2.4.24 (ubuntu 10.04) - */ - len = strlen(output); - /* g_print ("\n[%s] (%d)\n", output, len); */ - g_assert (len == 370 || len == 358 || len == 350 || len == 349); + /* + * note: there are two possibilities here; older versions of + * GMime will produce: + * + * From: "=?iso-8859-1?Q? =F6tzi ?=" + * + * while newer ones return something like: + * + * From: ?tzi + * + * or even + * + * From: \xc3\xb6tzi + * + * both are 'okay' from mu's perspective; it'd be even better + * to have some #ifdefs for the GMime versions, but this + * should work for now + * + * Added 350 as 'okay', which comes with gmime 2.4.24 (ubuntu 10.04) + */ + len = strlen(output); + /* g_print ("\n[%s] (%d)\n", output, len); */ + g_assert (len == 370 || len == 358 || len == 350 || len == 349); - g_free (output); - g_free (cmdline); - g_free (tmpdir); + g_free (output); + g_free (cmdline); + g_free (tmpdir); } @@ -415,38 +426,38 @@ static void test_mu_mkdir_01 (void) { gchar *cmdline, *output, *tmpdir; - gchar *dir; + gchar *dir; - tmpdir = test_mu_common_get_random_tmpdir(); - g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); + tmpdir = test_mu_common_get_random_tmpdir(); + g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0); - cmdline = g_strdup_printf ("%s mkdir --muhome=%s %s%ctest1 %s%ctest2", - MU_PROGRAM,tmpdir, - tmpdir, G_DIR_SEPARATOR, - tmpdir, G_DIR_SEPARATOR); + cmdline = g_strdup_printf ("%s mkdir --muhome=%s %s%ctest1 %s%ctest2", + MU_PROGRAM,tmpdir, + tmpdir, G_DIR_SEPARATOR, + tmpdir, G_DIR_SEPARATOR); - output = NULL; - g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); - g_assert_cmpstr (output, ==, ""); + output = NULL; + g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL)); + g_assert_cmpstr (output, ==, ""); - dir = g_strdup_printf ("%s%ctest1%ccur", tmpdir, G_DIR_SEPARATOR, - G_DIR_SEPARATOR); - g_assert (access (dir, F_OK) == 0); - g_free (dir); + dir = g_strdup_printf ("%s%ctest1%ccur", tmpdir, G_DIR_SEPARATOR, + G_DIR_SEPARATOR); + g_assert (access (dir, F_OK) == 0); + g_free (dir); - dir = g_strdup_printf ("%s%ctest2%ctmp", tmpdir, G_DIR_SEPARATOR, - G_DIR_SEPARATOR); - g_assert (access (dir, F_OK) == 0); - g_free (dir); + dir = g_strdup_printf ("%s%ctest2%ctmp", tmpdir, G_DIR_SEPARATOR, + G_DIR_SEPARATOR); + g_assert (access (dir, F_OK) == 0); + g_free (dir); - dir = g_strdup_printf ("%s%ctest1%cnew", tmpdir, G_DIR_SEPARATOR, - G_DIR_SEPARATOR); - g_assert (access (dir, F_OK) == 0); - g_free (dir); + dir = g_strdup_printf ("%s%ctest1%cnew", tmpdir, G_DIR_SEPARATOR, + G_DIR_SEPARATOR); + g_assert (access (dir, F_OK) == 0); + g_free (dir); - g_free (output); - g_free (tmpdir); - g_free (cmdline); + g_free (output); + g_free (tmpdir); + g_free (cmdline); } @@ -454,30 +465,29 @@ test_mu_mkdir_01 (void) int main (int argc, char *argv[]) { - int rv; - g_test_init (&argc, &argv, NULL); + int rv; + g_test_init (&argc, &argv, NULL); - g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index); - g_test_add_func ("/mu-cmd/test-mu-find-01", test_mu_find_01); - g_test_add_func ("/mu-cmd/test-mu-find-02", test_mu_find_02); - g_test_add_func ("/mu-cmd/test-mu-find-03", test_mu_find_03); - g_test_add_func ("/mu-cmd/test-mu-find-04", test_mu_find_04); - g_test_add_func ("/mu-cmd/test-mu-extract-01", test_mu_extract_01); - g_test_add_func ("/mu-cmd/test-mu-extract-02", test_mu_extract_02); - g_test_add_func ("/mu-cmd/test-mu-extract-03", test_mu_extract_03); - g_test_add_func ("/mu-cmd/test-mu-extract-04", test_mu_extract_04); - g_test_add_func ("/mu-cmd/test-mu-view-01", test_mu_view_01); - g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01); - - g_log_set_handler (NULL, - G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING| - G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, - (GLogFunc)black_hole, NULL); + g_test_add_func ("/mu-cmd/test-mu-index", test_mu_index); + g_test_add_func ("/mu-cmd/test-mu-find-01", test_mu_find_01); + g_test_add_func ("/mu-cmd/test-mu-find-02", test_mu_find_02); + g_test_add_func ("/mu-cmd/test-mu-find-03", test_mu_find_03); + g_test_add_func ("/mu-cmd/test-mu-find-04", test_mu_find_04); + g_test_add_func ("/mu-cmd/test-mu-extract-01", test_mu_extract_01); + g_test_add_func ("/mu-cmd/test-mu-extract-02", test_mu_extract_02); + g_test_add_func ("/mu-cmd/test-mu-extract-03", test_mu_extract_03); + g_test_add_func ("/mu-cmd/test-mu-extract-04", test_mu_extract_04); + g_test_add_func ("/mu-cmd/test-mu-view-01", test_mu_view_01); + g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01); + + g_log_set_handler (NULL, + G_LOG_LEVEL_MASK | G_LOG_LEVEL_WARNING| + G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION, + (GLogFunc)black_hole, NULL); - mu_msg_gmime_init (); - rv = g_test_run (); - mu_msg_gmime_uninit(); + rv = g_test_run (); - return rv; + + return rv; } diff --git a/src/tests/test-mu-contacts.c b/src/tests/test-mu-contacts.c index d7ce3bda..990d57f9 100644 --- a/src/tests/test-mu-contacts.c +++ b/src/tests/test-mu-contacts.c @@ -171,7 +171,7 @@ main (int argc, char *argv[]) int rv; g_test_init (&argc, &argv, NULL); - g_test_add_func ("/mu-contact/test-mu-contacts-01", test_mu_contacts_01); + g_test_add_func ("/mu-contacts/test-mu-contacts-01", test_mu_contacts_01); g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,