text
stringlengths
0
357
int dc_imap_delete_msg(dc_imap_t* imap, const char* rfc724_mid, const char* folder, uint32_t server_uid)
{
int success = 0;
int r = 0;
clist* fetch_result = NULL;
char* is_rfc724_mid = NULL;
char* new_folder = NULL;
if (imap==NULL || rfc724_mid==NULL || folder==NULL || folder[0]==0 || server_uid==0) {
success = 1; /* job done, do not try over */
goto cleanup;
}
dc_log_info(imap->context, 0, "Marking message \"%s\", %s/%i for deletion...", rfc724_mid, folder, (int)server_uid);
if (select_folder(imap, folder)==0) {
dc_log_warning(imap->context, 0, "Cannot select folder %s for deleting message.", folder);
goto cleanup;
}
/* check if Folder+UID matches the Message-ID (to detect if the messages
was moved around by other MUAs and in place of an UIDVALIDITY check)
*/
{
clistiter* cur = NULL;
const char* is_quoted_rfc724_mid = NULL;
struct mailimap_set* set = mailimap_set_new_single(server_uid);
r = mailimap_uid_fetch(imap->etpan, set, imap->fetch_type_prefetch, &fetch_result);
FREE_SET(set);
if (dc_imap_is_error(imap, r) || fetch_result==NULL) {
fetch_result = NULL;
dc_log_warning(imap->context, 0, "Cannot delete on IMAP, %s/%i not found.", folder, (int)server_uid);
server_uid = 0;
}
if( (cur=clist_begin(fetch_result))==NULL
|| (is_quoted_rfc724_mid=peek_rfc724_mid((struct mailimap_msg_att*)clist_content(cur)))==NULL
|| (is_rfc724_mid=unquote_rfc724_mid(is_quoted_rfc724_mid))==NULL
|| strcmp(is_rfc724_mid, rfc724_mid)!=0)
{
dc_log_warning(imap->context, 0, "Cannot delete on IMAP, %s/%i does not match %s.", folder, (int)server_uid, rfc724_mid);
server_uid = 0;
}
}
/* mark the message for deletion */
if (add_flag(imap, server_uid, mailimap_flag_new_deleted())==0) {
dc_log_warning(imap->context, 0, "Cannot mark message as \"Deleted\"."); /* maybe the message is already deleted */
goto cleanup;
}
/* force an EXPUNGE resp. CLOSE for the selected folder */
imap->selected_folder_needs_expunge = 1;
success = 1;
cleanup:
FREE_FETCH_LIST(fetch_result);
free(is_rfc724_mid);
free(new_folder);
return success? 1 : dc_imap_is_connected(imap); /* only return 0 on connection problems; we should try later again in this case */
}
void dc_imap_empty_folder(dc_imap_t* imap, const char* folder)
{
struct mailimap_flag_list* flag_list = NULL;
struct mailimap_store_att_flags* store_att_flags = NULL;
struct mailimap_set* set = NULL;
if (imap==NULL || folder==NULL || folder[0]==0) {
goto cleanup;
}
dc_log_info(imap->context, 0, "Emptying folder \"%s\" ...", folder);
if (select_folder(imap, folder)==0) {
dc_log_warning(imap->context, 0, "Cannot select folder %s for emptying.", folder);
goto cleanup;
}
set = mailimap_set_new_interval(1/*start with smallest uid*/, 0/*0=`*`=largets uid*/);
flag_list = mailimap_flag_list_new_empty();
mailimap_flag_list_add(flag_list, mailimap_flag_new_deleted());
store_att_flags = mailimap_store_att_flags_new_add_flags(flag_list); /* FLAGS.SILENT does not return the new value */
mailimap_uid_store(imap->etpan, set, store_att_flags);
imap->selected_folder_needs_expunge = 1;
select_folder(imap, NULL);
dc_log_info(imap->context, 0, "Emptying folder \"%s\" done.", folder);
cleanup: