#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)
{
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;
}
}
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)) {
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);
}
/* 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) {
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;
}
#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__ */
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;
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) {
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)) {
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: