mirror of https://github.com/djcb/mu.git
* mu-msg-iter.{cc,h}: add mu_msg_iter_get_refs, small updates
This commit is contained in:
parent
c07b8e4529
commit
e611c8cb8f
|
@ -35,14 +35,19 @@ struct _MuMsgIter {
|
||||||
_matches = _enq.get_mset (0, _batchsize);
|
_matches = _enq.get_mset (0, _batchsize);
|
||||||
_cursor = _matches.begin();
|
_cursor = _matches.begin();
|
||||||
_is_null = _matches.empty();
|
_is_null = _matches.empty();
|
||||||
|
clear_fields (false);
|
||||||
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i)
|
|
||||||
_str[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~_MuMsgIter () {
|
~_MuMsgIter () {
|
||||||
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i)
|
clear_fields (true);
|
||||||
g_free (_str[i]);
|
}
|
||||||
|
|
||||||
|
void clear_fields (bool dofree) {
|
||||||
|
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i) {
|
||||||
|
if (dofree)
|
||||||
|
g_free(_str[i]);
|
||||||
|
_str[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Xapian::Enquire _enq;
|
const Xapian::Enquire _enq;
|
||||||
|
@ -50,7 +55,9 @@ struct _MuMsgIter {
|
||||||
Xapian::MSet::const_iterator _cursor;
|
Xapian::MSet::const_iterator _cursor;
|
||||||
size_t _batchsize, _offset;
|
size_t _batchsize, _offset;
|
||||||
char* _str[MU_MSG_FIELD_ID_NUM];
|
char* _str[MU_MSG_FIELD_ID_NUM];
|
||||||
bool _is_null;
|
bool _is_null;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,19 +149,18 @@ mu_msg_iter_next (MuMsgIter *iter)
|
||||||
return FALSE; /* no more matches */
|
return FALSE; /* no more matches */
|
||||||
|
|
||||||
/* the message may not be readable / existing, e.g.,
|
/* the message may not be readable / existing, e.g.,
|
||||||
* because of the database not being fully up to
|
* because of the database not being fully up to
|
||||||
* date. in that case, we ignore the message. it
|
* date. in that case, we ignore the message. it
|
||||||
* might be nice to auto-delete these messages from
|
* might be nice to auto-delete these messages from
|
||||||
* the db, but that might screw up the search;
|
* the db, but that might screw up the search;
|
||||||
* also, we only have read-only access to the db
|
* also, we only have read-only access to the db
|
||||||
* here */
|
* here */
|
||||||
|
/* TODO: only mark it as such, let clients handle
|
||||||
|
* it */
|
||||||
if (!message_is_readable (iter))
|
if (!message_is_readable (iter))
|
||||||
return mu_msg_iter_next (iter);
|
return mu_msg_iter_next (iter);
|
||||||
|
|
||||||
for (int i = 0; i != MU_MSG_FIELD_ID_NUM; ++i) {
|
iter->clear_fields (true);
|
||||||
g_free (iter->_str[i]);
|
|
||||||
iter->_str[i] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -205,7 +211,6 @@ get_field_numeric (MuMsgIter *iter, MuMsgFieldId mfid)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return static_cast<gint64>(Xapian::sortable_unserialise(str));
|
return static_cast<gint64>(Xapian::sortable_unserialise(str));
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(static_cast<gint64>(-1));
|
} MU_XAPIAN_CATCH_BLOCK_RETURN(static_cast<gint64>(-1));
|
||||||
|
@ -295,6 +300,13 @@ mu_msg_iter_get_bcc (MuMsgIter *iter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
mu_msg_iter_get_refs (MuMsgIter *iter)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL);
|
||||||
|
return get_field (iter, MU_MSG_FIELD_ID_REFS);
|
||||||
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_iter_get_subject (MuMsgIter *iter)
|
mu_msg_iter_get_subject (MuMsgIter *iter)
|
||||||
{
|
{
|
||||||
|
@ -351,8 +363,9 @@ MuMsgData*
|
||||||
mu_msg_iter_get_msgdata (MuMsgIter *iter)
|
mu_msg_iter_get_msgdata (MuMsgIter *iter)
|
||||||
{
|
{
|
||||||
MuMsgData *mdata;
|
MuMsgData *mdata;
|
||||||
g_return_val_if_fail (!mu_msg_iter_is_done(iter),
|
|
||||||
NULL);
|
g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL);
|
||||||
|
|
||||||
mdata = mu_msg_data_new ();
|
mdata = mu_msg_data_new ();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -361,6 +374,7 @@ mu_msg_iter_get_msgdata (MuMsgIter *iter)
|
||||||
mdata->maildir = get_field_copy (iter, MU_MSG_FIELD_ID_MAILDIR);
|
mdata->maildir = get_field_copy (iter, MU_MSG_FIELD_ID_MAILDIR);
|
||||||
mdata->msgid = get_field_copy (iter, MU_MSG_FIELD_ID_MSGID);
|
mdata->msgid = get_field_copy (iter, MU_MSG_FIELD_ID_MSGID);
|
||||||
mdata->path = get_field_copy (iter, MU_MSG_FIELD_ID_PATH);
|
mdata->path = get_field_copy (iter, MU_MSG_FIELD_ID_PATH);
|
||||||
|
mdata->refs = get_field_copy (iter, MU_MSG_FIELD_ID_REFS);
|
||||||
mdata->subject = get_field_copy (iter, MU_MSG_FIELD_ID_SUBJECT);
|
mdata->subject = get_field_copy (iter, MU_MSG_FIELD_ID_SUBJECT);
|
||||||
mdata->to = get_field_copy (iter, MU_MSG_FIELD_ID_TO);
|
mdata->to = get_field_copy (iter, MU_MSG_FIELD_ID_TO);
|
||||||
|
|
||||||
|
@ -373,7 +387,10 @@ mu_msg_iter_get_msgdata (MuMsgIter *iter)
|
||||||
mdata->prio = static_cast<MuMsgPrio>(get_field_numeric
|
mdata->prio = static_cast<MuMsgPrio>(get_field_numeric
|
||||||
(iter, MU_MSG_FIELD_ID_PRIO));
|
(iter, MU_MSG_FIELD_ID_PRIO));
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN(NULL);
|
return mdata;
|
||||||
|
|
||||||
return mdata;
|
} MU_XAPIAN_CATCH_BLOCK;
|
||||||
|
|
||||||
|
mu_msg_data_destroy (mdata); /* something bad happended */
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,6 +253,18 @@ MuMsgFlags mu_msg_iter_get_flags (MuMsgIter *iter);
|
||||||
MuMsgPrio mu_msg_iter_get_prio (MuMsgIter *iter);
|
MuMsgPrio mu_msg_iter_get_prio (MuMsgIter *iter);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the references (References: and Reply-To:) as a comma-separated
|
||||||
|
* string, with the last one pointing at the parent
|
||||||
|
*
|
||||||
|
* @param iter a valid MuMsgIter iterator
|
||||||
|
*
|
||||||
|
* @return the message references, or NULL in case of error or if
|
||||||
|
* there is none
|
||||||
|
*/
|
||||||
|
const char* mu_msg_iter_get_refs (MuMsgIter *iter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get some message field
|
* get some message field
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue