thread-subject: ignore '<prefix>:' when comparing
Should catch most cases. Fixes: #2083.
This commit is contained in:
@ -366,6 +366,20 @@ to_string (const ThreadPath& tpath, size_t digits)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool // compare subjects, ignore anything before ':'
|
||||||
|
subject_matches (const std::string& sub1, const std::string& sub2)
|
||||||
|
{
|
||||||
|
auto search_str =[](const std::string&s) -> const char* {
|
||||||
|
const auto pos = s.find_first_of(':');
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
return s.c_str();
|
||||||
|
else
|
||||||
|
return s.c_str() + pos + 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
//g_debug ("'%s' '%s'", search_str(sub1), search_str(sub2));
|
||||||
|
return g_strcmp0(search_str(sub1), search_str(sub2)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
update_container (Container& container, bool descending,
|
update_container (Container& container, bool descending,
|
||||||
@ -385,7 +399,6 @@ update_container (Container& container, bool descending,
|
|||||||
return false; // nothing else to do.
|
return false; // nothing else to do.
|
||||||
|
|
||||||
auto& qmatch(*container.query_match);
|
auto& qmatch(*container.query_match);
|
||||||
|
|
||||||
if (!container.parent)
|
if (!container.parent)
|
||||||
qmatch.flags |= QueryMatch::Flags::Root;
|
qmatch.flags |= QueryMatch::Flags::Root;
|
||||||
else if (!container.parent->query_match)
|
else if (!container.parent->query_match)
|
||||||
@ -394,20 +407,10 @@ update_container (Container& container, bool descending,
|
|||||||
if (!container.children.empty())
|
if (!container.children.empty())
|
||||||
qmatch.flags |= QueryMatch::Flags::HasChild;
|
qmatch.flags |= QueryMatch::Flags::HasChild;
|
||||||
|
|
||||||
// see whether this message has the thread subject, i.e., the
|
if (qmatch.has_flag(QueryMatch::Flags::Root) || prev_subject.empty() ||
|
||||||
// first message in this thread with the given subject.
|
!subject_matches(prev_subject, qmatch.subject))
|
||||||
if (qmatch.has_flag(QueryMatch::Flags::Root) ||
|
|
||||||
//qmatch.has_flag(QueryMatch::Flags::Orphan) ||
|
|
||||||
prev_subject.empty() ||
|
|
||||||
(qmatch.subject.find(prev_subject) > 5))
|
|
||||||
qmatch.flags |= QueryMatch::Flags::ThreadSubject;
|
qmatch.flags |= QueryMatch::Flags::ThreadSubject;
|
||||||
|
|
||||||
// g_debug ("%c%c: '%s' vs '%s'",
|
|
||||||
// any_of(qmatch.flags & QueryMatch::Flags::Root) ? 'r' : 'c',
|
|
||||||
// any_of(qmatch.flags & QueryMatch::Flags::ThreadSubject) ? 'y' : 'n',
|
|
||||||
// qmatch.subject.c_str(),
|
|
||||||
// prev_subject.c_str());
|
|
||||||
|
|
||||||
if (descending && container.parent) {
|
if (descending && container.parent) {
|
||||||
// trick xapian by giving it "inverse" sorting key so our
|
// trick xapian by giving it "inverse" sorting key so our
|
||||||
// ascending-date sorted threads stay in that order
|
// ascending-date sorted threads stay in that order
|
||||||
@ -427,20 +430,19 @@ update_container (Container& container, bool descending,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
update_containers (Containers& children, bool descending, ThreadPath& tpath,
|
update_containers (Containers& children, bool descending, ThreadPath& tpath,
|
||||||
size_t seg_size, const std::string& prev_subject)
|
size_t seg_size, std::string& prev_subject)
|
||||||
{
|
{
|
||||||
size_t idx{0};
|
size_t idx{0};
|
||||||
std::string last_subject = prev_subject;
|
|
||||||
|
|
||||||
for (auto&& c: children) {
|
for (auto&& c: children) {
|
||||||
tpath.emplace_back(idx++);
|
tpath.emplace_back(idx++);
|
||||||
if (c->query_match) {
|
if (c->query_match) {
|
||||||
update_container(*c, descending, tpath, seg_size,
|
update_container(*c, descending, tpath, seg_size,
|
||||||
last_subject);
|
prev_subject);
|
||||||
last_subject = c->query_match->subject;
|
prev_subject = c->query_match->subject;
|
||||||
}
|
}
|
||||||
update_containers(c->children, descending, tpath, seg_size,
|
update_containers(c->children, descending, tpath, seg_size,
|
||||||
last_subject);
|
prev_subject);
|
||||||
tpath.pop_back();
|
tpath.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user