LIBETPAN_EXPORT void mailimap_uidplus_resp_code_copy_free(struct mailimap_uidplus_resp_code_copy * resp_code_copy) { if (resp_code_copy->uid_dest_set != NULL) mailimap_set_free(resp_code_copy->uid_dest_set); if (resp_code_copy->uid_source_set != NULL) mailimap_set_free(resp_code_copy->uid_source_set); free(resp_code_copy); }
LIBETPAN_EXPORT void mailimap_uidplus_resp_code_apnd_free(struct mailimap_uidplus_resp_code_apnd * resp_code_apnd) { if (resp_code_apnd->uid_set != NULL) mailimap_set_free(resp_code_apnd->uid_set); free(resp_code_apnd); }
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; }
static int vanished_parse(mailstream * fd, MMAPString * buffer, struct mailimap_parser_context * parser_ctx, size_t * indx, struct mailimap_qresync_vanished ** result) { int r; struct mailimap_set * set; int earlier; struct mailimap_qresync_vanished * vanished; size_t cur_token; int res; cur_token = * indx; r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "VANISHED"); if (r != MAILIMAP_NO_ERROR) { res = r; goto err; } r = mailimap_space_parse(fd, buffer, &cur_token); if (r != MAILIMAP_NO_ERROR) { res = r; goto err; } earlier = 0; r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "(EARLIER)"); if (r == MAILIMAP_NO_ERROR) { earlier = 1; r = mailimap_space_parse(fd, buffer, &cur_token); if (r != MAILIMAP_NO_ERROR) { res = r; goto err; } } r = mailimap_set_parse(fd, buffer, parser_ctx, &cur_token, &set); if (r != MAILIMAP_NO_ERROR) { res = r; goto err; } vanished = mailimap_qresync_vanished_new(earlier, set); if (vanished == NULL) { res = MAILIMAP_ERROR_MEMORY; goto free_set; } * indx = cur_token; * result = vanished; return MAILIMAP_NO_ERROR; free_set: mailimap_set_free(set); err: return res; }
static int fetch_imap(mailmessage * msg, struct mailimap_fetch_type * fetch_type, char ** result, size_t * result_len) { int r; struct mailimap_msg_att * msg_att; struct mailimap_msg_att_item * msg_att_item; clist * fetch_result; struct mailimap_set * set; char * text; size_t text_length; clistiter * cur; set = mailimap_set_new_single(msg->msg_index); if (set == NULL) return MAIL_ERROR_MEMORY; r = mailimap_uid_fetch(get_imap_session(msg), set, fetch_type, &fetch_result); mailimap_set_free(set); switch (r) { case MAILIMAP_NO_ERROR: break; default: return imap_error_to_mail_error(r); } if (clist_begin(fetch_result) == NULL) { mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; } msg_att = clist_begin(fetch_result)->data; text = NULL; text_length = 0; for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { msg_att_item = clist_content(cur); if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL; text_length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length; } } } mailimap_fetch_list_free(fetch_result); if (text == NULL) return MAIL_ERROR_FETCH; * result = text; * result_len = text_length; return MAIL_NO_ERROR; }
static int imap_get_bodystructure(mailmessage * msg_info, struct mailmime ** result) { int r; struct mailimap_set * set; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; clist * fetch_result; struct mailimap_msg_att * msg_att; struct mailimap_body * imap_body; struct mailmime * body; int res; struct mailimf_fields * fields; struct mailmime * new_body; struct mailmime_content * content_message; struct mailimap_envelope * envelope; uint32_t uid; char * references; size_t ref_size; clistiter * cur; if (msg_info->msg_mime != NULL) { * result = msg_info->msg_mime; return MAIL_NO_ERROR; } set = mailimap_set_new_single(msg_info->msg_index); if (set == NULL) { res = MAIL_ERROR_MEMORY; goto err; } fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); if (fetch_type == NULL) { res = MAIL_ERROR_MEMORY; goto free_set; } fetch_att = mailimap_fetch_att_new_uid(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); if (r != MAILIMAP_NO_ERROR) { mailimap_fetch_att_free(fetch_att); res = MAIL_ERROR_MEMORY; goto free_fetch_type; } fetch_att = mailimap_fetch_att_new_bodystructure(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); if (r != MAILIMAP_NO_ERROR) { mailimap_fetch_att_free(fetch_att); res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = imap_add_envelope_fetch_att(fetch_type); if (r != MAIL_NO_ERROR) { res = r; goto free_fetch_type; } r = mailimap_uid_fetch(get_imap_session(msg_info), set, fetch_type, &fetch_result); mailimap_fetch_type_free(fetch_type); mailimap_set_free(set); switch (r) { case MAILIMAP_NO_ERROR: break; default: return imap_error_to_mail_error(r); } cur = clist_begin(fetch_result); if (cur == NULL) { mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; } msg_att = clist_content(cur); uid = 0; references = NULL; ref_size = 0; imap_body = NULL; envelope = NULL; r = imap_get_msg_att_info(msg_att, &uid, &envelope, &references, &ref_size, NULL, &imap_body); if (r != MAIL_NO_ERROR) { mailimap_fetch_list_free(fetch_result); res = r; goto err; } if (uid != msg_info->msg_index) { mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MSG_NOT_FOUND; goto err; } if (imap_body == NULL) { mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_FETCH; goto err; } r = imap_body_to_body(imap_body, &body); if (r != MAIL_NO_ERROR) { mailimap_fetch_list_free(fetch_result); res = r; goto err; } fields = NULL; if (envelope != NULL) { r = imap_env_to_fields(envelope, references, ref_size, &fields); if (r != MAIL_NO_ERROR) { mailmime_free(body); mailimap_fetch_list_free(fetch_result); res = r; goto err; } } content_message = mailmime_get_content_message(); if (content_message == NULL) { if (fields != NULL) mailimf_fields_free(fields); mailmime_free(body); mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MEMORY; goto err; } new_body = mailmime_new(MAILMIME_MESSAGE, NULL, 0, NULL, content_message, NULL, NULL, NULL, NULL, fields, body); if (new_body == NULL) { mailmime_content_free(content_message); if (fields != NULL) mailimf_fields_free(fields); mailmime_free(body); mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MEMORY; goto err; } msg_info->msg_mime = new_body; mailimap_fetch_list_free(fetch_result); * result = new_body; return MAIL_NO_ERROR; free_fetch_type: mailimap_fetch_type_free(fetch_type); free_set: mailimap_set_free(set); err: return res; }
static int imap_fetch_size(mailmessage * msg_info, size_t * result) { int r; struct mailimap_set * set; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; clist * fetch_result; struct mailimap_msg_att * msg_att; struct mailimap_msg_att_item * msg_att_item; size_t size; int res; clistiter * cur; set = mailimap_set_new_single(msg_info->msg_index); if (set == NULL) { res = MAIL_ERROR_MEMORY; goto err; } fetch_att = mailimap_fetch_att_new_rfc822_size(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_set; } fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); if (fetch_type == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_att; } r = mailimap_uid_fetch(get_imap_session(msg_info), set, fetch_type, &fetch_result); mailimap_fetch_type_free(fetch_type); mailimap_set_free(set); switch (r) { case MAILIMAP_ERROR_BAD_STATE: return MAIL_ERROR_BAD_STATE; case MAILIMAP_ERROR_STREAM: return MAIL_ERROR_STREAM; case MAILIMAP_NO_ERROR: break; default: return MAIL_ERROR_FETCH; } if (clist_begin(fetch_result) == NULL) { mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; } msg_att = clist_begin(fetch_result)->data; for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { msg_att_item = clist_content(cur); if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_SIZE) { size = msg_att_item->att_data.att_static->att_data.att_rfc822_size; * result = size; mailimap_fetch_list_free(fetch_result); return MAIL_NO_ERROR; } } } mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; free_fetch_att: mailimap_fetch_att_free(fetch_att); free_set: mailimap_set_free(set); err: return res; }
static int imap_fetch_body(mailmessage * msg_info, char ** result, size_t * result_len) { int r; struct mailimap_set * set; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; clist * fetch_result; struct mailimap_msg_att * msg_att; struct mailimap_msg_att_item * msg_att_item; char * text; size_t text_length; int res; clistiter * cur; struct mailimap_section * section; set = mailimap_set_new_single(msg_info->msg_index); if (set == NULL) { res = MAIL_ERROR_MEMORY; goto err; } #if 0 fetch_att = mailimap_fetch_att_new_rfc822_text(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_set; } fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); if (fetch_type == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_att; } r = mailimap_uid_fetch(get_imap_session(msg_info->session), set, fetch_type, &fetch_result); mailimap_fetch_type_free(fetch_type); #endif section = mailimap_section_new_text(); if (section == NULL) { res = MAIL_ERROR_MEMORY; goto free_set; } fetch_att = mailimap_fetch_att_new_body_peek_section(section); if (fetch_att == NULL) { mailimap_section_free(section); res = MAIL_ERROR_MEMORY; goto free_set; } fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att); if (fetch_type == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_att; } r = mailimap_uid_fetch(get_imap_session(msg_info), set, fetch_type, &fetch_result); mailimap_fetch_type_free(fetch_type); mailimap_set_free(set); switch (r) { case MAILIMAP_NO_ERROR: break; default: return imap_error_to_mail_error(r); } cur = clist_begin(fetch_result); if (cur == NULL) { mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; } msg_att = clist_content(cur); text = NULL; text_length = 0; for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { msg_att_item = clist_content(cur); if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { #if 0 if (msg_att_item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_TEXT) { text = msg_att_item->msg_att_static->rfc822_text; msg_att_item->msg_att_static->rfc822_text = NULL; text_length = msg_att_item->msg_att_static->length; } #endif if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL; text_length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length; } } } mailimap_fetch_list_free(fetch_result); if (text == NULL) return MAIL_ERROR_FETCH; * result = text; * result_len = text_length; return MAIL_NO_ERROR; free_fetch_att: mailimap_fetch_att_free(fetch_att); free_set: mailimap_set_free(set); err: return res; }
static int imap_fetch_envelope(mailmessage * msg_info, struct mailimf_fields ** result) { int r; struct mailimap_set * set; struct mailimap_fetch_att * fetch_att; struct mailimap_fetch_type * fetch_type; clist * fetch_result; struct mailimap_msg_att * msg_att; int res; struct mailimf_fields * fields; struct mailimap_envelope * envelope; uint32_t uid; char * references; size_t ref_size; set = mailimap_set_new_single(msg_info->msg_index); if (set == NULL) { res = MAIL_ERROR_MEMORY; goto err; } fetch_type = mailimap_fetch_type_new_fetch_att_list_empty(); if (fetch_type == NULL) { res = MAIL_ERROR_MEMORY; goto free_set; } fetch_att = mailimap_fetch_att_new_uid(); if (fetch_att == NULL) { res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att); if (r != MAILIMAP_NO_ERROR) { mailimap_fetch_att_free(fetch_att); res = MAIL_ERROR_MEMORY; goto free_fetch_type; } r = imap_add_envelope_fetch_att(fetch_type); if (r != MAIL_NO_ERROR) { res = r; goto free_fetch_type; } r = mailimap_uid_fetch(get_imap_session(msg_info), set, fetch_type, &fetch_result); mailimap_fetch_type_free(fetch_type); mailimap_set_free(set); switch (r) { case MAILIMAP_NO_ERROR: break; default: return imap_error_to_mail_error(r); } if (clist_begin(fetch_result) == NULL) { mailimap_fetch_list_free(fetch_result); return MAIL_ERROR_FETCH; } msg_att = clist_begin(fetch_result)->data; uid = 0; references = NULL; ref_size = 0; envelope = NULL; r = imap_get_msg_att_info(msg_att, &uid, &envelope, &references, &ref_size, NULL, NULL); if (r != MAIL_NO_ERROR) { mailimap_fetch_list_free(fetch_result); res = r; goto err; } if (uid != msg_info->msg_index) { mailimap_fetch_list_free(fetch_result); res = MAIL_ERROR_MSG_NOT_FOUND; goto err; } fields = NULL; if (envelope != NULL) { r = imap_env_to_fields(envelope, references, ref_size, &fields); if (r != MAIL_NO_ERROR) { mailimap_fetch_list_free(fetch_result); res = r; goto err; } } mailimap_fetch_list_free(fetch_result); * result = fields; return MAIL_NO_ERROR; free_fetch_type: mailimap_fetch_type_free(fetch_type); free_set: mailimap_set_free(set); err: return res; }
static int resp_text_code_parse(mailstream * fd, MMAPString * buffer, struct mailimap_parser_context * parser_ctx, size_t * indx, struct mailimap_condstore_resptextcode ** result) { size_t cur_token; struct mailimap_condstore_resptextcode * resptextcode; int r; cur_token = * indx; /* resp-text-code =/ "HIGHESTMODSEQ" SP mod-sequence-value / "NOMODSEQ" / "MODIFIED" SP set */ r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "HIGHESTMODSEQ"); if (r == MAILIMAP_NO_ERROR) { uint64_t value; r = mailimap_space_parse(fd, buffer, &cur_token); if (r != MAILIMAP_NO_ERROR) { return r; } r = mailimap_mod_sequence_value_parse(fd, buffer, parser_ctx, &cur_token, &value); if (r != MAILIMAP_NO_ERROR) { return r; } resptextcode = mailimap_condstore_resptextcode_new(MAILIMAP_CONDSTORE_RESPTEXTCODE_HIGHESTMODSEQ, value, NULL); if (resptextcode == NULL) return MAILIMAP_ERROR_MEMORY; * indx = cur_token; * result = resptextcode; return MAILIMAP_NO_ERROR; } r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "NOMODSEQ"); if (r == MAILIMAP_NO_ERROR) { resptextcode = mailimap_condstore_resptextcode_new(MAILIMAP_CONDSTORE_RESPTEXTCODE_NOMODSEQ, 0, NULL); if (resptextcode == NULL) return MAILIMAP_ERROR_MEMORY; * indx = cur_token; * result = resptextcode; return MAILIMAP_NO_ERROR; } r = mailimap_token_case_insensitive_parse(fd, buffer, &cur_token, "MODIFIED"); if (r == MAILIMAP_NO_ERROR) { struct mailimap_set * set; r = mailimap_space_parse(fd, buffer, &cur_token); if (r != MAILIMAP_NO_ERROR) { return r; } r = mailimap_set_parse(fd, buffer, parser_ctx, &cur_token, &set); if (r != MAILIMAP_NO_ERROR) { return r; } resptextcode = mailimap_condstore_resptextcode_new(MAILIMAP_CONDSTORE_RESPTEXTCODE_MODIFIED, 0, set); if (resptextcode == NULL) { mailimap_set_free(set); return MAILIMAP_ERROR_MEMORY; } * indx = cur_token; * result = resptextcode; return MAILIMAP_NO_ERROR; } return MAILIMAP_ERROR_PARSE; }
void mailimap_qresync_vanished_free(struct mailimap_qresync_vanished * vanished) { mailimap_set_free(vanished->qr_known_uids); free(vanished); }