Exemplo n.º 1
0
struct mailmime_fields * mailmime_fields_new_empty(void)
{
  clist * list;
  struct mailmime_fields * fields;

  list = clist_new();
  if (list == NULL)
    goto err;

  fields = mailmime_fields_new(list);
  if (fields == NULL)
    goto free;

  return fields;

 free:
  clist_free(list);
 err:
  return NULL;
}
Exemplo n.º 2
0
LIBETPAN_EXPORT
int
mailmime_fields_parse(struct mailimf_fields *
		      fields,
		      struct mailmime_fields **
		      result)
{
  clistiter * cur;
  struct mailmime_fields * mime_fields;
  clist * list;
  int r;
  int res;

  list = clist_new();
  if (list == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto err;
  }

  for(cur = clist_begin(fields->fld_list) ; cur != NULL ;
      cur = clist_next(cur)) {
    struct mailimf_field * field;
    struct mailmime_field * mime_field;
    
    field = clist_content(cur);
    
    if (field->fld_type == MAILIMF_FIELD_OPTIONAL_FIELD) {
      r = mailmime_field_parse(field->fld_data.fld_optional_field,
          &mime_field);
      if (r == MAILIMF_NO_ERROR) {
	r = clist_append(list, mime_field);
	if (r < 0) {
	  mailmime_field_free(mime_field);
	  res = MAILIMF_ERROR_MEMORY;
	  goto free_list;
	}
      }
      else if (r == MAILIMF_ERROR_PARSE) {
	/* do nothing */
      }
      else {
	res = r;
	goto free_list;
      }
    }
  }

  if (clist_begin(list) == NULL) {
    res = MAILIMF_ERROR_PARSE;
    goto free_list;
  }

  mime_fields = mailmime_fields_new(list);
  if (mime_fields == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_list;
  }

  * result = mime_fields;

  return MAILIMF_NO_ERROR;

 free_list:
  clist_foreach(list, (clist_func) mailmime_field_free, NULL);
  clist_free(list);
 err:
  return res;
}
Exemplo n.º 3
0
LIBETPAN_EXPORT
int
mailmime_unparsed_fields_parse(struct mailimf_unparsed_fields *
			       fields,
			       struct mailmime_fields **
			       result)
{
  clistiter * cur;
  struct mailmime_fields * mime_fields;
  clist * list;
  int r;
  int res;

  list = clist_new();
  if (list == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto err;
  }

  if (fields->list == NULL) {
    res = MAILIMF_ERROR_PARSE;
    goto err;
  }

  for(cur = clist_begin(fields->list) ; cur != NULL ;
      cur = clist_next(cur)) {
    struct mailimf_optional_field * field = cur->data;
    struct mailmime_field * mime_field;

    r = mailmime_field_parse(field, &mime_field);
    if (r == MAILIMF_NO_ERROR) {
      r = clist_append(list, mime_field);
      if (r < 0) {
	mailmime_field_free(mime_field);
	res = MAILIMF_ERROR_MEMORY;
	goto free_list;
      }
    }
  }

  if (clist_begin(list) == NULL) {
    res = MAILIMF_ERROR_PARSE;
    goto free_list;
  }

  mime_fields = mailmime_fields_new(list);
  if (mime_fields == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_list;
  }

  * result = mime_fields;

  return MAILIMF_NO_ERROR;

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