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 { And, Or };
35
36 enum SearchKey { All, Bcc, Body, Cc, From, Subject, Text, To, Keyword };
37
38 enum BooleanSearchKey { New, Old, Recent, Seen, Draft, Deleted, Flagged, Answered };
39
40 enum DateSearchKey { Before, On, Since, SentBefore, SentOn, SentSince };
41 enum NumberSearchKey { Larger, Smaller };
42 enum SequenceSearchKey { Uid, SequenceNumber };
43
44 Term();
45 ~Term();
46 Term(Relation relation, const QList<Term> &subterms);
47 Term(SearchKey key, const QString &value);
48 Term(BooleanSearchKey key);
49 Term(DateSearchKey key, const QDate &date);
50 Term(NumberSearchKey key, int value);
51 Term(SequenceSearchKey key, const KIMAP::ImapSet &);
52 Term(const QString &header, const QString &value);
53
54 Term(const Term &other);
55
56 Term &operator=(const Term &other);
57 bool operator==(const Term &other) const;
58
59 [[nodiscard]] bool isNull() const;
60
61 Term &setFuzzy(bool fuzzy);
62 Term &setNegated(bool negated);
63
64 [[nodiscard]] QByteArray serialize() const;
65
66private:
67 class Private;
69};
70
71class KIMAP_EXPORT SearchJob : public Job
72{
73 Q_OBJECT
74 Q_DECLARE_PRIVATE(SearchJob)
75
76 friend class SessionPrivate;
77
78public:
79 enum SearchLogic { And = 0, Or, Not };
80
81 enum SearchCriteria {
82 All = 0,
83 Answered,
84 BCC,
85 Before,
86 Body,
87 CC,
88 Deleted,
89 Draft,
90 Flagged,
91 From,
92 Header,
93 Keyword,
94 Larger,
95 New,
96 Old,
97 On,
98 Recent,
99 Seen,
100 SentBefore,
101 SentOn,
102 SentSince,
103 Since,
104 Smaller,
105 Subject,
106 Text,
107 To,
108 Uid,
109 Unanswered,
110 Undeleted,
111 Undraft,
112 Unflagged,
113 Unkeyword,
114 Unseen
115 };
116
117 explicit SearchJob(Session *session);
118 ~SearchJob() override;
119
120 void setUidBased(bool uidBased);
121 bool isUidBased() const;
122
123 void setCharset(const QByteArray &charSet);
124 QByteArray charset() const;
125
126 /**
127 * Get the search result, as a list of sequence numbers or UIDs, based on the isUidBased status
128 * @return the found items
129 * @since 4.6
130 */
131 QList<qint64> results() const;
132
133 /**
134 * Add a search criteria that doesn't have an argument. Passing a criteria that
135 * should have an argument will be ignored.
136 * @param criteria a criteria from SearchCriterias
137 * @deprecated since 4.13
138 */
139 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria);
140
141 /**
142 * Add a search criteria that has one or more space separate string arguments.
143 * Passing a criteria that accepts a different type or argument or no
144 * argument will be ignored.
145 * @param criteria a criteria from SearchCriterias
146 * @param argument the arguments
147 * @deprecated since 4.13
148 */
149 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, const QByteArray &argument);
150
151 /**
152 * Add a search criteria that has an integer argument.
153 * Passing a criteria that accepts a different type or argument or no
154 * argument will be ignored.
155 * @param criteria a criteria from SearchCriterias
156 * @param argument a number argument
157 * @deprecated since 4.13
158 */
159 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, int argument);
160
161 /**
162 * Add a search criteria that has a date as argument.
163 * Passing a criteria that accepts a different type or argument or no
164 * argument will be ignored.
165 * @param criteria a criteria from SearchCriterias
166 * @param argument a date
167 * @deprecated since 4.13
168 */
169 KIMAP_DEPRECATED void addSearchCriteria(SearchCriteria criteria, const QDate &argument);
170
171 /**
172 * Add a custom criteria. No checks are done, the data is sent as it is
173 * to the server.
174 * @param searchCriteria free form search criteria.
175 * @deprecated since 4.13
176 */
177 KIMAP_DEPRECATED void addSearchCriteria(const QByteArray &searchCriteria);
178
179 /**
180 * Set the logic combining the search criteria.
181 * @param logic AND (the default), OR, NOT. See SearchLogics.
182 * @deprecated since 4.13
183 */
184 KIMAP_DEPRECATED void setSearchLogic(SearchLogic logic);
185
186 /**
187 * Sets the search term.
188 * @param term The search term.
189 * @since 4.13
190 */
191 void setTerm(const Term &);
192
193protected:
194 void doStart() override;
195 void handleResponse(const Response &response) override;
196};
197
198}
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 Tue Mar 26 2024 11:14:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.