EmailSrvNetworkProt.h 34 KB
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 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *  EmailSrvNetworkProt.h
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  This file is used to define the Email network internal functions.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *----------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 * removed!
 *----------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#ifndef EMAILNETWORKPORT_H
#define EMAILNETWORKPORT_H

#include "app_base64.h"
#include "app_qp.h"

#include "EmailSrvComposer.h"
#include "email_ps_public.h"
#include "EmailSrvStorage.h"

#include "EmailSrvGprot.h"
#include "customer_ps_inc.h"
#include "MMI_trc_Int.h"
#include "mmi_inet_app_trc.h"
#include "EmailSrvNetwork.h"
#include "MMIDataType.h"
#include "kal_general_types.h"
#include "fs_type.h"
#include "fs_gprot.h"
#include "EmailSrvProt.h"

#define SRV_EMAIL_MAX_MSG_NUM           SRV_EMAIL_GLOBAL_MAX_MSG_NUM
#define SRV_EMAIL_MAX_FLDR_NUM          MMI_EMAIL_MAX_REMOTE_FOLDER_NUM
#define SRV_EMAIL_MAX_ADDR_NUM          MMI_EMAIL_MAX_ADDR_NUM
#define SRV_EMAIL_MAX_ATTACH_NUM        MMI_EMAIL_MAX_ATTACH_NUMBER
#define SRV_EMAIL_GET_NUM_PER_TIME      (250)

#define SRV_EMAIL_NWK_CLOUD_DECODE_BUFF_SIZE    (1024)

#define SRV_EMAIL_MAX_CB_NUM            (10)

#define SRV_EMAIL_NWK_FILE_PATH         "Network\\"

#define SRV_EMAIL_INBOX_NAME            "INBOX"

#define SRV_EMAIL_NWK_CB_CONNECTED      0x01

#define SRV_EMAIL_NWK_SET_STATE(cntx_p, state) \
            MMI_TRACE(MMI_INET_TRC_G9_EMAIL, SRV_EMAIL_STATE_NWK_FSM_SET_STATE, cntx_p, state); \
            cntx_p->nwk_state = state

#define SRV_EMAIL_NWK_CLOUD_SET_STATE(cntx_p, state) \
            MMI_TRACE(MMI_INET_TRC_G9_EMAIL, SRV_EMAIL_CLD_FSM_SET_STATE, cntx_p, state); \
            cntx_p->nwk_state = state

#define SRV_EMAIL_NWK_CLOUD_SET_SUB_STATE(cntx_p, state) \
            MMI_TRACE(MMI_INET_TRC_G9_EMAIL, SRV_EMAIL_CLD_FSM_SET_SUB_STATE, cntx_p, state); \
            cntx_p->sub_state = state

/* The network context state enum */
typedef enum
{
    SRV_EMAIL_NWK_STATE_INIT,
    SRV_EMAIL_NWK_STATE_CREATING,
    SRV_EMAIL_NWK_STATE_CREATED,
    SRV_EMAIL_NWK_STATE_ACTIVATING,
    SRV_EMAIL_NWK_STATE_ACTIVATED,
    SRV_EMAIL_NWK_STATE_CONNECTING,
    SRV_EMAIL_NWK_STATE_AUTHORIZING,
    SRV_EMAIL_NWK_STATE_QUERYING,
    SRV_EMAIL_NWK_STATE_READY,
    SRV_EMAIL_NWK_STATE_UPDATING,
    SRV_EMAIL_NWK_STATE_UPDATED,
    SRV_EMAIL_NWK_STATE_SENDING,
    SRV_EMAIL_NWK_STATE_RECEIVING,
    SRV_EMAIL_NWK_STATE_SYNCING,
    SRV_EMAIL_NWK_STATE_LISTING_FOLDER,
    SRV_EMAIL_NWK_STATE_DISCONNECTING,
#if defined(__MMI_SSO__) || defined(__SMS_CLOUD_SUPPORT__)
    SRV_EMAIL_NWK_STATE_CLOUD_QUERYING,
    SRV_EMAIL_NWK_STATE_CLOUD_REFRESHING,
    SRV_EMAIL_NWK_STATE_CLOUD_UPGRADING,
#endif /* defined(__MMI_SSO__) || defined(__SMS_CLOUD_SUPPORT__) */
    SRV_EMAIL_NWK_STATE_TOTAL
} srv_email_nwk_state_enum;

typedef enum
{
    SRV_EMAIL_NWK_SUB_STATE_NONE,

    SRV_EMAIL_NWK_SUB_STATE_SEND_INIT = 100,    /* The send related sub-states */
    SRV_EMAIL_NWK_SUB_STATE_SEND_LIST,
    SRV_EMAIL_NWK_SUB_STATE_SEND_COMPOSE,
    SRV_EMAIL_NWK_SUB_STATE_SEND_SEND,
    SRV_EMAIL_NWK_SUB_STATE_SEND_APPEND,
    SRV_EMAIL_NWK_SUB_STATE_SEND_DONE,

    SRV_EMAIL_NWK_SUB_STATE_UPDATE_INIT = 200,  /* The update related sub-states */
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_OPEN_FOLDER,
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_CREATE_FOLDER,
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_LIST_UID,
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_LIST_SIZE,
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_LIST_FLAG,
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_UPDATE_LOCAL,
    SRV_EMAIL_NWK_SUB_STATE_UPDATE_DONE,

    SRV_EMAIL_NWK_SUB_STATE_RECV_INIT = 300,    /* The receive related sub-states */
    SRV_EMAIL_NWK_SUB_STATE_RECV_UID,
    SRV_EMAIL_NWK_SUB_STATE_RECV_RECEIVE,
    SRV_EMAIL_NWK_SUB_STATE_RECV_PARSE,
    SRV_EMAIL_NWK_SUB_STATE_RECV_SAVE,
    SRV_EMAIL_NWK_SUB_STATE_RECV_DONE,

    SRV_EMAIL_NWK_SUB_STATE_DISC_INIT = 400,    /* The POP3 delete related sub-states */
    SRV_EMAIL_NWK_SUB_STATE_DISC_DEL_SERVER,
    SRV_EMAIL_NWK_SUB_STATE_DISC_DISCONNECT,
    SRV_EMAIL_NWK_SUB_STATE_DISC_DEL_LOCAL,
    SRV_EMAIL_NWK_SUB_STATE_DISC_DONE,

    SRV_EMAIL_NWK_SUB_STATE_SYNC_INIT = 500,    /* The IMAP4 sync related sub-states */
    SRV_EMAIL_NWK_SUB_STATE_SYNC_FLAGS,
    SRV_EMAIL_NWK_SUB_STATE_SYNC_DELETE,
    SRV_EMAIL_NWK_SUB_STATE_SYNC_DONE,

    SRV_EMAIL_NWK_SUB_STATE_LIST_FLDR_INIT = 600,   /* The remote folder related sub-states */
    SRV_EMAIL_NWK_SUB_STATE_LIST_FLDR_LIST_SERVER,
    SRV_EMAIL_NWK_SUB_STATE_LIST_FLDR_LIST_LOCAL,
    SRV_EMAIL_NWK_SUB_STATE_LIST_FLDR_DONE,

    SRV_EMAIL_NWK_SUB_STATE_TOTAL
} srv_email_nwk_sub_state_enum;

typedef enum
{
    SRV_EMAIL_NWK_FLAG_IN_LOCAL      = 0x0001,
    SRV_EMAIL_NWK_FLAG_HEADER_ONLY   = 0x0002,
    SRV_EMAIL_NWK_FLAG_UPDATE_LOCAL  = 0x0010,
    SRV_EMAIL_NWK_FLAG_UPDATE_SERVER = 0x0020,
    SRV_EMAIL_NWK_FLAG_DELETE_LOCAL  = 0x0100,
    SRV_EMAIL_NWK_FLAG_DELETE_SERVER = 0x0200,
    SRV_EMAIL_NWK_FLAG_FLAG_VALID    = 0x1000,
    SRV_EMAIL_NWK_FLAG_TOTAL
} srv_email_nwk_flag_enum;

typedef enum
{
    SRV_EMAIL_IMAP4_FETCH_NONE,
    SRV_EMAIL_IMAP4_FETCH_ENVELOPE,
    SRV_EMAIL_IMAP4_FETCH_BODY_STRUCT,
    SRV_EMAIL_IMAP4_FETCH_CONTENT,
    SRV_EMAIL_IMAP4_FETCH_ATTACHMENT,
    SRV_EMAIL_IMAP4_FETCH_TOTAL
} srv_email_imap4_fetch_type_enum;

typedef enum
{
    SRV_EMAIL_IMAP4_PARSE_NONE,
    SRV_EMAIL_IMAP4_DECODE_CONTENT,
    SRV_EMAIL_IMAP4_DECODE_ATTACHMENT,
    SRV_EMAIL_IMAP4_PARSE_DRM,
    SRV_EMAIL_IMAP4_PARSE_READ_FILE,
    SRV_EMAIL_IMAP4_PARSE_WRITE_FILE,
    SRV_EMAIL_IMAP4_PARSE_TOTAL
} srv_email_imap4_parse_enum;

typedef struct _srv_email_addr_list_struct
{
    struct _srv_email_addr_list_struct *next;
    srv_email_stor_addr_struct addr;
} srv_email_addr_list_struct;

typedef struct _srv_email_cont_list_struct
{
    struct _srv_email_cont_list_struct *next;
    srv_email_stor_cont_header_struct cont;
    srv_email_stor_msg_cont_type type;
    WCHAR filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
} srv_email_cont_list_struct;

typedef struct _srv_email_attach_list_struct
{
    struct _srv_email_attach_list_struct *next;
    srv_email_stor_attch_struct attach;
    EMAIL_ATTCH_ID attach_id;
    WCHAR filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
} srv_email_attach_list_struct;

typedef struct
{
    srv_email_stor_msg_create_header_struct *msg_header_p;
    CHAR *subject_p;
    srv_email_stor_addr_struct *from_p;
    srv_email_stor_addr_struct *reply_to_p;
    srv_email_addr_list_struct *to_addr_p;
    srv_email_addr_list_struct *cc_addr_p;
    srv_email_addr_list_struct *bcc_addr_p;
    srv_email_cont_list_struct *cont_p;
    srv_email_attach_list_struct *attach_p;
} srv_email_msg_env_struct;

/* Network control block structure */
typedef struct _srv_email_nwk_cb_struct
{
    struct _srv_email_nwk_cb_struct *next;
    srv_email_nwk_action_enum action;
    void *action_data;
    srv_email_nwk_proc_funcptr_type proc_callback;
    void *proc_user_data;
    srv_email_nwk_finish_funcptr_type finish_callback;
    void *finish_user_data;
    EMAIL_FLDR_ID fldr_id[SRV_EMAIL_MAX_FLDR_NUM + 1];
    U16 fldr_index;
    U16 fldr_count;
    S32 state;
} srv_email_nwk_cb_struct;

#ifdef __MMI_EMAIL__

/* The Email connect context structure */
typedef struct
{
    srv_email_nwk_cb_struct *idle_cb_list_p;
    srv_email_nwk_cb_struct *pending_cb_list_p;
    srv_email_nwk_cb_struct *running_cb_p;
    srv_email_nwk_cb_struct *sync_cb_p;

    EMAIL_ACCT_ID acct_id;
    email_ps_protocol_type_enum protocol;

    EMAIL_ACCT_HANDLE acct_handle;
    //EMAIL_STOR_HANDLE stor_handle;
    EMAIL_PS_HANDLE ps_handle;

    U8 acct_digest[SRV_EMAIL_MD5_DIGEST_LEN];
    U32 wait_bearer_info;
    U32 nwk_acct_id;
    U32 capa_mask;
    CHAR from_addr[SRV_EMAIL_MAX_ADDR_LEN + 1];
    srv_email_server_struct server_addr; /* The server info */
    srv_email_auth_struct auth;        /* The user info */
    srv_email_download_option_enum download_opt;
    U32 download_size;
    U32 retrieve_amount;

    srv_email_result_struct result;

    MMI_BOOL reauth_flag;
    MMI_BOOL destroy_flag;
    MMI_BOOL abort_flag;
    MMI_BOOL schdl_flag;
    EMAIL_REQ_ID req_id;

    MMI_BOOL refresh_result;
    MMI_BOOL refresh_notified;
    MMI_BOOL refresh_flag;
    U32 refresh_type;

#ifdef __MMI_SSO__
    U32 provider_id;
    U8 cloud_acct_id;
    S32 sso_req_id;
#endif /* __MMI_SSO__ */
} srv_email_comm_cntx_struct;

/* The Email network context structure */
typedef struct _srv_email_nwk_cntx_struct
{
    struct _srv_email_nwk_cntx_struct *next;
    srv_email_nwk_state_enum nwk_state;
    srv_email_nwk_state_enum prev_state;
    srv_email_nwk_sub_state_enum sub_state;
    email_ps_protocol_state_enum ps_state;
    srv_email_comm_cntx_struct common;
} srv_email_nwk_cntx_struct;

typedef struct _srv_email_smtp_item_struct
{
    struct _srv_email_smtp_item_struct *next;
    EMAIL_MSG_ID msg_id;
    U32 msg_time;
    MMI_BOOL is_sent;
} srv_email_smtp_item_struct;

typedef struct
{
    S32 record_num;
    srv_email_smtp_item_struct *record;
    srv_email_smtp_item_struct *curr_record;
} srv_email_smtp_list_struct;

typedef struct
{
    EMAIL_MSG_HANDLE msg_handle;
    EMAIL_MSG_ID msg_id;
    MMI_BOOL send_outbox;
    MMI_BOOL send_msg_handle;
    MMI_BOOL send_msg_id;
    MMI_BOOL move_to_sent;
    U32 total_count;
    U32 curr_count;
    srv_email_smtp_list_struct list;
} srv_email_smtp_session_struct;

typedef struct
{
    EMAIL_COMP_HANDLE comp_handle;
    EMAIL_STOR_HANDLE stor_handle;
    EMAIL_MSG_ID last_msg_id;

    CHAR from_addr[SRV_EMAIL_MAX_ADDR_LEN + 1];               /* The from address */
    WCHAR rcpt_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];   /* The recipient file name */
    WCHAR msg_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];    /* The email file name */

    EMAIL_MSG_ID dst_msg_id;

    S32 total_count;    /* The count of the total mails */
    S32 sent_count;     /* The count of the mails sent successfully */
    S32 fail_count;     /* The count of the mails sent unsuccessfully */

    S32 major;
    S32 minor;
} srv_email_smtp_state_struct;

/* The Email SMTP context structure */
typedef struct
{
    struct _srv_email_nwk_cntx_struct *next;
    srv_email_nwk_state_enum nwk_state;
    srv_email_nwk_state_enum prev_state;
    srv_email_nwk_sub_state_enum sub_state;
    email_ps_protocol_state_enum ps_state;
    srv_email_comm_cntx_struct common;
    srv_email_smtp_session_struct session;
    srv_email_smtp_state_struct state;
    srv_email_nwk_funcptr_type callback;
    void *user_data;
} srv_email_smtp_cntx_struct;

typedef struct _srv_email_pop3_item_struct
{
    struct _srv_email_pop3_item_struct *next;
    U32 seq_no;
    U8 uid_digest[SRV_EMAIL_MD5_DIGEST_LEN];
    U32 size;
    U16 nwk_flag;
    //U16 msg_flag;
    EMAIL_MSG_ID msg_id;
} srv_email_pop3_item_struct;

typedef struct
{
    S32 record_num;
    srv_email_pop3_item_struct *record;
} srv_email_pop3_list_struct;

typedef struct
{
    MMI_BOOL sync_with_server;
    U32 total_msg_num;
    srv_email_pop3_list_struct list;
} srv_email_pop3_session_struct;

typedef struct
{
    EMAIL_STOR_HANDLE stor_handle;
    EMAIL_MSG_ID last_msg_id;

    EMAIL_MSG_HANDLE msg_handle;
    EMAIL_REQ_ID req_id;
    EMAIL_MSG_ID msg_id;

    MMI_BOOL batch_download;
    MMI_BOOL delete_fail;

    srv_email_receive_option_enum recv_opt;
    srv_email_download_option_enum download_opt;
    srv_email_retrieve_option_enum retr_opt;

    srv_email_pop3_item_struct *curr_rec_p;

    email_ps_fetch_type_enum fetch_type;

    U32 download_size;
    U32 retrieve_amount;
    U32 total_num;
    U32 received_num;
    U32 fail_num;

    U32 total_count;
    U32 curr_count;
    U32 start_index;
    U32 list_count;
    WCHAR req_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
    WCHAR rsp_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];

    S32 major;
    S32 minor;
} srv_email_pop3_state_struct;

/* The Email POP3 context structure */
typedef struct
{
    struct _srv_email_nwk_cntx_struct *next;
    srv_email_nwk_state_enum nwk_state;
    srv_email_nwk_state_enum prev_state;
    srv_email_nwk_sub_state_enum sub_state;
    email_ps_protocol_state_enum ps_state;
    srv_email_comm_cntx_struct common;
    srv_email_pop3_session_struct session;
    srv_email_pop3_state_struct state;
    srv_email_nwk_funcptr_type callback;
    void *user_data;
} srv_email_pop3_cntx_struct;

typedef struct _srv_email_imap4_item_struct
{
    struct _srv_email_imap4_item_struct *next;
    U32 seq_no;
    U32 uid;
    U32 size;
    U16 nwk_flag; /* See srv_email_nwk_flag_enum */
    U16 msg_flag; /* EMAIL_MSG_FLAG_SEEN */
    EMAIL_MSG_ID msg_id;
} srv_email_imap4_item_struct;

typedef struct
{
    S32 record_num;
    srv_email_imap4_item_struct *record;
} srv_email_imap4_list_struct;

typedef struct
{
    EMAIL_FLDR_ID fldr_id;
    MMI_BOOL sync_with_server;
    U32 total_msg_num;
    U32 uid_validity;
    srv_email_imap4_list_struct list;
} srv_email_imap4_session_struct;

typedef struct _srv_email_nwk_fldr_list_struct
{
    struct _srv_email_nwk_fldr_list_struct *next;
    srv_email_nwk_fldr_info_struct fldr_info;
} srv_email_nwk_fldr_list_struct;

typedef struct
{
    EMAIL_STOR_HANDLE stor_handle;
    EMAIL_MSG_ID last_msg_id;
    EMAIL_STOR_HANDLE msg_create_handle;

    //EMAIL_MSG_HANDLE msg_handle;
    //EMAIL_REQ_ID req_id;
    srv_email_msg_env_struct *msg_env_p;

    MMI_BOOL batch_download;
    MMI_BOOL subcribed_only;

    S32 fldr_count;
    S32 fldr_index;

    srv_email_receive_option_enum recv_opt;
    srv_email_download_option_enum download_opt;
    srv_email_retrieve_option_enum retr_opt;

    srv_email_imap4_item_struct *curr_rec_p;
    srv_email_cont_list_struct *curr_cont_p;
    srv_email_attach_list_struct *curr_att_p;
    srv_email_nwk_fldr_list_struct *fldr_list_p;
    srv_email_nwk_fldr_info_header_struct fldr_header;

    srv_email_imap4_fetch_type_enum fetch_type;

    CHAR *part_num;

    U32 download_size;
    U32 retrieve_amount;
    U32 total_num;
    U32 received_num;
    U32 fail_num;

    U32 fldr_num;
    U32 total_count;
    U32 curr_count;
    U32 start_index;
    U32 list_count;
    WCHAR *fldr_filename;

    WCHAR filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
    srv_email_imap4_parse_enum parse_state;
    FS_HANDLE src_fd;
    FS_HANDLE dst_fd;
    U32 total_size;
    U32 curr_size;
    applib_base64_part_context *base64_p;
    applib_qprint_context *qprint_p;
    U8 drm_serial;

    WCHAR req_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
    WCHAR rsp_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];

    CHAR *async_fs_data_buf;
    U32 async_fs_data_len;
    U32 async_fs_data_size;
    CHAR *async_fs_work_buf;
    fs_job_id async_fs_job_id;
    srv_email_imap4_parse_enum async_fs_state;

    /* Sync related */
    MMI_BOOL all_msg;
    EMAIL_MSG_ID msg_id;
    MMI_BOOL need_expunge;

    S32 major;
    S32 minor;
} srv_email_imap4_state_struct;

/* The Email IMAP4 context structure */
typedef struct
{
    struct _srv_email_nwk_cntx_struct *next;
    srv_email_nwk_state_enum nwk_state;
    srv_email_nwk_state_enum prev_state;
    srv_email_nwk_sub_state_enum sub_state;
    email_ps_protocol_state_enum ps_state;
    srv_email_comm_cntx_struct common;
    srv_email_imap4_session_struct session;
    srv_email_imap4_state_struct state;
    srv_email_nwk_funcptr_type callback;
    void *user_data;
} srv_email_imap4_cntx_struct;

typedef struct
{
    email_ps_imap_push_type_enum type;
    U32 seq_num;
    U32 new_flag;
} srv_email_imap4_push_struct;

// for send before sync
typedef struct _srv_email_app_id_reg_struct
{
    kal_uint16 app_str_id;
    kal_uint16 app_icon_id;
    U8 incoming_app_id;
    U8 outgoing_app_id;
    EMAIL_ACCT_ID acct_id;
    MMI_BOOL hold_incoming;    
    MMI_BOOL hold_outgoing;
    struct _srv_email_app_id_reg_struct *next;
} srv_email_app_id_reg_struct;

#endif /* __MMI_EMAIL__ */

#ifdef __SMS_CLOUD_SUPPORT__

typedef struct
{
    srv_email_nwk_cb_struct *idle_cb_list_p;
    srv_email_nwk_cb_struct *pending_cb_list_p;
    srv_email_nwk_cb_struct *running_cb_p;

    EMAIL_ACCT_ID acct_id;
    EMAIL_PS_HANDLE ps_handle;

    U32 wait_bearer_info;
    U32 nwk_acct_id;
    U32 capa_mask;

    U32 provider_id;
    U8 cloud_acct_id;
    S32 sso_req_id;

    CHAR from_addr[SRV_EMAIL_MAX_ADDR_LEN + 1];
    srv_email_server_struct server_addr;
    srv_email_auth_struct auth;

    MMI_BOOL destroy_flag;
    MMI_BOOL abort_flag;
    MMI_BOOL schdl_flag;
    EMAIL_REQ_ID req_id;

    srv_email_result_struct result;
} srv_email_nwk_cloud_comm_cntx_struct;

typedef struct
{
    CHAR fldr_name[SRV_EMAIL_FLDR_NAME_LEN + 1];
    MMI_BOOL sync_with_server;
    U32 total_msg_num;
} srv_email_nwk_cloud_session_struct;

typedef struct
{
    EMAIL_COMP_HANDLE comp_handle;
    EMAIL_MSG_HANDLE msg_handle;

    U32 msg_part;
    U32 msg_uid;
    U32 uid_max_num;

    WCHAR filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
    WCHAR msg_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];    /* The email file name */
    WCHAR part_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];
    WCHAR rsp_filename[SRV_EMAIL_NWK_MAX_FILE_NAME_LEN + 1];

    srv_email_msg_env_struct *msg_env_p;
    srv_email_cont_list_struct *curr_cont_p;
    srv_email_attach_list_struct *curr_att_p;
    CHAR *part_num;
    U32 fetch_type;

    U32 start_index;
    U32 list_count;

    srv_email_imap4_parse_enum parse_state;
    FS_HANDLE src_fd;
    FS_HANDLE dst_fd;
    U32 total_size;
    U32 curr_size;
    applib_base64_part_context *base64_p;
    applib_qprint_context *qprint_p;

    CHAR *async_fs_data_buf;
    U32 async_fs_data_len;
    U32 async_fs_data_size;
    CHAR *async_fs_work_buf;
    fs_job_id async_fs_job_id;
    srv_email_imap4_parse_enum async_fs_state;

    MMI_BOOL fldr_create_flag;
    MMI_BOOL fldr_open_fail_flag;

    S32 major;
    S32 minor;
} srv_email_nwk_cloud_state_struct;

/* The Cloud Email network context structure */
typedef struct _srv_email_nwk_cloud_cntx_struct
{
    struct _srv_email_nwk_cloud_cntx_struct *next;
    srv_email_nwk_state_enum nwk_state;
    srv_email_nwk_sub_state_enum sub_state;
    email_ps_protocol_state_enum ps_state;
    srv_email_nwk_cloud_comm_cntx_struct common;
    srv_email_nwk_cloud_session_struct session;
    srv_email_nwk_cloud_state_struct state;
    srv_email_nwk_funcptr_type callback;
    void *user_data;
} srv_email_nwk_cloud_cntx_struct;

#endif /* __SMS_CLOUD_SUPPORT__ */

typedef struct _srv_email_fs_async_struct
{
    struct _srv_email_fs_async_struct *next;
    fs_job_id job_id;
    void *work_buf;
    void *data_buf;
} srv_email_fs_async_struct;

EMAIL_SRV_HANDLE srv_email_get_int_srv_handle(void);

/* Set/Get error code */
void srv_email_set_error_cause(srv_email_result_struct *result, S32 major, S32 minor, CHAR *err_string);
void srv_email_get_ps_error(email_ps_result_struct *result_p, S32 *major, S32 *minor);
void srv_email_get_stor_error(S32 ret, S32 *major, S32 *minor);
void srv_email_get_acct_error(S32 ret, S32 *major, S32 *minor);
void srv_email_get_msg_error(S32 ret, S32 *major, S32 *minor);

/* Activate bearer */
srv_email_result_enum srv_email_nwk_activate_bearer(U32 nwk_acct_id, S32 *major, S32 *minor);
MMI_BOOL srv_email_nwk_is_bearer_activated(U32 nwk_acct_id);

void srv_email_compute_md5_digest(const CHAR *input, S32 input_len, U8 *digest);

void srv_email_add_fs_async_job(fs_job_id job_id, void *work_buf_p, void *data_buf_p);
MMI_BOOL srv_email_delete_fs_async_job(fs_job_id job_id);
void srv_email_fs_async_abort(fs_job_id *job_id_p, void **work_buf_p, void **data_buf_p);

MMI_BOOL srv_email_nwk_make_conn_req_file(
            U32 provider_id,
            const CHAR *from_addr_p,
            U32 protocol,
            srv_email_server_struct *server_p,
            const WCHAR *filename,
            S32 *errcode);

void srv_email_ps_send_msg(U16 msg_id, void *local_param_ptr, void *peer_buf_ptr);

/* Create the PS instance */
void srv_email_ps_create_instance_req(U32 req_id, email_ps_protocol_type_enum protocol);
void srv_email_ps_create_instance_rsp(void *inMsg);

/* Destroy the PS instance */
void srv_email_ps_destroy_instance_req(EMAIL_PS_HANDLE handle);
void srv_email_ps_destroy_instance_rsp(void *inMsg);

/* Connect the server */
void srv_email_ps_connect_req(
        EMAIL_PS_HANDLE handle,
        U32 nwk_acct_id,
        srv_email_server_struct *server_addr_p,
        const WCHAR *req_filename,
        const WCHAR *rsp_filename);
void srv_email_ps_connect_rsp(void *inMsg);

/* Disconnect the server */
void srv_email_ps_disconnect_req(EMAIL_PS_HANDLE handle);
void srv_email_ps_disconnect_rsp(void *inMsg);

/* Authorize with server */
void srv_email_ps_auth_req(EMAIL_PS_HANDLE handle, U32 capa_mask, srv_email_auth_struct *auth_p);
void srv_email_ps_auth_rsp(void *inMsg);

/* Open inbox or remote folder */
void srv_email_ps_open_folder_req(EMAIL_PS_HANDLE handle, const CHAR *mailbox);
void srv_email_ps_open_folder_rsp(void *inMsg);

/* List the UID */
void srv_email_ps_list_uid_req(EMAIL_PS_HANDLE handle, S32 start_index, S32 count, const WCHAR *filename, U32 ext_field);
void srv_email_ps_list_uid_rsp(void *inMsg);

/* Fetch email */
void srv_email_ps_fetch_mail_req(
        EMAIL_PS_HANDLE handle,
        U32 msg_uid,
        email_ps_fetch_type_enum type,
        S32 partial_count,
        const CHAR *part_num,
        const WCHAR *filename);
void srv_email_ps_fetch_mail_rsp(void *inMsg);

/* Abort */
void srv_email_ps_abort_req(EMAIL_PS_HANDLE handle);
void srv_email_ps_abort_rsp(void *inMsg);

/* Indication */
void srv_email_ps_disconnect_ind(void *inMsg);
void srv_email_ps_fetch_mail_ind(void *inMsg);
void srv_email_ps_imap4_push_ind(void *inMsg);

#ifdef __MMI_EMAIL__

srv_email_nwk_cntx_struct *srv_email_nwk_create_cntx(EMAIL_ACCT_ID acct_id, MMI_BOOL is_incoming, S32 *errcode);
srv_email_result_enum srv_email_nwk_run_cntx(srv_email_nwk_cntx_struct *cntx);
void srv_email_nwk_destroy_cntx(void *data);

MMI_BOOL srv_email_nwk_is_cntx_valid(srv_email_nwk_cntx_struct *cntx);
srv_email_nwk_cntx_struct *srv_email_nwk_get_cntx_list(void);

srv_email_nwk_cntx_struct *srv_email_nwk_get_cntx_by_id(EMAIL_ACCT_ID acct_id, MMI_BOOL is_incoming);
srv_email_nwk_cntx_struct *srv_email_nwk_get_cntx_by_cb(srv_email_nwk_cb_struct *cb);
srv_email_nwk_cntx_struct *srv_email_nwk_get_cntx_by_ps_handle(EMAIL_PS_HANDLE handle);

srv_email_nwk_cb_struct *srv_email_nwk_get_running_cb(srv_email_nwk_cntx_struct *cntx);
srv_email_nwk_cb_struct *srv_email_nwk_update_running_cb(srv_email_nwk_cntx_struct *cntx, MMI_BOOL notify_result);
srv_email_nwk_cb_struct *srv_email_nwk_update_running_cb_for_disc_ind(srv_email_nwk_cntx_struct *cntx);
MMI_BOOL srv_email_nwk_is_sync_cb(srv_email_nwk_cntx_struct *cntx, srv_email_nwk_cb_struct *cb);

MMI_BOOL srv_email_nwk_is_cb_full(srv_email_nwk_cntx_struct *cntx);
MMI_BOOL srv_email_nwk_is_cb_empty(srv_email_nwk_cntx_struct *cntx);
MMI_BOOL srv_email_nwk_is_pending_cb_empty(srv_email_nwk_cntx_struct *cntx);
MMI_BOOL srv_email_nwk_is_connected_cb_exist(srv_email_nwk_cntx_struct *cntx);

void srv_email_nwk_append_cb_to_idle_list(
        srv_email_nwk_cntx_struct *cntx,
        srv_email_nwk_cb_struct *cb);
void srv_email_nwk_move_cb_to_pending(
        srv_email_nwk_cntx_struct *cntx,
        srv_email_nwk_cb_struct *cb);
void srv_email_nwk_move_cb_to_idle(
        srv_email_nwk_cntx_struct *cntx,
        srv_email_nwk_cb_struct *cb);
void srv_email_nwk_move_cb_running_to_idle(srv_email_nwk_cntx_struct *cntx);

void srv_email_nwk_remove_cb(
        srv_email_nwk_cntx_struct *cntx,
        srv_email_nwk_cb_struct *cb,
        MMI_BOOL *cntx_valid);
void srv_email_nwk_abort_cb(srv_email_nwk_cntx_struct *cntx, srv_email_nwk_cb_struct *cb);

void srv_email_nwk_cb_process_notify(
        srv_email_nwk_cntx_struct *cntx,
        srv_email_nwk_cb_struct *cb,
        srv_email_nwk_status_enum status,
        void *status_data);
void srv_email_nwk_cb_finish_notify(srv_email_nwk_cb_struct *cb, srv_email_result_struct *result);

srv_email_result_enum srv_email_nwk_fsm(void *ptr);
void srv_email_nwk_fsm_abort(srv_email_nwk_cntx_struct *cntx_p);
void srv_email_nwk_fsm_disconn_ind(srv_email_nwk_cntx_struct *cntx_p);
void srv_email_nwk_fsm_imap4_push_ind(srv_email_nwk_cntx_struct *cntx_p, email_ps_imap_push_ind_struct *ind_p);
void srv_email_nwk_fsm_schdl(void *user_data);
void srv_email_nwk_om_notify_callback(const srv_email_om_notify_struct *data);

void srv_email_nwk_start_job(srv_email_schdl_funcptr_type callback, srv_email_nwk_cntx_struct *cntx_p);
void srv_email_nwk_stop_job(srv_email_nwk_cntx_struct *cntx_p);

srv_email_result_enum srv_email_nwk_list_remote_fldr_id(
                        EMAIL_ACCT_ID acct_id,
                        EMAIL_FLDR_ID *fldr_id,
                        U16 *fldr_cnt);

U8 srv_email_nwk_get_cbm_app_id(EMAIL_ACCT_ID acct_id, MMI_BOOL is_incoming, U32 dataacct_id, srv_email_nwk_cntx_struct *cntx_p);

/* Deactivate bearer */
void srv_email_nwk_deactivate_bearer(U32 nwk_acct_id,srv_email_nwk_cntx_struct *cntx);

void srv_email_compute_acct_digest(WCHAR *server_name, WCHAR *username, U8 *digest);

/* Send email (SMTP only) */
void srv_email_ps_send_mail_req(
        EMAIL_PS_HANDLE handle,
        const CHAR *from_addr,
        const WCHAR *rcpt_filename,
        const WCHAR *msg_filename);
void srv_email_ps_send_mail_rsp(void *inMsg);

/* List the size */
void srv_email_ps_list_size_req(EMAIL_PS_HANDLE handle, S32 start_index, S32 count, const WCHAR *filename);
void srv_email_ps_list_size_rsp(void *inMsg);

/* Delete email */
void srv_email_ps_delete_mail_req(EMAIL_PS_HANDLE handle, const WCHAR *filename);
void srv_email_ps_delete_mail_rsp(void *inMsg);

/* List remote folder (IMAP4 only) */
void srv_email_ps_list_folder_req(EMAIL_PS_HANDLE handle, MMI_BOOL subscribed_only, const WCHAR *filename);
void srv_email_ps_list_folder_rsp(void *inMsg);

/* Get email flag (IMAP4 only) */
void srv_email_ps_get_flag_req(EMAIL_PS_HANDLE handle, const WCHAR *req_filename, const WCHAR *rsp_filename);
void srv_email_ps_get_flag_rsp(void *inMsg);

/* Set email flag (IMAP4 only) */
void srv_email_ps_set_flag_req(EMAIL_PS_HANDLE handle, const WCHAR *req_filename);
void srv_email_ps_set_flag_rsp(void *inMsg);

/* Expunge email (IMAP4 only) */
void srv_email_ps_expunge_mail_req(EMAIL_PS_HANDLE handle);
void srv_email_ps_expunge_mail_rsp(void *inMsg);

/* Close folder (IMAP4 only) */
void srv_email_ps_close_folder_req(EMAIL_PS_HANDLE handle);
void srv_email_ps_close_folder_rsp(void *inMsg);

/* Indication */
void srv_email_ps_send_mail_ind(void *inMsg);

#ifdef __MMI_SSO__
srv_email_result_enum srv_email_nwk_upgrade_cloud_plugin(U32 provider_id);
MMI_BOOL srv_email_nwk_query_cloud_server_info(
            U32 provider_id,
            email_ps_protocol_type_enum protocol,
            srv_email_server_struct *server_p);
MMI_BOOL srv_email_nwk_query_cloud_dtcnt_id(U32 provider_id, U32 *dtcnt_id);
#endif /* __MMI_SSO__ */

#endif /* __MMI_EMAIL__ */

#ifdef __SMS_CLOUD_SUPPORT__

void srv_email_nwk_cloud_session_init(srv_email_nwk_cloud_session_struct *sess_p);
void srv_email_nwk_cloud_session_free(srv_email_nwk_cloud_session_struct *sess_p);

void srv_email_nwk_cloud_state_init(srv_email_nwk_cloud_state_struct *state_p);
void srv_email_nwk_cloud_state_free(srv_email_nwk_cloud_state_struct *state_p);

void srv_email_nwk_cloud_cntx_init(srv_email_nwk_cloud_cntx_struct *cntx_p);
void srv_email_nwk_cloud_cntx_free(srv_email_nwk_cloud_cntx_struct *cntx_p);

MMI_BOOL srv_email_nwk_cloud_is_cntx_valid(srv_email_nwk_cloud_cntx_struct *cntx_p);
srv_email_nwk_cloud_cntx_struct *srv_email_nwk_cloud_create_cntx(EMAIL_ACCT_ID acct_id, S32 *errcode);
void srv_email_nwk_cloud_destroy_cntx(void *data);

MMI_BOOL srv_email_nwk_cloud_is_cb_empty(srv_email_nwk_cloud_cntx_struct *cntx_p);
MMI_BOOL srv_email_nwk_cloud_is_pending_cb_empty(srv_email_nwk_cloud_cntx_struct *cntx_p);
MMI_BOOL srv_email_nwk_cloud_is_cb_full(srv_email_nwk_cloud_cntx_struct *cntx_p);

void srv_email_nwk_cloud_append_cb_to_idle_list(
        srv_email_nwk_cloud_cntx_struct *cntx_p,
        srv_email_nwk_cb_struct *cb_p);
void srv_email_nwk_cloud_move_cb_to_idle(
        srv_email_nwk_cloud_cntx_struct *cntx_p,
        srv_email_nwk_cb_struct *cb_p);
void srv_email_nwk_cloud_move_cb_to_pending(
        srv_email_nwk_cloud_cntx_struct *cntx_p,
        srv_email_nwk_cb_struct *cb_p);

srv_email_nwk_cloud_cntx_struct *srv_email_nwk_cloud_get_cntx_by_cb(srv_email_nwk_cb_struct *cb_p);
srv_email_nwk_cb_struct *srv_email_nwk_cloud_get_running_cb(srv_email_nwk_cloud_cntx_struct *cntx_p);

void srv_email_nwk_cloud_abort_cb(
        srv_email_nwk_cloud_cntx_struct *cntx_p,
        srv_email_nwk_cb_struct *cb_p);
void srv_email_nwk_cloud_remove_cb(
        srv_email_nwk_cloud_cntx_struct *cntx_p,
        srv_email_nwk_cb_struct *cb_p,
        MMI_BOOL *cntx_valid);

void srv_email_nwk_cloud_start_job(
        srv_email_schdl_funcptr_type callback,
        srv_email_nwk_cloud_cntx_struct *cntx_p);
void srv_email_nwk_cloud_stop_job(srv_email_nwk_cloud_cntx_struct *cntx_p);

srv_email_nwk_cloud_cntx_struct *srv_email_nwk_cloud_get_cntx_by_id(EMAIL_ACCT_ID acct_id);
srv_email_nwk_cloud_cntx_struct *srv_email_nwk_cloud_get_cntx_by_ps_handle(EMAIL_PS_HANDLE handle);

srv_email_result_enum srv_email_nwk_cloud_run_cntx(srv_email_nwk_cloud_cntx_struct *cntx_p);

void srv_email_nwk_cloud_fsm_schdl(void *user_data);
void srv_email_nwk_cloud_fsm_abort(srv_email_nwk_cloud_cntx_struct *cntx_p);
srv_email_result_enum srv_email_nwk_cloud_fsm_retry(srv_email_nwk_cloud_cntx_struct *cntx_p);

MMI_BOOL srv_email_nwk_cloud_create_instance_rsp_hdlr(email_ps_create_instance_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_connect_rsp_hdlr(email_ps_conn_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_disconnect_rsp_hdlr(email_ps_disconn_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_auth_rsp_hdlr(email_ps_auth_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_fldr_open_rsp_hdlr(email_ps_fld_open_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_fldr_create_rsp_hdlr(email_ps_fld_create_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_append_mail_rsp_hdlr(email_ps_msg_append_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_list_uid_rsp_hdlr(email_ps_msg_uid_list_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_fetch_mail_rsp_hdlr(email_ps_msg_fetch_rsp_struct *rsp_p);
MMI_BOOL srv_email_nwk_cloud_disconnect_ind_hdlr(email_ps_disconn_ind_struct *ind_p);
MMI_BOOL srv_email_nwk_cloud_imap4_push_ind_hdlr(email_ps_imap_push_ind_struct *ind_p);

void srv_email_ps_create_folder_req(EMAIL_PS_HANDLE handle, const CHAR *mailbox);
void srv_email_ps_create_folder_rsp(void *inMsg);
void srv_email_ps_append_mail_req(
        EMAIL_PS_HANDLE handle,
        const CHAR *fldr_name_p,
        const WCHAR *msg_filename);
void srv_email_ps_append_mail_rsp(void *inMsg);

#endif /* __SMS_CLOUD_SUPPORT__ */

#endif /* EMAILNETWORKPORT_H */