text
stringlengths
0
357
}
res = DC_SUCCESS;
cleanup:
return res==DC_RETRY_LATER?
(imap->should_reconnect? DC_RETRY_LATER : DC_FAILED) : res;
}
dc_imap_res dc_imap_set_mdnsent(dc_imap_t* imap, const char* folder, uint32_t uid)
{
// returns 0=job should be retried later, 1=job done, 2=job done and flag just set
dc_imap_res res = DC_RETRY_LATER;
struct mailimap_set* set = mailimap_set_new_single(uid);
clist* fetch_result = NULL;
if (imap==NULL || folder==NULL || uid==0 || set==NULL) {
res = DC_FAILED;
goto cleanup;
}
if (imap->etpan==NULL) {
goto cleanup;
}
dc_log_info(imap->context, 0, "Marking message %s/%i as $MDNSent...", folder, (int)uid);
if (select_folder(imap, folder)==0) {
dc_log_warning(imap->context, 0, "Cannot select folder %s for setting $MDNSent flag.", folder);
goto cleanup;
}
/* Check if the folder can handle the `$MDNSent` flag (see RFC 3503). If so, and not set: set the flags and return this information.
If the folder cannot handle the `$MDNSent` flag, we risk duplicated MDNs; it's up to the receiving MUA to handle this then (eg. Delta Chat has no problem with this). */
int can_create_flag = 0;
if (imap->etpan->imap_selection_info!=NULL
&& imap->etpan->imap_selection_info->sel_perm_flags!=NULL)
{
clistiter* iter;
for (iter=clist_begin(imap->etpan->imap_selection_info->sel_perm_flags); iter!=NULL; iter=clist_next(iter))
{
struct mailimap_flag_perm* fp = (struct mailimap_flag_perm*)clist_content(iter);
if (fp) {
if (fp->fl_type==MAILIMAP_FLAG_PERM_ALL) {
can_create_flag = 1;
break;
}
else if (fp->fl_type==MAILIMAP_FLAG_PERM_FLAG && fp->fl_flag) {
struct mailimap_flag* fl = (struct mailimap_flag*)fp->fl_flag;
if (fl->fl_type==MAILIMAP_FLAG_KEYWORD
&& fl->fl_data.fl_keyword
&& strcmp(fl->fl_data.fl_keyword, "$MDNSent")==0) {
can_create_flag = 1;
break;
}
}
}
}
}
if (can_create_flag)
{
int r = mailimap_uid_fetch(imap->etpan, set, imap->fetch_type_flags, &fetch_result);
if (dc_imap_is_error(imap, r) || fetch_result==NULL) {
fetch_result = NULL;
goto cleanup;
}
clistiter* cur=clist_begin(fetch_result);
if (cur==NULL) {
goto cleanup;
}
if (peek_flag_keyword((struct mailimap_msg_att*)clist_content(cur), "$MDNSent")) {
res = DC_ALREADY_DONE;
}
else {
if (add_flag(imap, uid, mailimap_flag_new_flag_keyword(dc_strdup("$MDNSent")))==0) {
goto cleanup;
}
res = DC_SUCCESS;
}
dc_log_info(imap->context, 0, res==DC_SUCCESS? "$MDNSent just set and MDN will be sent." : "$MDNSent already set and MDN already sent.");
}
else
{
res = DC_SUCCESS;
dc_log_info(imap->context, 0, "Cannot store $MDNSent flags, risk sending duplicate MDN.");
}
cleanup:
FREE_SET(set);
FREE_FETCH_LIST(fetch_result);
return res==DC_RETRY_LATER?
(imap->should_reconnect? DC_RETRY_LATER : DC_FAILED) : res;
}