static void fetch_messages(struct mailimap * imap) { struct mailimap_set * set; struct mailimap_fetch_type * fetch_type; struct mailimap_fetch_att * fetch_att; clist * fetch_result; clistiter * cur; int r; /* as improvement UIDVALIDITY should be read and the message cache should be cleaned if the UIDVALIDITY is not the same */ set = mailimap_set_new_interval(1, 0); /* fetch in interval 1:* */ fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); fetch_att = mailimap_fetch_att_new_uid(); mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); r = mailimap_fetch(imap, set, fetch_type, &fetch_result); check_error(r, "could not fetch"); /* for each message */ for(cur = clist_begin(fetch_result) ; cur != NULL ; cur = clist_next(cur)) { struct mailimap_msg_att * msg_att; uint32_t uid; msg_att = clist_content(cur); uid = get_uid(msg_att); if (uid == 0) continue; fetch_msg(imap, uid); } mailimap_fetch_list_free(fetch_result); }
int mailimap_fetch_envelope(mailimap * session, uint32_t first, uint32_t last, clist ** result) { int r; clist * fetch_list; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; struct mailimap_set * set; fetch_att = mailimap_fetch_att_new_envelope(); fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); set = mailimap_set_new_interval(first, last); r = mailimap_fetch(session, set, fetch_type, &fetch_list); mailimap_set_free(set); mailimap_fetch_type_free(fetch_type); if (r != MAILIMAP_NO_ERROR) return r; * result = fetch_list; return MAILIMAP_NO_ERROR; }
int mailimap_fetch_rfc822(mailimap * session, uint32_t msgid, char ** result) { int r; clist * fetch_list; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; struct mailimap_set * set; struct mailimap_msg_att * msg_att; struct mailimap_msg_att_item * item; int res; fetch_att = mailimap_fetch_att_new_rfc822(); fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); set = mailimap_set_new_single(msgid); r = mailimap_fetch(session, set, fetch_type, &fetch_list); mailimap_set_free(set); mailimap_fetch_type_free(fetch_type); if (r != MAILIMAP_NO_ERROR) { res = r; goto err; } if (clist_isempty(fetch_list)) { res = MAILIMAP_ERROR_FETCH; goto free; } msg_att = (struct mailimap_msg_att *) clist_begin(fetch_list)->data; if (clist_isempty(msg_att->att_list)) { res = MAILIMAP_ERROR_FETCH; goto free; } item = (struct mailimap_msg_att_item *) clist_begin(msg_att->att_list)->data; if (item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) { res = MAILIMAP_ERROR_FETCH; goto free; } if (item->att_data.att_static->att_type != MAILIMAP_MSG_ATT_RFC822) { res = MAILIMAP_ERROR_FETCH; goto free; } * result = item->att_data.att_static->att_data.att_rfc822.att_content; item->att_data.att_static->att_data.att_rfc822.att_content = NULL; mailimap_fetch_list_free(fetch_list); return MAILIMAP_NO_ERROR; free: mailimap_fetch_list_free(fetch_list); err: return res; }