text:
/*
 * $Id: mailimap_types.c,v 1.31 2011/03/16 22:40:04 hoa Exp $
 */

#ifdef HAVE_CONFIG_H
#	include <config.h>
#endif

#include "mailimap_types.h"
#include "mmapstring.h"
#include "mail.h"
#include "mailimap_extension.h"

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */

/* from parser */

uint32_t * mailimap_number_alloc_new(uint32_t number)
{
  uint32_t * pnumber;

  pnumber = malloc(sizeof(* pnumber));
  if (pnumber == NULL)
    return NULL;

  * pnumber = number;

  return pnumber;
}

void mailimap_number_alloc_free(uint32_t * pnumber)
{
  free(pnumber);
}

/* ************************************************************************* */

struct mailimap_address *
mailimap_address_new(char * ad_personal_name, char * ad_source_route,
		     char * ad_mailbox_name, char * ad_host_name)
{
  struct mailimap_address * addr;

  addr = malloc(sizeof(* addr));
  if (addr == NULL)
    return NULL;

  addr->ad_personal_name = ad_personal_name;
  addr->ad_source_route = ad_source_route;
  addr->ad_mailbox_name = ad_mailbox_name;
  addr->ad_host_name = ad_host_name;

  return addr;
}

void mailimap_address_free(struct mailimap_address * addr)
{
  mailimap_addr_host_free(addr->ad_host_name);
  mailimap_addr_mailbox_free(addr->ad_mailbox_name);
  mailimap_addr_adl_free(addr->ad_source_route);
  mailimap_addr_name_free(addr->ad_personal_name);
  free(addr);
}

void mailimap_addr_host_free(char * addr_host)
{
  mailimap_nstring_free(addr_host);
}

void mailimap_addr_mailbox_free(char * addr_mailbox)
{
  mailimap_nstring_free(addr_mailbox);
}

void mailimap_addr_adl_free(char * addr_adl)
{
  mailimap_nstring_free(addr_adl);
}

void mailimap_addr_name_free(char * addr_name)
{
  mailimap_nstring_free(addr_name);
}

/*
struct mailimap_astring *
mailimap_astring_new(gint type,
		     gchar * atom_astring,
		     gchar * string)
{
  struct mailimap_astring * astring;

  astring = g_new(struct mailimap_astring, 1);
  if (astring == NULL)
    return FALSE;

  astring->type = type;
  astring->atom_astring = atom_astring;
  astring->string = string;

  return astring;
}

void mailimap_astring_free(struct mailimap_astring * astring)
{
  if (astring->atom_astring)
    mailimap_atom_astring_free(astring->atom_astring);
  if (astring->string)
    mailimap_string_free(astring->string);
  free(astring);
}
*/

void mailimap_astring_free(char * astring)
{
  if (mmap_string_unref(astring) != 0)
    free(astring);
}

static void mailimap_custom_string_free(char * str)
{
  free(str);
}

void mailimap_atom_free(char * atom)
{
  free(atom);
}

void mailimap_auth_type_free(char * auth_type)
{
  mailimap_atom_free(auth_type);
}

void mailimap_base64_free(char * base64)
{
  free(base64);
}

struct mailimap_body *
mailimap_body_new(int bd_type,
		  struct mailimap_body_type_1part * bd_body_1part,
		  struct mailimap_body_type_mpart * bd_body_mpart)
{
  struct mailimap_body * body;

  body = malloc(sizeof(* body));
  if (body == NULL)
    return NULL;

  body->bd_type = bd_type;
  switch (bd_type) {
  case MAILIMAP_BODY_1PART:
    body->bd_data.bd_body_1part = bd_body_1part;
    break;
  case MAILIMAP_BODY_MPART:
    body->bd_data.bd_body_mpart = bd_body_mpart;
    break;
  }

  return body;
}

void mailimap_body_free(struct mailimap_body * body)
{
  switch (body->bd_type) {
  case MAILIMAP_BODY_1PART:
    mailimap_body_type_1part_free(body->bd_data.bd_body_1part);
    break;
  case MAILIMAP_BODY_MPART:
    mailimap_body_type_mpart_free(body->bd_data.bd_body_mpart);
    break;
  }
  free(body);
}

struct mailimap_body_extension *
mailimap_body_extension_new(int ext_type, char * ext_nstring,
			    uint32_t ext_number,
    clist * ext_body_extension_list)
{
  struct mailimap_body_extension * body_extension;

  body_extension = malloc(sizeof(* body_extension));
  if (body_extension == NULL)
    return NULL;

  body_extension->ext_type = ext_type;
  switch (ext_type) {
  case MAILIMAP_BODY_EXTENSION_NSTRING:
    body_extension->ext_data.ext_nstring = ext_nstring;
    break;
  case MAILIMAP_BODY_EXTENSION_NUMBER:
    body_extension->ext_data.ext_number = ext_number;
    break;
  case MAILIMAP_BODY_EXTENSION_LIST:
    body_extension->ext_data.ext_body_extension_list = ext_body_extension_list;
    break;
  }

  return body_extension;
}

static void
mailimap_body_ext_list_free(clist * body_ext_list);

void mailimap_body_extension_free(struct mailimap_body_extension * be)
{
  switch (be->ext_type) {
  case MAILIMAP_BODY_EXTENSION_NSTRING:
    mailimap_nstring_free(be->ext_data.ext_nstring);
    break;
  case MAILIMAP_BODY_EXTENSION_LIST:
    mailimap_body_ext_list_free(be->ext_data.ext_body_extension_list);
    break;
  }

  free(be);
}

static void
mailimap_body_ext_list_free(clist * body_ext_list)
{
  clist_foreach(body_ext_list, (clist_func) mailimap_body_extension_free,
		NULL);
  clist_free(body_ext_list);
}

struct mailimap_body_ext_1part *
mailimap_body_ext_1part_new(char * bd_md5,
			    struct mailimap_body_fld_dsp * bd_disposition,
			    struct mailimap_body_fld_lang * bd_language,
          char * bd_loc,
			    clist * bd_extension_list)
{
  struct mailimap_body_ext_1part * body_ext_1part;

  body_ext_1part = malloc(sizeof(* body_ext_1part));
  if (body_ext_1part == NULL)
    return NULL;

  body_ext_1part->bd_md5 = bd_md5;
  body_ext_1part->bd_disposition = bd_disposition;
  body_ext_1part->bd_language = bd_language;
  body_ext_1part->bd_loc = bd_loc;
  body_ext_1part->bd_extension_list = bd_extension_list;

  return body_ext_1part;
}

void
mailimap_body_ext_1part_free(struct mailimap_body_ext_1part * body_ext_1part)
{
  mailimap_body_fld_md5_free(body_ext_1part->bd_md5);
  if (body_ext_1part->bd_disposition)
    mailimap_body_fld_dsp_free(body_ext_1part->bd_disposition);
  if (body_ext_1part->bd_language)
    mailimap_body_fld_lang_free(body_ext_1part->bd_language);
  if (body_ext_1part->bd_extension_list)
    mailimap_body_ext_list_free(body_ext_1part->bd_extension_list);
  mailimap_body_fld_loc_free(body_ext_1part->bd_loc);

  free(body_ext_1part);
}

struct mailimap_body_ext_mpart *
mailimap_body_ext_mpart_new(struct mailimap_body_fld_param * bd_parameter,
                            struct mailimap_body_fld_dsp * bd_disposition,
                            struct mailimap_body_fld_lang * bd_language,
                            char * bd_loc,
                            clist * bd_extension_list)
{
  struct mailimap_body_ext_mpart * body_ext_mpart;

  body_ext_mpart = malloc(sizeof(* body_ext_mpart));
  if (body_ext_mpart == NULL)
    return NULL;

  body_ext_mpart->bd_parameter = bd_parameter;
  body_ext_mpart->bd_disposition = bd_disposition;
  body_ext_mpart->bd_language = bd_language;
  body_ext_mpart->bd_extension_list = bd_extension_list;
  body_ext_mpart->bd_loc = bd_loc;

  return body_ext_mpart;
}

void
mailimap_body_ext_mpart_free(struct mailimap_body_ext_mpart * body_ext_mpart)
{
  if (body_ext_mpart->bd_parameter != NULL)
    mailimap_body_fld_param_free(body_ext_mpart->bd_parameter);
  if (body_ext_mpart->bd_disposition)
    mailimap_body_fld_dsp_free(body_ext_mpart->bd_disposition);
  if (body_ext_mpart->bd_language)
    mailimap_body_fld_lang_free(body_ext_mpart->bd_language);
  if (body_ext_mpart->bd_extension_list)
    mailimap_body_ext_list_free(body_ext_mpart->bd_extension_list);
  mailimap_body_fld_loc_free(body_ext_mpart->bd_loc);
  free(body_ext_mpart);
}

struct mailimap_body_fields *
mailimap_body_fields_new(struct mailimap_body_fld_param * bd_parameter,
			 char * bd_id,
			 char * bd_description,
			 struct mailimap_body_fld_enc * bd_encoding,
			 uint32_t bd_size)
{
  struct mailimap_body_fields * body_fields;

  body_fields = malloc(sizeof(* body_fields));
  if (body_fields == NULL)
    return NULL;
  body_fields->bd_parameter = bd_parameter;
  body_fields->bd_id = bd_id;
  body_fields->bd_description = bd_description;
  body_fields->bd_encoding = bd_encoding;
  body_fields->bd_size = bd_size;

  return body_fields;
}

void
mailimap_body_fields_free(struct mailimap_body_fields * body_fields)
{
  if (body_fields->bd_parameter != NULL)
    mailimap_body_fld_param_free(body_fields->bd_parameter);
  mailimap_body_fld_id_free(body_fields->bd_id);
  mailimap_body_fld_desc_free(body_fields->bd_description);
  mailimap_body_fld_enc_free(body_fields->bd_encoding);
  free(body_fields);
}

void mailimap_body_fld_desc_free(char * body_fld_desc)
{
  mailimap_nstring_free(body_fld_desc);
}

struct mailimap_body_fld_dsp *
mailimap_body_fld_dsp_new(char * dsp_type,
    struct mailimap_body_fld_param * dsp_attributes)
{
  struct mailimap_body_fld_dsp * body_fld_dsp;

  body_fld_dsp = malloc(sizeof(* body_fld_dsp));
  if (body_fld_dsp == NULL)
    return NULL;

  body_fld_dsp->dsp_type = dsp_type;
  body_fld_dsp->dsp_attributes = dsp_attributes;

  return body_fld_dsp;
}

void mailimap_body_fld_dsp_free(struct mailimap_body_fld_dsp * bfd)
{
  if (bfd->dsp_type != NULL)
    mailimap_string_free(bfd->dsp_type);
  if (bfd->dsp_attributes != NULL)
    mailimap_body_fld_param_free(bfd->dsp_attributes);
  free(bfd);
}

struct mailimap_body_fld_enc *
mailimap_body_fld_enc_new(int enc_type, char * enc_value)
{
  struct mailimap_body_fld_enc * body_fld_enc;

  body_fld_enc = malloc(sizeof(* body_fld_enc));
  if (body_fld_enc == NULL)
    return NULL;

  body_fld_enc->enc_type = enc_type;
  body_fld_enc->enc_value = enc_value;

  return body_fld_enc;
}

void mailimap_body_fld_enc_free(struct mailimap_body_fld_enc * bfe)
{
  if (bfe->enc_value)
    mailimap_string_free(bfe->enc_value);
  free(bfe);
}

void mailimap_body_fld_id_free(char * body_fld_id)
{
  mailimap_nstring_free(body_fld_id);
}

struct mailimap_body_fld_lang *
mailimap_body_fld_lang_new(int lg_type, char * lg_single, clist * lg_list)
{
  struct mailimap_body_fld_lang * fld_lang;

  fld_lang = malloc(sizeof(* fld_lang));
  if (fld_lang == NULL)
    return NULL;

  fld_lang->lg_type = lg_type;
  switch (lg_type) {
  case MAILIMAP_BODY_FLD_LANG_SINGLE:
    fld_lang->lg_data.lg_single = lg_single;
    break;
  case MAILIMAP_BODY_FLD_LANG_LIST:
    fld_lang->lg_data.lg_list = lg_list;
    break;
  }

  return fld_lang;
}

void
mailimap_body_fld_lang_free(struct mailimap_body_fld_lang * fld_lang)
{
  switch (fld_lang->lg_type) {
  case MAILIMAP_BODY_FLD_LANG_SINGLE:
    mailimap_nstring_free(fld_lang->lg_data.lg_single);
    break;
  case MAILIMAP_BODY_FLD_LANG_LIST:
    clist_foreach(fld_lang->lg_data.lg_list,
        (clist_func) mailimap_string_free, NULL);
    clist_free(fld_lang->lg_data.lg_list);
    break;
  }
  free(fld_lang);
}

void mailimap_body_fld_md5_free(char * body_fld_md5)
{
  mailimap_nstring_free(body_fld_md5);
}

void mailimap_body_fld_loc_free(char * body_fld_loc)
{
  mailimap_nstring_free(body_fld_loc);
}

struct mailimap_single_body_fld_param *
mailimap_single_body_fld_param_new(char * pa_name, char * pa_value)
{
  struct mailimap_single_body_fld_param * param;

  param = malloc(sizeof(* param));
  if (param == NULL)
    return NULL;
  param->pa_name = pa_name;
  param->pa_value = pa_value;

  return param;
}

void
mailimap_single_body_fld_param_free(struct mailimap_single_body_fld_param * p)
{
  mailimap_string_free(p->pa_name);
  mailimap_string_free(p->pa_value);
  free(p);
}

struct mailimap_body_fld_param *
mailimap_body_fld_param_new(clist * pa_list)
{
  struct mailimap_body_fld_param * fld_param;

  fld_param = malloc(sizeof(* fld_param));
  if (fld_param == NULL)
    return NULL;
  fld_param->pa_list = pa_list;

  return fld_param;
}

void
mailimap_body_fld_param_free(struct mailimap_body_fld_param * fld_param)
{
  clist_foreach(fld_param->pa_list,
		(clist_func) mailimap_single_body_fld_param_free, NULL);
  clist_free(fld_param->pa_list);
  free(fld_param);
}

struct mailimap_body_type_1part *
mailimap_body_type_1part_new(int bd_type,
			     struct mailimap_body_type_basic * bd_type_basic,
			     struct mailimap_body_type_msg * bd_type_msg,
			     struct mailimap_body_type_text * bd_type_text,
			     struct mailimap_body_ext_1part * bd_ext_1part)
{
  struct mailimap_body_type_1part * body_type_1part;

  body_type_1part = malloc(sizeof(* body_type_1part));
  if (body_type_1part == NULL)
    return NULL;

  body_type_1part->bd_type = bd_type;
  switch (bd_type) {
  case MAILIMAP_BODY_TYPE_1PART_BASIC:
    body_type_1part->bd_data.bd_type_basic = bd_type_basic;
    break;
  case MAILIMAP_BODY_TYPE_1PART_MSG:
    body_type_1part->bd_data.bd_type_msg = bd_type_msg;
    break;
  case MAILIMAP_BODY_TYPE_1PART_TEXT:
    body_type_1part->bd_data.bd_type_text = bd_type_text;
    break;
  }
  body_type_1part->bd_ext_1part = bd_ext_1part;

  return body_type_1part;
}

void
mailimap_body_type_1part_free(struct mailimap_body_type_1part * bt1p)
{
  switch (bt1p->bd_type) {
  case MAILIMAP_BODY_TYPE_1PART_BASIC:
    mailimap_body_type_basic_free(bt1p->bd_data.bd_type_basic);
    break;
  case MAILIMAP_BODY_TYPE_1PART_MSG:
    mailimap_body_type_msg_free(bt1p->bd_data.bd_type_msg);
    break;
  case MAILIMAP_BODY_TYPE_1PART_TEXT:
    mailimap_body_type_text_free(bt1p->bd_data.bd_type_text);
    break;
  }
  if (bt1p->bd_ext_1part)
    mailimap_body_ext_1part_free(bt1p->bd_ext_1part);

  free(bt1p);
}

struct mailimap_body_type_basic *
mailimap_body_type_basic_new(struct mailimap_media_basic * bd_media_basic,
			     struct mailimap_body_fields * bd_fields)
{
  struct mailimap_body_type_basic * body_type_basic;

  body_type_basic = malloc(sizeof(* body_type_basic));
  if (body_type_basic == NULL)
    return NULL;

  body_type_basic->bd_media_basic = bd_media_basic;
  body_type_basic->bd_fields = bd_fields;

  return body_type_basic;
}

void mailimap_body_type_basic_free(struct mailimap_body_type_basic *
    body_type_basic)
{
  mailimap_media_basic_free(body_type_basic->bd_media_basic);
  mailimap_body_fields_free(body_type_basic->bd_fields);
  free(body_type_basic);
}

struct mailimap_body_type_mpart *
mailimap_body_type_mpart_new(clist * bd_list, char * bd_media_subtype,
			     struct mailimap_body_ext_mpart * bd_ext_mpart)
{
  struct mailimap_body_type_mpart * body_type_mpart;

  body_type_mpart = malloc(sizeof(* body_type_mpart));
  if (body_type_mpart == NULL)
    return NULL;

  body_type_mpart->bd_list = bd_list;
  body_type_mpart->bd_media_subtype = bd_media_subtype;
  body_type_mpart->bd_ext_mpart = bd_ext_mpart;

  return body_type_mpart;
}

void mailimap_body_type_mpart_free(struct mailimap_body_type_mpart *
				   body_type_mpart)
{
  clist_foreach(body_type_mpart->bd_list,
		(clist_func) mailimap_body_free, NULL);
  clist_free(body_type_mpart->bd_list);
  mailimap_media_subtype_free(body_type_mpart->bd_media_subtype);
  if (body_type_mpart->bd_ext_mpart)
    mailimap_body_ext_mpart_free(body_type_mpart->bd_ext_mpart);

  free(body_type_mpart);
}

struct mailimap_body_type_msg *
mailimap_body_type_msg_new(struct mailimap_body_fields * bd_fields,
			   struct mailimap_envelope * bd_envelope,
			   struct mailimap_body * bd_body,
			   uint32_t bd_lines)
{
  struct mailimap_body_type_msg * body_type_msg;

  body_type_msg = malloc(sizeof(* body_type_msg));
  if (body_type_msg == NULL)
    return NULL;

  body_type_msg->bd_fields = bd_fields;
  body_type_msg->bd_envelope = bd_envelope;
  body_type_msg->bd_body = bd_body;
  body_type_msg->bd_lines = bd_lines;

  return body_type_msg;
}

void
mailimap_body_type_msg_free(struct mailimap_body_type_msg * body_type_msg)
{
  mailimap_body_fields_free(body_type_msg->bd_fields);
  mailimap_envelope_free(body_type_msg->bd_envelope);
  mailimap_body_free(body_type_msg->bd_body);
  free(body_type_msg);
}

struct mailimap_body_type_text *
mailimap_body_type_text_new(char * bd_media_text,
			    struct mailimap_body_fields * bd_fields,
			    uint32_t bd_lines)
{
  struct mailimap_body_type_text * body_type_text;

  body_type_text = malloc(sizeof(* body_type_text));
  if (body_type_text == NULL)
    return NULL;

  body_type_text->bd_media_text = bd_media_text;
  body_type_text->bd_fields = bd_fields;
  body_type_text->bd_lines = bd_lines;

  return body_type_text;
}

void
mailimap_body_type_text_free(struct mailimap_body_type_text * body_type_text)
{
  mailimap_media_text_free(body_type_text->bd_media_text);
  mailimap_body_fields_free(body_type_text->bd_fields);
  free(body_type_text);
}

struct mailimap_capability *
mailimap_capability_new(int cap_type, char * cap_auth_type, char * cap_name)
{
  struct mailimap_capability * cap;

  cap = malloc(sizeof(* cap));
  if (cap == NULL)
    return NULL;
  cap->cap_type = cap_type;
  switch (cap_type) {
  case MAILIMAP_CAPABILITY_AUTH_TYPE:
    cap->cap_data.cap_auth_type = cap_auth_type;
    break;
  case MAILIMAP_CAPABILITY_NAME:
    cap->cap_data.cap_name = cap_name;
    break;
  }

  return cap;
}

void mailimap_capability_free(struct mailimap_capability * c)
{
  switch (c->cap_type) {
  case MAILIMAP_CAPABILITY_AUTH_TYPE:
    free(c->cap_data.cap_auth_type);
    break;
  case MAILIMAP_CAPABILITY_NAME:
    free(c->cap_data.cap_name);
    break;
  }
  free(c);
}

struct mailimap_capability_data *
mailimap_capability_data_new(clist * cap_list)
{
  struct mailimap_capability_data * cap_data;

  cap_data = malloc(sizeof(* cap_data));
  if (cap_data == NULL)
    return NULL;

  cap_data->cap_list = cap_list;

  return cap_data;
}

void
mailimap_capability_data_free(struct mailimap_capability_data * cap_data)
{
  if (cap_data->cap_list) {
    clist_foreach(cap_data->cap_list,
        (clist_func) mailimap_capability_free, NULL);
    clist_free(cap_data->cap_list);
  }
  free(cap_data);
}

struct mailimap_continue_req *
mailimap_continue_req_new(int cr_type, struct mailimap_resp_text * cr_text,
    char * cr_base64)
{
  struct mailimap_continue_req * cont_req;

  cont_req = malloc(sizeof(* cont_req));
  if (cont_req == NULL)
    return NULL;
  cont_req->cr_type = cr_type;
  switch (cr_type) {
  case MAILIMAP_CONTINUE_REQ_TEXT:
    cont_req->cr_data.cr_text = cr_text;
    break;
  case MAILIMAP_CONTINUE_REQ_BASE64:
    cont_req->cr_data.cr_base64 = cr_base64;
    break;
  }

  return cont_req;
}

void mailimap_continue_req_free(struct mailimap_continue_req * cont_req)
{
  switch (cont_req->cr_type) {
  case MAILIMAP_CONTINUE_REQ_TEXT:
    mailimap_resp_text_free(cont_req->cr_data.cr_text);
    break;
  case MAILIMAP_CONTINUE_REQ_BASE64:
    mailimap_base64_free(cont_req->cr_data.cr_base64);
    break;
  }
  free(cont_req);
}

struct mailimap_date_time *
mailimap_date_time_new(int dt_day, int dt_month, int dt_year, int dt_hour,
    int dt_min, int dt_sec, int dt_zone)
{
  struct mailimap_date_time * date_time;

  date_time = malloc(sizeof(* date_time));
  if (date_time == NULL)
    return NULL;

  date_time->dt_day = dt_day;
  date_time->dt_month = dt_month;
  date_time->dt_year = dt_year;
  date_time->dt_hour = dt_hour;
  date_time->dt_min = dt_min;
  date_time->dt_sec = dt_sec;
  date_time->dt_zone = dt_zone;

  return date_time;
}

void mailimap_date_time_free(struct mailimap_date_time * date_time)
{
  free(date_time);
}

struct mailimap_envelope *
mailimap_envelope_new(char * env_date, char * env_subject,
		      struct mailimap_env_from * env_from,
		      struct mailimap_env_sender * env_sender,
		      struct mailimap_env_reply_to * env_reply_to,
		      struct mailimap_env_to * env_to,
		      struct mailimap_env_cc* env_cc,
		      struct mailimap_env_bcc * env_bcc,
		      char * env_in_reply_to, char * env_message_id)
{
  struct mailimap_envelope * env;

  env = malloc(sizeof(* env));
  if (env == NULL)
    return NULL;

  env->env_date = env_date;
  env->env_subject = env_subject;
  env->env_from = env_from;
  env->env_sender = env_sender;
  env->env_reply_to = env_reply_to;
  env->env_to = env_to;
  env->env_cc = env_cc;
  env->env_bcc = env_bcc;
  env->env_in_reply_to = env_in_reply_to;
  env->env_message_id = env_message_id;

  return env;
}

void mailimap_envelope_free(struct mailimap_envelope * env)
{
  if (env->env_date)
    mailimap_env_date_free(env->env_date);
  if (env->env_subject)
    mailimap_env_subject_free(env->env_subject);
  if (env->env_from)
    mailimap_env_from_free(env->env_from);
  if (env->env_sender)
    mailimap_env_sender_free(env->env_sender);
  if (env->env_reply_to)
    mailimap_env_reply_to_free(env->env_reply_to);
  if (env->env_to)
    mailimap_env_to_free(env->env_to);
  if (env->env_cc)
    mailimap_env_cc_free(env->env_cc);
  if (env->env_bcc)
    mailimap_env_bcc_free(env->env_bcc);
  if (env->env_in_reply_to)
    mailimap_env_in_reply_to_free(env->env_in_reply_to);
  if (env->env_message_id)
    mailimap_env_message_id_free(env->env_message_id);

  free(env);
}

static void mailimap_address_list_free(clist * addr_list)
{
  if (addr_list != NULL) {
    clist_foreach(addr_list, (clist_func) mailimap_address_free, NULL);
    clist_free(addr_list);
  }
}

struct mailimap_env_bcc * mailimap_env_bcc_new(clist * bcc_list)
{
  struct mailimap_env_bcc * env_bcc;

  env_bcc = malloc(sizeof(* env_bcc));
  if (env_bcc == NULL)
    return NULL;
  env_bcc->bcc_list = bcc_list;

  return env_bcc;
}

void mailimap_env_bcc_free(struct mailimap_env_bcc * env_bcc)
{
  mailimap_address_list_free(env_bcc->bcc_list);
  free(env_bcc);
}

struct mailimap_env_cc * mailimap_env_cc_new(clist * cc_list)
{
  struct mailimap_env_cc * env_cc;

  env_cc = malloc(sizeof(* env_cc));
  if (env_cc == NULL)
    return NULL;
  env_cc->cc_list = cc_list;

  return env_cc;
}

void mailimap_env_cc_free(struct mailimap_env_cc * env_cc)
{
  mailimap_address_list_free(env_cc->cc_list);
  free(env_cc);
}

void mailimap_env_date_free(char * date)
{
  mailimap_nstring_free(date);
}

struct mailimap_env_from * mailimap_env_from_new(clist * frm_list)
{
  struct mailimap_env_from * env_from;

  env_from = malloc(sizeof(* env_from));
  if (env_from == NULL)
    return NULL;
  env_from->frm_list = frm_list;

  return env_from;
}

void mailimap_env_from_free(struct mailimap_env_from * env_from)
{
  mailimap_address_list_free(env_from->frm_list);
  free(env_from);
}

void mailimap_env_in_reply_to_free(char * in_reply_to)
{
  mailimap_nstring_free(in_reply_to);
}

void mailimap_env_message_id_free(char * message_id)
{
  mailimap_nstring_free(message_id);
}

struct mailimap_env_reply_to * mailimap_env_reply_to_new(clist * rt_list)
{
  struct mailimap_env_reply_to * env_reply_to;

  env_reply_to = malloc(sizeof(* env_reply_to));
  if (env_reply_to == NULL)
    return NULL;
  env_reply_to->rt_list = rt_list;

  return env_reply_to;
}

void
mailimap_env_reply_to_free(struct mailimap_env_reply_to * env_reply_to)
{
  mailimap_address_list_free(env_reply_to->rt_list);
  free(env_reply_to);
}

struct mailimap_env_sender * mailimap_env_sender_new(clist * snd_list)
{
  struct mailimap_env_sender * env_sender;

  env_sender = malloc(sizeof(* env_sender));
  if (env_sender == NULL)
    return NULL;
  env_sender->snd_list = snd_list;

  return env_sender;
}

void mailimap_env_sender_free(struct mailimap_env_sender * env_sender)
{
  mailimap_address_list_free(env_sender->snd_list);
  free(env_sender);
}

void mailimap_env_subject_free(char * subject)
{
  mailimap_nstring_free(subject);
}

struct mailimap_env_to * mailimap_env_to_new(clist * to_list)
{
  struct mailimap_env_to * env_to;

  env_to = malloc(sizeof(* env_to));
  if (env_to == NULL)
    return NULL;
  env_to->to_list = to_list;

  return env_to;
}

void mailimap_env_to_free(struct mailimap_env_to * env_to)
{
  mailimap_address_list_free(env_to->to_list);
  free(env_to);
}

struct mailimap_flag * mailimap_flag_new(int fl_type,
    char * fl_keyword, char * fl_extension)
{
  struct mailimap_flag * f;

  f = malloc(sizeof(* f));
  if (f == NULL)
    return NULL;
  f->fl_type = fl_type;
  switch (fl_type) {
  case MAILIMAP_FLAG_KEYWORD:
    f->fl_data.fl_keyword = fl_keyword;
    break;
  case MAILIMAP_FLAG_EXTENSION:
    f->fl_data.fl_extension = fl_extension;
    break;
  }

  return f;
}

void mailimap_flag_free(struct mailimap_flag * f)
{
  switch (f->fl_type) {
  case MAILIMAP_FLAG_KEYWORD:
    mailimap_flag_keyword_free(f->fl_data.fl_keyword);
    break;
  case MAILIMAP_FLAG_EXTENSION:
    mailimap_flag_extension_free(f->fl_data.fl_extension);
    break;
  }
  free(f);
}

void mailimap_flag_extension_free(char * flag_extension)
{
  mailimap_atom_free(flag_extension);
}

struct mailimap_flag_fetch *
mailimap_flag_fetch_new(int fl_type, struct mailimap_flag * fl_flag)
{
  struct mailimap_flag_fetch * flag_fetch;

  flag_fetch = malloc(sizeof(* flag_fetch));
  if (flag_fetch == NULL)
    return NULL;

  flag_fetch->fl_type = fl_type;
  flag_fetch->fl_flag = fl_flag;

  return flag_fetch;
}

void mailimap_flag_fetch_free(struct mailimap_flag_fetch * flag_fetch)
{
  if (flag_fetch->fl_flag)
    mailimap_flag_free(flag_fetch->fl_flag);
  free(flag_fetch);
}

void mailimap_flag_keyword_free(char * flag_keyword)
{
  mailimap_atom_free(flag_keyword);
}

struct mailimap_flag_list *
mailimap_flag_list_new(clist * fl_list)
{
  struct mailimap_flag_list * flag_list;

  flag_list = malloc(sizeof(* flag_list));
  if (flag_list == NULL)
    return NULL;
  flag_list->fl_list = fl_list;

  return flag_list;
}

void mailimap_flag_list_free(struct mailimap_flag_list * flag_list)
{
  clist_foreach(flag_list->fl_list, (clist_func) mailimap_flag_free, NULL);
  clist_free(flag_list->fl_list);
  free(flag_list);
}

struct mailimap_flag_perm *
mailimap_flag_perm_new(int fl_type, struct mailimap_flag * fl_flag)
{
  struct mailimap_flag_perm * flag_perm;

  flag_perm = malloc(sizeof(* flag_perm));
  if (flag_perm == NULL)
    return NULL;

  flag_perm->fl_type = fl_type;
  flag_perm->fl_flag = fl_flag;

  return flag_perm;
}

void mailimap_flag_perm_free(struct mailimap_flag_perm * flag_perm)
{
  if (flag_perm->fl_flag != NULL)
    mailimap_flag_free(flag_perm->fl_flag);
  free(flag_perm);
}

struct mailimap_greeting *
mailimap_greeting_new(int gr_type,
    struct mailimap_resp_cond_auth * gr_auth,
    struct mailimap_resp_cond_bye * gr_bye)
{
  struct mailimap_greeting * greeting;

  greeting = malloc(sizeof(* greeting));
  if (greeting == NULL)
    return NULL;
  greeting->gr_type = gr_type;
  switch (gr_type) {
  case MAILIMAP_GREETING_RESP_COND_AUTH:
    greeting->gr_data.gr_auth = gr_auth;
    break;
  case MAILIMAP_GREETING_RESP_COND_BYE:
    greeting->gr_data.gr_bye = gr_bye;
    break;
  }

  return greeting;
}

void mailimap_greeting_free(struct mailimap_greeting * greeting)
{
  switch (greeting->gr_type) {
  case MAILIMAP_GREETING_RESP_COND_AUTH:
    mailimap_resp_cond_auth_free(greeting->gr_data.gr_auth);
    break;
  case MAILIMAP_GREETING_RESP_COND_BYE:
    mailimap_resp_cond_bye_free(greeting->gr_data.gr_bye);
    break;
  }
  free(greeting);
}

void
mailimap_header_fld_name_free(char * header_fld_name)
{
  mailimap_astring_free(header_fld_name);
}

struct mailimap_header_list *
mailimap_header_list_new(clist * hdr_list)
{
  struct mailimap_header_list * header_list;

  header_list = malloc(sizeof(* header_list));
  if (header_list == NULL)
    return NULL;

  header_list->hdr_list = hdr_list;

  return header_list;
}

void
mailimap_header_list_free(struct mailimap_header_list * header_list)
{
  clist_foreach(header_list->hdr_list,
      (clist_func) mailimap_header_fld_name_free,
      NULL);
  clist_free(header_list->hdr_list);
  free(header_list);
}

void mailimap_literal_free(char * literal)
{
  /*  free(literal); */
  mmap_string_unref(literal);
}

void mailimap_mailbox_free(char * mb)
{
  mailimap_astring_free(mb);
}

struct mailimap_status_info *
mailimap_status_info_new(int st_att, uint32_t st_value,
  struct mailimap_extension_data * st_ext_data)
{
  struct mailimap_status_info * info;

  info = malloc(sizeof(* info));
  if (info == NULL)
    return NULL;
  info->st_att = st_att;
  info->st_value = st_value;
  info->st_ext_data = st_ext_data;

  return info;
}

void mailimap_status_info_free(struct mailimap_status_info * info)
{
  if (info->st_ext_data != NULL) {
    mailimap_extension_data_free(info->st_ext_data);
  }
  free(info);
}

struct mailimap_mailbox_data_status *
mailimap_mailbox_data_status_new(char * st_mailbox,
    clist * st_info_list)
{
  struct mailimap_mailbox_data_status * mb_data_status;

  mb_data_status = malloc(sizeof(* mb_data_status));
  if (mb_data_status == NULL)
    return NULL;
  mb_data_status->st_mailbox = st_mailbox;
  mb_data_status->st_info_list = st_info_list;

  return mb_data_status;
}

void
mailimap_mailbox_data_search_free(clist * data_search)
{
  clist_foreach(data_search, (clist_func) mailimap_number_alloc_free, NULL);
  clist_free(data_search);
}

void
mailimap_mailbox_data_status_free(struct mailimap_mailbox_data_status * info)
{
  mailimap_mailbox_free(info->st_mailbox);
  clist_foreach(info->st_info_list, (clist_func) mailimap_status_info_free,
		 NULL);
  clist_free(info->st_info_list);
  free(info);
}

static void
mailimap_mailbox_data_flags_free(struct mailimap_flag_list * flag_list)
{
  mailimap_flag_list_free(flag_list);
}

static void
mailimap_mailbox_data_list_free(struct mailimap_mailbox_list * mb_list)
{
  mailimap_mailbox_list_free(mb_list);
}

static void
mailimap_mailbox_data_lsub_free(struct mailimap_mailbox_list * mb_lsub)
{
  mailimap_mailbox_list_free(mb_lsub);
}

struct mailimap_mailbox_data *
mailimap_mailbox_data_new(int mbd_type, struct mailimap_flag_list * mbd_flags,
    struct mailimap_mailbox_list * mbd_list,
    struct mailimap_mailbox_list * mbd_lsub,
    clist * mbd_search,
    struct mailimap_mailbox_data_status * mbd_status,
    uint32_t mbd_exists,
    uint32_t mbd_recent,
    struct mailimap_extension_data * mbd_extension)
{
  struct mailimap_mailbox_data * data;

  data = malloc(sizeof(* data));
  if (data == NULL)
    return NULL;

  data->mbd_type = mbd_type;
  switch (mbd_type) {
  case MAILIMAP_MAILBOX_DATA_FLAGS:
    data->mbd_data.mbd_flags = mbd_flags;
    break;
  case MAILIMAP_MAILBOX_DATA_LIST:
    data->mbd_data.mbd_list = mbd_list;
    break;
  case MAILIMAP_MAILBOX_DATA_LSUB:
    data->mbd_data.mbd_lsub = mbd_lsub;
    break;
  case MAILIMAP_MAILBOX_DATA_SEARCH:
    data->mbd_data.mbd_search = mbd_search;
    break;
  case MAILIMAP_MAILBOX_DATA_STATUS:
    data->mbd_data.mbd_status = mbd_status;
    break;
  case MAILIMAP_MAILBOX_DATA_EXISTS:
    data->mbd_data.mbd_exists = mbd_exists;
    break;
  case MAILIMAP_MAILBOX_DATA_RECENT:
    data->mbd_data.mbd_recent = mbd_recent;
    break;
  case MAILIMAP_MAILBOX_DATA_EXTENSION_DATA:
    data->mbd_data.mbd_extension = mbd_extension;
    break;
  }

  return data;
}

void
mailimap_mailbox_data_free(struct mailimap_mailbox_data * mb_data)
{
  switch (mb_data->mbd_type) {
  case MAILIMAP_MAILBOX_DATA_FLAGS:
    if (mb_data->mbd_data.mbd_flags != NULL)
      mailimap_mailbox_data_flags_free(mb_data->mbd_data.mbd_flags);
    break;
  case MAILIMAP_MAILBOX_DATA_LIST:
    if (mb_data->mbd_data.mbd_list != NULL)
      mailimap_mailbox_data_list_free(mb_data->mbd_data.mbd_list);
    break;
  case MAILIMAP_MAILBOX_DATA_LSUB:
    if (mb_data->mbd_data.mbd_lsub != NULL)
      mailimap_mailbox_data_lsub_free(mb_data->mbd_data.mbd_lsub);
    break;
  case MAILIMAP_MAILBOX_DATA_SEARCH:
    if (mb_data->mbd_data.mbd_search != NULL)
      mailimap_mailbox_data_search_free(mb_data->mbd_data.mbd_search);
    break;
  case MAILIMAP_MAILBOX_DATA_STATUS:
    if (mb_data->mbd_data.mbd_status != NULL)
      mailimap_mailbox_data_status_free(mb_data->mbd_data.mbd_status);
    break;
  case MAILIMAP_MAILBOX_DATA_EXTENSION_DATA:
    if (mb_data->mbd_data.mbd_extension != NULL)
      mailimap_extension_data_free(mb_data->mbd_data.mbd_extension);
    break;
  }
  free(mb_data);
}

struct mailimap_mbx_list_flags *
mailimap_mbx_list_flags_new(int mbf_type, clist * mbf_oflags,
			    int mbf_sflag)
{
  struct mailimap_mbx_list_flags * mbx_list_flags;

  mbx_list_flags = malloc(sizeof(* mbx_list_flags));
  if (mbx_list_flags == NULL)
    return NULL;

  mbx_list_flags->mbf_type = mbf_type;
  mbx_list_flags->mbf_oflags = mbf_oflags;
  mbx_list_flags->mbf_sflag = mbf_sflag;

  return mbx_list_flags;
}

void
mailimap_mbx_list_flags_free(struct mailimap_mbx_list_flags * mbx_list_flags)
{
  clist_foreach(mbx_list_flags->mbf_oflags,
      (clist_func) mailimap_mbx_list_oflag_free,
      NULL);
  clist_free(mbx_list_flags->mbf_oflags);

  free(mbx_list_flags);
}

struct mailimap_mbx_list_oflag *
mailimap_mbx_list_oflag_new(int of_type, char * of_flag_ext)
{
  struct mailimap_mbx_list_oflag * oflag;

  oflag = malloc(sizeof(* oflag));
  if (oflag == NULL)
    return NULL;

  oflag->of_type = of_type;
  oflag->of_flag_ext = of_flag_ext;

  return oflag;
}

void
mailimap_mbx_list_oflag_free(struct mailimap_mbx_list_oflag * oflag)
{
  if (oflag->of_flag_ext != NULL)
    mailimap_flag_extension_free(oflag->of_flag_ext);
  free(oflag);
}

struct mailimap_mailbox_list *
mailimap_mailbox_list_new(struct mailimap_mbx_list_flags * mbx_flags,
			  char mb_delimiter, char * mb_name)
{
  struct mailimap_mailbox_list * mb_list;

  mb_list = malloc(sizeof(* mb_list));
  if (mb_list == NULL)
    return NULL;

  mb_list->mb_flag = mbx_flags;
  mb_list->mb_delimiter = mb_delimiter;
  mb_list->mb_name = mb_name;

  return mb_list;
}

void
mailimap_mailbox_list_free(struct mailimap_mailbox_list * mb_list)
{
  if (mb_list->mb_flag != NULL)
    mailimap_mbx_list_flags_free(mb_list->mb_flag);
  if (mb_list->mb_name != NULL)
    mailimap_mailbox_free(mb_list->mb_name);
  free(mb_list);
}

struct mailimap_media_basic *
mailimap_media_basic_new(int med_type,
    char * med_basic_type, char * med_subtype)
{
  struct mailimap_media_basic * media_basic;

  media_basic = malloc(sizeof(* media_basic));
  if (media_basic == NULL)
    return NULL;
  media_basic->med_type = med_type;
  media_basic->med_basic_type = med_basic_type;
  media_basic->med_subtype = med_subtype;

  return media_basic;
}

void
mailimap_media_basic_free(struct mailimap_media_basic * media_basic)
{
  mailimap_string_free(media_basic->med_basic_type);
  mailimap_media_subtype_free(media_basic->med_subtype);
  free(media_basic);
}

void mailimap_media_subtype_free(char * media_subtype)
{
  mmap_string_unref(media_subtype);
}

void mailimap_media_text_free(char * media_text)
{
  mailimap_media_subtype_free(media_text);
}

struct mailimap_message_data *
mailimap_message_data_new(uint32_t mdt_number, int mdt_type,
			  struct mailimap_msg_att * mdt_msg_att)
{
  struct mailimap_message_data * msg_data;

  msg_data = malloc(sizeof(* msg_data));
  if (msg_data == NULL) {
    free(msg_data);
    return NULL;
  }

  msg_data->mdt_number = mdt_number;
  msg_data->mdt_type = mdt_type;
  msg_data->mdt_msg_att = mdt_msg_att;

  return msg_data;
}

void
mailimap_message_data_free(struct mailimap_message_data * msg_data)
{
  if (msg_data->mdt_msg_att != NULL)
    mailimap_msg_att_free(msg_data->mdt_msg_att);
  free(msg_data);
}

struct mailimap_msg_att_item *
mailimap_msg_att_item_new(int att_type,
			  struct mailimap_msg_att_dynamic * att_dyn,
			  struct mailimap_msg_att_static * att_static,
        struct mailimap_extension_data * att_extension_data)
{
  struct mailimap_msg_att_item * item;

  item = malloc(sizeof(* item));
  if (item == NULL)
    return item;

  item->att_type = att_type;
  switch (att_type) {
  case MAILIMAP_MSG_ATT_ITEM_DYNAMIC:
    item->att_data.att_dyn = att_dyn;
    break;
  case MAILIMAP_MSG_ATT_ITEM_STATIC:
    item->att_data.att_static = att_static;
    break;
  case MAILIMAP_MSG_ATT_ITEM_EXTENSION:
    item->att_data.att_extension_data = att_extension_data;
    break;
  }

  return item;
}

void
mailimap_msg_att_item_free(struct mailimap_msg_att_item * item)
{
  switch (item->att_type) {
  case MAILIMAP_MSG_ATT_ITEM_DYNAMIC:
    mailimap_msg_att_dynamic_free(item->att_data.att_dyn);
    break;
  case MAILIMAP_MSG_ATT_ITEM_STATIC:
    mailimap_msg_att_static_free(item->att_data.att_static);
    break;
  case MAILIMAP_MSG_ATT_ITEM_EXTENSION:
    mailimap_extension_data_free(item->att_data.att_extension_data);
    break;
  }
  free(item);
}

struct mailimap_msg_att *
mailimap_msg_att_new(clist * att_list)
{
  struct mailimap_msg_att * msg_att;

  msg_att = malloc(sizeof(* msg_att));
  if (msg_att == NULL)
    return NULL;

  msg_att->att_list = att_list;
  msg_att->att_number = 0;

  return msg_att;
}

void mailimap_msg_att_free(struct mailimap_msg_att * msg_att)
{
  clist_foreach(msg_att->att_list,
      (clist_func) mailimap_msg_att_item_free, NULL);
  clist_free(msg_att->att_list);
  free(msg_att);
}

struct mailimap_msg_att_dynamic *
mailimap_msg_att_dynamic_new(clist * att_list)
{
  struct mailimap_msg_att_dynamic * msg_att_dyn;

  msg_att_dyn = malloc(sizeof(* msg_att_dyn));
  if (msg_att_dyn == NULL)
    return NULL;

  msg_att_dyn->att_list = att_list;

  return msg_att_dyn;
}

void
mailimap_msg_att_dynamic_free(struct mailimap_msg_att_dynamic * msg_att_dyn)
{
  if (msg_att_dyn->att_list != NULL) {
    clist_foreach(msg_att_dyn->att_list,
        (clist_func) mailimap_flag_fetch_free,
        NULL);
    clist_free(msg_att_dyn->att_list);
  }
  free(msg_att_dyn);
}

struct mailimap_msg_att_body_section *
mailimap_msg_att_body_section_new(struct mailimap_section * sec_section,
				  uint32_t sec_origin_octet,
				  char * sec_body_part,
				  size_t sec_length)
{
  struct mailimap_msg_att_body_section * msg_att_body_section;

  msg_att_body_section = malloc(sizeof(* msg_att_body_section));
  if (msg_att_body_section == NULL)
    return NULL;

  msg_att_body_section->sec_section = sec_section;
  msg_att_body_section->sec_origin_octet = sec_origin_octet;
  msg_att_body_section->sec_body_part = sec_body_part;
  msg_att_body_section->sec_length = sec_length;

  return msg_att_body_section;
}

void
mailimap_msg_att_body_section_free(struct mailimap_msg_att_body_section *
    msg_att_body_section)
{
  if (msg_att_body_section->sec_section != NULL)
    mailimap_section_free(msg_att_body_section->sec_section);
  if (msg_att_body_section->sec_body_part != NULL)
    mailimap_nstring_free(msg_att_body_section->sec_body_part);
  free(msg_att_body_section);
}

void mailimap_msg_att_envelope_free(struct mailimap_envelope * env)
{
  mailimap_envelope_free(env);
}

void
mailimap_msg_att_internaldate_free(struct mailimap_date_time * date_time)
{
  mailimap_date_time_free(date_time);
}

void
mailimap_msg_att_rfc822_free(char * str)
{
  mailimap_nstring_free(str);
}

void
mailimap_msg_att_rfc822_header_free(char * str)
{
  mailimap_nstring_free(str);
}

void
mailimap_msg_att_rfc822_text_free(char * str)
{
  mailimap_nstring_free(str);
}

void
mailimap_msg_att_body_free(struct mailimap_body * body)
{
  mailimap_body_free(body);
}

void
mailimap_msg_att_bodystructure_free(struct mailimap_body * body)
{
  mailimap_body_free(body);
}

struct mailimap_msg_att_static *
mailimap_msg_att_static_new(int att_type, struct mailimap_envelope * att_env,
    struct mailimap_date_time * att_internal_date,
    char * att_rfc822,
    char * att_rfc822_header,
    char * att_rfc822_text,
    size_t att_length,
    uint32_t att_rfc822_size,
    struct mailimap_body * att_bodystructure,
    struct mailimap_body * att_body,
    struct mailimap_msg_att_body_section * att_body_section,
    uint32_t att_uid)
{
  struct mailimap_msg_att_static * item;

  item = malloc(sizeof(* item));
  if (item == NULL)
    return FALSE;

  item->att_type = att_type;
  switch (att_type) {
  case MAILIMAP_MSG_ATT_ENVELOPE:
    item->att_data.att_env = att_env;
    break;
  case MAILIMAP_MSG_ATT_INTERNALDATE:
    item->att_data.att_internal_date = att_internal_date;
    break;
  case MAILIMAP_MSG_ATT_RFC822:
    item->att_data.att_rfc822.att_content = att_rfc822;
    item->att_data.att_rfc822.att_length = att_length;
    break;
  case MAILIMAP_MSG_ATT_RFC822_HEADER:
    item->att_data.att_rfc822_header.att_content = att_rfc822_header;
    item->att_data.att_rfc822_header.att_length = att_length;
    break;
  case MAILIMAP_MSG_ATT_RFC822_TEXT:
    item->att_data.att_rfc822_text.att_content = att_rfc822_text;
    item->att_data.att_rfc822_text.att_length = att_length;
    break;
  case MAILIMAP_MSG_ATT_RFC822_SIZE:
    item->att_data.att_rfc822_size = att_rfc822_size;
    break;
  case MAILIMAP_MSG_ATT_BODY:
    item->att_data.att_body = att_body;
    break;
  case MAILIMAP_MSG_ATT_BODYSTRUCTURE:
    item->att_data.att_bodystructure = att_bodystructure;
    break;
  case MAILIMAP_MSG_ATT_BODY_SECTION:
    item->att_data.att_body_section = att_body_section;
    break;
  case MAILIMAP_MSG_ATT_UID:
    item->att_data.att_uid = att_uid;
    break;
  }

  return item;
}

void
mailimap_msg_att_static_free(struct mailimap_msg_att_static * item)
{
  switch (item->att_type) {
  case MAILIMAP_MSG_ATT_ENVELOPE:
    if (item->att_data.att_env != NULL)
      mailimap_msg_att_envelope_free(item->att_data.att_env);
    break;
  case MAILIMAP_MSG_ATT_INTERNALDATE:
    if (item->att_data.att_internal_date != NULL)
      mailimap_msg_att_internaldate_free(item->att_data.att_internal_date);
    break;
  case MAILIMAP_MSG_ATT_RFC822:
    if (item->att_data.att_rfc822.att_content != NULL)
      mailimap_msg_att_rfc822_free(item->att_data.att_rfc822.att_content);
    break;
  case MAILIMAP_MSG_ATT_RFC822_HEADER:
    if (item->att_data.att_rfc822_header.att_content != NULL)
      mailimap_msg_att_rfc822_header_free(item->att_data.att_rfc822_header.att_content);
    break;
  case MAILIMAP_MSG_ATT_RFC822_TEXT:
    if (item->att_data.att_rfc822_text.att_content != NULL)
      mailimap_msg_att_rfc822_text_free(item->att_data.att_rfc822_text.att_content);
    break;
  case MAILIMAP_MSG_ATT_BODYSTRUCTURE:
    if (item->att_data.att_bodystructure != NULL)
      mailimap_msg_att_bodystructure_free(item->att_data.att_bodystructure);
    break;
  case MAILIMAP_MSG_ATT_BODY:
    if (item->att_data.att_body != NULL)
      mailimap_msg_att_body_free(item->att_data.att_body);
    break;
  case MAILIMAP_MSG_ATT_BODY_SECTION:
    if (item->att_data.att_body_section != NULL)
      mailimap_msg_att_body_section_free(item->att_data.att_body_section);
    break;
  }
  free(item);
}

void mailimap_nstring_free(char * str)
{
  if (str != NULL)
    mailimap_string_free(str);
}

struct mailimap_cont_req_or_resp_data *
mailimap_cont_req_or_resp_data_new(int rsp_type,
    struct mailimap_continue_req * rsp_cont_req,
    struct mailimap_response_data * rsp_resp_data)
{
  struct mailimap_cont_req_or_resp_data * cont_req_or_resp_data;

  cont_req_or_resp_data = malloc(sizeof(* cont_req_or_resp_data));
  if (cont_req_or_resp_data == NULL)
    return NULL;

  cont_req_or_resp_data->rsp_type = rsp_type;
  switch (rsp_type) {
  case MAILIMAP_RESP_CONT_REQ:
    cont_req_or_resp_data->rsp_data.rsp_cont_req = rsp_cont_req;
    break;
  case MAILIMAP_RESP_RESP_DATA:
    cont_req_or_resp_data->rsp_data.rsp_resp_data = rsp_resp_data;
    break;
  }

  return cont_req_or_resp_data;
}

void
mailimap_cont_req_or_resp_data_free(struct mailimap_cont_req_or_resp_data *
				    cont_req_or_resp_data)
{
  switch (cont_req_or_resp_data->rsp_type) {
  case MAILIMAP_RESP_CONT_REQ:
    if (cont_req_or_resp_data->rsp_data.rsp_cont_req != NULL)
      mailimap_continue_req_free(cont_req_or_resp_data->rsp_data.rsp_cont_req);
    break;
  case MAILIMAP_RESP_RESP_DATA:
    if (cont_req_or_resp_data->rsp_data.rsp_resp_data != NULL)
      mailimap_response_data_free(cont_req_or_resp_data->rsp_data.rsp_resp_data);
    break;
  }
  free(cont_req_or_resp_data);
}

struct mailimap_response *
mailimap_response_new(clist * rsp_cont_req_or_resp_data_list,
    struct mailimap_response_done * rsp_resp_done)
{
  struct mailimap_response * resp;

  resp = malloc(sizeof(* resp));
  if (resp == NULL)
    return NULL;

  resp->rsp_cont_req_or_resp_data_list = rsp_cont_req_or_resp_data_list;
  resp->rsp_resp_done = rsp_resp_done;

  return resp;
}

void
mailimap_response_free(struct mailimap_response * resp)
{
  if (resp->rsp_cont_req_or_resp_data_list != NULL) {
    clist_foreach(resp->rsp_cont_req_or_resp_data_list,
        (clist_func) mailimap_cont_req_or_resp_data_free, NULL);
    clist_free(resp->rsp_cont_req_or_resp_data_list);
  }
  mailimap_response_done_free(resp->rsp_resp_done);
  free(resp);
}

struct mailimap_response_data *
mailimap_response_data_new(int rsp_type,
    struct mailimap_resp_cond_state * rsp_cond_state,
    struct mailimap_resp_cond_bye * rsp_bye,
    struct mailimap_mailbox_data * rsp_mailbox_data,
    struct mailimap_message_data * rsp_message_data,
    struct mailimap_capability_data * rsp_capability_data,
    struct mailimap_extension_data * rsp_extension_data)
{
  struct mailimap_response_data * resp_data;

  resp_data = malloc(sizeof(* resp_data));
  if (resp_data == NULL)
    return NULL;
  resp_data->rsp_type = rsp_type;

  switch (rsp_type) {
  case MAILIMAP_RESP_DATA_TYPE_COND_STATE:
    resp_data->rsp_data.rsp_cond_state = rsp_cond_state;
    break;
  case MAILIMAP_RESP_DATA_TYPE_COND_BYE:
    resp_data->rsp_data.rsp_bye = rsp_bye;
    break;
  case MAILIMAP_RESP_DATA_TYPE_MAILBOX_DATA:
    resp_data->rsp_data.rsp_mailbox_data = rsp_mailbox_data;
    break;
  case MAILIMAP_RESP_DATA_TYPE_MESSAGE_DATA:
    resp_data->rsp_data.rsp_message_data = rsp_message_data;
    break;
  case MAILIMAP_RESP_DATA_TYPE_CAPABILITY_DATA:
    resp_data->rsp_data.rsp_capability_data = rsp_capability_data;
    break;
  case MAILIMAP_RESP_DATA_TYPE_EXTENSION_DATA:
    resp_data->rsp_data.rsp_extension_data = rsp_extension_data;
    break;
  }

  return resp_data;
}

void
mailimap_response_data_free(struct mailimap_response_data * resp_data)
{
  switch (resp_data->rsp_type) {
  case MAILIMAP_RESP_DATA_TYPE_COND_STATE:
    if (resp_data->rsp_data.rsp_cond_state != NULL)
      mailimap_resp_cond_state_free(resp_data->rsp_data.rsp_cond_state);
    break;
  case MAILIMAP_RESP_DATA_TYPE_COND_BYE:
    if (resp_data->rsp_data.rsp_bye != NULL)
      mailimap_resp_cond_bye_free(resp_data->rsp_data.rsp_bye);
    break;
  case MAILIMAP_RESP_DATA_TYPE_MAILBOX_DATA:
    if (resp_data->rsp_data.rsp_mailbox_data != NULL)
      mailimap_mailbox_data_free(resp_data->rsp_data.rsp_mailbox_data);
    break;
  case MAILIMAP_RESP_DATA_TYPE_MESSAGE_DATA:
    if (resp_data->rsp_data.rsp_message_data != NULL)
      mailimap_message_data_free(resp_data->rsp_data.rsp_message_data);
    break;
  case MAILIMAP_RESP_DATA_TYPE_CAPABILITY_DATA:
    if (resp_data->rsp_data.rsp_capability_data != NULL)
      mailimap_capability_data_free(resp_data->rsp_data.rsp_capability_data);
    break;
  case MAILIMAP_RESP_DATA_TYPE_EXTENSION_DATA:
    if (resp_data->rsp_data.rsp_extension_data != NULL)
      mailimap_extension_data_free(resp_data->rsp_data.rsp_extension_data);
    break;
  }
  free(resp_data);
}

struct mailimap_response_done *
mailimap_response_done_new(int rsp_type,
    struct mailimap_response_tagged * rsp_tagged,
    struct mailimap_response_fatal * rsp_fatal)
{
  struct mailimap_response_done * resp_done;

  resp_done = malloc(sizeof(* resp_done));
  if (resp_done == NULL)
    return NULL;

  resp_done->rsp_type = rsp_type;
  switch (rsp_type) {
  case MAILIMAP_RESP_DONE_TYPE_TAGGED:
    resp_done->rsp_data.rsp_tagged = rsp_tagged;
    break;
  case MAILIMAP_RESP_DONE_TYPE_FATAL:
    resp_done->rsp_data.rsp_fatal = rsp_fatal;
    break;
  }

  return resp_done;
}

void mailimap_response_done_free(struct mailimap_response_done *
				 resp_done)
{
  switch (resp_done->rsp_type) {
  case MAILIMAP_RESP_DONE_TYPE_TAGGED:
    mailimap_response_tagged_free(resp_done->rsp_data.rsp_tagged);
    break;
  case MAILIMAP_RESP_DONE_TYPE_FATAL:
    mailimap_response_fatal_free(resp_done->rsp_data.rsp_fatal);
    break;
  }
  free(resp_done);
}

struct mailimap_response_fatal *
mailimap_response_fatal_new(struct mailimap_resp_cond_bye * rsp_bye)
{
  struct mailimap_response_fatal * resp_fatal;

  resp_fatal = malloc(sizeof(* resp_fatal));
  if (resp_fatal == NULL)
    return NULL;

  resp_fatal->rsp_bye = rsp_bye;

  return resp_fatal;
}

void mailimap_response_fatal_free(struct mailimap_response_fatal * resp_fatal)
{
  mailimap_resp_cond_bye_free(resp_fatal->rsp_bye);
  free(resp_fatal);
}

struct mailimap_response_tagged *
mailimap_response_tagged_new(char * rsp_tag,
    struct mailimap_resp_cond_state * rsp_cond_state)
{
  struct mailimap_response_tagged * resp_tagged;

  resp_tagged = malloc(sizeof(* resp_tagged));
  if (resp_tagged == NULL)
    return NULL;

  resp_tagged->rsp_tag = rsp_tag;
  resp_tagged->rsp_cond_state = rsp_cond_state;

  return resp_tagged;
}

void
mailimap_response_tagged_free(struct mailimap_response_tagged * tagged)
{
  mailimap_tag_free(tagged->rsp_tag);
  mailimap_resp_cond_state_free(tagged->rsp_cond_state);
  free(tagged);
}

struct mailimap_resp_cond_auth *
mailimap_resp_cond_auth_new(int rsp_type,
    struct mailimap_resp_text * rsp_text)
{
  struct mailimap_resp_cond_auth * cond_auth;

  cond_auth = malloc(sizeof(* cond_auth));
  if (cond_auth == NULL)
    return NULL;

  cond_auth->rsp_type = rsp_type;
  cond_auth->rsp_text = rsp_text;

  return cond_auth;
}

void
mailimap_resp_cond_auth_free(struct mailimap_resp_cond_auth * cond_auth)
{
  mailimap_resp_text_free(cond_auth->rsp_text);
  free(cond_auth);
}

struct mailimap_resp_cond_bye *
mailimap_resp_cond_bye_new(struct mailimap_resp_text * rsp_text)
{
  struct mailimap_resp_cond_bye * cond_bye;

  cond_bye = malloc(sizeof(* cond_bye));
  if (cond_bye == NULL)
    return NULL;

  cond_bye->rsp_text = rsp_text;

  return cond_bye;
}

void
mailimap_resp_cond_bye_free(struct mailimap_resp_cond_bye * cond_bye)
{
  mailimap_resp_text_free(cond_bye->rsp_text);
  free(cond_bye);
}

struct mailimap_resp_cond_state *
mailimap_resp_cond_state_new(int rsp_type,
    struct mailimap_resp_text * rsp_text)
{
  struct mailimap_resp_cond_state * cond_state;

  cond_state = malloc(sizeof(* cond_state));
  if (cond_state == NULL)
    return NULL;

  cond_state->rsp_type = rsp_type;
  cond_state->rsp_text = rsp_text;

  return cond_state;
}

void
mailimap_resp_cond_state_free(struct mailimap_resp_cond_state * cond_state)
{
  mailimap_resp_text_free(cond_state->rsp_text);
  free(cond_state);
}

struct mailimap_resp_text *
mailimap_resp_text_new(struct mailimap_resp_text_code * rsp_code,
    char * rsp_text)
{
  struct mailimap_resp_text * resp_text;

  resp_text = malloc(sizeof(* resp_text));
  if (resp_text == NULL)
    return NULL;

  resp_text->rsp_code = rsp_code;
  resp_text->rsp_text = rsp_text;

  return resp_text;
}

void mailimap_resp_text_free(struct mailimap_resp_text * resp_text)
{
  if (resp_text->rsp_code)
    mailimap_resp_text_code_free(resp_text->rsp_code);
  if (resp_text->rsp_text)
    mailimap_text_free(resp_text->rsp_text);
  free(resp_text);
}

struct mailimap_resp_text_code *
mailimap_resp_text_code_new(int rc_type, clist * rc_badcharset,
    struct mailimap_capability_data * rc_cap_data,
    clist * rc_perm_flags,
    uint32_t rc_uidnext, uint32_t rc_uidvalidity,
    uint32_t rc_first_unseen, char * rc_atom, char * rc_atom_value,
    struct mailimap_extension_data * rc_ext_data)
{
  struct mailimap_resp_text_code * resp_text_code;

  resp_text_code = malloc(sizeof(* resp_text_code));
  if (resp_text_code == NULL)
    return NULL;

  resp_text_code->rc_type = rc_type;
  switch (rc_type) {
  case MAILIMAP_RESP_TEXT_CODE_BADCHARSET:
    resp_text_code->rc_data.rc_badcharset = rc_badcharset;
    break;
  case MAILIMAP_RESP_TEXT_CODE_CAPABILITY_DATA:
    resp_text_code->rc_data.rc_cap_data = rc_cap_data;
    break;
  case MAILIMAP_RESP_TEXT_CODE_PERMANENTFLAGS:
    resp_text_code->rc_data.rc_perm_flags = rc_perm_flags;
    break;
  case MAILIMAP_RESP_TEXT_CODE_UIDNEXT:
    resp_text_code->rc_data.rc_uidnext = rc_uidnext;
    break;
  case MAILIMAP_RESP_TEXT_CODE_UIDVALIDITY:
    resp_text_code->rc_data.rc_uidvalidity = rc_uidvalidity;
    break;
  case MAILIMAP_RESP_TEXT_CODE_UNSEEN:
    resp_text_code->rc_data.rc_first_unseen = rc_first_unseen;
    break;
  case MAILIMAP_RESP_TEXT_CODE_OTHER:
    resp_text_code->rc_data.rc_atom.atom_name = rc_atom;
    resp_text_code->rc_data.rc_atom.atom_value = rc_atom_value;
    break;
  case MAILIMAP_RESP_TEXT_CODE_EXTENSION:
    resp_text_code->rc_data.rc_ext_data = rc_ext_data;
    break;
  }

  return resp_text_code;
}

void
mailimap_resp_text_code_free(struct mailimap_resp_text_code * resp_text_code)
{
  switch (resp_text_code->rc_type) {
  case MAILIMAP_RESP_TEXT_CODE_BADCHARSET:
    if (resp_text_code->rc_data.rc_badcharset != NULL) {
      clist_foreach(resp_text_code->rc_data.rc_badcharset,
          (clist_func) mailimap_astring_free,
          NULL);
      clist_free(resp_text_code->rc_data.rc_badcharset);
    }
    break;
  case MAILIMAP_RESP_TEXT_CODE_CAPABILITY_DATA:
    if (resp_text_code->rc_data.rc_cap_data != NULL)
      mailimap_capability_data_free(resp_text_code->rc_data.rc_cap_data);
    break;
  case MAILIMAP_RESP_TEXT_CODE_PERMANENTFLAGS:
    if (resp_text_code->rc_data.rc_perm_flags != NULL) {
      clist_foreach(resp_text_code->rc_data.rc_perm_flags,
          (clist_func) mailimap_flag_perm_free, NULL);
      clist_free(resp_text_code->rc_data.rc_perm_flags);
    }
    break;
  case MAILIMAP_RESP_TEXT_CODE_OTHER:
    if (resp_text_code->rc_data.rc_atom.atom_name != NULL)
      mailimap_atom_free(resp_text_code->rc_data.rc_atom.atom_name);
    if (resp_text_code->rc_data.rc_atom.atom_value != NULL)
      mailimap_custom_string_free(resp_text_code->rc_data.rc_atom.atom_value);
    break;
  case MAILIMAP_RESP_TEXT_CODE_EXTENSION:
    if (resp_text_code->rc_data.rc_ext_data != NULL)
      mailimap_extension_data_free(resp_text_code->rc_data.rc_ext_data);
    break;
  }
  free(resp_text_code);
}

struct mailimap_section *
mailimap_section_new(struct mailimap_section_spec * sec_spec)
{
  struct mailimap_section * section;

  section = malloc(sizeof(* section));
  if (section == NULL)
    return NULL;

  section->sec_spec = sec_spec;

  return section;
}

void mailimap_section_free(struct mailimap_section * section)
{
  if (section->sec_spec != NULL)
    mailimap_section_spec_free(section->sec_spec);
  free(section);
}

struct mailimap_section_msgtext *
mailimap_section_msgtext_new(int sec_type,
    struct mailimap_header_list * sec_header_list)
{
  struct mailimap_section_msgtext * msgtext;

  msgtext = malloc(sizeof(* msgtext));
  if (msgtext == NULL)
    return FALSE;

  msgtext->sec_type = sec_type;
  msgtext->sec_header_list = sec_header_list;

  return msgtext;
}

void
mailimap_section_msgtext_free(struct mailimap_section_msgtext * msgtext)
{
  if (msgtext->sec_header_list != NULL)
    mailimap_header_list_free(msgtext->sec_header_list);
  free(msgtext);
}

struct mailimap_section_part *
mailimap_section_part_new(clist * sec_id)
{
  struct mailimap_section_part * section_part;

  section_part = malloc(sizeof(* section_part));
  if (section_part == NULL)
    return NULL;

  section_part->sec_id = sec_id;

  return section_part;
}

void
mailimap_section_part_free(struct mailimap_section_part * section_part)
{
  clist_foreach(section_part->sec_id,
      (clist_func) mailimap_number_alloc_free, NULL);
  clist_free(section_part->sec_id);
  free(section_part);
}

struct mailimap_section_spec *
mailimap_section_spec_new(int sec_type,
    struct mailimap_section_msgtext * sec_msgtext,
    struct mailimap_section_part * sec_part,
    struct mailimap_section_text * sec_text)
{
  struct mailimap_section_spec * section_spec;

  section_spec = malloc(sizeof(* section_spec));
  if (section_spec == NULL)
    return NULL;

  section_spec->sec_type = sec_type;
  switch (sec_type) {
  case MAILIMAP_SECTION_SPEC_SECTION_MSGTEXT:
    section_spec->sec_data.sec_msgtext = sec_msgtext;
    break;
  case MAILIMAP_SECTION_SPEC_SECTION_PART:
    section_spec->sec_data.sec_part = sec_part;
    break;
  }
  section_spec->sec_text = sec_text;

  return section_spec;
}

void
mailimap_section_spec_free(struct mailimap_section_spec * section_spec)
{
  if (section_spec->sec_text)
    mailimap_section_text_free(section_spec->sec_text);

  switch (section_spec->sec_type) {
  case MAILIMAP_SECTION_SPEC_SECTION_PART:
    if (section_spec->sec_data.sec_part != NULL)
      mailimap_section_part_free(section_spec->sec_data.sec_part);
    break;
  case MAILIMAP_SECTION_SPEC_SECTION_MSGTEXT:
    /* handle case where it can be detached */
    if (section_spec->sec_data.sec_msgtext != NULL)
      mailimap_section_msgtext_free(section_spec->sec_data.sec_msgtext);
    break;
  }
  free(section_spec);
}

struct mailimap_section_text *
mailimap_section_text_new(int sec_type,
    struct mailimap_section_msgtext * sec_msgtext)
{
  struct mailimap_section_text * section_text;

  section_text = malloc(sizeof(* section_text));
  if (section_text == NULL)
    return NULL;

  section_text->sec_type = sec_type;
  section_text->sec_msgtext = sec_msgtext;

  return section_text;
}

void
mailimap_section_text_free(struct mailimap_section_text * section_text)
{
  if (section_text->sec_msgtext != NULL)
    mailimap_section_msgtext_free(section_text->sec_msgtext);
  free(section_text);
}

void
mailimap_string_free(char * str)
{
  mmap_string_unref(str);
}

void mailimap_tag_free(char * tag)
{
  mailimap_custom_string_free(tag);
}

void mailimap_text_free(char * text)
{
  mailimap_custom_string_free(text);
}

/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */
/* ************************************************************************* */

/* sender only */

/* COPY FETCH SEARCH STORE */
/* set */

struct mailimap_set_item *
mailimap_set_item_new(uint32_t set_first, uint32_t set_last)
{
  struct mailimap_set_item * item;

  item = malloc(sizeof(* item));
  if (item == NULL)
    return NULL;

  item->set_first = set_first;
  item->set_last = set_last;

  return item;
}

void mailimap_set_item_free(struct mailimap_set_item * set_item)
{
  free(set_item);
}

struct mailimap_set * mailimap_set_new(clist * set_list)
{
  struct mailimap_set * set;

  set = malloc(sizeof(* set));
  if (set == NULL)
    return NULL;

  set->set_list = set_list;

  return set;
}

void mailimap_set_free(struct mailimap_set * set)
{
  clist_foreach(set->set_list, (clist_func) mailimap_set_item_free, NULL);
  clist_free(set->set_list);
  free(set);
}

/* SEARCH with date key */
/* date */

struct mailimap_date *
mailimap_date_new(int dt_day, int dt_month, int dt_year)
{
  struct mailimap_date * date;

  date = malloc(sizeof(* date));
  if (date == NULL)
    return NULL;

  date->dt_day = dt_day;
  date->dt_month = dt_month;
  date->dt_year = dt_year;

  return date;
}

void mailimap_date_free(struct mailimap_date * date)
{
  free(date);
}

struct mailimap_fetch_att *
mailimap_fetch_att_new(int att_type, struct mailimap_section * att_section,
                       uint32_t att_offset, uint32_t att_size, char * att_extension)
{
  struct mailimap_fetch_att * fetch_att;

  fetch_att = malloc(sizeof(* fetch_att));
  if (fetch_att == NULL)
    return NULL;
  fetch_att->att_type = att_type;
  fetch_att->att_section = att_section;
  fetch_att->att_offset = att_offset;
  fetch_att->att_size = att_size;
  fetch_att->att_extension = att_extension;

  return fetch_att;
}

void mailimap_fetch_att_free(struct mailimap_fetch_att * fetch_att)
{
  if (fetch_att->att_extension != NULL)
    free(fetch_att->att_extension);
  if (fetch_att->att_section != NULL)
    mailimap_section_free(fetch_att->att_section);
  free(fetch_att);
}

struct mailimap_fetch_type *
mailimap_fetch_type_new(int ft_type,
    struct mailimap_fetch_att * ft_fetch_att,
    clist * ft_fetch_att_list)
{
  struct mailimap_fetch_type * fetch_type;

  fetch_type = malloc(sizeof(* fetch_type));
  if (fetch_type == NULL)
    return NULL;
  fetch_type->ft_type = ft_type;
  switch (ft_type) {
  case MAILIMAP_FETCH_TYPE_FETCH_ATT:
    fetch_type->ft_data.ft_fetch_att = ft_fetch_att;
    break;
  case MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST:
    fetch_type->ft_data.ft_fetch_att_list = ft_fetch_att_list;
    break;
  }

  return fetch_type;
}

void mailimap_fetch_type_free(struct mailimap_fetch_type * fetch_type)
{
  switch (fetch_type->ft_type) {
  case MAILIMAP_FETCH_TYPE_FETCH_ATT:
    mailimap_fetch_att_free(fetch_type->ft_data.ft_fetch_att);
    break;
  case MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST:
    clist_foreach(fetch_type->ft_data.ft_fetch_att_list,
        (clist_func) mailimap_fetch_att_free, NULL);
    clist_free(fetch_type->ft_data.ft_fetch_att_list);
    break;
  }
  free(fetch_type);
}

struct mailimap_store_att_flags *
mailimap_store_att_flags_new(int fl_sign, int fl_silent,
    struct mailimap_flag_list * fl_flag_list)
{
  struct mailimap_store_att_flags * store_att_flags;

  store_att_flags = malloc(sizeof(* store_att_flags));
  if (store_att_flags == NULL)
    return NULL;

  store_att_flags->fl_sign = fl_sign;
  store_att_flags->fl_silent = fl_silent;
  store_att_flags->fl_flag_list = fl_flag_list;

  return store_att_flags;
}

void mailimap_store_att_flags_free(struct mailimap_store_att_flags *
				   store_att_flags)
{
  mailimap_flag_list_free(store_att_flags->fl_flag_list);
  free(store_att_flags);
}

struct mailimap_search_key *
mailimap_search_key_new(int sk_type,
    char * sk_bcc, struct mailimap_date * sk_before, char * sk_body,
    char * sk_cc, char * sk_from, char * sk_keyword,
    struct mailimap_date * sk_on, struct mailimap_date * sk_since,
    char * sk_subject, char * sk_text, char * sk_to,
    char * sk_unkeyword, char * sk_header_name,
    char * sk_header_value, uint32_t sk_larger,
    struct mailimap_search_key * sk_not,
    struct mailimap_search_key * sk_or1,
    struct mailimap_search_key * sk_or2,
    struct mailimap_date * sk_sentbefore,
    struct mailimap_date * sk_senton,
    struct mailimap_date * sk_sentsince,
    uint32_t sk_smaller, struct mailimap_set * sk_uid,
    struct mailimap_set * sk_set, clist * sk_multiple)
{
  struct mailimap_search_key * key;

  key = malloc(sizeof(* key));
  if (key == NULL)
    return NULL;

  key->sk_type = sk_type;
  switch (sk_type) {
  case MAILIMAP_SEARCH_KEY_BCC:
    key->sk_data.sk_bcc = sk_bcc;
    break;
  case MAILIMAP_SEARCH_KEY_BEFORE:
    key->sk_data.sk_before = sk_before;
    break;
  case MAILIMAP_SEARCH_KEY_BODY:
    key->sk_data.sk_body = sk_body;
    break;
  case MAILIMAP_SEARCH_KEY_CC:
    key->sk_data.sk_cc = sk_cc;
    break;
  case MAILIMAP_SEARCH_KEY_FROM:
    key->sk_data.sk_from = sk_from;
    break;
  case MAILIMAP_SEARCH_KEY_KEYWORD:
    key->sk_data.sk_keyword = sk_keyword;
    break;
  case MAILIMAP_SEARCH_KEY_ON:
    key->sk_data.sk_on = sk_on;
    break;
  case MAILIMAP_SEARCH_KEY_SINCE:
    key->sk_data.sk_since = sk_since;
    break;
  case MAILIMAP_SEARCH_KEY_SUBJECT:
    key->sk_data.sk_subject = sk_subject;
    break;
  case MAILIMAP_SEARCH_KEY_TEXT:
    key->sk_data.sk_text = sk_text;
    break;
  case MAILIMAP_SEARCH_KEY_TO:
    key->sk_data.sk_to = sk_to;
    break;
  case MAILIMAP_SEARCH_KEY_UNKEYWORD:
    key->sk_data.sk_unkeyword = sk_unkeyword;
    break;
  case MAILIMAP_SEARCH_KEY_HEADER:
    key->sk_data.sk_header.sk_header_name = sk_header_name;
    key->sk_data.sk_header.sk_header_value = sk_header_value;
    break;
  case MAILIMAP_SEARCH_KEY_LARGER:
    key->sk_data.sk_larger = sk_larger;
    break;
  case MAILIMAP_SEARCH_KEY_NOT:
    key->sk_data.sk_not = sk_not;
    break;
  case MAILIMAP_SEARCH_KEY_OR:
    key->sk_data.sk_or.sk_or1 = sk_or1;
    key->sk_data.sk_or.sk_or2 = sk_or2;
    break;
  case MAILIMAP_SEARCH_KEY_SENTBEFORE:
    key->sk_data.sk_sentbefore = sk_sentbefore;
    break;
  case MAILIMAP_SEARCH_KEY_SENTON:
    key->sk_data.sk_senton = sk_senton;
    break;
  case MAILIMAP_SEARCH_KEY_SENTSINCE:
    key->sk_data.sk_sentsince = sk_sentsince;
    break;
  case MAILIMAP_SEARCH_KEY_SMALLER:
    key->sk_data.sk_smaller = sk_smaller;
    break;
  case MAILIMAP_SEARCH_KEY_UID:
    key->sk_data.sk_uid = sk_uid;
    break;
  case MAILIMAP_SEARCH_KEY_SET:
    key->sk_data.sk_set = sk_set;
    break;
  case MAILIMAP_SEARCH_KEY_MULTIPLE:
    key->sk_data.sk_multiple = sk_multiple;
    break;
  }
  return key;
}

void mailimap_search_key_free(struct mailimap_search_key * key)
{
  switch (key->sk_type) {
  case MAILIMAP_SEARCH_KEY_BCC:
    mailimap_astring_free(key->sk_data.sk_bcc);
    break;
  case MAILIMAP_SEARCH_KEY_BEFORE:
    mailimap_date_free(key->sk_data.sk_before);
    break;
  case MAILIMAP_SEARCH_KEY_BODY:
    mailimap_astring_free(key->sk_data.sk_body);
    break;
  case MAILIMAP_SEARCH_KEY_CC:
    mailimap_astring_free(key->sk_data.sk_cc);
    break;
  case MAILIMAP_SEARCH_KEY_FROM:
    mailimap_astring_free(key->sk_data.sk_from);
    break;
  case MAILIMAP_SEARCH_KEY_KEYWORD:
    mailimap_flag_keyword_free(key->sk_data.sk_keyword);
    break;
  case MAILIMAP_SEARCH_KEY_ON:
    mailimap_date_free(key->sk_data.sk_on);
    break;
  case MAILIMAP_SEARCH_KEY_SINCE:
    mailimap_date_free(key->sk_data.sk_since);
    break;
  case MAILIMAP_SEARCH_KEY_SUBJECT:
    mailimap_astring_free(key->sk_data.sk_subject);
    break;
  case MAILIMAP_SEARCH_KEY_TEXT:
    mailimap_astring_free(key->sk_data.sk_text);
    break;
  case MAILIMAP_SEARCH_KEY_TO:
    mailimap_astring_free(key->sk_data.sk_to);
    break;
  case MAILIMAP_SEARCH_KEY_UNKEYWORD:
    mailimap_flag_keyword_free(key->sk_data.sk_unkeyword);
    break;
  case MAILIMAP_SEARCH_KEY_HEADER:
    mailimap_header_fld_name_free(key->sk_data.sk_header.sk_header_name);
    mailimap_astring_free(key->sk_data.sk_header.sk_header_value);
    break;
  case MAILIMAP_SEARCH_KEY_NOT:
    mailimap_search_key_free(key->sk_data.sk_not);
    break;
  case MAILIMAP_SEARCH_KEY_OR:
    mailimap_search_key_free(key->sk_data.sk_or.sk_or1);
    mailimap_search_key_free(key->sk_data.sk_or.sk_or2);
    break;
  case MAILIMAP_SEARCH_KEY_SENTBEFORE:
    mailimap_date_free(key->sk_data.sk_sentbefore);
    break;
  case MAILIMAP_SEARCH_KEY_SENTON:
    mailimap_date_free(key->sk_data.sk_senton);
    break;
  case MAILIMAP_SEARCH_KEY_SENTSINCE:
    mailimap_date_free(key->sk_data.sk_sentsince);
    break;
  case MAILIMAP_SEARCH_KEY_UID:
    mailimap_set_free(key->sk_data.sk_uid);
    break;
  case MAILIMAP_SEARCH_KEY_SET:
    mailimap_set_free(key->sk_data.sk_set);
    break;
  case MAILIMAP_SEARCH_KEY_MULTIPLE:
    clist_foreach(key->sk_data.sk_multiple,
        (clist_func) mailimap_search_key_free, NULL);
    clist_free(key->sk_data.sk_multiple);
    break;
	case MAILIMAP_SEARCH_KEY_MODSEQ:
	  if (key->sk_data.sk_modseq.sk_entry_name != NULL) {
			mailimap_flag_free(key->sk_data.sk_modseq.sk_entry_name);
		}
	  break;
  }

  free(key);
}

struct mailimap_status_att_list *
mailimap_status_att_list_new(clist * att_list)
{
  struct mailimap_status_att_list * status_att_list;

  status_att_list = malloc(sizeof(* status_att_list));
  if (status_att_list == NULL)
    return NULL;
  status_att_list->att_list = att_list;

  return status_att_list;
}

void mailimap_status_att_list_free(struct mailimap_status_att_list *
				   status_att_list)
{
  clist_foreach(status_att_list->att_list, (clist_func) free, NULL);
  clist_free(status_att_list->att_list);
  free(status_att_list);
}

/* main */

struct mailimap_selection_info *
mailimap_selection_info_new(void)
{
  struct mailimap_selection_info * sel_info;

  sel_info = malloc(sizeof(* sel_info));
  if (sel_info == NULL)
    return NULL;

  sel_info->sel_perm_flags = NULL;
  sel_info->sel_perm = MAILIMAP_MAILBOX_READWRITE;
  sel_info->sel_uidnext = 0;
  sel_info->sel_uidvalidity = 0;
  sel_info->sel_first_unseen = 0;
  sel_info->sel_flags = NULL;
  sel_info->sel_exists = 0;
  sel_info->sel_recent = 0;
  sel_info->sel_unseen = 0;
  sel_info->sel_has_exists = 0;
  sel_info->sel_has_recent = 0 ;

  return sel_info;
}

void
mailimap_selection_info_free(struct mailimap_selection_info * sel_info)
{
  if (sel_info->sel_perm_flags != NULL) {
    clist_foreach(sel_info->sel_perm_flags,
        (clist_func) mailimap_flag_perm_free, NULL);
    clist_free(sel_info->sel_perm_flags);
  }
  if (sel_info->sel_flags)
    mailimap_flag_list_free(sel_info->sel_flags);

  free(sel_info);
}

struct mailimap_connection_info *
mailimap_connection_info_new(void)
{
  struct mailimap_connection_info * conn_info;

  conn_info = malloc(sizeof(* conn_info));
  if (conn_info == NULL)
    return NULL;

  conn_info->imap_capability = NULL;

  return conn_info;
}

void
mailimap_connection_info_free(struct mailimap_connection_info * conn_info)
{
  if (conn_info->imap_capability != NULL)
    mailimap_capability_data_free(conn_info->imap_capability);
  free(conn_info);
}

struct mailimap_response_info *
mailimap_response_info_new(void)
{
  struct mailimap_response_info * resp_info;

  resp_info = malloc(sizeof(* resp_info));
  if (resp_info == NULL)
    goto err;

  resp_info->rsp_alert = NULL;
  resp_info->rsp_parse = NULL;
  resp_info->rsp_badcharset = NULL;
  resp_info->rsp_trycreate = FALSE;
  resp_info->rsp_mailbox_list = clist_new();
  if (resp_info->rsp_mailbox_list == NULL)
    goto free;
  resp_info->rsp_extension_list = clist_new();
  if (resp_info->rsp_extension_list == NULL)
    goto free_mb_list;
  resp_info->rsp_mailbox_lsub = clist_new();
  if (resp_info->rsp_mailbox_lsub == NULL)
    goto free_extension_list;
  resp_info->rsp_search_result = clist_new();
  if (resp_info->rsp_search_result == NULL)
    goto free_mb_lsub;
  resp_info->rsp_status = NULL;
  resp_info->rsp_expunged = clist_new();
  if (resp_info->rsp_expunged == NULL)
    goto free_search_result;
  resp_info->rsp_fetch_list = clist_new();
  if (resp_info->rsp_fetch_list == NULL)
    goto free_expunged;
  resp_info->rsp_atom = NULL;
  resp_info->rsp_value = NULL;

  return resp_info;

 free_expunged:
  clist_free(resp_info->rsp_expunged);
 free_search_result:
  clist_free(resp_info->rsp_search_result);
 free_mb_lsub:
  clist_free(resp_info->rsp_mailbox_lsub);
 free_extension_list:
  clist_free(resp_info->rsp_extension_list);
 free_mb_list:
  clist_free(resp_info->rsp_mailbox_list);
 free:
  free(resp_info);
 err:
  return NULL;
}

void
mailimap_response_info_free(struct mailimap_response_info * resp_info)
{
  free(resp_info->rsp_value);
  free(resp_info->rsp_atom);
  if (resp_info->rsp_alert != NULL)
    free(resp_info->rsp_alert);
  if (resp_info->rsp_parse != NULL)
    free(resp_info->rsp_parse);
  if (resp_info->rsp_badcharset != NULL) {
    clist_foreach(resp_info->rsp_badcharset,
        (clist_func) mailimap_astring_free, NULL);
    clist_free(resp_info->rsp_badcharset);
  }
  if (resp_info->rsp_mailbox_list != NULL) {
    clist_foreach(resp_info->rsp_mailbox_list,
        (clist_func) mailimap_mailbox_list_free, NULL);
    clist_free(resp_info->rsp_mailbox_list);
  }
  if (resp_info->rsp_extension_list != NULL) {
    clist_foreach(resp_info->rsp_extension_list,
      (clist_func) mailimap_extension_data_free, NULL);
    clist_free(resp_info->rsp_extension_list);
  }
  if (resp_info->rsp_mailbox_lsub != NULL) {
    clist_foreach(resp_info->rsp_mailbox_lsub,
        (clist_func) mailimap_mailbox_list_free, NULL);
    clist_free(resp_info->rsp_mailbox_lsub);
  }
  if (resp_info->rsp_search_result != NULL)
    mailimap_mailbox_data_search_free(resp_info->rsp_search_result);
  if (resp_info->rsp_status != NULL)
    mailimap_mailbox_data_status_free(resp_info->rsp_status);
  if (resp_info->rsp_expunged != NULL) {
    clist_foreach(resp_info->rsp_expunged,
		   (clist_func) mailimap_number_alloc_free, NULL);
    clist_free(resp_info->rsp_expunged);
  }
  if (resp_info->rsp_fetch_list != NULL) {
    clist_foreach(resp_info->rsp_fetch_list,
		  (clist_func) mailimap_msg_att_free, NULL);
    clist_free(resp_info->rsp_fetch_list);
  }

  free(resp_info);
}


text:
HomeSportsBasketballHarvesters claim spot in final four after blowing past Cyclones
Harvesters claim spot in final four after blowing past Cyclones
March 13, 2020 etcetera Basketball, Sports 0
TaMarcus Butler pushes against a St. Cloud defender towards the basket on Thursday night. Photo by Skye Seipp/The Et Cetera
Guard DaJuan Ridgeway breaks from a huddle during the second period of the quarterfinal game Thursday night against St. Cloud Technical and Community College. Ridgeway led the team in points scored with 24. Photo by Skye Seipp/The Et Cetera
By SAZOUN GRAYER
@sazoungrayerETC
Forward D'Angelo Smith gets his teammates to celebrate after a slam dunk against the Cyclones. Photo by Skye Seipp/The Et Cetera
ROCHESTER, MINN — The Harvesters advanced to the 2020 NJCAA Division III national tournament final four after dominating the No. 11 seeded St. Cloud Technical and Community College 96-63 in the quarterfinal matchup.
Though the two teams looked similar on paper, Eastfield won in convincing fashion to claim their spot in today's semifinal round. The Harvesters were executing in all phases for most of the game and continued to run up the score even with a big lead.
At first, it looked like the game was going to be close. The Cyclones started with a 5-0 run and Eastfield's starting guard Calvin Williams went down with an ankle injury within the first two minutes.
However, Eastfield came back to seize the lead after a three-pointer by Williams' replacement guard, Ezekiel Fields, put the Harvesters up 12-11. Fields finished unofficially with 13 points and four steals. Official statistics weren't available after the game due to problems with the system.
"That's what a back-up point guard is for," Fields said. "Just in case the starting point guard gets hurt or isn't doing the job, the back-up is there to do it."
Some big plays helped Eastfield build momentum in the first half including blocks by forward Tyrese Davis and a slam dunk from forward D'Angelo Smith. Guard DaJuan Ridgeway led the team with an unofficial 24 points to go along with nine assists on the night.
Eastfield went on an 8-0 run with seven minutes left in the first period and then an 8-1 run right before halftime to give them a 47-35 advantage at the break.
The Harvesters go over strategies before the NJCAA Division III quarterfinal game against St. Cloud on Thursday. Photo by Skye Seipp/The Et Cetera
"It was just some great calls by the coach," forward Kyree Rogers said. "A lot of the stuff we do wouldn't happen if it wasn't for him and his system. We got a great coach, we got some great players, put two and two together [and] we'll see what happens."
The Harvesters went on a 14-3 run right after halftime. As the second period went on, timely steals, good ball movement and a shutdown of the Cyclones' offense propelled Eastfield to an almost 40-point advantage. The score was never close again.
"We really just pressured them into shooting the ball and doing stuff that they didn't want to do," Fields said. "We were making them play our game."
Ahead of the Harvesters is the No. 2 seeded Mohawk Valley Hawks.
The Hawks secured their spot in the final four after beating No. 10 Nassau 101-91 in their fifteenth 100-point performance of the season. Mohawk Valley is 29-2 with a 17 game winning streak and is ranked second in the country in scoring.
"Good team," Fletcher said. "They got some guys that can shoot, a lefty that can drive and do some good things … They score the ball, they play defense, they do a little bit of everything."
Coach Anthony Fletcher talks with players in the locker room after defeating St. Cloud 96-63 and advancing to the final four on Friday. Photo by Skye Seipp/The Et Cetera
The two teams last met in the 2016 national tournament when Eastfield beat the Hawks in overtime 96-90 in the fourth-place consolation game.
A win against the Hawks means the Harvesters will play again later tonight in the championship game after it was moved up a day due to concerns of the coronavirus outbreak. It may not have been part of the original plans, but Fletcher says it's just the way life is sometimes.
"Bottom line, we just got to go find a way," he said said. "If you don't get it done, you don't get it done. If we get it done, great. We'll be ready."
Eastfield will play Mohawk Valley at 1 p.m. after the 11 a.m. semifinal between No. 1 Sandhills Community College and No. 4 Rochester. The national championship game will take place at 6 p.m.
Coach Anthony Fletcher prepares for the team prayer before the NJCAA Division III quarterfinal game Thursday night. Photo by Skye Seipp/The Et Cetera
D'Angelo Smith secured the jump ball for the Harvesters against St. Cloud. Photo by Skye Seipp/The Et Cetera
Ezekiel Fields defends a St. Cloud player while coach Anthony Fletcher and team mates yell on the sidelines. Photo by Skye Seipp/The Et Cetera
D'Angelo Smith listens to coach Anthony Fletcher talk in the locker room during halftime. Photo by Skye Seipp/The Et Cetera
TaMarcuse Butler takes a shot in Eastfield's 96-63 victory over St. Cloud. Photo by Skye Seipp/The Et Cetera
D'Angelo Smith jumps a slam dunk against the Cyclones on Thursday night. Photo by Skye Seipp/The Et Cetera
Coach Anthony Fletcher goes over plays with team during a timeout in the second period. Photo by Skye Seipp/The Et Cetera
TaMarcus Butler yells at his team mates from the sidelines during the second period of the quarterfinal game against St. Cloud. Photo by Skye Seipp/The Et Cetera
Fletcher looks to cement legacy with title win
DCCCD
Harvesters Basketball
NJCAA Division III
The Et Cetera
Harvesters brace for Cyclones tonight amid changes to tournament scheduling
Coronavirus affects DCCCD
The Et Cetera brings in 52 TIPA awards, first place for overall excellence
April 26, 2020 etcetera News 0
By HARRIET RAMOS @HarrietRamosETC The Et Cetera won first place for Newspaper Overall Excellence in Division 3 from the Texas Intercollegiate Press Association, and Editor-in-Chief Skye Seipp was named both Editor and Reporter of the […]
Danforth remembered for charisma, love of Star Wars
June 13, 2020 etcetera News 0
By HARRIET RAMOS @HarrietRamosETC David Danforth, Eastfield's former Digital Media Technology program coordinator and faculty, will be remembered for his obsession with Star Wars, sense of humor and the impact he had on his students. […]
Rapid Response Team helps students, employees adjust during crisis
April 16, 2020 etcetera Coronavirus, News 0
By HARRIET RAMOS @HarrietRamosETC In response to the COVID-19 crisis, Dallas County Community College District Chancellor Joe May has assembled a Rapid Response Team to address the needs of students, staff and faculty as they […]

redpajama_set_name: RedPajamaCommonCrawl


At 2:45 AM two men broke into the house of a 53 year old woman. Her daughter was sleeping on the couch when the burglers invaded the home.
She quickly ran to her mother's room and they enabled the device to call for help. As the speaker on the device sounded with the emergency operator on the other side, the invaders got startled and fled the scene.


text:
Colin Wilson Fries Up Hump Day
Features, Hump Day Interviews
Midwest-Bred Colin Wilson is a tall drink of water with a mellow demeanor, and a ton of board control. Though plagued with injuries, his positive attitude and Trollhaugen upbringing have enabled him to make his way through the snowboard world as a Burton Knowbuddy and now a Lobster global am. With a slot in the VG am movie due to drop this fall, Colin will continue to turn heads with his controlled tall-guy style and hefty bag of tricks.
How tall are you?
I think I'm about 6'2".
Do you ever wish you were shorter? I feel like snowboarding is one of the few things where being short is an advantage.
No, I think it's kind of cool being a little bit different. I don't think people realize how much harder it is to snowboard when you're tall. It's a lot more to control, but I think that's what's kind of fun about it is the challenge for sure.
You're filming for the VG am movie this year. What can you tell me about that project?
It was pretty spontaneous this year. I really had no plans and I got asked to do it which was really cool. I definitely didn't expect it, but it was definitely a huge opportunity that I was really stoked to get. Just trying to make the best of it. I broke my back earlier this season at the second spot. After six weeks I was back filming with those guys and that was probably the best feeling I could have had. Back on my board, back with the boys.
Who else is filming for the VG movie?
The am movie is Riley Nickerson, Jesse Gouviea, Brady Lem, Jordan Morse, Jordan Small, and I feel like I'm forgetting one but I think that's about it. It's a pretty small crew.
Are they doing a pro movie too?
They're doing a pro movie and they're also doing an Adidas movie, so the Adidas guys are doing that one, Derrek Lever, Mark Wilson, Tommy Gesme and Wiz and all those other dudes that are really good. They're doing their own thing with Colton Feldman. What's cool about the am movie is it's not really it's own thing. All of us riders, whether you're in the pro movie or the Adidas movie, whatever you wanna call it, we all get to film together. I'll go out and film with Jake or Joe and the Minnesota boys and it's all going into different projects but we're all hitting the same spots. It's really cool.
Sounds like we're in for a good Fall of movie drops.
Oh yeah. Riley Nickerson. That's all I'm gonna say, but he's got some stuff for people to see.
This was at Elm Creek. That day we went out and hit a few spots and it was really nice out so wanted to keep snowboarding. We had this idea to go to elm creek and went snowboarding. It was really cool, there was a bunch of kids watching. We all started snowboarding and I feel like it created this energy like it was a band performing. We were just doing trains on everything and people were getting really stoked on it, it was fun.
How did you break your back?
I broke my back on a street rail. I over-pressed a little bit and gutted a kink rail really hard. Pretty much broke my back from the contortion. I had a spinal fracture, I fractured 3 vertebrae in my lower back, broke a few ribs and bruised everything on my inside on the left side. What took the longest to heal was mostly just my organs and my muscles on my side. My back actually felt pretty good after about three weeks.
Was that your worst injury?
Back in 2012, at Superpark 17 at Mt Bachelor, it was day 2, second run. I was bombing down to a step down and there was a photographer standing on top of it. I was bombing, no stopping and he jumps in front of me to stop me. I tried to stop, and I almost came to a stop but didn't and slid off the edge of the step down. I don't know how far I dropped, but way too far to walk away from and completely destroyed my knee. It was like a list of everything in your knee, like a bomb went off. I was out for a whole season and half of the next one. In the meantime, the Knowbuddy program was starting, and Zack Nigro had hit me up right after I had surgery and I told him, I just had surgery, I'm not going to be able to snowboard this whole season. And he's like, nah dude, we know, we got your back. They sent me a snowboard and gear, clothes and everything. He was like take your time, don't worry about it. I spent the following two season trying to mend my knee back into shape and learn how to snowboard again. Ended up having a second surgery to clean up my knee. It took me a little while to get back. It was a big mental thing for sure. It taught me a lot. I got into carpentry at lot more during the off time. When I got back into snowboarding I took it more seriously in the way to taking care of my body and being healthy, but i didn't take it more seriously like it had to be a job or anything like that. I still have a very mellow mentality about snowboarding. The best way to do it is to not take it seriously, that's when you do your best. That was a pretty gnarly injury.
You're from Wisconsin, right?
Yeah I actually grew up in Wisconsin, right by Trollhaugen. I went to the same school as Ethan Deiss, him and I have known each other since we were about 3. We used to wrestle together. We grew up snowboarding together and going to summer school and stuff like that together. Getting in a lot of trouble when we were little. I grew up there until I right after I graduated from High School. Eventually made my way to the Twin Cities and went to school part time and filmed with my friends, the Impaler guys. It was actually Working for the City at the time with Stark and Brett Spurr, Chris Duncan and Sam Duncan, that was pretty cool. I live here now and I love it. I'm close to all the hills for the most part. I'm further away from Trollhaugen then I would like but I still make it there plenty of times a week.
What's the difference between Minnesota and Wisconsin?
Wisconsin, at least where Trollhaugen is, is a a little more redneck I feel like. It's a little more rough around the edges than kids who came from the city. You get a different mix of cultures and kids who were raised different. It has its good and bad but it all kinda works out. Everybody's homies with everybody. There's not a bunch of crews and everyone's not real cliqued up trying to be cooler than everybody else. We all kind feed off of each other.
What was it like growing up riding Trollhaugen. Is that why you're so good?
(laughs) I don't think I'm good. Trollhaugen is my home. I don't live in Wisconsin any more, my family doesn't live there anymore, so when I go to Trollhaugen that's the closest thing I feel to home for sure. I have a lot of history there. I started snowboarding when I was 8, I skied there when I was little. When I got into snowboarding it all changed and I quit playing winter sports and all that. My parents would drop me off every day after school and I would snowboard till it closed.
What was Ethan like as a little kid? Has Burton changed him?
No, Ethan definitely my best friend. He's like a brother to me. I think Burton changed his approach to snowboarding. They're more of a simulated type brand as far as they way they market their riders and their expectations and things like that. I think maybe that has taken a little bit of a toll on Ethan, but he has insane amounts of talent. I don't think we've seen Ethan's best video part yet. I'm pretty excited for what he has to come, he's filming with Absinthe and he's always got something up his sleeve.
While we're on Burton… you were a Knowbuddy, are you excited to be somebody now?
There were so many people that were so bummed on the Knowboddy thing, but I tried to be as optimistic as I could with Burton and the whole Knowbuddy thing. With Ethan being on Burton, I kinda had an idea and a taste of how Burton works with things. I didn't necessarily have this goal to be on Burton for the rest of my life and I didn't have that expectation. I knew it was kind of a stepping stone. It definitely built a foundation for me in snowboarding and helped me with meeting people. I met Bridges and spent a week with the Snowboarder guys when we did an editorial and it was definitely one of the best trips of my life. I got nothing but good things from the whole opportunity. It led me to getting on Lobster and led me to where I am now, which I'm stoked on.
How did you end up getting on Lobster?
A couple people that I didn't know had hit me up. I didn't really know if they were serious or not because the guy that hit me up was French and I couldn't really understand and of his words. I kinda thought it was joke at first and the Haldor hit me up. He spoke really briefly and said he was down to put me on Lobster if I was down. I talked to Diggles and everything kinda came together from there. It was pretty mellow. They don't really have any expectations of me other than to have fun and film a video part.
So Eiki and Haldor don't make you do crazy shit?
No, they don't at all. I actually got the chance to hang with Haldor while he was here in Minnesota. We didn't really get to film together, which I wish we could have, but we were both doing our own projects so we were pretty busy. He came over one night though and we went out in Minneapolis. He was just the raddest dude. That's when it really clicked with my with Lobster, I got this immediate satisfaction. I was just so stoked to be a part of it. All Haldor wants to do is have fun, so I'm excited for what's to come.
"I had just landed on my face off of a wall ride. I imagined what it looked like if someone was on the rope and they saw it happen and I just started laughing, so that's why I'm laughing in the picture."
You work construction as well. What sort of stuff do you do?
I'm an independent contractor, so I work with other contractors and do my own jobs as well. I do new construction and I also do finish carpentry, finishing houses and remodeling old houses. Kinda do a little bit of everything.
Do you do that in the summer?
Yeah and I do it on and off during the snowboard season. When I get time gaps or if the snow is really bad or it's really cold and there's just not a lot of snow. I'll just work that week or in-between trips. For the most part I try to limit it to working spring through fall and taking the winter off.
Do you ever think about moving West?
Yes and no. I always have this itch to wanna move west every time I travel there, but I always get sucked into staying here in Minnesota. I think it's the fact that it's a really good place to be stationed as far as work and the community here and the connections and the resources here. As long as I have the ability to travel to those places more often than not I think that replaces the idea of having to live there. I definitely want to move somewhere else in my lifetime to try other things. As I get older I feel like I'm going to get out of street snowboarding a little more, as my body won't be able to handle as much, and there's definitely other parts of snowboarding that I want to explore as far as backcountry and stuff like that I really want to get into.
Is there anything specific that you want to do in the future?
I've always really liked snowboard parts that have everything in them. Like Keagan and Kazu, they always have street stuff and backcountry stuff and they always have really well rounded parts like they can do anything. That's always what I've followed as far people that try to blaze a new trial and try new things and not just do the same tricks that everyone else does.
What about Mike Cassanova?
He's insane… at snowboarding. He's both, but he's just one of the raddest dudes. I've known him since I was a young dude and I've always idolized him as far as his style and his approach to snowboarding and as far as just being humbled and always having fun. Like don't worry about sponsors and what people tell you to do all the time, just go out and have fun. Put some good music in your ears. It's not always about doing the biggest and gnarliest tricks, it's about being able to do them controlled and with good style and I've always liked the fact that he's a really proper snowboarder, so I've always idolized him in that way.
What are you most hyped on in snowboarding right now?
Honestly, I don't follow snowboarding very closely as far as watching tons of videos and keeping up with that stuff. I'm stoked on what I'm doing right now and the projects that I've been working with. All I wanna do is see my friends' video parts, that's all I really care about.
"That just his last weekend that was the first day I experienced this season of full on spring boarding. That was a really good day at Trollhaugen. We grilled out, it was a textbook bluebird day, grilling in the parking lot, drinking beers with everyone, we didn't film much because we were having too much fun snowboarding, but we managed to get a couple photos."
What's the secret to a good fish fry?
Shore lunch, eggs and panko. You need some wall eye, you batter it all with the shore lunch and then just drop it in the deep fryer or pan fry it. It's the best. But first you gotta get good fish. I like to fry fish that I catch. get a bunch of Walleye or crappie from Northern Minnesota or our cabin and just fry em up. It's pretty cool.
How often do you fish?
In the summer I fish every weekend. Not a lot of people know, I feel like when they come to Minnesota. Some people, not gonna say any names, but some people come and are like this place seems so boring. In the winter when they're filming and it's cold, but they don't understand what its like here in the summer. There's lakes everywhere, there's amazing views and trails and rivers. I have a cabins that I go to, so it's definitely a great place to be.
Everywhere is better in the summer. As a snowboarder I feel bad saying that but summer rules.
That's why it's hard for me to leave. I like being here in the winter. It's close to an airport, there's spots everywhere, there's resorts everywhere, there's friends everywhere and people who wanna film. It's a lot easier to get things done and make things happen, but as soon as you run out of snow as far as filming it's not the most productive place to be.
Did it snow in Minnesota this year?
It did, just a week ago we lost all our snow. We were filming in Duluth last weekend, and they're losing all their snow now it's starting to get warm up there. Minnesota is always tricky. We might end up getting a foot of snow in the next two weeks, but with the weather being the way it is now probably not.
What's next for you? Got any trips planned?
Right now I'm trying to plan a trip to Bear with Jake OE and some guys to possibly do some stuff with Snowboarder mag, but I really just wanna go where there's snow and keep riding my snowboard. I wanna head to Tahoe to keep filming there, they just got a bunch of snow, and then spend some time in Bear, then make my way to Mammoth for Holy Bowly and Superpark. That'll be my next month and we'll see where I end up from there.
Is there anything else you'd like to say to the snowboarding public?
I don't really wanna tell anybody what to do or anything, but I just feel like snowboarding is getting a little carried away with trending and being the coolest thing and being these isolated, solo artists. I feel like it should be more of a team effort. People need to try and help each other out and work together to climb the ladder instead of everyone trying to one up each other and be the coolest person and be part of the coolest crew. Be a little more humble.
Snowboarding as a team sport.
It is 100%. If you think about it you can't go to a spot and film a trick and get it edited into a movie by yourself. You have to have a filmer, you to have people to help you shovel, you have to have people to run a winch or pull a bungee. Not to mention the support that you have from your friends when you're at a spot or when you're snowboarding in general. Going snowboarding by yourself can be fun sometimes, but that's what I love the most about Minnesota. The Minnesota and Wisconsin snowboard communities, you can go snowboarding and you don't have to call anyone. You know there's gonna be somebody there that you know or you're down to shred with. It's pretty cool.
Sponsors, shout outs?
Definitely big thanks to Haldor and Eiki and Diggles and all the dudes at Lobster and Switchback. David and all the snowboarders at Trollhaugen. The whole midwest crew and all my friends from around the US and across the globe, I want to thank all of them for all the support they've given me and making snowboarding what it is. Shout outs to my family and all of my friends, Trollhaugen, Lobster, Switchback, Videograss, the Impaler, Zach Nigro, Alex Andrews and all the dudes at Burton.
March 9, 2016 /18 Comments/by Brooke Geery
Tags: Colin Wilson, lobster snowboards, switchback bindings, trollhaugen, wisconsin
https://yobeat.com/wp-content/uploads/2016/03/IMG_0724.jpg 1068 1600 Brooke Geery http://yobeat.com/wp-content/uploads/2018/05/yobeatdotcomsite.jpg Brooke Geery2016-03-09 06:15:552016-03-09 15:20:03Colin Wilson Fries Up Hump Day
Seasons Enders in Wisconsin
Granite Peak Bans Snowboarding! (from three trails)
Trollhaugen is Open
Trollhaugen-tage
The Helgasons Announce Lobster Snowboards
State of Shred: Wisconsin
Wisconsin's Best Week Ever
Five Days Late with BLS
proof reading is a good thing says:
you should probably hire someone who can proof read for you…
4n_litjesus says:
Typo God for real
Lee key buts says:
Am i dog shit for not knowing about this dude?
mont says:
he's got fire tall guy steeze.
Typo tuesday says:
Gets dropped by a company and still shouts them out? Ok
bobsyuruncle says:
Not burning bridges and paying respect to those who've helped you along the way? Seems legit to me?
Sweaty mike says:
Not giving a shout out is enough to burn a bridge… well actually in the snowboard industry, yea thats probably all it takes
fastest dude at troll
Meaty swike says:
Colin deserves a cooler board sponsor than Lobster.
yep says:
its true. their whole thing just seems so half assed
The thumb down is probably halldor
huh says:
Define cooler…?
Pretty Boys says:
Colin is the shit! Best attitude and nicest guy and also really sick at snowboarding. His WFTC part is amazing.
Also low key Riley Nickerson should be fully hooked up by Adidas.
UPS says:
And rome he shoulda went pro before ozzy imo
strangest3w says:
superpark at mammoth? sick
dblock says:
Heavy, 2 year knee injury and still put out that sick part. Stoked to see whats next
troll vs mt snow says:
team snowboarding would be sick!
my dad would have called him a knucklehead, but in a good way
Austin Leleu & Kyle Walsh Duel Part Claudia Avon FULL PART 2016


Hi guys,yestrdy I had a visit 2 my doctor.she says evrythg is normal,but I did tell her that sometimes my tummy gets stiff n I get mild pain she gave me a medicine called surfaX nd suggested to take it regularly or else I might deliver the baby early. M tensed. I went for the sonography as well my baby's weight is 1663grams it says all normal. I have been suggested more liquids as well..