apply removal of mailbox_name field
[platform/core/messaging/email-service.git] / utilities / test-application / testapp-others.c
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21
22
23 /* common header */
24 #include <stdio.h>
25 #include <string.h>
26
27 /* open header */
28 #include <glib.h>
29 #include <dlfcn.h>
30 #include <vconf.h>
31 #include "c-client.h" 
32
33
34 #include "email-api.h"
35 #include "email-api-account.h"
36 #include "email-api-network.h"
37
38
39 /* internal header */
40 #include "testapp-utility.h"
41 #include "testapp-others.h"
42 #include "email-ipc.h"
43 #include "email-core-utils.h"
44
45 static gboolean testapp_test_cancel_job ()
46 {
47         int account_id = 0;
48         int handle = 0;
49         int result_from_scanf = 0;
50
51         testapp_print("\n > Enter account_id (0: all account): ");
52         result_from_scanf = scanf("%d", &account_id);
53
54         testapp_print("\n > Enter handle: ");
55         result_from_scanf = scanf("%d", &handle);
56
57         if(email_cancel_job(account_id, handle, EMAIL_CANCELED_BY_USER) < 0)
58                 testapp_print("email_cancel_job failed..!");
59         return FALSE;
60 }
61
62 static gboolean testapp_test_set_dnet_proper_profile_type()
63 {
64         testapp_print("NOT Support\n");
65         
66         return TRUE;
67 }
68
69 static gboolean testapp_test_get_dnet_proper_profile_type()
70 {
71         testapp_print("NOT Support\n");
72
73         return TRUE;
74 }
75
76 static gboolean testapp_test_get_preview_text_from_file()
77 {
78         int   result_from_scanf;
79         char *preview_buffer = NULL;
80         char  html_file_path[1024] = { 0, };
81
82         testapp_print("\n > Enter file path : ");
83         result_from_scanf = scanf("%s", html_file_path);
84
85         emcore_get_preview_text_from_file(NULL, html_file_path, 1024, &preview_buffer);
86
87         testapp_print("\n result :\n %s ", preview_buffer);
88
89         return TRUE;
90 }
91
92 static gboolean testapp_test_get_task_information()
93 {
94         int i = 0;
95         int err = EMAIL_ERROR_NONE;
96         int task_information_count = 0;
97         email_task_information_t *task_information_array = NULL;
98
99         
100         err = email_get_task_information(&task_information_array, &task_information_count);
101
102         testapp_print("\n======================================================================\n");
103         for(i = 0; i < task_information_count; i++)
104                 testapp_print("type[%d], account_id[%d], handle[%d], status[%d]", task_information_array[i].type, task_information_array[i].account_id, task_information_array[i].handle, task_information_array[i].status);
105         testapp_print("\n======================================================================\n");
106
107         testapp_print("testapp_test_get_task_information  ..........End\n");
108
109         return err;
110 }
111
112 static gboolean testapp_test_create_db_full()
113 {
114         int err;
115
116         err = email_create_db_full();
117         
118         testapp_print("testapp_test_create_db_full returns [%d]", err);
119
120         return err;
121 }
122
123 static int encode_base64(char *src, unsigned long src_len, char **enc, unsigned long* enc_len, int *err_code)
124 {
125         unsigned char *content = NULL;
126         int ret = true; 
127         int err = EMAIL_ERROR_NONE;
128
129         if (err_code != NULL) {
130                 *err_code = EMAIL_ERROR_NONE;
131         }
132
133         content = rfc822_binary(src, src_len, enc_len);
134
135         if (content)
136                 *enc = (char *)content;
137         else {
138                 err = EMAIL_ERROR_UNKNOWN;
139                 ret = false;
140         }
141
142         if (err_code)
143             *err_code = err;
144
145         return ret;
146 }
147
148
149 static gboolean testapp_test_encoding_test()
150 {
151         int error = EMAIL_ERROR_NONE;
152         int has_special_character = 0, base64_file_name_length = 0, i;
153         gsize bytes_read, bytes_written;
154         char *encoded_file_name = NULL, *base64_file_name = NULL;
155         SIZEDTEXT source_text;
156         GError *glib_error = NULL;
157         CHARSET *result_charset = NULL;
158         char filename[] = {0xEB, 0xB0, 0x94, 0xED, 0x83, 0x95, 0x32, 0x2E, 0x70, 0x6E, 0x67, 0x00}; /* UTF-8 */
159
160         source_text.data = (unsigned char*)filename; 
161         source_text.size = strlen(filename);
162
163         result_charset = (CHARSET*)utf8_infercharset(&source_text);
164
165         if(result_charset) {
166                 testapp_print("return_charset->name [%s]", result_charset->name);
167                 encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", result_charset->name, &bytes_read, &bytes_written, &glib_error);
168         }
169         else {
170                 i = 0;
171                 while(filename[i++] & 0x80)
172                         has_special_character = 1;
173                 testapp_print("has_special_character [%d]", has_special_character);
174                 if(has_special_character)
175                         encoded_file_name = (char*)g_convert (filename, -1, "UTF-8", "EUC-KR", &bytes_read, &bytes_written, &glib_error);
176         }
177         
178         if(encoded_file_name == NULL)
179                 encoded_file_name = strdup(filename);
180
181         testapp_print("encoded_file_name [%s]", encoded_file_name);
182
183         if(!encode_base64(encoded_file_name, strlen(encoded_file_name), &base64_file_name, (unsigned long*)&base64_file_name_length, &error)) {
184                 testapp_print("encode_base64 failed. error [%d]", error);
185                 goto FINISH_OFF;
186         }
187
188         testapp_print("base64_file_name [%s]", base64_file_name);
189
190         if(base64_file_name) {
191                 free(encoded_file_name);
192                 encoded_file_name = malloc(strlen(base64_file_name) + 15);
193                 if(!encoded_file_name) {
194                         testapp_print("em_malloc failed.");
195                         goto FINISH_OFF;
196                 }
197                 snprintf(encoded_file_name, strlen(base64_file_name) + 15, "=?UTF-8?B?%s?=", base64_file_name);
198                 testapp_print("encoded_file_name [%s]", encoded_file_name);
199         }
200 FINISH_OFF:
201
202         if (encoded_file_name)
203                 free(encoded_file_name);
204
205         if (base64_file_name)
206                 free(base64_file_name);
207
208         return error;
209 }
210
211 #define LIB_EMAIL_SERVICE_PATH  "/usr/lib/libemail-api.so"
212
213 int (*Datastore_FI_EMTB)(char **);
214 int (*Datastore_FI_EMSB)(char **);
215 int (*Datastore_FI_EMOB)(char **);
216 int (*Datastore_FI_EMDR)(char **);
217 int (*Datastore_FI_EMMF)(char **);
218 int (*Datastore_FI_EMTR)(char **);
219 int (*Datastore_FI_EMSP)(char **);
220
221 static gboolean email_test_dtt_Datastore_FI()
222 {
223         void *handle = NULL;
224         char *dl_error = NULL, *output_str = NULL;
225
226         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
227         if (!handle) {
228                 dl_error = dlerror();
229                 if (dl_error)
230                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
231                 return false;
232         }       
233
234         Datastore_FI_EMTB = dlsym(handle, "Datastore_FI_EMTB");
235         Datastore_FI_EMSB = dlsym(handle, "Datastore_FI_EMSB");
236         Datastore_FI_EMOB = dlsym(handle, "Datastore_FI_EMOB");
237         Datastore_FI_EMDR = dlsym(handle, "Datastore_FI_EMDR");
238         Datastore_FI_EMMF = dlsym(handle, "Datastore_FI_EMMF");
239         Datastore_FI_EMTR = dlsym(handle, "Datastore_FI_EMTR");
240         Datastore_FI_EMSP = dlsym(handle, "Datastore_FI_EMSP");
241
242         Datastore_FI_EMTB(&output_str);
243
244         testapp_print("\nemail_test_dtt_Datastore_FI\n%s\n", output_str);
245         
246         if(output_str)
247                 free(output_str);
248
249         if (handle) {
250                 dlclose(handle);
251                 dl_error = dlerror();
252                 if (dl_error)
253                         testapp_print("\t Close handle return  :  %s\n", dl_error);
254         }
255
256         return true;
257 }
258
259 int (*Datastore_R_EMTB)(char **);
260 int (*Datastore_R_EMSB)(char **);
261 int (*Datastore_R_EMOB)(char **);
262 int (*Datastore_R_EMDR)(char **);
263 int (*Datastore_R_EMMF)(char **);
264 int (*Datastore_R_EMTR)(char **);
265 int (*Datastore_R_EMSP)(char **);
266
267
268 static gboolean email_test_dtt_Datastore_R()
269 {
270         void *handle = NULL;
271         char *dl_error = NULL, *output_str = NULL;
272
273         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
274         if (!handle) {
275                 dl_error = dlerror();
276                 if (dl_error)
277                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
278                 return false;
279         }       
280
281         Datastore_R_EMTB = dlsym(handle, "Datastore_R_EMTB");
282         Datastore_R_EMSB = dlsym(handle, "Datastore_R_EMSB");
283         Datastore_R_EMOB = dlsym(handle, "Datastore_R_EMOB");
284         Datastore_R_EMDR = dlsym(handle, "Datastore_R_EMDR");
285         Datastore_R_EMMF = dlsym(handle, "Datastore_R_EMMF");
286         Datastore_R_EMTR = dlsym(handle, "Datastore_R_EMTR");
287         Datastore_R_EMSP = dlsym(handle, "Datastore_R_EMSP");
288
289         Datastore_R_EMTB(&output_str);
290
291         testapp_print("\nemail_test_dtt_Datastore_R\n%s\n", output_str);
292
293         if(output_str)
294                 free(output_str);
295
296         if (handle) {
297                 dlclose(handle);
298                 dl_error = dlerror();
299                 if (dl_error)
300                         testapp_print("\t Close handle return  :  %s\n", dl_error);
301         }
302
303         return true;
304 }
305
306 int (*Datastore_C_EMTB)(char **);
307 int (*Datastore_C_EMSB)(char **);
308 int (*Datastore_C_EMOB)(char **);
309 int (*Datastore_C_EMDR)(char **);
310 int (*Datastore_C_EMMF)(char **);
311 int (*Datastore_C_EMTR)(char **);
312 int (*Datastore_C_EMSP)(char **);
313
314 static gboolean email_test_dtt_Datastore_C()
315 {
316         void *handle = NULL;
317         char *dl_error = NULL, *output_str = NULL;
318
319         handle = dlopen(LIB_EMAIL_SERVICE_PATH, RTLD_LAZY | RTLD_GLOBAL);
320         if (!handle) {
321                 dl_error = dlerror();
322                 if (dl_error)
323                         testapp_print("\t dlopen error : Open Library with absolute path return  :  %s\n", dl_error);
324                 return false;
325         }       
326
327         Datastore_C_EMTB = dlsym(handle, "Datastore_C_EMTB");
328         Datastore_C_EMSB = dlsym(handle, "Datastore_C_EMSB");
329         Datastore_C_EMOB = dlsym(handle, "Datastore_C_EMOB");
330         Datastore_C_EMDR = dlsym(handle, "Datastore_C_EMDR");
331         Datastore_C_EMMF = dlsym(handle, "Datastore_C_EMMF");
332         Datastore_C_EMTR = dlsym(handle, "Datastore_C_EMTR");
333         Datastore_C_EMSP = dlsym(handle, "Datastore_C_EMSP");
334
335         Datastore_C_EMTB(&output_str);
336
337
338         testapp_print("\nemail_test_dtt_Datastore_C\n%s\n", output_str);
339         
340         if(output_str)
341                 free(output_str);
342
343         if (handle) {
344                 dlclose(handle);
345                 dl_error = dlerror();
346                 if (dl_error)
347                         testapp_print("\t Close handle return  :  %s\n", dl_error);
348         }
349
350         return true;
351 }
352
353 static gboolean testapp_test_show_user_message()
354 {
355         int mail_id;
356         int result_from_scanf = 0;
357
358         testapp_print("\n > Enter mail id : ");
359         result_from_scanf = scanf("%d", &mail_id);
360
361         email_show_user_message(mail_id, EMAIL_ACTION_SEND_MAIL, EMAIL_ERROR_NETWORK_NOT_AVAILABLE);
362         return FALSE;
363 }
364
365 static gboolean testapp_test_get_mime_entity()
366 {
367         char mime_path[512] = {0, };
368         int result_from_scanf = 0;
369         char *mime_entity = NULL;
370
371         testapp_print("\n > Enter mime path for parsing : ");
372         result_from_scanf = scanf("%s", mime_path);
373         
374         email_get_mime_entity(mime_path, &mime_entity);
375
376         testapp_print("\nmime_entity = %s\n", mime_entity);
377         return true;
378 }
379
380 static gboolean testapp_test_interpret_command (int menu_number)
381 {
382         gboolean go_to_loop = TRUE;
383
384         switch (menu_number) {
385                 case 3:
386                         testapp_test_cancel_job ();
387                         break;
388                 case 5: 
389                         testapp_test_set_dnet_proper_profile_type();
390                         break;
391                 case 6:
392                         testapp_test_get_dnet_proper_profile_type();
393                         break;
394                 case 7:
395                         testapp_test_get_preview_text_from_file();
396                         break;
397                 case 11:
398                         testapp_test_get_task_information();
399                         break;
400                 case 12:
401                         testapp_test_create_db_full();
402                         break;
403                 case 13:
404                         testapp_test_encoding_test();
405                         break;
406                 case 14:
407                         email_test_dtt_Datastore_FI();
408                         email_test_dtt_Datastore_C();
409                         email_test_dtt_Datastore_R();
410                         break;
411                 case 15:
412                         testapp_test_show_user_message();
413                         break;
414                 case 16:
415                         testapp_test_get_mime_entity();
416                         break;
417                 case 0:
418                         go_to_loop = FALSE;
419                         break;
420                 default:
421                         break;
422         }
423
424         return go_to_loop;
425 }
426
427 void testapp_others_main()
428 {
429         gboolean go_to_loop = TRUE;
430         int menu_number = 0;
431         int result_from_scanf = 0;
432
433         while (go_to_loop) {
434                 testapp_show_menu (EMAIL_OTHERS_MENU);
435                 testapp_show_prompt (EMAIL_OTHERS_MENU);
436
437                 result_from_scanf = scanf ("%d", &menu_number);
438
439                 go_to_loop = testapp_test_interpret_command (menu_number);
440         }
441 }
442