Example #1
0
struct mailmime_composite_type *
mailmime_composite_type_dup(struct mailmime_composite_type * composite_type)
{
  struct mailmime_composite_type * dup_composite;
  char * token;
  
  token = NULL;
  if (composite_type->ct_token != NULL) {
    token = strdup(composite_type->ct_token);
    if (token == NULL)
      goto err;
  }
  
  dup_composite = mailmime_composite_type_new(composite_type->ct_type, token);
  if (dup_composite == NULL)
    goto free_token;
  
  return dup_composite;
  
 free_token:
  if (token != NULL)
    free(token);
 err:
  return NULL;
}
Example #2
0
static int
mailmime_composite_type_parse(const char * message, size_t length,
			      size_t * indx,
			      struct mailmime_composite_type ** result)
{
  char * extension_token;
  int type;
  struct mailmime_composite_type * ct;
  size_t cur_token;
  int r;
  int res;

  cur_token = * indx;

  extension_token = NULL;

  type = MAILMIME_COMPOSITE_TYPE_ERROR; /* XXX - removes a gcc warning */

  r = mailimf_token_case_insensitive_parse(message, length,
					   &cur_token, "message");
  if (r == MAILIMF_NO_ERROR)
    type = MAILMIME_COMPOSITE_TYPE_MESSAGE;

  if (r == MAILIMF_ERROR_PARSE) {
    r = mailimf_token_case_insensitive_parse(message, length,
					     &cur_token, "multipart");
    if (r == MAILIMF_NO_ERROR)
      type = MAILMIME_COMPOSITE_TYPE_MULTIPART;
  }

  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto err;
  }

  ct = mailmime_composite_type_new(type, extension_token);
  if (ct == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_extension;
  }

  * result = ct;
  * indx = cur_token;

  return MAILIMF_NO_ERROR;

 free_extension:
  if (extension_token != NULL)
    mailmime_extension_token_free(extension_token);
 err:
  return res;
}
Example #3
0
struct mailmime_content * mailmime_get_content_message(void)
{
  clist * list;
  struct mailmime_composite_type * composite_type;
  struct mailmime_type * mime_type;
  struct mailmime_content * content;
  char * subtype;

  composite_type =
    mailmime_composite_type_new(MAILMIME_COMPOSITE_TYPE_MESSAGE,
				NULL);
  if (composite_type == NULL)
    goto err;
  
  mime_type = mailmime_type_new(MAILMIME_TYPE_COMPOSITE_TYPE,
				NULL, composite_type);
  if (mime_type == NULL)
    goto free_composite;
  composite_type = NULL;

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

  subtype = strdup("rfc822");
  if (subtype == NULL)
    goto free_list;

  content = mailmime_content_new(mime_type, subtype, list);
  if (content == NULL)
    goto free_subtype;

  return content;

 free_subtype:
  free(subtype);
 free_list:
  clist_free(list);
 free_mime_type:
  mailmime_type_free(mime_type);
 free_composite:
  if (composite_type != NULL)
    mailmime_composite_type_free(composite_type);
 err:
  return NULL;
}