KIMAP

searchjob.h
1/*
2 SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org>
3 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "kimap_export.h"
11
12#include "job.h"
13
14#include <QSharedDataPointer>
15
16class QDate;
17
18namespace KIMAP
19{
20class ImapSet;
21
22class Session;
23struct Response;
24class SearchJobPrivate;
25
26/**
27 * A query term.
28 * Refer to the IMAP RFC for the meaning of the individual terms.
29 * @since 4.13
30 */
31class KIMAP_EXPORT Term
32{
33public:
34 enum Relation {
35 And,
36 Or
37 };
38
39 enum SearchKey {
40 All,
41 Bcc,
42 Body,
43 Cc,
44 From,
45 Subject,
46 Text,
47 To,
48 Keyword
49 };
50
51 enum BooleanSearchKey {
52 New,
53 Old,
54 Recent,
55 Seen,
56 Draft,
57 Deleted,
58 Flagged,
59 Answered
60 };
61
62 enum DateSearchKey {
63 Before,
64 On,
65 Since,
66 SentBefore,
67 SentOn,
68 SentSince
69 };
70 enum NumberSearchKey {
71 Larger,
72 Smaller
73 };
74 enum SequenceSearchKey {
75 Uid,
76 SequenceNumber
77 };
78
79 Term();
80 ~Term();
81 Term(Relation relation, const QList<Term> &subterms);
82 Term(SearchKey key, const QString &value);
83 Term(BooleanSearchKey key);
84 Term(DateSearchKey key, const QDate &date);
85 Term(NumberSearchKey key, int value);
86 Term(SequenceSearchKey key, const KIMAP::ImapSet &);
87 Term(const QString &header, const QString &value);
88
89 Term(const Term &other);
90
91 Term &operator=(const Term &other);
92 bool operator==(const Term &other) const;
93
94 [[nodiscard]] bool isNull() const;
95
96 Term &setFuzzy(bool fuzzy);
97 Term &setNegated(bool negated);
98
99 [[nodiscard]] QByteArray serialize() const;
100
101private:
102 class Private;
104};
105
106class KIMAP_EXPORT SearchJob : public Job
107{
108 Q_OBJECT
109 Q_DECLARE_PRIVATE(SearchJob)
110
111 friend class SessionPrivate;
112
113public:
114 enum SearchLogic {
115 And = 0,
116 Or,
117 Not
118 };
119
120 enum SearchCriteria {
121 All = 0,
122 Answered,
123 BCC,
124 Before,
125 Body,
126 CC,
127 Deleted,
128 Draft,
129 Flagged,
130 From,
131 Header,
132 Keyword,
133 Larger,
134 New,
135 Old,
136 On,
137 Recent,
138 Seen,
139 SentBefore,
140 SentOn,
141 SentSince,
142 Since,
143 Smaller,
144 Subject,
145 Text,
146 To,
147 Uid,
148 Unanswered,
149 Undeleted,
150 Undraft,
151 Unflagged,
152 Unkeyword,
153 Unseen
154 };
155
156 explicit SearchJob(Session *session);
157 ~SearchJob() override;
158
159 void setUidBased(bool uidBased);
160 bool isUidBased() const;
161
162 void setCharset(const QByteArray &charSet);
163 QByteArray charset() const;
164
165 /**
166 * Get the search result, as a list of sequence numbers or UIDs, based on the isUidBased status
167 * @return the found items
168 * @since 4.6
169 */
170 QList<qint64> results() const;
171
172 /**
173 * Add a search criteria that doesn't have an argument. Passing a criteria that
174 * should have an argument will be ignored.
175 * @param criteria a criteria from SearchCriterias
176 * @deprecated since 4.13
177 */
178 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria);
179
180 /**
181 * Add a search criteria that has one or more space separate string arguments.
182 * Passing a criteria that accepts a different type or argument or no
183 * argument will be ignored.
184 * @param criteria a criteria from SearchCriterias
185 * @param argument the arguments
186 * @deprecated since 4.13
187 */
188 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, const QByteArray &argument);
189
190 /**
191 * Add a search criteria that has an integer argument.
192 * Passing a criteria that accepts a different type or argument or no
193 * argument will be ignored.
194 * @param criteria a criteria from SearchCriterias
195 * @param argument a number argument
196 * @deprecated since 4.13
197 */
198 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, int argument);
199
200 /**
201 * Add a search criteria that has a date as argument.
202 * Passing a criteria that accepts a different type or argument or no
203 * argument will be ignored.
204 * @param criteria a criteria from SearchCriterias
205 * @param argument a date
206 * @deprecated since 4.13
207 */
208 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, const QDate &argument);
209
210 /**
211 * Add a custom criteria. No checks are done, the data is sent as it is
212 * to the server.
213 * @param searchCriteria free form search criteria.
214 * @deprecated since 4.13
215 */
216 KIMAP_DEPRECATED void addSearchCriteria(const QByteArray &searchCriteria);
217
218 /**
219 * Set the logic combining the search criteria.
220 * @param logic AND (the default), OR, NOT. See SearchLogics.
221 * @deprecated since 4.13
222 */
223 KIMAP_DEPRECATED void setSearchLogic(SearchLogic logic);
224
225 /**
226 * Sets the search term.
227 * @param term The search term.
228 * @since 4.13
229 */
230 void setTerm(const Term &);
231
232protected:
233 void doStart() override;
234 void handleResponse(const Response &response) override;
235};
236
237}
Represents a set of natural numbers (1->∞) in a as compact as possible form.
Definition imapset.h:127
A query term.
Definition searchjob.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:06:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.