File indexing completed on 2024-05-12 05:17:16
0001 /* 0002 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org> 0003 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "kimap_export.h" 0011 0012 #include "job.h" 0013 0014 #include <QSharedDataPointer> 0015 0016 class QDate; 0017 0018 namespace KIMAP 0019 { 0020 class ImapSet; 0021 0022 class Session; 0023 struct Response; 0024 class SearchJobPrivate; 0025 0026 /** 0027 * A query term. 0028 * Refer to the IMAP RFC for the meaning of the individual terms. 0029 * @since 4.13 0030 */ 0031 class KIMAP_EXPORT Term 0032 { 0033 public: 0034 enum Relation { And, Or }; 0035 0036 enum SearchKey { All, Bcc, Body, Cc, From, Subject, Text, To, Keyword }; 0037 0038 enum BooleanSearchKey { New, Old, Recent, Seen, Draft, Deleted, Flagged, Answered }; 0039 0040 enum DateSearchKey { Before, On, Since, SentBefore, SentOn, SentSince }; 0041 enum NumberSearchKey { Larger, Smaller }; 0042 enum SequenceSearchKey { Uid, SequenceNumber }; 0043 0044 Term(); 0045 ~Term(); 0046 Term(Relation relation, const QList<Term> &subterms); 0047 Term(SearchKey key, const QString &value); 0048 Term(BooleanSearchKey key); 0049 Term(DateSearchKey key, const QDate &date); 0050 Term(NumberSearchKey key, int value); 0051 Term(SequenceSearchKey key, const KIMAP::ImapSet &); 0052 Term(const QString &header, const QString &value); 0053 0054 Term(const Term &other); 0055 0056 Term &operator=(const Term &other); 0057 bool operator==(const Term &other) const; 0058 0059 [[nodiscard]] bool isNull() const; 0060 0061 Term &setFuzzy(bool fuzzy); 0062 Term &setNegated(bool negated); 0063 0064 [[nodiscard]] QByteArray serialize() const; 0065 0066 private: 0067 class Private; 0068 QSharedDataPointer<Private> d; 0069 }; 0070 0071 class KIMAP_EXPORT SearchJob : public Job 0072 { 0073 Q_OBJECT 0074 Q_DECLARE_PRIVATE(SearchJob) 0075 0076 friend class SessionPrivate; 0077 0078 public: 0079 enum SearchLogic { And = 0, Or, Not }; 0080 0081 enum SearchCriteria { 0082 All = 0, 0083 Answered, 0084 BCC, 0085 Before, 0086 Body, 0087 CC, 0088 Deleted, 0089 Draft, 0090 Flagged, 0091 From, 0092 Header, 0093 Keyword, 0094 Larger, 0095 New, 0096 Old, 0097 On, 0098 Recent, 0099 Seen, 0100 SentBefore, 0101 SentOn, 0102 SentSince, 0103 Since, 0104 Smaller, 0105 Subject, 0106 Text, 0107 To, 0108 Uid, 0109 Unanswered, 0110 Undeleted, 0111 Undraft, 0112 Unflagged, 0113 Unkeyword, 0114 Unseen 0115 }; 0116 0117 explicit SearchJob(Session *session); 0118 ~SearchJob() override; 0119 0120 void setUidBased(bool uidBased); 0121 bool isUidBased() const; 0122 0123 void setCharset(const QByteArray &charSet); 0124 QByteArray charset() const; 0125 0126 /** 0127 * Get the search result, as a list of sequence numbers or UIDs, based on the isUidBased status 0128 * @return the found items 0129 * @since 4.6 0130 */ 0131 QList<qint64> results() const; 0132 0133 /** 0134 * Add a search criteria that doesn't have an argument. Passing a criteria that 0135 * should have an argument will be ignored. 0136 * @param criteria a criteria from SearchCriterias 0137 * @deprecated since 4.13 0138 */ 0139 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria); 0140 0141 /** 0142 * Add a search criteria that has one or more space separate string arguments. 0143 * Passing a criteria that accepts a different type or argument or no 0144 * argument will be ignored. 0145 * @param criteria a criteria from SearchCriterias 0146 * @param argument the arguments 0147 * @deprecated since 4.13 0148 */ 0149 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, const QByteArray &argument); 0150 0151 /** 0152 * Add a search criteria that has an integer argument. 0153 * Passing a criteria that accepts a different type or argument or no 0154 * argument will be ignored. 0155 * @param criteria a criteria from SearchCriterias 0156 * @param argument a number argument 0157 * @deprecated since 4.13 0158 */ 0159 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, int argument); 0160 0161 /** 0162 * Add a search criteria that has a date as argument. 0163 * Passing a criteria that accepts a different type or argument or no 0164 * argument will be ignored. 0165 * @param criteria a criteria from SearchCriterias 0166 * @param argument a date 0167 * @deprecated since 4.13 0168 */ 0169 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, const QDate &argument); 0170 0171 /** 0172 * Add a custom criteria. No checks are done, the data is sent as it is 0173 * to the server. 0174 * @param searchCriteria free form search criteria. 0175 * @deprecated since 4.13 0176 */ 0177 KIMAP_DEPRECATED void addSearchCriteria(const QByteArray &searchCriteria); 0178 0179 /** 0180 * Set the logic combining the search criteria. 0181 * @param logic AND (the default), OR, NOT. See SearchLogics. 0182 * @deprecated since 4.13 0183 */ 0184 KIMAP_DEPRECATED void setSearchLogic(SearchLogic logic); 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() override; 0195 void handleResponse(const Response &response) override; 0196 }; 0197 0198 }