Skip to content

Commit 2ddddaa

Browse files
committed
Add is:status and isnot:status search expressions in the search bar.
1 parent 64a4277 commit 2ddddaa

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/selectmail.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ msgs_filter::parse_search_string(QString s, fts_options& opt)
240240
}
241241
else if (state==20) {
242242
if (c==' ') {
243-
opt.m_operators.insert(curr_op, curr_opval);
243+
opt.m_operators.insertMulti(curr_op, curr_opval);
244244
state=10;
245245
}
246246
else
@@ -276,7 +276,7 @@ msgs_filter::parse_search_string(QString s, fts_options& opt)
276276
DBG_PRINTF(3, "parse error: state=%d", state);
277277
}
278278
if (state==20)
279-
opt.m_operators.insert(curr_op, curr_opval);
279+
opt.m_operators.insertMulti(curr_op, curr_opval);
280280

281281
if (!curr_word.isEmpty()) {
282282
if (curr_word.at(0)=='-')
@@ -462,6 +462,14 @@ msgs_filter::build_query(sql_query& q)
462462

463463
// </date clause>
464464

465+
// status clause through is:status and isnot:status
466+
if (m_fts.m_operators.contains("is")) {
467+
process_status_clause(q, status_is, m_fts.m_operators.values("is"));
468+
}
469+
if (m_fts.m_operators.contains("isnot")) {
470+
process_status_clause(q, status_isnot, m_fts.m_operators.values("isnot"));
471+
}
472+
465473
if (!m_body_substring.isEmpty()) {
466474
q.add_table("body b");
467475
q.add_clause(QString("strpos(b.bodytext,'") + m_body_substring + QString("')>0 and m.mail_id=b.mail_id"));
@@ -676,6 +684,40 @@ msgs_filter::process_date_clause(sql_query& q, date_comparator comp, QString dat
676684
}
677685
}
678686

687+
/*
688+
Create SQL clauses from the given comparator (status_is, status_isnot)
689+
to test if mail.status has or doesn't have bits corresponding
690+
to the statuses named in <vals>.
691+
*/
692+
void
693+
msgs_filter::process_status_clause(sql_query& q,
694+
status_comparator comp,
695+
QList<QString> vals)
696+
{
697+
static struct {
698+
const char* name;
699+
int bitmask;
700+
} statuses[] = {
701+
{"read", mail_msg::statusRead},
702+
{"replied", mail_msg::statusReplied},
703+
{"forwarded", mail_msg::statusFwded},
704+
{"archived", mail_msg::statusArchived},
705+
{"sent", mail_msg::statusSent}
706+
};
707+
708+
for (int si=0; si < vals.size(); ++si) {
709+
const QString& s = vals.at(si);
710+
for (int i=0; i < (int)sizeof(statuses)/(int)sizeof(statuses[0]); i++) {
711+
if (QString::compare(s, statuses[i].name, Qt::CaseInsensitive)==0) {
712+
if (comp == status_is)
713+
q.add_clause(QString("m.status&%1=%1").arg(statuses[i].bitmask));
714+
else if (comp == status_isnot)
715+
q.add_clause(QString("m.status&%1=0").arg(statuses[i].bitmask));
716+
}
717+
}
718+
}
719+
}
720+
679721
/*
680722
Return values: same as build_query()
681723

src/selectmail.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,21 @@ class msgs_filter
170170
date_after,
171171
date_before
172172
};
173+
enum status_comparator {
174+
status_is,
175+
status_isnot
176+
};
173177
/* Add criteria to the sql_query that correspond to a comparison
174178
with date_expr using the date_comparator (equal or after or
175179
before) */
176180
void process_date_clause(sql_query& q,
177181
date_comparator comp,
178182
QString date_expr);
183+
/* Add criteria to the sql_query that correspond to a status test,
184+
m.status having or not having certain status bits. */
185+
void process_status_clause(sql_query& q,
186+
status_comparator comp,
187+
QList<QString> vals);
179188
bool m_auto_refresh;
180189
int add_address_selection (sql_query& q, const QString email_addr, int addr_type);
181190
/* number of criteria that needs to match an address from

0 commit comments

Comments
 (0)