Merge branch 'procmule'
This commit is contained in:
@ -99,7 +99,6 @@ GSList* mu_msg_file_get_str_list_field (MuMsgFile *self,
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get a numeric value for this message -- the return value should be
|
||||
* cast into the actual type, e.g., time_t, MuMsgPrio etc.
|
||||
|
||||
88
src/mu-msg.c
88
src/mu-msg.c
@ -521,25 +521,19 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
|
||||
|
||||
|
||||
static void
|
||||
address_list_foreach (InternetAddressList *addrlist,
|
||||
MuMsgContactType ctype,
|
||||
MuMsgContactForeachFunc func,
|
||||
gpointer user_data)
|
||||
address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
|
||||
MuMsgContactForeachFunc func, gpointer user_data)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!addrlist)
|
||||
return;
|
||||
|
||||
for (i = 0; i != internet_address_list_length(addrlist); ++i) {
|
||||
|
||||
for (i = 0; addrlist && i != internet_address_list_length(addrlist);
|
||||
++i) {
|
||||
|
||||
MuMsgContact contact;
|
||||
if (!fill_contact(&contact,
|
||||
internet_address_list_get_address (addrlist, i),
|
||||
ctype)) {
|
||||
MU_WRITE_LOG ("ignoring contact");
|
||||
ctype))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(func)(&contact, user_data))
|
||||
break;
|
||||
@ -547,30 +541,25 @@ address_list_foreach (InternetAddressList *addrlist,
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
get_contacts_from (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
gpointer user_data)
|
||||
addresses_foreach (const char* addrs, MuMsgContactType ctype,
|
||||
MuMsgContactForeachFunc func, gpointer user_data)
|
||||
{
|
||||
InternetAddressList *lst;
|
||||
|
||||
/* we go through this whole excercise of trying to get a *list*
|
||||
* of 'From:' address (usually there is only one...), because
|
||||
* internet_address_parse_string has the nice side-effect of
|
||||
* splitting in names and addresses for us */
|
||||
lst = internet_address_list_parse_string (
|
||||
g_mime_message_get_sender (msg->_file->_mime_msg));
|
||||
InternetAddressList *addrlist;
|
||||
|
||||
if (lst) {
|
||||
address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
|
||||
func, user_data);
|
||||
g_object_unref (G_OBJECT(lst));
|
||||
}
|
||||
if (!addrs)
|
||||
return;
|
||||
|
||||
addrlist = internet_address_list_parse_string (addrs);
|
||||
if (addrlist) {
|
||||
address_list_foreach (addrlist, ctype, func, user_data);
|
||||
g_object_unref (addrlist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
int i;
|
||||
@ -583,11 +572,10 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
||||
};
|
||||
|
||||
g_return_if_fail (func && msg);
|
||||
|
||||
/* first, get the from address(es) */
|
||||
get_contacts_from (msg, func, user_data);
|
||||
|
||||
/* sender */
|
||||
addresses_foreach (g_mime_message_get_sender (msg->_file->_mime_msg),
|
||||
MU_MSG_CONTACT_TYPE_FROM, func, user_data);
|
||||
|
||||
/* get to, cc, bcc */
|
||||
for (i = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
||||
InternetAddressList *addrlist;
|
||||
@ -598,6 +586,38 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
addresses_foreach (mu_msg_get_from (msg),
|
||||
MU_MSG_CONTACT_TYPE_FROM, func, user_data);
|
||||
addresses_foreach (mu_msg_get_to (msg),
|
||||
MU_MSG_CONTACT_TYPE_TO, func, user_data);
|
||||
addresses_foreach (mu_msg_get_cc (msg),
|
||||
MU_MSG_CONTACT_TYPE_CC, func, user_data);
|
||||
addresses_foreach (mu_msg_get_bcc (msg),
|
||||
MU_MSG_CONTACT_TYPE_BCC, func, user_data);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (msg);
|
||||
g_return_if_fail (func);
|
||||
|
||||
if (msg->_doc)
|
||||
msg_contact_foreach_doc (msg, func, user_data);
|
||||
else if (msg->_file)
|
||||
msg_contact_foreach_file (msg, func, user_data);
|
||||
else
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
cmp_str (const char* s1, const char *s2)
|
||||
{
|
||||
|
||||
@ -77,7 +77,7 @@ MuMsg *mu_msg_new_from_doc (XapianDocument* doc, GError **err)
|
||||
* @return the message with its reference count increased, or NULL in
|
||||
* case of error.
|
||||
*/
|
||||
MuMsg * mu_msg_ref (MuMsg *msg);
|
||||
MuMsg *mu_msg_ref (MuMsg *msg);
|
||||
|
||||
/**
|
||||
* decrease the reference count for this message. if the reference
|
||||
@ -305,7 +305,7 @@ MuMsgPrio mu_msg_get_prio (MuMsg *msg);
|
||||
*
|
||||
* @return the timestamp or 0 in case of error
|
||||
*/
|
||||
time_t mu_msg_get_timestamp (MuMsg *msg);
|
||||
time_t mu_msg_get_timestamp (MuMsg *msg);
|
||||
|
||||
|
||||
|
||||
@ -334,10 +334,6 @@ const char* mu_msg_get_header (MuMsg *self, const char *header);
|
||||
*/
|
||||
const GSList* mu_msg_get_references (MuMsg *msg);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get the list of tags (ie., X-Label)
|
||||
*
|
||||
|
||||
@ -222,29 +222,36 @@ struct _MuQuery {
|
||||
MuSizeRangeProcessor _size_range_processor;
|
||||
};
|
||||
|
||||
static bool
|
||||
set_query (MuQuery *mqx, Xapian::Query& q, const char* searchexpr,
|
||||
GError **err) {
|
||||
static const Xapian::Query
|
||||
get_query (MuQuery *mqx, const char* searchexpr, GError **err)
|
||||
{
|
||||
Xapian::Query query;
|
||||
char *preprocessed;
|
||||
|
||||
preprocessed = mu_query_preprocess (searchexpr);
|
||||
|
||||
try {
|
||||
q = mqx->_qparser.parse_query
|
||||
(searchexpr,
|
||||
query = mqx->_qparser.parse_query
|
||||
(preprocessed,
|
||||
Xapian::QueryParser::FLAG_BOOLEAN |
|
||||
Xapian::QueryParser::FLAG_PURE_NOT |
|
||||
Xapian::QueryParser::FLAG_WILDCARD |
|
||||
Xapian::QueryParser::FLAG_AUTO_SYNONYMS |
|
||||
Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE);
|
||||
|
||||
return true;
|
||||
g_free (preprocessed);
|
||||
return query;
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK;
|
||||
|
||||
/* some error occured */
|
||||
g_set_error (err, 0, MU_ERROR_QUERY, "parse error in query '%s'",
|
||||
searchexpr);
|
||||
|
||||
return false;
|
||||
} catch (...) {
|
||||
/* some error occured */
|
||||
g_set_error (err, 0, MU_ERROR_QUERY, "parse error in query '%s'",
|
||||
searchexpr);
|
||||
g_free (preprocessed);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
add_prefix (MuMsgFieldId mfid, Xapian::QueryParser* qparser)
|
||||
{
|
||||
@ -343,17 +350,6 @@ mu_query_run (MuQuery *self, const char* searchexpr, gboolean threads,
|
||||
sortfieldid == MU_MSG_FIELD_ID_NONE,
|
||||
NULL);
|
||||
try {
|
||||
Xapian::Query query;
|
||||
char *preprocessed;
|
||||
|
||||
preprocessed = mu_query_preprocess (searchexpr);
|
||||
|
||||
if (!set_query(self, query, preprocessed, err)) {
|
||||
g_free (preprocessed);
|
||||
return NULL;
|
||||
}
|
||||
g_free (preprocessed);
|
||||
|
||||
Xapian::Enquire enq (self->_db);
|
||||
|
||||
/* note, when our result will be *threaded*, we sort
|
||||
@ -361,7 +357,13 @@ mu_query_run (MuQuery *self, const char* searchexpr, gboolean threads,
|
||||
if (!threads && sortfieldid != MU_MSG_FIELD_ID_NONE)
|
||||
enq.set_sort_by_value ((Xapian::valueno)sortfieldid,
|
||||
ascending ? true : false);
|
||||
enq.set_query(query);
|
||||
|
||||
if (!mu_str_is_empty(searchexpr)) /* NULL or "" */
|
||||
enq.set_query(get_query (self, searchexpr, err));
|
||||
else
|
||||
enq.set_query(Xapian::Query::MatchAll);
|
||||
|
||||
|
||||
enq.set_cutoff(0,0);
|
||||
|
||||
return mu_msg_iter_new (
|
||||
@ -379,17 +381,7 @@ mu_query_as_string (MuQuery *self, const char *searchexpr, GError **err)
|
||||
g_return_val_if_fail (searchexpr, NULL);
|
||||
|
||||
try {
|
||||
Xapian::Query query;
|
||||
char *preprocessed;
|
||||
|
||||
preprocessed = mu_query_preprocess (searchexpr);
|
||||
|
||||
if (!set_query(self, query, preprocessed, err)) {
|
||||
g_free (preprocessed);
|
||||
return NULL;
|
||||
}
|
||||
g_free (preprocessed);
|
||||
|
||||
Xapian::Query query (get_query(self, searchexpr, err));
|
||||
return g_strdup(query.get_description().c_str());
|
||||
|
||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
||||
|
||||
@ -68,7 +68,7 @@ char* mu_query_version (MuQuery *store)
|
||||
* manpage, or http://xapian.org/docs/queryparser.html
|
||||
*
|
||||
* @param self a valid MuQuery instance
|
||||
* @param expr the search expression
|
||||
* @param expr the search expression or "" to match all messages
|
||||
* @param threads calculate message-threads
|
||||
* @param sortfield the field id to sort by or MU_MSG_FIELD_ID_NONE if
|
||||
* sorting is not desired
|
||||
|
||||
@ -78,45 +78,6 @@ typedef enum _MuRuntimePath MuRuntimePath;
|
||||
const char* mu_runtime_path (MuRuntimePath path);
|
||||
|
||||
|
||||
/**
|
||||
* get the mu home directory (typically, ~/.mu); this can only be
|
||||
* called after mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return mu home directory as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_mu_home_dir (void);
|
||||
|
||||
/**
|
||||
* get the xapian directory (typically, ~/.mu/xapian/); this can only
|
||||
* be called after mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return the xapian directory as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_xapian_dir (void);
|
||||
|
||||
|
||||
/**
|
||||
* get the mu bookmarks file (typically, ~/.mu/bookmarks); this can
|
||||
* only be called after mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return the bookmarks file as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_bookmarks_file (void);
|
||||
|
||||
/**
|
||||
* get the mu contacts cache file name (typically,
|
||||
* ~/.mu/contacts.cache); this can only be called after
|
||||
* mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return the contacts cache file name as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_contacts_cache_file (void);
|
||||
|
||||
|
||||
/**
|
||||
* get the mu configuration options (ie., the parsed command line
|
||||
* parameters)
|
||||
|
||||
@ -443,7 +443,6 @@ mu_str_subject_normalize (const gchar* str)
|
||||
gchar *last_colon;
|
||||
g_return_val_if_fail (str, NULL);
|
||||
|
||||
/* FIXME: improve this */
|
||||
last_colon = g_strrstr (str, ":");
|
||||
if (!last_colon)
|
||||
return str;
|
||||
|
||||
@ -150,6 +150,7 @@ test_mu_query_01 (void)
|
||||
{ "foo:pepernoot", 0 },
|
||||
{ "funky", 1 },
|
||||
{ "fünkÿ", 1 },
|
||||
{ "", 13 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user