예제 #1
0
static int
mailmime_size_parm_parse(const char * message, size_t length,
                         size_t * indx, size_t * result)
{
    uint32_t value;
    size_t cur_token;
    int r;

    cur_token = * indx;

    r = mailimf_token_case_insensitive_parse(message, length,
            &cur_token, "size");
    if (r != MAILIMF_NO_ERROR)
        return r;

    r = mailimf_unstrict_char_parse(message, length, &cur_token, '=');
    if (r != MAILIMF_NO_ERROR)
        return r;

    r = mailimf_cfws_parse(message, length, &cur_token);
    if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE))
        return r;

    r = mailimf_number_parse(message, length, &cur_token, &value);
    if (r != MAILIMF_NO_ERROR)
        return r;

    * indx = cur_token;
    * result = value;

    return MAILIMF_NO_ERROR;
}
예제 #2
0
static int
mailmime_modification_date_parm_parse(const char * message, size_t length,
                                      size_t * indx, char ** result)
{
    char * value;
    size_t cur_token;
    int r;

    cur_token = * indx;

    r = mailimf_token_case_insensitive_parse(message, length,
            &cur_token, "modification-date");
    if (r != MAILIMF_NO_ERROR)
        return r;

    r = mailimf_unstrict_char_parse(message, length, &cur_token, '=');
    if (r != MAILIMF_NO_ERROR)
        return r;

    r = mailimf_cfws_parse(message, length, &cur_token);
    if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE))
        return r;

    r = mailmime_quoted_date_time_parse(message, length, &cur_token, &value);
    if (r != MAILIMF_NO_ERROR)
        return r;

    * indx = cur_token;
    * result = value;

    return MAILIMF_NO_ERROR;
}
예제 #3
0
LIBETPAN_EXPORT
int mailmime_parameter_parse(const char * message, size_t length,
			     size_t * indx,
			     struct mailmime_parameter ** result)
{
  char * attribute;
  char * value;
  struct mailmime_parameter * parameter;
  size_t cur_token;
  int r;
  int res;

  cur_token = * indx;

  r = mailmime_attribute_parse(message, length, &cur_token, &attribute);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto err;
  }

  r = mailimf_unstrict_char_parse(message, length, &cur_token, '=');
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto free_attr;
  }

  r = mailimf_cfws_parse(message, length, &cur_token);
  if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
    res = r;
    goto free_attr;
  }

  r = mailmime_value_parse(message, length, &cur_token, &value);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto free_attr;
  }

  parameter = mailmime_parameter_new(attribute, value);
  if (parameter == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_value;
  }

  * result = parameter;
  * indx = cur_token;

  return MAILIMF_NO_ERROR;

 free_value:
  mailmime_value_free(value);
 free_attr:
  mailmime_attribute_free(attribute);
 err:
  return res;
}
예제 #4
0
LIBETPAN_EXPORT
int mailmime_version_parse(const char * message, size_t length,
			   size_t * indx,
			   uint32_t * result)
{
  size_t cur_token;
  uint32_t hi;
  uint32_t low;
  uint32_t version;
  int r;

  cur_token = * indx;

  r = mailimf_number_parse(message, length, &cur_token, &hi);
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_unstrict_char_parse(message, length, &cur_token, '.');
  if (r != MAILIMF_NO_ERROR)
    return r;

  r = mailimf_cfws_parse(message, length, &cur_token);
  if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE))
    return r;

  r = mailimf_number_parse(message, length, &cur_token, &low);
  if (r != MAILIMF_NO_ERROR)
    return r;

  version = (hi << 16) + low;

  * result = version;
  * indx = cur_token;

  return MAILIMF_NO_ERROR;
}
예제 #5
0
LIBETPAN_EXPORT
int mailmime_content_parse(const char * message, size_t length,
			   size_t * indx,
			   struct mailmime_content ** result)
{
  size_t cur_token;
  struct mailmime_type * type;
  char * subtype;
  clist * parameters_list;
  struct mailmime_content * content;
  int r;
  int res;

  cur_token = * indx;

  mailimf_cfws_parse(message, length, &cur_token);

  type = NULL;
  r = mailmime_type_parse(message, length, &cur_token, &type);
  if (r != MAILIMF_NO_ERROR) {
    res = r;
    goto err;
  }

  r = mailimf_unstrict_char_parse(message, length, &cur_token, '/');
  switch (r) {
  case MAILIMF_NO_ERROR:
    r = mailimf_cfws_parse(message, length, &cur_token);
    if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
      res = r;
      goto free_type;
    }
    
    r = mailmime_subtype_parse(message, length, &cur_token, &subtype);
    if (r != MAILIMF_NO_ERROR) {
      res = r;
      goto free_type;
    }
    break;

  case MAILIMF_ERROR_PARSE:
    subtype = strdup("unknown");
    break;

  default:
    res = r;
    goto free_type;
  }

  parameters_list = clist_new();
  if (parameters_list == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_subtype;
  }

  while (1) {
    size_t final_token;
    struct mailmime_parameter * parameter;

    final_token = cur_token;
    r = mailimf_unstrict_char_parse(message, length, &cur_token, ';');
    if (r != MAILIMF_NO_ERROR) {
      cur_token = final_token;
      break;
    }

    r = mailimf_cfws_parse(message, length, &cur_token);
    if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
      res = r;
      goto free_type;
    }

    r = mailmime_parameter_parse(message, length, &cur_token, &parameter);
    if (r == MAILIMF_NO_ERROR) {
      /* do nothing */
    }
    else if (r == MAILIMF_ERROR_PARSE) {
      cur_token = final_token;
      break;
    }
    else {
      res = r;
      goto err;
    }

    r = clist_append(parameters_list, parameter);
    if (r < 0) {
      mailmime_parameter_free(parameter);
      res = MAILIMF_ERROR_MEMORY;
      goto free_parameters;
    }
  }

  content = mailmime_content_new(type, subtype, parameters_list);
  if (content == NULL) {
    res = MAILIMF_ERROR_MEMORY;
    goto free_parameters;
  }
 
  * result = content;
  * indx = cur_token;

  return MAILIMF_NO_ERROR;
 
 free_parameters:
  clist_foreach(parameters_list, (clist_func) mailmime_parameter_free, NULL);
  clist_free(parameters_list);
 free_subtype:
  mailmime_subtype_free(subtype);
 free_type:
  mailmime_type_free(type);
 err:
  return res;
}
예제 #6
0
static int
mailmime_disposition_parm_parse(const char * message, size_t length,
                                size_t * indx,
                                struct mailmime_disposition_parm **
                                result)
{
    char * filename;
    char * creation_date;
    char * modification_date;
    char * read_date;
    size_t size;
    struct mailmime_parameter * parameter;
    size_t cur_token;
    struct mailmime_disposition_parm * dsp_parm;
    int type;
    int guessed_type;
    int r;
    int res;

    cur_token = * indx;

    filename = NULL;
    creation_date = NULL;
    modification_date = NULL;
    read_date = NULL;
    size = 0;
    parameter = NULL;

    r = mailimf_cfws_parse(message, length, &cur_token);
    if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
        res = r;
        goto err;
    }

    guessed_type = mailmime_disposition_guess_type(message, length, cur_token);

    type = MAILMIME_DISPOSITION_PARM_PARAMETER;

    switch (guessed_type) {
    case MAILMIME_DISPOSITION_PARM_FILENAME:
        r = mailmime_filename_parm_parse(message, length, &cur_token,
                                         &filename);
        if (r == MAILIMF_NO_ERROR)
            type = guessed_type;
        else if (r == MAILIMF_ERROR_PARSE) {
            /* do nothing */
        }
        else {
            res = r;
            goto err;
        }
        break;

    case MAILMIME_DISPOSITION_PARM_CREATION_DATE:
        r = mailmime_creation_date_parm_parse(message, length, &cur_token,
                                              &creation_date);
        if (r == MAILIMF_NO_ERROR)
            type = guessed_type;
        else if (r == MAILIMF_ERROR_PARSE) {
            /* do nothing */
        }
        else {
            res = r;
            goto err;
        }
        break;

    case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE:
        r = mailmime_modification_date_parm_parse(message, length, &cur_token,
                &modification_date);
        if (r == MAILIMF_NO_ERROR)
            type = guessed_type;
        else if (r == MAILIMF_ERROR_PARSE) {
            /* do nothing */
        }
        else {
            res = r;
            goto err;
        }
        break;

    case MAILMIME_DISPOSITION_PARM_READ_DATE:
        r = mailmime_read_date_parm_parse(message, length, &cur_token,
                                          &read_date);
        if (r == MAILIMF_NO_ERROR)
            type = guessed_type;
        else if (r == MAILIMF_ERROR_PARSE) {
            /* do nothing */
        }
        else {
            res = r;
            goto err;
        }
        break;

    case MAILMIME_DISPOSITION_PARM_SIZE:
        r = mailmime_size_parm_parse(message, length, &cur_token,
                                     &size);
        if (r == MAILIMF_NO_ERROR)
            type = guessed_type;
        else if (r == MAILIMF_ERROR_PARSE) {
            /* do nothing */
        }
        else {
            res = r;
            goto err;
        }
        break;
    }

    if (type == MAILMIME_DISPOSITION_PARM_PARAMETER) {
        r = mailmime_parameter_parse(message, length, &cur_token,
                                     &parameter);
        if (r != MAILIMF_NO_ERROR) {
            type = guessed_type;
            res = r;
            goto err;
        }
    }

    dsp_parm = mailmime_disposition_parm_new(type, filename, creation_date,
               modification_date, read_date,
               size, parameter);

    if (dsp_parm == NULL) {
        res = MAILIMF_ERROR_MEMORY;
        goto free;
    }

    * result = dsp_parm;
    * indx = cur_token;

    return MAILIMF_NO_ERROR;

free:
    if (filename != NULL)
        mailmime_filename_parm_free(filename);
    if (creation_date != NULL)
        mailmime_creation_date_parm_free(creation_date);
    if (modification_date != NULL)
        mailmime_modification_date_parm_free(modification_date);
    if (read_date != NULL)
        mailmime_read_date_parm_free(read_date);
    if (parameter != NULL)
        mailmime_parameter_free(parameter);
err:
    return res;
}
예제 #7
0
int
mailmime_disposition_type_parse(const char * message, size_t length,
                                size_t * indx,
                                struct mailmime_disposition_type ** result)
{
    size_t cur_token;
    int type;
    char * extension;
    struct mailmime_disposition_type * dsp_type;
    int r;
    int res;

    cur_token = * indx;

    r = mailimf_cfws_parse(message, length, &cur_token);
    if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
        res = r;
        goto err;
    }

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

    extension = NULL;
    r = mailimf_token_case_insensitive_parse(message, length,
            &cur_token, "inline");
    if (r == MAILIMF_NO_ERROR)
        type = MAILMIME_DISPOSITION_TYPE_INLINE;

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

    if (r == MAILIMF_ERROR_PARSE) {
        r = mailmime_extension_token_parse(message, length, &cur_token,
                                           &extension);
        if (r == MAILIMF_NO_ERROR)
            type = MAILMIME_DISPOSITION_TYPE_EXTENSION;
    }

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

    dsp_type = mailmime_disposition_type_new(type, extension);
    if (dsp_type == NULL) {
        res = MAILIMF_ERROR_MEMORY;
        goto free;
    }

    * result = dsp_type;
    * indx = cur_token;

    return MAILIMF_NO_ERROR;

free:
    if (extension != NULL)
        free(extension);
err:
    return res;
}