From 1872d210c92d458edafa2803893332a0d859c10a Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 17 Dec 2012 22:24:19 +0200 Subject: [PATCH] * add support for searching the mailing list of a message --- lib/mu-msg-fields.c | 68 +++++++++++++++++++++++++++------------------ lib/mu-msg-fields.h | 4 +++ lib/mu-msg-file.c | 30 ++++++++++++++++++++ 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/lib/mu-msg-fields.c b/lib/mu-msg-fields.c index 844403e7..28a0a581 100644 --- a/lib/mu-msg-fields.c +++ b/lib/mu-msg-fields.c @@ -159,15 +159,15 @@ static const MuMsgField FIELD_DATA[] = { FLAG_GMIME | FLAG_XAPIAN_CONTACT | FLAG_XAPIAN_VALUE }, + { - MU_MSG_FIELD_ID_PATH, + MU_MSG_FIELD_ID_LIST, MU_MSG_FIELD_TYPE_STRING, - "path", 'l', 'L', /* 'l' for location */ - FLAG_GMIME | FLAG_XAPIAN_VALUE | - FLAG_XAPIAN_BOOLEAN | FLAG_XAPIAN_PREFIX_ONLY | - FLAG_XAPIAN_ESCAPE + "list", 'v', 'L', + FLAG_GMIME | FLAG_XAPIAN_VALUE }, + { MU_MSG_FIELD_ID_MAILDIR, MU_MSG_FIELD_TYPE_STRING, @@ -184,6 +184,26 @@ static const MuMsgField FIELD_DATA[] = { FLAG_XAPIAN_TERM | FLAG_XAPIAN_ESCAPE | FLAG_XAPIAN_PREFIX_ONLY }, + + { + MU_MSG_FIELD_ID_MSGID, + MU_MSG_FIELD_TYPE_STRING, + "msgid", 'i', 'I', /* 'i' for Id */ + FLAG_GMIME | FLAG_XAPIAN_TERM | FLAG_XAPIAN_VALUE | + FLAG_XAPIAN_ESCAPE | FLAG_XAPIAN_PREFIX_ONLY + }, + + + { + MU_MSG_FIELD_ID_PATH, + MU_MSG_FIELD_TYPE_STRING, + "path", 'l', 'L', /* 'l' for location */ + FLAG_GMIME | FLAG_XAPIAN_VALUE | + FLAG_XAPIAN_BOOLEAN | FLAG_XAPIAN_PREFIX_ONLY | + FLAG_XAPIAN_ESCAPE + }, + + { MU_MSG_FIELD_ID_PRIO, MU_MSG_FIELD_TYPE_INT, @@ -192,6 +212,15 @@ static const MuMsgField FIELD_DATA[] = { FLAG_XAPIAN_PREFIX_ONLY }, + + { + MU_MSG_FIELD_ID_REFS, + MU_MSG_FIELD_TYPE_STRING_LIST, + "refs", 'r', 'R', + FLAG_GMIME | FLAG_XAPIAN_VALUE | FLAG_XAPIAN_PREFIX_ONLY + }, + + { MU_MSG_FIELD_ID_SIZE, MU_MSG_FIELD_TYPE_BYTESIZE, @@ -208,28 +237,6 @@ static const MuMsgField FIELD_DATA[] = { FLAG_XAPIAN_TERM | FLAG_XAPIAN_ESCAPE }, - { - MU_MSG_FIELD_ID_TO, - MU_MSG_FIELD_TYPE_STRING, - "to", 't', 'T', - FLAG_GMIME | FLAG_XAPIAN_CONTACT | FLAG_XAPIAN_VALUE - }, - - { - MU_MSG_FIELD_ID_MSGID, - MU_MSG_FIELD_TYPE_STRING, - "msgid", 'i', 'I', /* 'i' for Id */ - FLAG_GMIME | FLAG_XAPIAN_TERM | FLAG_XAPIAN_VALUE | - FLAG_XAPIAN_ESCAPE | FLAG_XAPIAN_PREFIX_ONLY - }, - - { - MU_MSG_FIELD_ID_REFS, - MU_MSG_FIELD_TYPE_STRING_LIST, - "refs", 'r', 'R', - FLAG_GMIME | FLAG_XAPIAN_VALUE | FLAG_XAPIAN_PREFIX_ONLY - }, - { MU_MSG_FIELD_ID_TAGS, MU_MSG_FIELD_TYPE_STRING_LIST, @@ -238,6 +245,13 @@ static const MuMsgField FIELD_DATA[] = { FLAG_XAPIAN_ESCAPE }, + { + MU_MSG_FIELD_ID_TO, + MU_MSG_FIELD_TYPE_STRING, + "to", 't', 'T', + FLAG_GMIME | FLAG_XAPIAN_CONTACT | FLAG_XAPIAN_VALUE + }, + { /* special, internal field, to get a unique key */ MU_MSG_FIELD_ID_UID, MU_MSG_FIELD_TYPE_STRING, diff --git a/lib/mu-msg-fields.h b/lib/mu-msg-fields.h index 7e1a60fb..e7d93c0d 100644 --- a/lib/mu-msg-fields.h +++ b/lib/mu-msg-fields.h @@ -55,6 +55,10 @@ enum _MuMsgFieldId { MU_MSG_FIELD_ID_PRIO, MU_MSG_FIELD_ID_SIZE, + /* add new ones here... */ + MU_MSG_FIELD_ID_LIST, /* mailing list */ + + MU_MSG_FIELD_ID_NUM }; typedef guint8 MuMsgFieldId; diff --git a/lib/mu-msg-file.c b/lib/mu-msg-file.c index 9f26b669..728486eb 100644 --- a/lib/mu-msg-file.c +++ b/lib/mu-msg-file.c @@ -198,6 +198,29 @@ get_recipient (MuMsgFile *self, GMimeRecipientType rtype) return recip; } +static gchar* +get_mailing_list (MuMsgFile *self) +{ + const char *hdr, *b, *e; + + hdr = g_mime_object_get_header (GMIME_OBJECT(self->_mime_msg), + "List-Id"); + if (mu_str_is_empty (hdr)) + return NULL; + + e = NULL; + b = strchr (hdr, '<'); + if (b) + e = strchr (b, '>'); + + if (b && e) + return g_strndup (b + 1, e - b - 1); + else + return NULL; +} + + + static gboolean looks_like_attachment (GMimeObject *part) @@ -500,6 +523,9 @@ get_references (MuMsgFile *self) return g_slist_reverse (msgids); } + + + /* see: http://does-not-exist.org/mail-archives/mutt-dev/msg08249.html */ static GSList* get_tags (MuMsgFile *self) @@ -592,6 +618,10 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid, case MU_MSG_FIELD_ID_PATH: return self->_path; + case MU_MSG_FIELD_ID_LIST: + *do_free = TRUE; + return (char*)get_mailing_list (self); + case MU_MSG_FIELD_ID_SUBJECT: return (char*)maybe_cleanup (g_mime_message_get_subject (self->_mime_msg),