2 * Funambol is a mobile platform developed by Funambol, Inc.
3 * Copyright (C) 2003 - 2007 Funambol, Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by
7 * the Free Software Foundation with the addition of the following permission
8 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
10 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program; if not, see http://www.gnu.org/licenses or write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
23 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License
30 * version 3, these Appropriate Legal Notices must retain the display of the
31 * "Powered by Funambol" logo. If the display of the logo is not reasonably
32 * feasible for technical reasons, the Appropriate Legal Notices must display
33 * the words "Powered by Funambol".
38 #include "base/fscapi.h"
39 #include "base/messages.h"
41 #include "base/util/ArrayList.h"
42 #include "base/util/StringBuffer.h"
43 #include "client/SyncClient.h"
44 #include "client/DMTClientConfig.h"
45 #include "client/MailSourceManagementNode.h"
46 #include "examples/TestSyncSource.h"
47 #include "examples/TestSyncSource2.h"
48 #include "filter/AllClause.h"
49 #include "filter/ClauseUtil.h"
50 #include "filter/LogicalClause.h"
51 #include "filter/FieldClause.h"
52 #include "filter/sourceFilter.h"
53 #include "filter/WhereClause.h"
54 #include "spdm/constants.h"
55 #include "spds/spdsutils.h"
56 #include "spds/constants.h"
57 #include "spds/MailSyncSourceConfig.h"
58 #include "syncml/core/core.h"
59 #include "syncml/formatter/Formatter.h"
60 #include "base/globalsdef.h"
65 void testConfigFilter() {
68 // Let's create the DM subtrees first
71 MailSyncSourceConfig config;
73 config.setDownloadAge(-1);
74 config.setBodySize(-1);
75 config.setAttachSize(-1);
77 MailSourceManagementNode node("sources", "mail", config);
81 // Now we can read the config and than create the needed clause
83 MailSourceManagementNode node("sources", "mail");
84 MailSyncSourceConfig& config = node.getMailSourceConfig(true);
90 MessageBox(0, TEXT("No filter"), TEXT("Config to filter"), MB_OK);
92 SourceFilter* filter =
93 ClauseUtil::createSourceFilter(NULL, config.getBodySize(),config.getAttachSize());
96 MessageBox(0, TEXT("No filter is required!"), TEXT("Config to filter"), MB_OK);
98 MessageBox(0, TEXT("There must be an erro..."), TEXT("Config to filter"), MB_OK);
104 MessageBox(0, TEXT("Subject only"), TEXT("Config to filter"), MB_OK);
106 filter = ClauseUtil::createSourceFilter(NULL, 0, -1);
108 if (filter == NULL) {
109 MessageBox(0, TEXT("There must be an error..."), TEXT("Config to filter"), MB_OK);
111 Filter* f = ClauseUtil::toFilter(*filter);
113 MessageBox(0, TEXT("There must be an error..."), TEXT("Config to filter"), MB_OK);
115 StringBuffer* sb = Formatter::getFilter(f);
116 WCHAR *msg = toWideChar(sb->c_str());
118 MessageBox(0, msg, TEXT("Config to filter"), MB_OK);
125 delete filter; filter = NULL;
134 // 10Kb body, no attachment
136 MessageBox(0, TEXT("10Kb body, no attachment"), TEXT("Config to filter"), MB_OK);
138 filter = ClauseUtil::createSourceFilter(NULL, 10, 0);
140 if (filter == NULL) {
141 MessageBox(0, TEXT("There must be an error..."), TEXT("10Kb body, no attachment"), MB_OK);
143 Filter* f = ClauseUtil::toFilter(*filter);
145 MessageBox(0, TEXT("There must be an error..."), TEXT("10Kb body, no attachment"), MB_OK);
147 StringBuffer* sb = Formatter::getFilter(f);
148 WCHAR *msg = toWideChar(sb->c_str());
149 MessageBox(0, msg, TEXT("10Kb body, no attachment"), MB_OK);
156 delete filter; filter = NULL;
164 // 10Kb body, attachment up to 25Kb
166 MessageBox(0, TEXT("10Kb body, attachment up to 25Kb"), TEXT("Config to filter"), MB_OK);
168 filter = ClauseUtil::createSourceFilter(NULL, 10, 25);
170 if (filter == NULL) {
171 MessageBox(0, TEXT("There must be an error..."), TEXT("10Kb body, attachment up to 25Kb"), MB_OK);
173 Filter* f = ClauseUtil::toFilter(*filter);
175 MessageBox(0, TEXT("There must be an error..."), TEXT("10Kb body, attachment up to 25Kb"), MB_OK);
177 StringBuffer* sb = Formatter::getFilter(f);
178 WCHAR *msg = toWideChar(sb->c_str());
180 MessageBox(0, msg, TEXT("10Kb body, attachment up to 25Kb"), MB_OK);
187 delete filter; filter = NULL;
195 // TODAY's emails, no attachments
197 WCHAR* TODAY = TEXT("20051211T000000Z");
198 MessageBox(0, TEXT("TODAY's emails, no attachments"), TEXT("Config to filter"), MB_OK);
200 filter = ClauseUtil::createSourceFilter(TODAY, -1, 0);
202 if (filter == NULL) {
203 MessageBox(0, TEXT("There must be an error..."), TEXT("TODAY's emails, no attachments"), MB_OK);
205 Filter* f = ClauseUtil::toFilter(*filter);
207 MessageBox(0, TEXT("There must be an error..."), TEXT("TODAY's emails, no attachments"), MB_OK);
209 StringBuffer* sb = Formatter::getFilter(f);
210 WCHAR *msg = toWideChar(sb->c_str());
212 MessageBox(0, msg, TEXT("TODAY's emails, no attachments"), MB_OK);
215 delete sb; sb = NULL;
221 delete filter; filter = NULL;
229 // All in one reading from the DM
231 MessageBox(0, TEXT("All in one"), TEXT("Config to filter"), MB_OK);
233 MailSyncSourceConfig config;
235 config.setDownloadAge(3);
236 config.setBodySize(5);
237 config.setAttachSize(30);
239 MailSourceManagementNode node("sources", "mail", config);
242 config = node.getMailSourceConfig(true); // reread from the DM
244 filter = ClauseUtil::createSourceFilter(TODAY, config.getBodySize(), config.getAttachSize());
246 if (filter == NULL) {
247 MessageBox(0, TEXT("There must be an error..."), TEXT("All in one"), MB_OK);
249 Filter* f = ClauseUtil::toFilter(*filter);
251 MessageBox(0, TEXT("There must be an error..."), TEXT("All in one"), MB_OK);
253 StringBuffer* sb = Formatter::getFilter(f);
254 WCHAR *msg = toWideChar(sb->c_str());
256 MessageBox(0, msg, TEXT("All in one"), MB_OK);
259 delete sb; sb = NULL;
265 delete filter; filter = NULL;