text stringlengths 0 357 |
|---|
{ |
*uidvalidity = 0; |
*lastseenuid = 0; |
char* key = dc_mprintf("imap.mailbox.%s", folder); |
char* val1 = imap->get_config(imap, key, NULL), *val2 = NULL, *val3 = NULL; |
if (val1) |
{ |
/* the entry has the format `imap.mailbox.<folder>=<uidvalidity>:<lastseenuid>` */ |
val2 = strchr(val1, ':'); |
if (val2) |
{ |
*val2 = 0; |
val2++; |
val3 = strchr(val2, ':'); |
if (val3) { *val3 = 0; /* ignore everything bethind an optional second colon to allow future enhancements */ } |
*uidvalidity = atol(val1); |
*lastseenuid = atol(val2); |
} |
} |
free(val1); /* val2 and val3 are only pointers inside val1 and MUST NOT be free()'d */ |
free(key); |
} |
static void set_config_lastseenuid(dc_imap_t* imap, const char* folder, uint32_t uidvalidity, uint32_t lastseenuid) |
{ |
char* key = dc_mprintf("imap.mailbox.%s", folder); |
char* val = dc_mprintf("%lu:%lu", uidvalidity, lastseenuid); |
imap->set_config(imap, key, val); |
free(val); |
free(key); |
} |
/******************************************************************************* |
* Handle folders |
******************************************************************************/ |
static int select_folder(dc_imap_t* imap, const char* folder /*may be NULL*/) |
{ |
if (imap==NULL) { |
return 0; |
} |
if (imap->etpan==NULL) { |
imap->selected_folder[0] = 0; |
imap->selected_folder_needs_expunge = 0; |
return 0; |
} |
/* if there is a new folder and the new folder is equal to the selected one, there's nothing to do. |
if there is _no_ new folder, we continue as we might want to expunge below. */ |
if (folder && folder[0] && strcmp(imap->selected_folder, folder)==0) { |
return 1; |
} |
/* deselect existing folder, if needed (it's also done implicitly by SELECT, however, without EXPUNGE then) */ |
if (imap->selected_folder_needs_expunge) { |
if (imap->selected_folder[0]) { |
dc_log_info(imap->context, 0, "Expunge messages in \"%s\".", imap->selected_folder); |
mailimap_close(imap->etpan); /* a CLOSE-SELECT is considerably faster than an EXPUNGE-SELECT, see https://tools.ietf.org/html/rfc3501#section-6.4.2 */ |
} |
imap->selected_folder_needs_expunge = 0; |
} |
/* select new folder */ |
if (folder) { |
int r = mailimap_select(imap->etpan, folder); |
if (dc_imap_is_error(imap, r) || imap->etpan->imap_selection_info==NULL) { |
dc_log_info(imap->context, 0, "Cannot select folder; code=%i, imap_response=%s", r, |
imap->etpan->imap_response? imap->etpan->imap_response : "<none>"); |
imap->selected_folder[0] = 0; |
return 0; |
} |
} |
free(imap->selected_folder); |
imap->selected_folder = dc_strdup(folder); |
return 1; |
} |
/******************************************************************************* |
* Fetch Messages |
******************************************************************************/ |
static uint32_t peek_uid(struct mailimap_msg_att* msg_att) |
{ |
/* search the UID in a list of attributes returned by a FETCH command */ |
clistiter* iter1; |
for (iter1=clist_begin(msg_att->att_list); iter1!=NULL; iter1=clist_next(iter1)) |
{ |
struct mailimap_msg_att_item* item = (struct mailimap_msg_att_item*)clist_content(iter1); |
if (item) |
{ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.