struct mailmime_content * mailmime_content_dup(struct mailmime_content * content) { clist * list; struct mailmime_type * type; int r; struct mailmime_content * dup_content; char * subtype; type = mailmime_type_dup(content->ct_type); if (type == NULL) goto err; subtype = strdup(content->ct_subtype); if (subtype == NULL) goto free_type; list = clist_new(); if (list == NULL) goto free_subtype; if (content->ct_parameters != NULL) { clistiter * cur; for(cur = clist_begin(content->ct_parameters) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime_parameter * param; param = mailmime_parameter_dup(clist_content(cur)); if (param == NULL) goto free_list; r = clist_append(list, param); if (r < 0) { mailmime_parameter_free(param); goto free_list; } } } dup_content = mailmime_content_new(type, subtype, list); if (dup_content == NULL) goto free_list; return dup_content; free_list: clist_foreach(list, (clist_func) mailmime_parameter_free, NULL); free_subtype: free(subtype); free_type: mailmime_type_free(type); err: return NULL; }
static int is_search_header_only(struct mail_search_key * key) { clistiter * cur; int result; switch (key->type) { case MAIL_SEARCH_KEY_ANSWERED: case MAIL_SEARCH_KEY_BCC: case MAIL_SEARCH_KEY_BEFORE: case MAIL_SEARCH_KEY_CC: case MAIL_SEARCH_KEY_DELETED: case MAIL_SEARCH_KEY_FLAGGED: case MAIL_SEARCH_KEY_FROM: case MAIL_SEARCH_KEY_NEW: case MAIL_SEARCH_KEY_OLD: case MAIL_SEARCH_KEY_ON: case MAIL_SEARCH_KEY_RECENT: case MAIL_SEARCH_KEY_SEEN: case MAIL_SEARCH_KEY_SINCE: case MAIL_SEARCH_KEY_SUBJECT: case MAIL_SEARCH_KEY_TO: case MAIL_SEARCH_KEY_UNANSWERED: case MAIL_SEARCH_KEY_UNDELETED: case MAIL_SEARCH_KEY_UNFLAGGED: case MAIL_SEARCH_KEY_UNSEEN: case MAIL_SEARCH_KEY_HEADER: case MAIL_SEARCH_KEY_LARGER: case MAIL_SEARCH_KEY_NOT: case MAIL_SEARCH_KEY_SMALLER: case MAIL_SEARCH_KEY_ALL: return TRUE; case MAIL_SEARCH_KEY_BODY: case MAIL_SEARCH_KEY_TEXT: return FALSE; case MAIL_SEARCH_KEY_OR: return (is_search_header_only(key->or1) && is_search_header_only(key->or2)); case MAIL_SEARCH_KEY_MULTIPLE: result = TRUE; for (cur = clist_begin(key->multiple) ; cur != NULL ; cur = clist_next(cur)) result = result && is_search_header_only(clist_content(cur)); return result; default: return TRUE; } }
static int etpan_fetch_mime(FILE * f, mailmessage * msg_info, struct mailmime * mime) { int r; clistiter * cur; struct mailmime_single_fields fields; int res; memset(&fields, 0, sizeof(struct mailmime_single_fields)); if (mime->mm_mime_fields != NULL) mailmime_single_fields_init(&fields, mime->mm_mime_fields, mime->mm_content_type); switch(mime->mm_type) { case MAILMIME_SINGLE: save_mime_content(msg_info, mime); break; case MAILMIME_MULTIPLE: for(cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { r = etpan_fetch_mime(f, msg_info, clist_content(cur)); if (r != NO_ERROR) { res = r; goto err; } } break; case MAILMIME_MESSAGE: if (mime->mm_data.mm_message.mm_msg_mime != NULL) { r = etpan_fetch_mime(f, msg_info, mime->mm_data.mm_message.mm_msg_mime); if (r != NO_ERROR) { res = r; goto err; } } break; } return NO_ERROR; err: return res; }
static int mhdriver_lsub_folders(mailsession * session, const char * mb, struct mail_list ** result) { clist * subscribed; clist * lsub_result; clistiter * cur; struct mail_list * lsub; size_t length; int r; length = strlen(mb); subscribed = get_data(session)->mh_subscribed_list; lsub_result = clist_new(); if (lsub_result == NULL) return MAIL_ERROR_MEMORY; for(cur = clist_begin(subscribed) ; cur != NULL ; cur = clist_next(cur)) { char * cur_mb; char * new_mb; cur_mb = clist_content(cur); if (strncmp(mb, cur_mb, length) == 0) { new_mb = strdup(cur_mb); if (new_mb == NULL) goto free_list; r = clist_append(lsub_result, new_mb); if (r < 0) { free(new_mb); goto free_list; } } } lsub = mail_list_new(lsub_result); if (lsub == NULL) goto free_list; * result = lsub; return MAIL_NO_ERROR; free_list: clist_foreach(lsub_result, (clist_func) free, NULL); clist_free(lsub_result); return MAIL_ERROR_MEMORY; }
int mailmime_transfer_encoding_get(struct mailmime_fields * fields) { clistiter * cur; for(cur = clist_begin(fields->fld_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime_field * field; field = clist_content(cur); if (field->fld_type == MAILMIME_FIELD_TRANSFER_ENCODING) return field->fld_data.fld_encoding->enc_type; } return MAILMIME_MECHANISM_8BIT; }
static void recursive_clear_registered_mime(struct mailprivacy * privacy, struct mailmime * mime) { clistiter * cur; struct mailmime_data * data; switch (mime->mm_type) { case MAILMIME_SINGLE: if (mime_is_registered(privacy, mime)) { data = mime->mm_data.mm_single; if (data != NULL) { if (data->dt_type == MAILMIME_DATA_FILE) unlink(data->dt_data.dt_filename); } } break; case MAILMIME_MULTIPLE: if (mime_is_registered(privacy, mime)) { data = mime->mm_data.mm_multipart.mm_preamble; if (data != NULL) { if (data->dt_type == MAILMIME_DATA_FILE) unlink(data->dt_data.dt_filename); } data = mime->mm_data.mm_multipart.mm_epilogue; if (data != NULL) { if (data->dt_type == MAILMIME_DATA_FILE) unlink(data->dt_data.dt_filename); } } for(cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime * child; child = clist_content(cur); recursive_clear_registered_mime(privacy, child); } break; case MAILMIME_MESSAGE: if (mime->mm_data.mm_message.mm_msg_mime) recursive_clear_registered_mime(privacy, mime->mm_data.mm_message.mm_msg_mime); break; } unregister_mime(privacy, mime); }
int mailimf_fields_write(FILE * f, int * col, struct mailimf_fields * fields) { clistiter * cur; for(cur = clist_begin(fields->fld_list) ; cur != NULL ; cur = clist_next(cur)) { int r; r = mailimf_field_write(f, col, clist_content(cur)); if (r != MAILIMF_NO_ERROR) return r; } return MAILIMF_NO_ERROR; }
int replace_page(CListElmt ** current) { /***************************************************************************** * Circle through the list of pages until one is found to replace. * *****************************************************************************/ while (((Page *) (*current)->data)->reference != 0) { ((Page *) (*current)->data)->reference = 0; *current = clist_next(*current); } return ((Page *) (*current)->data)->number; }
LIBETPAN_EXPORT int mailesmtp_send(mailsmtp * session, const char * from, int return_full, const char * envid, clist * addresses, const char * message, size_t size) { int r; clistiter * l; if (!session->esmtp) return mailsmtp_send(session, from, addresses, message, size); if ((session->esmtp & MAILSMTP_ESMTP_SIZE) != 0) { if (session->smtp_max_msg_size != 0) { if (size > session->smtp_max_msg_size) { return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION; } } } r = mailesmtp_mail_size(session, from, return_full, envid, size); if (r != MAILSMTP_NO_ERROR) return r; for(l = clist_begin(addresses) ; l != NULL; l = clist_next(l)) { struct esmtp_address * addr; addr = clist_content(l); r = mailesmtp_rcpt(session, addr->address, addr->notify, addr->orcpt); if (r != MAILSMTP_NO_ERROR) return r; } r = mailsmtp_data(session); if (r != MAILSMTP_NO_ERROR) return r; r = mailsmtp_data_message(session, message, size); if (r != MAILSMTP_NO_ERROR) return r; return MAILSMTP_NO_ERROR; }
int mail_flags_has_extension(struct mail_flags * flags, char * ext_flag) { clistiter * cur; for(cur = clist_begin(flags->fl_extension) ; cur != NULL ; cur = clist_next(cur)) { char * flag_name; flag_name = clist_content(cur); if (strcasecmp(flag_name, ext_flag) == 0) return TRUE; } return FALSE; }
void mailprivacy_mime_clear(struct mailmime * mime) { struct mailmime_data * data; clistiter * cur; switch (mime->mm_type) { case MAILMIME_SINGLE: data = mime->mm_data.mm_single; if (data != NULL) { if (data->dt_type == MAILMIME_DATA_FILE) unlink(data->dt_data.dt_filename); } break; case MAILMIME_MULTIPLE: data = mime->mm_data.mm_multipart.mm_preamble; if (data != NULL) { if (data->dt_type == MAILMIME_DATA_FILE) unlink(data->dt_data.dt_filename); } data = mime->mm_data.mm_multipart.mm_epilogue; if (data != NULL) { if (data->dt_type == MAILMIME_DATA_FILE) unlink(data->dt_data.dt_filename); } for(cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime * submime; submime = clist_content(cur); mailprivacy_mime_clear(submime); } break; case MAILMIME_MESSAGE: if (mime->mm_data.mm_message.mm_msg_mime != NULL) { mailprivacy_mime_clear(mime->mm_data.mm_message.mm_msg_mime); } break; } }
static int recipient_add_mb_list(char * recipient, size_t * len, struct mailimf_mailbox_list * mb_list) { clistiter * cur; int r; for(cur = clist_begin(mb_list->mb_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimf_mailbox * mb; mb = clist_content(cur); r = recipient_add_mb(recipient, len, mb); if (r != MAIL_NO_ERROR) return r; } return MAIL_NO_ERROR; }
static int recipient_add_addr_list(char * recipient, size_t * len, struct mailimf_address_list * addr_list) { clistiter * cur; int r; for(cur = clist_begin(addr_list->ad_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimf_address * addr; addr = clist_content(cur); r = recipient_add_addr(recipient, len, addr); if (r != MAIL_NO_ERROR) return r; } return MAIL_NO_ERROR; }
static struct mail_flags * mail_flags_dup(struct mail_flags * flags) { clist * list; struct mail_flags * new_flags; int r; clistiter * cur; list = clist_new(); if (list == NULL) { goto err; } for(cur = clist_begin(flags->fl_extension) ; cur != NULL ; cur = clist_next(cur)) { char * ext; char * original_ext; original_ext = clist_content(cur); ext = strdup(original_ext); if (ext == NULL) { goto free; } r = clist_append(list, ext); if (r < 0) { free(ext); goto free; } } new_flags = mail_flags_new(flags->fl_flags, list); if (new_flags == NULL) { goto free; } return new_flags; free: clist_foreach(list, (clist_func) free, NULL); clist_free(list); err: return NULL; }
int main() { CList list; CListElmt *element; clist_init(&list, free); int elements_left; int data1 = 4; int data2 = 9; clist_ins_next(&list, NULL, &data1); clist_ins_next(&list, clist_head(&list), &data2); elements_left = clist_size(&list); for (element = clist_head(&list); element != NULL && elements_left; element = clist_next(element), elements_left--) { printf("element->data = %d\n", *((int *) element->data)); } return 0; }
int mailimf_envelope_fields_write(FILE * f, int * col, struct mailimf_fields * fields) { clistiter * cur; for(cur = clist_begin(fields->fld_list) ; cur != NULL ; cur = clist_next(cur)) { int r; struct mailimf_field * field; field = clist_content(cur); if (field->fld_type != MAILIMF_FIELD_OPTIONAL_FIELD) { r = mailimf_field_write(f, col, field); if (r != MAILIMF_NO_ERROR) return r; } } return MAILIMF_NO_ERROR; }
static void do_storage_disconnect(struct storage_ref_info * ref_info) { clistiter * cur; /* storage is disconnected, session is lost */ for(cur = clist_begin(ref_info->storage->sto_shared_folders) ; cur != NULL ; cur = clist_next(cur)) { struct folder_ref_info * folder_ref_info; struct mailfolder * folder; folder = clist_content(cur); /* folder is disconnected (in storage), session is lost */ folder_ref_info = storage_get_folder_ref(ref_info, folder); folder_ref_info->lost_session = 1; } /* storage is disconnected */ mailstorage_disconnect(ref_info->storage); }
static int remove_from_list(mailsession * session, const char * mb) { clistiter * cur; struct nntp_session_state_data * data; data = get_data(session); for(cur = clist_begin(data->nntp_subscribed_list) ; cur != NULL ; cur = clist_next(cur)) { char * cur_name; cur_name = clist_content(cur); if (strcmp(cur_name, mb) == 0) { clist_delete(data->nntp_subscribed_list, cur); free(cur_name); return 0; } } return -1; }
int mail_flags_remove_extension(struct mail_flags * flags, char * ext_flag) { clistiter * cur; cur = clist_begin(flags->fl_extension); while (cur != NULL) { char * flag_name; flag_name = clist_content(cur); if (strcasecmp(flag_name, ext_flag) == 0) { free(flag_name); cur = clist_delete(flags->fl_extension, cur); } else cur = clist_next(cur); } return MAIL_NO_ERROR; }
static void generate_key_from_mime_section(char * key, size_t size, struct mailmime * mime) { clistiter * cur; MMAPString * gstr; struct mailmime_section * part; int r; snprintf(key, size, "unvalid"); r = mailmime_get_section_id(mime, &part); if (r != MAILIMF_NO_ERROR) goto err; gstr = mmap_string_new("part"); if (gstr == NULL) goto free_section; for(cur = clist_begin(part->sec_list) ; cur != NULL ; cur = clist_next(cur)) { char s[20]; snprintf(s, 20, ".%u", * (uint32_t *) clist_content(cur)); if (mmap_string_append(gstr, s) == NULL) goto free_str; } snprintf(key, size, "%s", gstr->str); mmap_string_free(gstr); mailmime_section_free(part); return; free_str: mmap_string_free(gstr); free_section: mailmime_section_free(part); err:; }
static void mailmime_disposition_single_fields_init(struct mailmime_single_fields * single_fields, struct mailmime_disposition * fld_disposition) { clistiter * cur; single_fields->fld_disposition = fld_disposition; for(cur = clist_begin(fld_disposition->dsp_parms) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime_disposition_parm * param; param = clist_content(cur); switch (param->pa_type) { case MAILMIME_DISPOSITION_PARM_FILENAME: single_fields->fld_disposition_filename = param->pa_data.pa_filename; break; case MAILMIME_DISPOSITION_PARM_CREATION_DATE: single_fields->fld_disposition_creation_date = param->pa_data.pa_creation_date; break; case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: single_fields->fld_disposition_modification_date = param->pa_data.pa_modification_date; break; case MAILMIME_DISPOSITION_PARM_READ_DATE: single_fields->fld_disposition_read_date = param->pa_data.pa_read_date; break; case MAILMIME_DISPOSITION_PARM_SIZE: single_fields->fld_disposition_size = param->pa_data.pa_size; break; } } }
static char * get_msg_content(clist * fetch_result, size_t * p_msg_size) { clistiter * cur; /* for each message (there will be probably only on message) */ for(cur = clist_begin(fetch_result) ; cur != NULL ; cur = clist_next(cur)) { struct mailimap_msg_att * msg_att; size_t msg_size; char * msg_content; msg_att = clist_content(cur); msg_content = get_msg_att_msg_content(msg_att, &msg_size); if (msg_content == NULL) { continue; } * p_msg_size = msg_size; return msg_content; } return NULL; }
static int recursive_register_mime(struct mailprivacy * privacy, struct mailmime * mime) { clistiter * cur; int r; r = register_mime(privacy, mime); if (r != MAIL_NO_ERROR) return r; switch (mime->mm_type) { case MAILMIME_SINGLE: break; case MAILMIME_MULTIPLE: for(cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime * child; child = clist_content(cur); r = recursive_register_mime(privacy, child); if (r != MAIL_NO_ERROR) return r; } break; case MAILMIME_MESSAGE: if (mime->mm_data.mm_message.mm_msg_mime) { r = recursive_register_mime(privacy, mime->mm_data.mm_message.mm_msg_mime); if (r != MAIL_NO_ERROR) return r; } break; } return MAIL_NO_ERROR; }
static uint32_t get_uid(struct mailimap_msg_att * msg_att) { clistiter * cur; /* iterate on each result of one given message */ for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimap_msg_att_item * item; item = clist_content(cur); if (item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) { continue; } if (item->att_data.att_static->att_type != MAILIMAP_MSG_ATT_UID) { continue; } return item->att_data.att_static->att_data.att_uid; } return 0; }
static int flags_extension_write(MMAPString * mmapstr, size_t * indx, clist * ext) { int r; clistiter * cur; r = mailimf_cache_int_write(mmapstr, indx, clist_count(ext)); if (r != MAIL_NO_ERROR) return r; for(cur = clist_begin(ext) ; cur != NULL ; cur = clist_next(cur)) { char * ext_flag; ext_flag = clist_content(cur); r = mailimf_cache_string_write(mmapstr, indx, ext_flag, strlen(ext_flag)); if (r != MAIL_NO_ERROR) return r; } return MAIL_NO_ERROR; }
static void print_list(const CList *list) { CListElmt *element; int *data, size, i; /***************************************************************************** * * * Display the circular list. * * * *****************************************************************************/ fprintf(stdout, "List size is %d (circling twice)\n", clist_size(list)); size = clist_size(list); element = clist_head(list); /***************************************************************************** * * * Iterate twice through the circular list to verify the circular links. * * * *****************************************************************************/ i = 0; while (i < size * 2) { data = clist_data(element); fprintf(stdout, "list[%03d]=%03d\n", (i % size), *data); element = clist_next(element); i++; } return; }
LIBETPAN_EXPORT int mailimap_extension_data_parse(int calling_parser, mailstream * fd, MMAPString * buffer, size_t * indx, struct mailimap_extension_data ** result, size_t progr_rate, progress_function * progr_fun) { clistiter * cur; int r; unsigned int i; for(i = 0 ; i < sizeof(internal_extension_list) / sizeof(* internal_extension_list) ; i ++) { struct mailimap_extension_api * ext; ext = internal_extension_list[i]; r = ext->ext_parser(calling_parser, fd, buffer, indx, result, progr_rate, progr_fun); if (r != MAILIMAP_ERROR_PARSE) return r; } if (mailimap_extension_list == NULL) return MAILIMAP_ERROR_PARSE; for (cur = clist_begin(mailimap_extension_list); cur != NULL; cur = clist_next(cur)) { struct mailimap_extension_api * ext; ext = clist_content(cur); r = ext->ext_parser(calling_parser, fd, buffer, indx, result, progr_rate, progr_fun); if (r != MAILIMAP_ERROR_PARSE) return r; } return MAILIMAP_ERROR_PARSE; }
static char * get_msg_att_msg_content(struct mailimap_msg_att * msg_att, size_t * p_msg_size) { clistiter * cur; /* iterate on each result of one given message */ for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimap_msg_att_item * item; item = clist_content(cur); if (item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) { continue; } if (item->att_data.att_static->att_type != MAILIMAP_MSG_ATT_BODY_SECTION) { continue; } * p_msg_size = item->att_data.att_static->att_data.att_body_section->sec_length; return item->att_data.att_static->att_data.att_body_section->sec_body_part; } return NULL; }
static void strip_mime_headers(struct mailmime * mime) { struct mailmime_fields * fields; clistiter * cur; fields = mime->mm_mime_fields; if (fields == NULL) return; for(cur = clist_begin(fields->fld_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime_field * field; field = clist_content(cur); if (field->fld_type == MAILMIME_FIELD_VERSION) { mailmime_field_free(field); clist_delete(fields->fld_list, cur); break; } } }
int main() { //linked list CList *l; int *data = 0; int *data1 = 1; int *data2 = 2; clist_init(l, (void *) &data); printf("Circular list has been initalized\n"); clist_ins_next(l, NULL, data); clist_ins_next(l, clist_head(l), data1); clist_ins_next(l, clist_next(clist_head(l)), data2); printf("Current linked list size %d\n", clist_size(l)); printf("Head elem %d\n", clist_head(l)->data); printf("Next of head %d\n", clist_head(l)->next->data); printf("Next next of head %d\n", clist_head(l)->next->next->data); clist_rem_next(l, clist_head(l)->next, (void *) &data2); clist_rem_next(l, clist_head(l), (void *) &data1); clist_rem_next(l, clist_head(l), (void *) &data); printf("Linked list has been cleared\n"); if (clist_size(l) == 0) { clist_destroy(l); printf("Circular list has been destroyed\n"); } else { printf("Can't delete list. It's not empty %d\n", clist_size(l)); }; return 0; }