mailimf_resent_fields_list_parse(const char * message, size_t length,
				 size_t * indx,
				 struct mailimf_resent_fields_list ** result)
{
  clist * list;
  size_t cur_token;
  struct mailimf_resent_fields_list * resent_fields_list;
  int r;
  int res;

  cur_token = * indx;
  list = NULL;

  r = mailimf_struct_multiple_parse(message, length, &cur_token, &list,
				    (mailimf_struct_parser *)
				    mailimf_resent_field_parse,
				    (mailimf_struct_destructor *)
				    mailimf_resent_field_free);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto err;
  }

  resent_fields_list = mailimf_resent_fields_list_new(list);
  if (resent_fields_list == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_list;
  }

  * result = resent_fields_list;
  * indx = cur_token;

  return MAILIMF_NO_ERROR;

 free_list:
  clist_foreach(list, (clist_func) mailimf_resent_field_free, NULL);
  clist_free(list);
 err:
  return res;
}
mailimf_resent_fields_list_parse(const char * message, size_t length,
				 size_t * indx,
				 struct mailimf_resent_fields_list ** result)
{
  clist * list;
  size_t cur_token;
  struct mailimf_resent_fields_list * resent_fields_list;
  int r;
  int res;

  cur_token = * indx;
  list = NULL;

  r = mailimf_struct_multiple_parse(message, length, &cur_token, &list,
				    (mailimf_struct_parser *)
				    mailimf_resent_field_parse,
				    (mailimf_struct_destructor *)
				    mailimf_resent_field_free);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto err;
  }

  resent_fields_list = mailimf_resent_fields_list_new(list);
  if (resent_fields_list == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_list;
  }

  * result = resent_fields_list;
  * indx = cur_token;

  return MAILIMF_NO_ERROR;

 free_list:
  clist_foreach(list, (clist_func) mailimf_resent_field_free, NULL);
  clist_free(list);
 err:
  return res;
}