/* thread-fp.cc - "thread:" field processor glue * * This file is part of notmuch. * * Copyright © 2017 Jani Nikula * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/ . */ #include "database-private.h" #include "thread-fp.h" #if HAVE_XAPIAN_FIELD_PROCESSOR Xapian::Query ThreadFieldProcessor::operator() (const std::string & thread) { std::string term_prefix = _find_prefix ("thread"); std::string thread_id; notmuch_message_t *message = NULL; /* * Only support thread queries via message-ids that have @. The * reason for this is twofold: First, it's an optimization for * regular thread-id queries. Second, and more importantly, it * prevents (potentially malicious) message-id and thread-id * collisions. Regular thread-ids are guaranteed to not have @ in * them, and we only lose the ability to query threads by invalid * message-ids that don't have @ in them. */ if (strchr (thread.c_str (), '@')) notmuch_database_find_message (notmuch, thread.c_str (), &message); if (message) { thread_id = notmuch_message_get_thread_id (message); notmuch_message_destroy (message); } else { thread_id = thread; } return Xapian::Query (term_prefix + thread_id); } #endif