1 | /* |
2 | Copyright (c) 2009 Andras Mantia <amantia@kde.org> |
3 | Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com> |
4 | |
5 | This library is free software; you can redistribute it and/or modify it |
6 | under the terms of the GNU Library General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or (at your |
8 | option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
13 | License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to the |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef KIMAP_SEARCHJOB_H |
22 | #define KIMAP_SEARCHJOB_H |
23 | |
24 | #include "kimap_export.h" |
25 | |
26 | #include "job.h" |
27 | |
28 | class QDate; |
29 | |
30 | namespace KIMAP { |
31 | |
32 | class ImapSet; |
33 | |
34 | class Session; |
35 | struct Message; |
36 | class SearchJobPrivate; |
37 | |
38 | /** |
39 | * A query term. |
40 | * Refer to the IMAP RFC for the meaning of the individual terms. |
41 | * @since 4.13 |
42 | */ |
43 | class KIMAP_EXPORT Term |
44 | { |
45 | public: |
46 | enum Relation { |
47 | And, |
48 | Or |
49 | }; |
50 | |
51 | enum SearchKey { |
52 | All, |
53 | Bcc, |
54 | Body, |
55 | Cc, |
56 | From, |
57 | Subject, |
58 | Text, |
59 | To, |
60 | Keyword |
61 | }; |
62 | |
63 | enum BooleanSearchKey { |
64 | New, |
65 | Old, |
66 | Recent, |
67 | Seen, |
68 | Draft, |
69 | Deleted, |
70 | Flagged, |
71 | Answered |
72 | }; |
73 | |
74 | enum DateSearchKey { |
75 | Before, |
76 | On, |
77 | Since, |
78 | SentBefore, |
79 | SentOn, |
80 | SentSince |
81 | }; |
82 | enum NumberSearchKey { |
83 | Larger, |
84 | Smaller |
85 | }; |
86 | enum SequenceSearchKey { |
87 | Uid, |
88 | SequenceNumber |
89 | }; |
90 | |
91 | Term(); |
92 | Term( Relation relation, const QVector<Term> &subterms ); |
93 | Term( SearchKey key, const QString &value ); |
94 | Term( BooleanSearchKey key ); |
95 | Term( DateSearchKey key, const QDate &date ); |
96 | Term( NumberSearchKey key, int value ); |
97 | Term( SequenceSearchKey key, const KIMAP::ImapSet & ); |
98 | Term( const QString &, const QString &value ); |
99 | |
100 | Term( const Term &other ); |
101 | |
102 | Term& operator=( const Term &other ); |
103 | bool operator==( const Term &other ) const; |
104 | |
105 | bool isNull() const; |
106 | |
107 | Term &setFuzzy( bool fuzzy ); |
108 | Term &setNegated( bool negated ); |
109 | |
110 | QByteArray serialize() const; |
111 | |
112 | private: |
113 | class Private; |
114 | QSharedPointer<Private> d; |
115 | }; |
116 | |
117 | class KIMAP_EXPORT SearchJob : public Job |
118 | { |
119 | Q_OBJECT |
120 | Q_DECLARE_PRIVATE( SearchJob ) |
121 | |
122 | friend class SessionPrivate; |
123 | |
124 | public: |
125 | enum SearchLogic { |
126 | And = 0, |
127 | Or, |
128 | Not |
129 | }; |
130 | |
131 | enum SearchCriteria { |
132 | All = 0, |
133 | Answered, |
134 | BCC, |
135 | Before, |
136 | Body, |
137 | CC, |
138 | Deleted, |
139 | Draft, |
140 | Flagged, |
141 | From, |
142 | , |
143 | Keyword, |
144 | Larger, |
145 | New, |
146 | Old, |
147 | On, |
148 | Recent, |
149 | Seen, |
150 | SentBefore, |
151 | SentOn, |
152 | SentSince, |
153 | Since, |
154 | Smaller, |
155 | Subject, |
156 | Text, |
157 | To, |
158 | Uid, |
159 | Unanswered, |
160 | Undeleted, |
161 | Undraft, |
162 | Unflagged, |
163 | Unkeyword, |
164 | Unseen |
165 | }; |
166 | |
167 | explicit SearchJob( Session *session ); |
168 | virtual ~SearchJob(); |
169 | |
170 | void setUidBased(bool uidBased); |
171 | bool isUidBased() const; |
172 | |
173 | void setCharset( const QByteArray &charSet ); |
174 | QByteArray charset() const; |
175 | |
176 | /** |
177 | * Get the search result, as a list of sequence numbers or UIDs, based on the isUidBased status |
178 | * @return the found items |
179 | * @deprecated use results() instead |
180 | */ |
181 | KIMAP_DEPRECATED QList<int> foundItems(); |
182 | |
183 | /** |
184 | * Get the search result, as a list of sequence numbers or UIDs, based on the isUidBased status |
185 | * @return the found items |
186 | * @since 4.6 |
187 | */ |
188 | QList<qint64> results() const; |
189 | |
190 | /** |
191 | * Add a search criteria that doesn't have an argument. Passing a criteria that |
192 | * should have an argument will be ignored. |
193 | * @param criteria a criteria from SearchCriterias |
194 | * @deprecated since 4.13 |
195 | */ |
196 | KIMAP_DEPRECATED void addSearchCriteria( SearchCriteria criteria ); |
197 | |
198 | /** |
199 | * Add a search criteria that has one or more space separate string arguments. |
200 | * Passing a criteria that accepts a different type or argument or no |
201 | * argument will be ignored. |
202 | * @param criteria a criteria from SearchCriterias |
203 | * @param argument the arguments |
204 | * @deprecated since 4.13 |
205 | */ |
206 | KIMAP_DEPRECATED void addSearchCriteria( SearchCriteria criteria, const QByteArray &argument ); |
207 | |
208 | /** |
209 | * Add a search criteria that has an integer argument. |
210 | * Passing a criteria that accepts a different type or argument or no |
211 | * argument will be ignored. |
212 | * @param criteria a criteria from SearchCriterias |
213 | * @param argument a number argument |
214 | * @deprecated since 4.13 |
215 | */ |
216 | KIMAP_DEPRECATED void addSearchCriteria( SearchCriteria criteria, int argument ); |
217 | |
218 | /** |
219 | * Add a search criteria that has a date as argument. |
220 | * Passing a criteria that accepts a different type or argument or no |
221 | * argument will be ignored. |
222 | * @param criteria a criteria from SearchCriterias |
223 | * @param argument a date |
224 | * @deprecated since 4.13 |
225 | */ |
226 | KIMAP_DEPRECATED void addSearchCriteria( SearchCriteria criteria, const QDate& argument ); |
227 | |
228 | /** |
229 | * Add a custom criteria. No checks are done, the data is sent as it is |
230 | * to the server. |
231 | * @param searchCriteria free form search criteria. |
232 | * @deprecated since 4.13 |
233 | */ |
234 | KIMAP_DEPRECATED void addSearchCriteria( const QByteArray &searchCriteria ); |
235 | |
236 | /** |
237 | * Set the logic combining the search criterias. |
238 | * @param logic AND (the default), OR, NOT. See SearchLogics. |
239 | * @deprecated since 4.13 |
240 | */ |
241 | KIMAP_DEPRECATED void setSearchLogic(SearchLogic logic); |
242 | |
243 | /** |
244 | * Sets the search term. |
245 | * @param term The search term. |
246 | * @since 4.13 |
247 | */ |
248 | void setTerm( const Term & ); |
249 | |
250 | protected: |
251 | virtual void doStart(); |
252 | virtual void handleResponse(const Message &response); |
253 | }; |
254 | |
255 | } |
256 | |
257 | #endif |
258 | |