File indexing completed on 2024-05-12 05:26:04

0001 /*
0002  * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  */
0020 #pragma once
0021 
0022 #include "query.h"
0023 
0024 namespace Sink {
0025 namespace StandardQueries {
0026 
0027     /**
0028      * Returns the complete thread, containing all mails from all folders.
0029      */
0030     static Query completeThread(const ApplicationDomain::Mail &mail)
0031     {
0032         Sink::Query query;
0033         query.setId("completethread");
0034         if (!mail.resourceInstanceIdentifier().isEmpty()) {
0035             query.resourceFilter(mail.resourceInstanceIdentifier());
0036         }
0037         query.filter(mail.identifier());
0038         query.sort<ApplicationDomain::Mail::Date>();
0039         query.bloom<ApplicationDomain::Mail::ThreadId>();
0040         return query;
0041     }
0042 
0043     /**
0044      * Returns thread leaders only, sorted by date.
0045      */
0046     static Query threadLeaders(const ApplicationDomain::Folder &folder)
0047     {
0048         Sink::Query query;
0049         query.setId("threadleaders");
0050         if (!folder.resourceInstanceIdentifier().isEmpty()) {
0051             query.resourceFilter(folder.resourceInstanceIdentifier());
0052         }
0053         query.filter<ApplicationDomain::Mail::Folder>(folder);
0054         query.sort<ApplicationDomain::Mail::Date>();
0055         query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>())
0056             .count()
0057             .select<ApplicationDomain::Mail::Subject>(Query::Reduce::Selector::Min)
0058             .collect<ApplicationDomain::Mail::Unread>()
0059             .collect<ApplicationDomain::Mail::Important>();
0060         return query;
0061     }
0062 
0063     /**
0064      * Outgoing mails.
0065      */
0066     static Query outboxMails()
0067     {
0068         Sink::Query query;
0069         query.setId("outbox");
0070         query.resourceContainsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport);
0071         query.sort<ApplicationDomain::Mail::Date>();
0072         return query;
0073     }
0074 
0075 }
0076 }