4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
33 #include "email-api-rule.h"
36 #include "testapp-utility.h"
37 #include "testapp-mailbox.h"
39 static gboolean testapp_test_add_rule()
41 email_rule_t* rule = NULL;
43 int target_mailbox_id = 0;
49 rule = malloc(sizeof(email_rule_t));
50 testapp_print("> Enter account id: ");
51 if (0 >= scanf("%d", &account_id))
52 testapp_print("Invalid input. ");
53 rule->account_id = account_id;
55 testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): ");
56 if (0 >= scanf("%d", &type))
57 testapp_print("Invalid input. ");
60 memset(arg, 0x00, 500);
61 testapp_print("\n> Enter Filtering Value:");
62 if (0 >= scanf("%s", arg))
63 testapp_print("Invalid input. ");
64 rule->value = strdup(arg);
66 testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): ");
67 if (0 >= scanf("%d", &action))
68 testapp_print("Invalid input. ");
69 rule->faction = action;
72 testapp_print("\n> Enter target mailbox id:");
73 if (0 >= scanf("%d", &target_mailbox_id))
74 testapp_print("Invalid input. ");
75 rule->target_mailbox_id = target_mailbox_id;
78 testapp_print("> Enter Flag1 value [On/Off]: ");
79 if (0 >= scanf("%d", &flag))
80 testapp_print("Invalid input. ");
83 testapp_print("> Enter Flag2 value [0:Exactly same as, 1:Include, 2:Compare Domain] : ");
84 if (0 >= scanf("%d", &flag))
85 testapp_print("Invalid input. ");
88 if (email_add_rule(rule) < 0)
89 testapp_print("\n email_add_rule failed");
91 testapp_print("ID of rule : [%d]\n", rule->filter_id);
93 if (email_apply_rule(rule->filter_id) != EMAIL_ERROR_NONE)
94 testapp_print("email_apply_rule failed\n");
96 email_free_rule(&rule, 1);
101 static gboolean testapp_test_delete_rule()
105 testapp_print("> Enter filter id: ");
106 if (0 >= scanf("%d", &filter_id))
107 testapp_print("Invalid input. ");
109 if (email_delete_rule(filter_id) < 0)
110 testapp_print("email_delete_rule failed..! ");
116 static gboolean testapp_test_update_rule()
118 email_rule_t* rule = NULL;
120 int target_mailbox_id = 0;
127 rule = malloc(sizeof(email_rule_t));
128 memset(rule, 0X00, sizeof(email_rule_t));
129 testapp_print("> Enter filter id: ");
130 if (0 >= scanf("%d", &filter_id))
131 testapp_print("Invalid input. ");
133 testapp_print("> Enter account id: ");
134 if (0 >= scanf("%d", &account_id))
135 testapp_print("Invalid input. ");
136 rule->account_id = account_id;
138 testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): ");
139 if (0 >= scanf("%d", &type))
140 testapp_print("Invalid input. ");
143 memset(arg, 0x00, 500);
144 testapp_print("\n> Enter Filtering Value:");
145 if (0 >= scanf("%s", arg))
146 testapp_print("Invalid input. ");
147 rule->value = strdup(arg);
149 testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): ");
150 if (0 >= scanf("%d", &action))
151 testapp_print("Invalid input. ");
152 rule->faction = action;
155 testapp_print("\n> Enter target mailbox id:");
156 if (0 >= scanf("%d", &target_mailbox_id))
157 testapp_print("Invalid input. ");
158 rule->target_mailbox_id = target_mailbox_id;
161 testapp_print("> Enter Flag1 value: ");
162 if (0 >= scanf("%d", &flag))
163 testapp_print("Invalid input. ");
166 testapp_print("> Enter Flag2 value: ");
167 if (0 >= scanf("%d", &flag))
168 testapp_print("Invalid input. ");
171 if (email_update_rule(filter_id, rule) < 0)
172 testapp_print("email_update_rule failed..! ");
174 email_free_rule(&rule, 1);
180 static gboolean testapp_test_get_rule(void)
182 email_rule_t* rule = NULL;
185 testapp_print("> Enter filter id: ");
186 if (0 >= scanf("%d", &filter_id))
187 testapp_print("Invalid input. ");
189 if (email_get_rule(filter_id, &rule) >= 0)
190 testapp_print("\n Got rule of account_id = %d and type = %d\n", rule->account_id, rule->type);
192 email_free_rule(&rule, 1);
198 static gboolean testapp_test_get_rule_list(void)
201 email_rule_t* rule_list = NULL;
203 if (email_get_rule_list(&rule_list, &count) < 0) {
204 testapp_print(" email_get_rule_list error\n");
208 for (i = 0; i < count; i++) {
209 testapp_print(" %2d) Fileter_Id: %d | Account_id: %d | Type: %d | Value %s \n", i + 1,
210 rule_list[i].filter_id,
211 rule_list[i].account_id,
216 email_free_rule(&rule_list, count);
223 static gboolean testapp_test_interpret_command(int menu_number)
225 gboolean go_to_loop = TRUE;
227 switch (menu_number) {
229 testapp_test_add_rule();
232 testapp_test_delete_rule();
235 testapp_test_update_rule();
238 testapp_test_get_rule();
241 testapp_test_get_rule_list();
254 void email_test_rule_main()
256 gboolean go_to_loop = TRUE;
260 testapp_show_menu(EMAIL_RULE_MENU);
261 testapp_show_prompt(EMAIL_RULE_MENU);
263 if (0 >= scanf("%d", &menu_number))
264 testapp_print("Invalid input. ");
266 go_to_loop = testapp_test_interpret_command(menu_number);