* mu: provide fake-msgids for messages without; this fixes the problem where e.g. draft messages
were not visible when using --include-related
This commit is contained in:
@ -541,8 +541,8 @@ get_references (MuMsgFile *self)
|
|||||||
msgid = g_mime_references_get_message_id (cur);
|
msgid = g_mime_references_get_message_id (cur);
|
||||||
/* don't include duplicates */
|
/* don't include duplicates */
|
||||||
if (msgid && !contains (msgids, msgid))
|
if (msgid && !contains (msgids, msgid))
|
||||||
/* explicitly ensure it's utf8-safe, as GMime
|
/* explicitly ensure it's utf8-safe,
|
||||||
* does not ensure that */
|
* as GMime does not ensure that */
|
||||||
msgids = g_slist_prepend (msgids,
|
msgids = g_slist_prepend (msgids,
|
||||||
g_strdup((msgid)));
|
g_strdup((msgid)));
|
||||||
}
|
}
|
||||||
@ -625,6 +625,22 @@ recipient_type (MuMsgFieldId mfid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
get_msgid (MuMsgFile *self, gboolean *do_free)
|
||||||
|
{
|
||||||
|
const char *msgid;
|
||||||
|
|
||||||
|
msgid = g_mime_message_get_message_id (self->_mime_msg);
|
||||||
|
if (msgid)
|
||||||
|
return (char*)msgid;
|
||||||
|
else { /* if there is none, fake it */
|
||||||
|
*do_free = TRUE;
|
||||||
|
return g_strdup_printf (
|
||||||
|
"%s@fake-msgid",
|
||||||
|
mu_util_get_hash (self->_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char*
|
char*
|
||||||
mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid,
|
mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid,
|
||||||
@ -659,7 +675,7 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid,
|
|||||||
self->_path, do_free);
|
self->_path, do_free);
|
||||||
|
|
||||||
case MU_MSG_FIELD_ID_MSGID:
|
case MU_MSG_FIELD_ID_MSGID:
|
||||||
return (char*)g_mime_message_get_message_id (self->_mime_msg);
|
return get_msgid (self, do_free);
|
||||||
|
|
||||||
case MU_MSG_FIELD_ID_MAILDIR: return self->_maildir;
|
case MU_MSG_FIELD_ID_MAILDIR: return self->_maildir;
|
||||||
|
|
||||||
|
|||||||
@ -125,22 +125,27 @@ public:
|
|||||||
|
|
||||||
MuMsgIterFlags flags() const { return _flags; }
|
MuMsgIterFlags flags() const { return _flags; }
|
||||||
|
|
||||||
|
const std::string msgid () const {
|
||||||
|
const Xapian::Document doc (cursor().get_document());
|
||||||
|
return doc.get_value(MU_MSG_FIELD_ID_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned docid () const {
|
||||||
|
const Xapian::Document doc (cursor().get_document());
|
||||||
|
return doc.get_docid();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool looks_like_dup () const {
|
bool looks_like_dup () const {
|
||||||
try {
|
try {
|
||||||
const Xapian::Document doc (cursor().get_document());
|
const Xapian::Document doc (cursor().get_document());
|
||||||
const std::string msgid (doc.get_value(MU_MSG_FIELD_ID_MSGID));
|
|
||||||
unsigned docid (doc.get_docid());
|
|
||||||
|
|
||||||
if (msgid.empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// is this message in the preferred map? if
|
// is this message in the preferred map? if
|
||||||
// so, it's not a duplicate, otherwise, it
|
// so, it's not a duplicate, otherwise, it
|
||||||
// isn't
|
// isn't
|
||||||
msgid_docid_map::const_iterator pref_iter (_preferred_map.find (msgid));
|
msgid_docid_map::const_iterator pref_iter (_preferred_map.find (msgid()));
|
||||||
if (pref_iter != _preferred_map.end()) {
|
if (pref_iter != _preferred_map.end()) {
|
||||||
//std::cerr << "in the set!" << std::endl;
|
//std::cerr << "in the set!" << std::endl;
|
||||||
if ((*pref_iter).second == docid)
|
if ((*pref_iter).second == docid())
|
||||||
return false; // in the set: not a dup!
|
return false; // in the set: not a dup!
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
@ -148,10 +153,10 @@ public:
|
|||||||
|
|
||||||
// otherwise, simply check if we've already seen this message-id,
|
// otherwise, simply check if we've already seen this message-id,
|
||||||
// and, if so, it's considered a dup
|
// and, if so, it's considered a dup
|
||||||
if (_msg_uid_set.find (msgid) != _msg_uid_set.end()) {
|
if (_msg_uid_set.find (msgid()) != _msg_uid_set.end()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
_msg_uid_set.insert (msgid);
|
_msg_uid_set.insert (msgid());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -159,7 +164,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void each_preferred (const char *msgid, gpointer docidp, msgid_docid_map *preferred_map) {
|
static void each_preferred (const char *msgid, gpointer docidp,
|
||||||
|
msgid_docid_map *preferred_map) {
|
||||||
(*preferred_map)[msgid] = GPOINTER_TO_SIZE(docidp);
|
(*preferred_map)[msgid] = GPOINTER_TO_SIZE(docidp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +352,7 @@ mu_msg_iter_get_docid (MuMsgIter *iter)
|
|||||||
g_return_val_if_fail (!mu_msg_iter_is_done(iter),
|
g_return_val_if_fail (!mu_msg_iter_is_done(iter),
|
||||||
(unsigned int)-1);
|
(unsigned int)-1);
|
||||||
try {
|
try {
|
||||||
return iter->cursor().get_document().get_docid();
|
return iter->docid();
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN ((unsigned int)-1);
|
} MU_XAPIAN_CATCH_BLOCK_RETURN ((unsigned int)-1);
|
||||||
}
|
}
|
||||||
@ -360,10 +366,7 @@ mu_msg_iter_get_msgid (MuMsgIter *iter)
|
|||||||
g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL);
|
g_return_val_if_fail (!mu_msg_iter_is_done(iter), NULL);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const std::string msgid (
|
return iter->msgid().c_str();
|
||||||
iter->cursor().get_document().get_value(MU_MSG_FIELD_ID_MSGID).c_str());
|
|
||||||
|
|
||||||
return msgid.empty() ? NULL : msgid.c_str();
|
|
||||||
|
|
||||||
} MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);
|
} MU_XAPIAN_CATCH_BLOCK_RETURN (NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -261,9 +261,9 @@ const char* mu_msg_get_subject (MuMsg *msg);
|
|||||||
*
|
*
|
||||||
* @param msg a valid MuMsg* instance
|
* @param msg a valid MuMsg* instance
|
||||||
*
|
*
|
||||||
* @return the Message-Id of this message (without the enclosing <>)
|
* @return the Message-Id of this message (without the enclosing <>),
|
||||||
* or NULL in case of error or if there is none. the returned string
|
* or a fake message-id for messages that don't have them, or NULL in
|
||||||
* should *not* be modified or freed.
|
* case of error.
|
||||||
*/
|
*/
|
||||||
const char* mu_msg_get_msgid (MuMsg *msg);
|
const char* mu_msg_get_msgid (MuMsg *msg);
|
||||||
|
|
||||||
|
|||||||
@ -460,6 +460,7 @@ add_terms_values_attach (Xapian::Document& doc, MuMsg *msg,
|
|||||||
(MuMsgPartForeachFunc)each_part, &pdata);
|
(MuMsgPartForeachFunc)each_part, &pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* escape the body -- for now, only replace '-' with '_' */
|
/* escape the body -- for now, only replace '-' with '_' */
|
||||||
static void
|
static void
|
||||||
body_escape_in_place (char *body)
|
body_escape_in_place (char *body)
|
||||||
@ -559,7 +560,6 @@ add_terms_values (MuMsgFieldId mfid, MsgDoc* msgdoc)
|
|||||||
case MU_MSG_FIELD_ID_MIME:
|
case MU_MSG_FIELD_ID_MIME:
|
||||||
case MU_MSG_FIELD_ID_EMBEDDED_TEXT:
|
case MU_MSG_FIELD_ID_EMBEDDED_TEXT:
|
||||||
break;
|
break;
|
||||||
///////////////////////////////////////////
|
|
||||||
|
|
||||||
case MU_MSG_FIELD_ID_THREAD_ID:
|
case MU_MSG_FIELD_ID_THREAD_ID:
|
||||||
case MU_MSG_FIELD_ID_UID:
|
case MU_MSG_FIELD_ID_UID:
|
||||||
|
|||||||
Reference in New Issue
Block a user