File indexing completed on 2024-05-12 05:17:24
0001 /* 0002 Copyright (c) 2009 Andras Mantia <amantia@kde.org> 0003 Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0004 0005 This library is free software; you can redistribute it and/or modify it 0006 under the terms of the GNU Library General Public License as published by 0007 the Free Software Foundation; either version 2 of the License, or (at your 0008 option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, but WITHOUT 0011 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0012 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0013 License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to the 0017 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0018 02110-1301, USA. 0019 */ 0020 0021 #ifndef KIMAP2_SEARCHJOB_H 0022 #define KIMAP2_SEARCHJOB_H 0023 0024 #include "kimap2_export.h" 0025 0026 #include "job.h" 0027 #include <QSharedPointer> 0028 0029 class QDate; 0030 0031 namespace KIMAP2 0032 { 0033 0034 class ImapSet; 0035 0036 class Session; 0037 struct Message; 0038 class SearchJobPrivate; 0039 0040 /** 0041 * A query term. 0042 * Refer to the IMAP RFC for the meaning of the individual terms. 0043 * @since 4.13 0044 */ 0045 class KIMAP2_EXPORT Term 0046 { 0047 public: 0048 enum Relation { 0049 And, 0050 Or 0051 }; 0052 0053 enum SearchKey { 0054 All, 0055 Bcc, 0056 Body, 0057 Cc, 0058 From, 0059 Subject, 0060 Text, 0061 To, 0062 Keyword 0063 }; 0064 0065 enum BooleanSearchKey { 0066 New, 0067 Old, 0068 Recent, 0069 Seen, 0070 Draft, 0071 Deleted, 0072 Flagged, 0073 Answered 0074 }; 0075 0076 enum DateSearchKey { 0077 Before, 0078 On, 0079 Since, 0080 SentBefore, 0081 SentOn, 0082 SentSince 0083 }; 0084 enum NumberSearchKey { 0085 Larger, 0086 Smaller 0087 }; 0088 enum SequenceSearchKey { 0089 Uid, 0090 SequenceNumber 0091 }; 0092 0093 Term(); 0094 ~Term() = default; // silence clazy rule of three warning 0095 Term(Relation relation, const QVector<Term> &subterms); 0096 Term(SearchKey key, const QString &value); 0097 Term(BooleanSearchKey key); 0098 Term(DateSearchKey key, const QDate &date); 0099 Term(NumberSearchKey key, int value); 0100 Term(SequenceSearchKey key, const KIMAP2::ImapSet &); 0101 Term(const QString &header, const QString &value); 0102 0103 Term(const Term &other); 0104 0105 Term &operator=(const Term &other); 0106 bool operator==(const Term &other) const; 0107 0108 bool isNull() const; 0109 0110 Term &setFuzzy(bool fuzzy); 0111 Term &setNegated(bool negated); 0112 0113 QByteArray serialize() const; 0114 0115 private: 0116 class Private; 0117 QSharedPointer<Private> d; 0118 }; 0119 0120 class KIMAP2_EXPORT SearchJob : public Job 0121 { 0122 Q_OBJECT 0123 Q_DECLARE_PRIVATE(SearchJob) 0124 0125 friend class SessionPrivate; 0126 0127 public: 0128 enum SearchLogic { 0129 And = 0, 0130 Or, 0131 Not 0132 }; 0133 0134 enum SearchCriteria { 0135 All = 0, 0136 Answered, 0137 BCC, 0138 Before, 0139 Body, 0140 CC, 0141 Deleted, 0142 Draft, 0143 Flagged, 0144 From, 0145 Header, 0146 Keyword, 0147 Larger, 0148 New, 0149 Old, 0150 On, 0151 Recent, 0152 Seen, 0153 SentBefore, 0154 SentOn, 0155 SentSince, 0156 Since, 0157 Smaller, 0158 Subject, 0159 Text, 0160 To, 0161 Uid, 0162 Unanswered, 0163 Undeleted, 0164 Undraft, 0165 Unflagged, 0166 Unkeyword, 0167 Unseen 0168 }; 0169 0170 explicit SearchJob(Session *session); 0171 virtual ~SearchJob(); 0172 0173 void setUidBased(bool uidBased); 0174 bool isUidBased() const; 0175 0176 void setCharset(const QByteArray &charSet); 0177 QByteArray charset() const; 0178 0179 /** 0180 * Get the search result, as a list of sequence numbers or UIDs, based on the isUidBased status 0181 * @return the found items 0182 * @since 4.6 0183 */ 0184 QVector<qint64> results() const; 0185 0186 /** 0187 * Sets the search term. 0188 * @param term The search term. 0189 * @since 4.13 0190 */ 0191 void setTerm(const Term &); 0192 0193 protected: 0194 void doStart() Q_DECL_OVERRIDE; 0195 void handleResponse(const Message &response) Q_DECL_OVERRIDE; 0196 }; 0197 0198 } 0199 0200 #endif