when downloading attachment automatically, mail body does not have to be downloaded... 85/94985/1
authorSan Cho <san.cho@samsung.com>
Tue, 26 Jul 2016 09:30:41 +0000 (18:30 +0900)
committerintae jeon <intae.jeon@samsung.com>
Wed, 2 Nov 2016 05:25:01 +0000 (22:25 -0700)
[Problem] auto download attachment was not operated well.
[Cause & Measure] Cause: mail body was being downloaded fully to get attachment information completely before downloading attachment.
Measure: attachment information have to exist unconditionally if email size is "Header only"

Change-Id: Ic3b9c745b2b40a2631a43fd30535aed0f1f65ad5
Signed-off-by: intae, jeon <intae.jeon@samsung.com>
(cherry picked from commit eb2b71afca503c9a390d0b7d50647f4ea552e372)

email-core/email-core-auto-download.c
email-core/email-core-mailbox-sync.c

index b990f97..7f5d045 100755 (executable)
@@ -59,7 +59,7 @@ INTERNAL_FUNC int auto_download_thread_run = 0;
 #define AUTO_DOWNLOAD_QUEUE_MAX 100
 
 static void* worker_auto_download_queue(void *arg);
-static gint auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data);
+static gint __auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data);
 
 INTERNAL_FUNC int emcore_start_auto_download_loop(int *err_code)
 {
@@ -178,7 +178,7 @@ INTERNAL_FUNC int emcore_insert_auto_download_event(email_event_auto_download *e
                ret = false;
        } else {
                event_data->status = EMAIL_EVENT_STATUS_WAIT;
-               g_queue_insert_sorted(g_auto_download_que, event_data, auto_download_compare_func, event_data);
+               g_queue_insert_sorted(g_auto_download_que, event_data, __auto_download_compare_func, event_data);
                //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal);
                ret = true;
        }
@@ -399,19 +399,15 @@ static void* worker_auto_download_queue(void *arg)
                                }
 
                                if (!(account_ref->wifi_auto_download)) {
-                                       if (account_ref) {
-                                               emcore_free_account(account_ref);
-                                               EM_SAFE_FREE(account_ref);
-                                       }
-
-                                       continue;
-                               }
-
-                               if (account_ref) {
+                                       EM_DEBUG_LOG("ACCOUNT[%d] AUTO DOWNLOAD MODE OFF", account_ref->account_id);
                                        emcore_free_account(account_ref);
                                        EM_SAFE_FREE(account_ref);
+                                       continue;
                                }
 
+                               emcore_free_account(account_ref);
+                               EM_SAFE_FREE(account_ref);
+
                                mailbox_count = 0;
                                EM_SAFE_FREE(mailbox_list);
                                if (!emstorage_get_auto_download_mailbox_list(NULL, account_list[ai], &mailbox_list, &mailbox_count, false, &err)) {
@@ -537,11 +533,6 @@ CHECK_CONTINUE:
                                goto POP_HEAD;
                        }
 
-                       if (account_ref) {
-                               emcore_free_account(account_ref);
-                               EM_SAFE_FREE(account_ref);
-                       }
-
                        if ((err = emstorage_get_mailbox_by_id(event_data->multi_user_name, event_data->mailbox_id, &target_mailbox)) != EMAIL_ERROR_NONE) {
                                EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_id failed. [%d]", err);
                        }
@@ -559,43 +550,51 @@ CHECK_CONTINUE:
                        /* Handling storage full */
                        if ((err = emcore_is_storage_full()) == EMAIL_ERROR_MAIL_MEMORY_FULL) {
                                EM_DEBUG_EXCEPTION("Storage is full");
-
                                ENTER_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock);
                                auto_download_thread_run = 0;
                                SLEEP_CONDITION_VARIABLE(_auto_downalod_available_signal, *_auto_download_queue_lock);
                                EM_DEBUG_LOG("Wake up by _auto_downalod_available_signal");
                                LEAVE_RECURSIVE_CRITICAL_SECTION(_auto_download_queue_lock);
 
+                               if (account_ref) {
+                                       emcore_free_account(account_ref);
+                                       EM_SAFE_FREE(account_ref);
+                               }
+
                                continue;
                        }
 
-                       snprintf(uid_str, sizeof(uid_str), "%ld", event_data->server_mail_id);
-                       if (!emstorage_get_maildata_by_servermailid(event_data->multi_user_name,
-                                                                                                               uid_str,
-                                                                                                               event_data->mailbox_id,
-                                                                                                               &mail,
-                                                                                                               true,
-                                                                                                               &err) || !mail) {
-                               EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err);
-                       } else {
+                       // POP3's UID is string, not integer type. So event_data->server_mail_id is invalid in this time.
+                       // emstorage_get_mail_data_by_servermailid() is always fail if it is POP3 event.
+                       if (!emstorage_get_mail_by_id(event_data->multi_user_name,
+                                                                               event_data->mail_id,
+                                                                               &mail,
+                                                                               true,
+                                                                               &err) || !mail) {
+                               EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err);
+                       }
+                       else {
                                if (mail->body_download_status & EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED) {
                                        EM_DEBUG_LOG("fully downloaded mail");
-                               } else {
-                                       EM_DEBUG_LOG("#####AUTO DOWNLOAD BODY: ACCOUNT_ID[%d] MAILBOX_ID[%d] MAIL_ID[%d] UID[%d] ACTIVITY[%d]#####",
-                                                       event_data->account_id, event_data->mailbox_id,
-                                                       event_data->mail_id, event_data->server_mail_id, event_data->activity_id);
-
-                                       if (!emcore_gmime_download_body_sections(event_data->multi_user_name,
-                                                                                                                               NULL,
-                                                                                                                               event_data->account_id,
-                                                                                                                               event_data->mail_id,
-                                                                                                                               0,
-                                                                                                                               NO_LIMITATION,
-                                                                                                                               -1,
-                                                                                                                               0,
-                                                                                                                               1,
-                                                                                                                               &err))
-                                               EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err);
+                               }
+                               else {
+                                       EM_DEBUG_LOG("partially downloaded mail");
+                                       if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_POP3) {
+                                               EM_DEBUG_LOG("#####AUTO DOWNLOAD BODY: ACCOUNT_ID[%d] MAILBOX_ID[%d] MAIL_ID[%d] UID[%d] ACTIVITY[%d]#####",
+                                                               event_data->account_id, event_data->mailbox_id,
+                                                               event_data->mail_id, event_data->server_mail_id, event_data->activity_id);
+                                               if (!emcore_gmime_download_body_sections(event_data->multi_user_name,
+                                                                       NULL,
+                                                                       event_data->account_id,
+                                                                       event_data->mail_id,
+                                                                       0,
+                                                                       NO_LIMITATION,
+                                                                       -1,
+                                                                       0,
+                                                                       1,
+                                                                       &err))
+                                                       EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err);
+                                       }
                                }
 
                                if (mail->attachment_count > 0) {
@@ -858,12 +857,17 @@ FINISH_OFF:
        return ret;
 }
 
-static gint auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data)
+static gint __auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data)
 {
        email_event_auto_download *first = (email_event_auto_download*)a;
        email_event_auto_download *second = (email_event_auto_download*)b;
-       if (first->server_mail_id == second->server_mail_id) return 0;
-       else if (first->server_mail_id > second->server_mail_id) return -1;
-       else return 1;
+       if (first->account_id == second->account_id) {
+               if (first->server_mail_id == second->server_mail_id) return 0;
+               else if (first->server_mail_id > second->server_mail_id) return -1;
+               else return 1;
+       } else {
+               if (first->account_id < second->account_id) return -1;
+               else return 1;
+       }
        return 1;
 }
index d6c8a3d..b7e2690 100755 (executable)
@@ -2442,17 +2442,15 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name,
 #ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
                                if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) {
 #endif /*  __FEATURE_PARTIAL_BODY_FOR_POP3__ */
-                                       if (account_ref->auto_download_size != 0) {
-                                               if (false == emcore_initiate_pbd(multi_user_name,
-                                                                                                               *stream,
-                                                                                                               account_id,
-                                                                                                               mail_id,
-                                                                                                               uid_elem->uid,
-                                                                                                               input_mailbox_tbl->mailbox_id,
-                                                                                                               input_mailbox_tbl->mailbox_name,
-                                                                                                               &err))
-                                                       EM_DEBUG_LOG("Partial body download initiation failed [%d]", err);
-                                       }
+                                       if (false == emcore_initiate_pbd(multi_user_name,
+                                                                                                       *stream,
+                                                                                                       account_id,
+                                                                                                       mail_id,
+                                                                                                       uid_elem->uid,
+                                                                                                       input_mailbox_tbl->mailbox_id,
+                                                                                                       input_mailbox_tbl->mailbox_name,
+                                                                                                       &err))
+                                               EM_DEBUG_LOG("Partial body download initiation failed [%d]", err);
 #ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__
                                }
 #endif /*  __FEATURE_PARTIAL_BODY_FOR_POP3__ */
@@ -3709,12 +3707,6 @@ INTERNAL_FUNC int emcore_initiate_pbd(char *multi_user_name, MAILSTREAM *stream,
                goto FINISH_OFF;
        }
 
-       if (account_ref->auto_download_size == 0) {
-               EM_DEBUG_LOG("Header only download");
-               ret = true;
-               goto FINISH_OFF;
-       }
-
        memset(&pbd_event, 0x00, sizeof(email_event_partial_body_thd));
 
        pbd_event.account_id = account_id;
@@ -3982,8 +3974,19 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
                                                                                                        false,
                                                                                                        &err) || !mail) {
                        EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err);
-                       if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail)
-                               goto FINISH_OFF;
+                       if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail) {
+                               if (false == emcore_delete_pbd_activity(pbd_event[temp_count].multi_user_name,
+                                                       pbd_event[temp_count].account_id,
+                                                       pbd_event[temp_count].mail_id,
+                                                       pbd_event[temp_count].activity_id,
+                                                       &err)) {
+                                       EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err);
+                               }
+                       }
+                       if (mail)
+                               emstorage_free_mail(&mail, 1, NULL);
+                       mail = NULL;
+                       continue;
                }
 
                if (mailbox_tbl) {
@@ -4076,11 +4079,15 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int
                        iter1 = g_mime_part_iter_new((GMimeObject *)message1);
                        iter2 = g_mime_part_iter_new((GMimeObject *)message2);
 
-                       if (!g_mime_part_iter_is_valid(iter1) || !g_mime_part_iter_is_valid(iter2)) {
-                               EM_DEBUG_EXCEPTION("Part iterator is not valid");
+                       if (!g_mime_part_iter_is_valid(iter1)) {
+                               EM_DEBUG_EXCEPTION("Part1 iterator is not valid");
                                goto FINISH_OFF;
                        }
 
+                       if (!g_mime_part_iter_is_valid(iter2)) {
+                               EM_DEBUG_EXCEPTION("Part2 iterator is not valid");
+                       }
+
                        do {
                                part_tmp2 = g_mime_part_iter_get_current(iter2);
                                if (part_tmp2 && GMIME_IS_PART(part_tmp2)) {
@@ -4652,7 +4659,12 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, ema
                goto FINISH_OFF;
        }
 
-       auto_download_size = (pbd_account_tbl->auto_download_size < 4096) ? 4096 : pbd_account_tbl->auto_download_size;
+       // To get attachment info in bodystructure for imap account
+       if (pbd_account_tbl->auto_download_size == 0) {
+               auto_download_size = 1;
+       } else {
+               auto_download_size = (pbd_account_tbl->auto_download_size < 4096) ? 4096 : pbd_account_tbl->auto_download_size;
+       }
 
        switch (pbd_account_tbl->incoming_server_type) {
                case EMAIL_SERVER_TYPE_IMAP4: