text
stringlengths
0
357
if (msg_att==NULL) {
return;
}
/* search body & Co. in a list of attributes returned by a FETCH command */
clistiter *iter1, *iter2;
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)
{
if (item->att_type==MAILIMAP_MSG_ATT_ITEM_DYNAMIC)
{
if (item->att_data.att_dyn->att_list /*I've seen NULL here ...*/)
{
for (iter2=clist_begin(item->att_data.att_dyn->att_list); iter2!=NULL ; iter2=clist_next(iter2))
{
struct mailimap_flag_fetch* flag_fetch =(struct mailimap_flag_fetch*) clist_content(iter2);
if (flag_fetch && flag_fetch->fl_type==MAILIMAP_FLAG_FETCH_OTHER)
{
struct mailimap_flag* flag = flag_fetch->fl_flag;
if (flag)
{
if (flag->fl_type==MAILIMAP_FLAG_SEEN) {
*flags |= DC_IMAP_SEEN;
}
else if (flag->fl_type==MAILIMAP_FLAG_DELETED) {
*deleted = 1;
}
}
}
}
}
}
else if (item->att_type==MAILIMAP_MSG_ATT_ITEM_STATIC)
{
if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_BODY_SECTION)
{
*p_msg = item->att_data.att_static->att_data.att_body_section->sec_body_part;
*p_msg_bytes = item->att_data.att_static->att_data.att_body_section->sec_length;
}
}
}
}
}
static int fetch_single_msg(dc_imap_t* imap, const char* folder, uint32_t server_uid)
{
/* the function returns:
0 the caller should try over again later
or 1 if the messages should be treated as received, the caller should not try to read the message again (even if no database entries are returned) */
char* msg_content = NULL;
size_t msg_bytes = 0;
int r = 0;
int retry_later = 0;
int deleted = 0;
uint32_t flags = 0;
clist* fetch_result = NULL;
clistiter* cur;
if (imap==NULL) {
goto cleanup;
}
if (imap->etpan==NULL) {
goto cleanup;
}
{
struct mailimap_set* set = mailimap_set_new_single(server_uid);
r = mailimap_uid_fetch(imap->etpan, set, imap->fetch_type_body, &fetch_result);
FREE_SET(set);
}
if (dc_imap_is_error(imap, r) || fetch_result==NULL) {
fetch_result = NULL;
dc_log_warning(imap->context, 0, "Error #%i on fetching message #%i from folder \"%s\"; retry=%i.", (int)r, (int)server_uid, folder, (int)imap->should_reconnect);
if (imap->should_reconnect) {
retry_later = 1; /* maybe we should also retry on other errors, however, we should check this carefully, as this may result in a dead lock! */
}
goto cleanup; /* this is an error that should be recovered; the caller should try over later to fetch the message again (if there is no such message, we simply get an empty result) */
}
if ((cur=clist_begin(fetch_result))==NULL) {
dc_log_warning(imap->context, 0, "Message #%i does not exist in folder \"%s\".", (int)server_uid, folder);
goto cleanup; /* server response is fine, however, there is no such message, do not try to fetch the message again */
}
struct mailimap_msg_att* msg_att = (struct mailimap_msg_att*)clist_content(cur);
peek_body(msg_att, &msg_content, &msg_bytes, &flags, &deleted);
if (msg_content==NULL || msg_bytes <= 0 || deleted) {
/* dc_log_warning(imap->context, 0, "Message #%i in folder \"%s\" is empty or deleted.", (int)server_uid, folder); -- this is a quite usual situation, do not print a warning */
goto cleanup;
}
imap->receive_imf(imap, msg_content, msg_bytes, folder, server_uid, flags);
cleanup:
FREE_FETCH_LIST(fetch_result);