text stringlengths 0 357 |
|---|
if (dc_imap_is_error(imap, r) || fetch_result==NULL) |
{ |
fetch_result = NULL; |
if (r==MAILIMAP_ERROR_PROTOCOL) { |
dc_log_info(imap->context, 0, "Folder \"%s\" is empty", folder); |
goto cleanup; /* the folder is simply empty, this is no error */ |
} |
dc_log_warning(imap->context, 0, "Cannot fetch message list from folder \"%s\".", folder); |
goto cleanup; |
} |
/* go through all mails in folder (this is typically _fast_ as we already have the whole list) */ |
for (cur = clist_begin(fetch_result); cur!=NULL ; cur = clist_next(cur)) |
{ |
struct mailimap_msg_att* msg_att = (struct mailimap_msg_att*)clist_content(cur); /* mailimap_msg_att is a list of attributes: list is a list of message attributes */ |
uint32_t cur_uid = peek_uid(msg_att); |
if (cur_uid > lastseenuid /* `UID FETCH <lastseenuid+1>:*` may include lastseenuid if "*"==lastseenuid - and also smaller uids may be returned! */) |
{ |
char* rfc724_mid = unquote_rfc724_mid(peek_rfc724_mid(msg_att)); |
read_cnt++; |
if (!imap->precheck_imf(imap, rfc724_mid, folder, cur_uid)) { |
if (fetch_single_msg(imap, folder, cur_uid)==0/* 0=try again later*/) { |
dc_log_info(imap->context, 0, "Read error for message %s from \"%s\", trying over later.", rfc724_mid, folder); |
read_errors++; // with read_errors, lastseenuid is not written |
} |
} |
else { |
dc_log_info(imap->context, 0, "Skipping message %s from \"%s\" by precheck.", rfc724_mid, folder); |
} |
if (cur_uid > new_lastseenuid) { |
new_lastseenuid = cur_uid; |
} |
free(rfc724_mid); |
} |
} |
if (!read_errors && new_lastseenuid > 0) { |
// TODO: it might be better to increase the lastseenuid also on partial errors. |
// however, this requires to sort the list before going through it above. |
set_config_lastseenuid(imap, folder, uidvalidity, new_lastseenuid); |
} |
/* done */ |
cleanup: |
if (read_errors) { |
dc_log_warning(imap->context, 0, "%i mails read from \"%s\" with %i errors.", (int)read_cnt, folder, (int)read_errors); |
} |
else { |
dc_log_info(imap->context, 0, "%i mails read from \"%s\".", (int)read_cnt, folder); |
} |
FREE_FETCH_LIST(fetch_result); |
return read_cnt; |
} |
/******************************************************************************* |
* Watch thread |
******************************************************************************/ |
int dc_imap_fetch(dc_imap_t* imap) |
{ |
int success = 0; |
if (imap==NULL || !imap->connected) { |
goto cleanup; |
} |
setup_handle_if_needed(imap); |
// as during the fetch commands, new messages may arrive, we fetch until we do not |
// get any more. if IDLE is called directly after, there is only a small chance that |
// messages are missed and delayed until the next IDLE call |
while (fetch_from_single_folder(imap, imap->watch_folder) > 0) { |
; |
} |
success = 1; |
cleanup: |
return success; |
} |
static void fake_idle(dc_imap_t* imap) |
{ |
/* Idle using timeouts. This is also needed if we're not yet configured - |
in this case, we're waiting for a configure job */ |
time_t fake_idle_start_time = time(NULL); |
time_t seconds_to_wait = 0; |
dc_log_info(imap->context, 0, "IMAP-fake-IDLEing..."); |
int do_fake_idle = 1; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.