1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
/*
* email-service
*
* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* email-tasks.c
*
* Created on: 2012. 11. 5.
* Author: kyuho.jo@samsung.com
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "email-debug-log.h"
#include "email-utilities.h"
#include "email-internal-types.h"
#include "email-core-tasks.h"
#include "email-core-task-manager.h"
#include "email-core-mail.h"
#include "email-core-smtp.h"
#include "email-core-mailbox-sync.h"
#include "email-core-signal.h"
#include "email-core-utils.h"
#include "tpl.h"
/*-------------------------------------------------------------------------------------------*/
/* to handle EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT */
#define task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT "iiiB"
/* LCOV_EXCL_START */
INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
{
EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
int err = EMAIL_ERROR_NONE;
task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_parameter = input_task_parameter_struct;
tpl_bin tb;
tpl_node *tn = NULL;
void *result_data = NULL;
size_t result_data_length = 0;
if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT
, &task_parameter->source_mailbox_id
, &task_parameter->target_mailbox_id
, &task_parameter->mail_id_count
, &tb);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tb.sz = sizeof(int) * task_parameter->mail_id_count;
tb.addr = task_parameter->mail_id_array;
tpl_pack(tn, 0);
tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
tpl_free(tn);
*output_byte_stream = result_data;
*output_stream_size = result_data_length;
FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
{
EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct);
int err = EMAIL_ERROR_NONE;
tpl_bin tb;
tpl_node *tn = NULL;
task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_parameter = NULL;
if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT));
if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT
, &task_parameter->source_mailbox_id
, &task_parameter->target_mailbox_id
, &task_parameter->mail_id_count
, &tb);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
tpl_unpack(tn, 0);
if (task_parameter->mail_id_count <= 0 || tb.addr == NULL) {
EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mail_id_count, tb.addr);
} else {
task_parameter->mail_id_array = tb.addr;
}
*output_task_parameter_struct = task_parameter;
FINISH_OFF:
if (tn)
tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT(void *input_param)
{
EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
int err = EMAIL_ERROR_NONE;
int err_for_signal = EMAIL_ERROR_NONE;
int i = 0;
int task_id = THREAD_SELF();
task_parameter_EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT *task_param = input_param;
for (i = 0; i < task_param->mail_id_count; i++) {
if ((err = emcore_move_mail_to_another_account(task_param->multi_user_name, task_param->mail_id_array[i], task_param->source_mailbox_id, task_param->target_mailbox_id, task_id)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_move_mail_to_another_account failed [%d]", err);
goto FINISH_OFF;
}
/* Send progress signal */
if ((err_for_signal = emcore_send_task_status_signal(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT, task_id, EMAIL_TASK_STATUS_IN_PROGRESS, i, task_param->mail_id_count)) != EMAIL_ERROR_NONE)
EM_DEBUG_LOG("emcore_send_task_status_signal failed [%d]", err_for_signal);
}
FINISH_OFF:
/* Free task parameter */
EM_SAFE_FREE(task_param->mail_id_array);
EM_SAFE_FREE(task_param);
EM_DEBUG_FUNC_END("err [%d]", err);
return NULL;
}
/*-------------------------------------------------------------------------------------------*/
/* to handle EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX */
#define task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX "iiBi"
INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
{
EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
int err = EMAIL_ERROR_NONE;
task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = input_task_parameter_struct;
tpl_bin tb;
tpl_node *tn = NULL;
void *result_data = NULL;
size_t result_data_length = 0;
if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
, &task_parameter->account_id
, &task_parameter->mailbox_id_count
, &tb
, &task_parameter->on_server);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tb.sz = sizeof(int) * task_parameter->mailbox_id_count;
tb.addr = task_parameter->mailbox_id_array;
tpl_pack(tn, 0);
tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
tpl_free(tn);
*output_byte_stream = result_data;
*output_stream_size = result_data_length;
FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
{
EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct);
int err = EMAIL_ERROR_NONE;
tpl_bin tb;
tpl_node *tn = NULL;
task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX *task_parameter = NULL;
if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX));
if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX
, &task_parameter->account_id
, &task_parameter->mailbox_id_count
, &tb
, &task_parameter->on_server);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
tpl_unpack(tn, 0);
if (task_parameter->mailbox_id_count <= 0 || tb.addr == NULL) {
EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]", task_parameter->mailbox_id_count, tb.addr);
} else {
task_parameter->mailbox_id_array = tb.addr;
}
*output_task_parameter_struct = task_parameter;
FINISH_OFF:
if (tn)
tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX(void *input_param)
{
return NULL;
}
/*-------------------------------------------------------------------------------------------*/
/* to handle EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL */
#define task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL "i"
INTERNAL_FUNC int email_encode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
{
EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
int err = EMAIL_ERROR_NONE;
task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = input_task_parameter_struct;
tpl_node *tn = NULL;
void *result_data = NULL;
size_t result_data_length = 0;
if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL
, &task_parameter->mail_id);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_pack(tn, 0);
tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
tpl_free(tn);
*output_byte_stream = result_data;
*output_stream_size = result_data_length;
FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
{
EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct);
int err = EMAIL_ERROR_NONE;
tpl_node *tn = NULL;
task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL *task_parameter = NULL;
if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL));
if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL
, &task_parameter->mail_id);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
tpl_unpack(tn, 0);
*output_task_parameter_struct = task_parameter;
FINISH_OFF:
if (tn)
tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL(void *input_param)
{
return NULL;
}
/*-------------------------------------------------------------------------------------------*/
/* to handle EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL */
#define task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL "ii"
INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
{
EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
int err = EMAIL_ERROR_NONE;
task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_parameter = input_task_parameter_struct;
tpl_node *tn = NULL;
void *result_data = NULL;
size_t result_data_length = 0;
if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL
, &task_parameter->mail_id, &task_parameter->scheduled_time);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_pack(tn, 0);
tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
tpl_free(tn);
*output_byte_stream = result_data;
*output_stream_size = result_data_length;
FINISH_OFF:
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
{
EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_byte_stream, input_stream_size, output_task_parameter_struct);
int err = EMAIL_ERROR_NONE;
tpl_node *tn = NULL;
task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_parameter = NULL;
if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL));
if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL
, &task_parameter->mail_id, &task_parameter->scheduled_time);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
EM_SAFE_FREE(task_parameter);
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
tpl_unpack(tn, 0);
*output_task_parameter_struct = task_parameter;
FINISH_OFF:
if (tn)
tpl_free(tn);
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC void* task_handler_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL(void *input_param)
{
EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
int err = EMAIL_ERROR_NONE;
int *return_err = NULL;
task_parameter_EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL *task_param = input_param;
if ((err = emcore_schedule_sending_mail(task_param->multi_user_name,
task_param->mail_id,
task_param->scheduled_time)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_schedule_sending_mail [%d]", err);
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
return_err = em_malloc(sizeof(int));
if (return_err == NULL) {
EM_DEBUG_EXCEPTION("em_mallocfailed");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
*return_err = err;
FINISH_OFF:
EM_SAFE_FREE(task_param);
emcore_close_smtp_stream_list();
EM_DEBUG_FUNC_END("err [%d]", err);
return (void *)return_err;
}
/*-------------------------------------------------------------------------------------------*/
/* to handle EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE */
#define task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE "iiBiiB"
INTERNAL_FUNC int email_encode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
{
EM_DEBUG_FUNC_BEGIN("input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_parameter_struct, output_byte_stream, output_stream_size);
int err = EMAIL_ERROR_NONE;
task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_parameter = input_task_parameter_struct;
email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
tpl_bin tb_mail_id_array;
tpl_bin tb_value;
tpl_node *tn = NULL;
void *result_data = NULL;
size_t result_data_length = 0;
if (task_parameter == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if ((err = emcore_get_mail_attribute_value_type(task_parameter->attribute_type, &attribute_value_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE
, &task_parameter->account_id
, &task_parameter->mail_id_count
, &tb_mail_id_array
, &task_parameter->attribute_type
, &task_parameter->value_length
, &tb_value);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tb_mail_id_array.sz = sizeof(int) * task_parameter->mail_id_count;
tb_mail_id_array.addr = task_parameter->mail_id_array;
switch (attribute_value_type) {
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER:
task_parameter->value_length = 4;
tb_value.sz = task_parameter->value_length;
tb_value.addr = &task_parameter->value.integer_type_value;
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING:
task_parameter->value_length = EM_SAFE_STRLEN(task_parameter->value.string_type_value);
tb_value.sz = task_parameter->value_length;
tb_value.addr = task_parameter->value.string_type_value;
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME:
task_parameter->value_length = 4;
tb_value.sz = task_parameter->value_length;
tb_value.addr = &task_parameter->value.datetime_type_value;
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE:
default:
EM_DEBUG_EXCEPTION("invalid attribute value type [%d]", attribute_value_type);
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
tpl_pack(tn, 0);
tpl_dump(tn, TPL_MEM, &result_data, &result_data_length);
*output_byte_stream = result_data;
*output_stream_size = result_data_length;
FINISH_OFF:
if (tn)
tpl_free(tn);
if (err != EMAIL_ERROR_NONE) {
EM_SAFE_FREE(result_data);
if (task_parameter) {
EM_SAFE_FREE(task_parameter->multi_user_name);
EM_SAFE_FREE(task_parameter->mail_id_array);
free(task_parameter);
}
}
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC int email_decode_task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(char *input_byte_stream,
int input_stream_size,
void **output_task_parameter_struct)
{
EM_DEBUG_FUNC_BEGIN("input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]",
input_byte_stream, input_stream_size, output_task_parameter_struct);
int err = EMAIL_ERROR_NONE;
tpl_node *tn = NULL;
tpl_bin tb_mail_id_array;
tpl_bin tb_value;
task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_parameter = NULL;
email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE;
if (input_byte_stream == NULL || input_stream_size == 0 || output_task_parameter_struct == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
task_parameter = em_malloc(sizeof(task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE));
if (task_parameter == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
tn = tpl_map(task_parameter_format_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE
, &task_parameter->account_id
, &task_parameter->mail_id_count
, &tb_mail_id_array
, &task_parameter->attribute_type
, &task_parameter->value_length
, &tb_value);
if (tn == NULL) {
EM_DEBUG_EXCEPTION("tpl_map failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
tpl_load(tn, TPL_MEM, input_byte_stream, input_stream_size);
tpl_unpack(tn, 0);
if (task_parameter->mail_id_count <= 0 || tb_mail_id_array.addr == NULL) {
EM_DEBUG_LOG("No mail id list. mail_id_count[%d] addr[%p]",
task_parameter->mail_id_count, tb_mail_id_array.addr);
} else {
task_parameter->mail_id_array = tb_mail_id_array.addr;
}
if (tb_value.addr) {
if ((err = emcore_get_mail_attribute_value_type(task_parameter->attribute_type,
&attribute_value_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);
goto FINISH_OFF;
}
switch (attribute_value_type) {
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER:
memcpy(&task_parameter->value.integer_type_value, tb_value.addr, tb_value.sz);
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING:
task_parameter->value.string_type_value = em_malloc(tb_value.sz + 1);
if (task_parameter->value.string_type_value == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
memcpy(&task_parameter->value.string_type_value, tb_value.addr, tb_value.sz);
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME:
memcpy(&task_parameter->value.datetime_type_value, tb_value.addr, tb_value.sz);
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE:
default:
EM_DEBUG_EXCEPTION("invalid attribute value type [%d]", attribute_value_type);
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
}
*output_task_parameter_struct = task_parameter;
FINISH_OFF:
if (tn)
tpl_free(tn);
if (err != EMAIL_ERROR_NONE) {
if (task_parameter) {
EM_SAFE_FREE(task_parameter->multi_user_name);
EM_SAFE_FREE(task_parameter->mail_id_array);
free(task_parameter);
}
}
EM_DEBUG_FUNC_END("err [%d]", err);
return err;
}
INTERNAL_FUNC void *task_handler_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE(void *input_param)
{
EM_DEBUG_FUNC_BEGIN("input_param [%p]", input_param);
if (!input_param) { /*prevent 43681*/
EM_DEBUG_EXCEPTION("NULL parameter");
return NULL;
}
int err = EMAIL_ERROR_NONE;
int *return_err = NULL;
char *field_name = NULL;
task_parameter_EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE *task_param = input_param;
email_mail_attribute_value_type attribute_value_type = EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE; /*prevent 43700*/
if ((field_name = emcore_get_mail_field_name_by_attribute_type(task_param->attribute_type)) == NULL) {
EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
err = EMAIL_ERROR_INVALID_PARAM;
goto FINISH_OFF;
}
if ((err = emcore_get_mail_attribute_value_type(task_param->attribute_type,
&attribute_value_type)) != EMAIL_ERROR_NONE) {
EM_DEBUG_EXCEPTION("emcore_get_mail_attribute_value_type failed [%d]", err);
goto FINISH_OFF;
}
switch (attribute_value_type) {
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_INTEGER:
if (!emstorage_set_field_of_mails_with_integer_value(task_param->multi_user_name,
task_param->account_id,
task_param->mail_id_array,
task_param->mail_id_count,
field_name,
task_param->value.integer_type_value,
true,
&err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING:
err = EMAIL_ERROR_NOT_SUPPORTED;
EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING is not supported");
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_TIME:
if (!emstorage_set_field_of_mails_with_integer_value(task_param->multi_user_name,
task_param->account_id,
task_param->mail_id_array,
task_param->mail_id_count,
field_name,
task_param->value.datetime_type_value,
true,
&err)) {
EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err);
goto FINISH_OFF;
}
break;
case EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE:
default:
EM_DEBUG_LOG("EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_NONE or default");
err = EMAIL_ERROR_INVALID_PARAM;
break;
}
return_err = em_malloc(sizeof(int));
if (return_err == NULL) {
EM_DEBUG_EXCEPTION("em_mallocfailed");
err = EMAIL_ERROR_OUT_OF_MEMORY;
goto FINISH_OFF;
}
*return_err = err;
FINISH_OFF:
EM_SAFE_FREE(task_param->multi_user_name);
EM_SAFE_FREE(task_param->mail_id_array);
if (attribute_value_type == EMAIL_MAIL_ATTRIBUTE_VALUE_TYPE_STRING) {
EM_SAFE_FREE(task_param->value.string_type_value);
}
EM_SAFE_FREE(task_param);
EM_DEBUG_FUNC_END("err [%d]", err);
return (void *)return_err;
}
/* LCOV_EXCL_STOP */
/*-------------------------------------------------------------------------------------------*/
|