Skip to content

Commit

Permalink
Add is:status and isnot:status search expressions in the search bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
manitou-mail committed Jul 7, 2016
1 parent 64a4277 commit 2ddddaa
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/selectmail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ msgs_filter::parse_search_string(QString s, fts_options& opt)
}
else if (state==20) {
if (c==' ') {
opt.m_operators.insert(curr_op, curr_opval);
opt.m_operators.insertMulti(curr_op, curr_opval);
state=10;
}
else
Expand Down Expand Up @@ -276,7 +276,7 @@ msgs_filter::parse_search_string(QString s, fts_options& opt)
DBG_PRINTF(3, "parse error: state=%d", state);
}
if (state==20)
opt.m_operators.insert(curr_op, curr_opval);
opt.m_operators.insertMulti(curr_op, curr_opval);

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

// </date clause>

// status clause through is:status and isnot:status
if (m_fts.m_operators.contains("is")) {
process_status_clause(q, status_is, m_fts.m_operators.values("is"));
}
if (m_fts.m_operators.contains("isnot")) {
process_status_clause(q, status_isnot, m_fts.m_operators.values("isnot"));
}

if (!m_body_substring.isEmpty()) {
q.add_table("body b");
q.add_clause(QString("strpos(b.bodytext,'") + m_body_substring + QString("')>0 and m.mail_id=b.mail_id"));
Expand Down Expand Up @@ -676,6 +684,40 @@ msgs_filter::process_date_clause(sql_query& q, date_comparator comp, QString dat
}
}

/*
Create SQL clauses from the given comparator (status_is, status_isnot)
to test if mail.status has or doesn't have bits corresponding
to the statuses named in <vals>.
*/
void
msgs_filter::process_status_clause(sql_query& q,
status_comparator comp,
QList<QString> vals)
{
static struct {
const char* name;
int bitmask;
} statuses[] = {
{"read", mail_msg::statusRead},
{"replied", mail_msg::statusReplied},
{"forwarded", mail_msg::statusFwded},
{"archived", mail_msg::statusArchived},
{"sent", mail_msg::statusSent}
};

for (int si=0; si < vals.size(); ++si) {
const QString& s = vals.at(si);
for (int i=0; i < (int)sizeof(statuses)/(int)sizeof(statuses[0]); i++) {
if (QString::compare(s, statuses[i].name, Qt::CaseInsensitive)==0) {
if (comp == status_is)
q.add_clause(QString("m.status&%1=%1").arg(statuses[i].bitmask));
else if (comp == status_isnot)
q.add_clause(QString("m.status&%1=0").arg(statuses[i].bitmask));
}
}
}
}

/*
Return values: same as build_query()
Expand Down
9 changes: 9 additions & 0 deletions src/selectmail.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,21 @@ class msgs_filter
date_after,
date_before
};
enum status_comparator {
status_is,
status_isnot
};
/* Add criteria to the sql_query that correspond to a comparison
with date_expr using the date_comparator (equal or after or
before) */
void process_date_clause(sql_query& q,
date_comparator comp,
QString date_expr);
/* Add criteria to the sql_query that correspond to a status test,
m.status having or not having certain status bits. */
void process_status_clause(sql_query& q,
status_comparator comp,
QList<QString> vals);
bool m_auto_refresh;
int add_address_selection (sql_query& q, const QString email_addr, int addr_type);
/* number of criteria that needs to match an address from
Expand Down

0 comments on commit 2ddddaa

Please sign in to comment.