Ejemplo n.º 1
0
int mailimap_fetch_xgmmsgid(mailimap * session,
                            struct mailimap_set * set,
                            clist ** results)
{
    struct mailimap_response * response;
    int r;
    int error_code;
    
    if (session->imap_state != MAILIMAP_STATE_SELECTED)
        return MAILIMAP_ERROR_BAD_STATE;
    
    r = mailimap_send_current_tag(session);
    if (r != MAILIMAP_NO_ERROR)
        return r;
    
    r = mailimap_token_send(session->imap_stream, "FETCH");
    if (r != MAILIMAP_NO_ERROR)
        return r;
    r = mailimap_space_send(session->imap_stream);
    if (r != MAILIMAP_NO_ERROR)
        return r;
    r = mailimap_set_send(session->imap_stream, set);
    if (r != MAILIMAP_NO_ERROR)
        return r;
    r = mailimap_space_send(session->imap_stream);
    if (r != MAILIMAP_NO_ERROR)
        return r;
    
    r = mailimap_token_send(session->imap_stream, "(X-GM-MSGID)");
    if (r != MAILIMAP_NO_ERROR)
        return r;
    
    r = mailimap_crlf_send(session->imap_stream);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    
    if (mailstream_flush(session->imap_stream) == -1)
        return MAILIMAP_ERROR_STREAM;
    
    if (mailimap_read_line(session) == NULL)
        return MAILIMAP_ERROR_STREAM;
   
    r = mailimap_parse_response(session, &response);
    if (r != MAILIMAP_NO_ERROR)
        return r;
    
    error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
    
    *results = response->rsp_cont_req_or_resp_data_list;

    mailimap_response_free(response);
    
    switch (error_code) {
        case MAILIMAP_RESP_COND_STATE_OK:
            return MAILIMAP_NO_ERROR;
            
        default:
            return MAILIMAP_ERROR_FETCH;
    }
}
Ejemplo n.º 2
0
static int send_command_private(mailpop3 * f, char * command, int can_be_published)
{
  ssize_t r;

  mailstream_set_privacy(f->pop3_stream, can_be_published);
  r = mailstream_write(f->pop3_stream, command, strlen(command));
  if (r == -1)
    return -1;

  r = mailstream_flush(f->pop3_stream);
  if (r == -1)
    return -1;

  return 0;
}
Ejemplo n.º 3
0
LIBETPAN_EXPORT
int mailimap_acl_setacl(mailimap * session,
    const char * mailbox,
    const char * identifier,
    const char * mod_rights)
{
  struct mailimap_response * response;
  int r;
  int error_code;

  if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_setacl_send(session->imap_stream,
    mailbox, identifier, mod_rights);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;

  default:
    return MAILIMAP_ERROR_EXTENSION;
  }
}
Ejemplo n.º 4
0
int
mailimap_uid_store_xgmlabels(mailimap * session,
                             struct mailimap_set * set,
                             int fl_sign, int fl_silent,
                             struct mailimap_msg_att_xgmlabels * labels)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  
  if (session->imap_state != MAILIMAP_STATE_SELECTED)
    return MAILIMAP_ERROR_BAD_STATE;
  
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_uid_store_xgmlabels_send(session->imap_stream, set, fl_sign, fl_silent, labels);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  
  mailimap_response_free(response);
  
  switch (error_code) {
    case MAILIMAP_RESP_COND_STATE_OK:
      return MAILIMAP_NO_ERROR;
      
    default:
      return MAILIMAP_ERROR_UID_STORE;
  }
}
Ejemplo n.º 5
0
int mailimap_uid_store_unchangedsince_optional(mailimap * session,
	struct mailimap_set * set, int use_unchangedsince, uint64_t mod_sequence_valzer,
	struct mailimap_store_att_flags * store_att_flags)
{
	struct mailimap_response * response;
	int r;
	int error_code;

	if (session->imap_state != MAILIMAP_STATE_SELECTED)
		return MAILIMAP_ERROR_BAD_STATE;

	r = mailimap_send_current_tag(session);
	if (r != MAILIMAP_NO_ERROR)
		return r;

	r = mailimap_uid_store_send(session->imap_stream, set,
		use_unchangedsince, mod_sequence_valzer, store_att_flags);
	if (r != MAILIMAP_NO_ERROR)
		return r;

	r = mailimap_crlf_send(session->imap_stream);
	if (r != MAILIMAP_NO_ERROR)
		return r;

	if (mailstream_flush(session->imap_stream) == -1)
		return MAILIMAP_ERROR_STREAM;

	if (mailimap_read_line(session) == NULL)
		return MAILIMAP_ERROR_STREAM;

	r = mailimap_parse_response(session, &response);
	if (r != MAILIMAP_NO_ERROR)
		return r;

	error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

	mailimap_response_free(response);

	switch (error_code) {
		case MAILIMAP_RESP_COND_STATE_OK:
		return MAILIMAP_NO_ERROR;

		default:
		return MAILIMAP_ERROR_UID_STORE;
	}
}
Ejemplo n.º 6
0
ssize_t mailstream_write(mailstream * s, const void * buf, size_t count)
{
  int r;

  if (s == NULL)
    return -1;

  if (count + s->write_buffer_len > s->buffer_max_size) {
    r = mailstream_flush(s);
    if (r == -1)
      return -1;

    if (count > s->buffer_max_size)
      return write_direct(s, buf, count);
  }

  return write_to_internal_buffer(s, buf, count);
}
Ejemplo n.º 7
0
static int send_data(mailsmtp * session, const char * message, size_t size)
{
  if (session->smtp_progress_fun != NULL) {
    if (mailstream_send_data_with_context(session->stream, message, size,
                             session->smtp_progress_fun, session->smtp_progress_context) == -1)
      return -1;
  }
  else {
    if (mailstream_send_data(session->stream, message, size,
                             session->progr_rate, session->progr_fun) == -1)
      return -1;
  }

  if (mailstream_flush(session->stream) == -1)
    return -1;

  return 0;
}
Ejemplo n.º 8
0
static inline int mailstream_send_data_progress(mailstream * s, const char * message,
                                                size_t size,
                                                size_t progr_rate,
                                                progress_function * progr_fun,
                                                mailprogress_function * progr_ctx_fun,
                                                void * context)
{
  if (send_data_crlf_progress(s, message, size, 1, progr_rate, progr_fun,
                              progr_ctx_fun, context) == -1)
    goto err;
  
  if (mailstream_write(s, "\r\n.\r\n", 5) == -1)
    goto err;
  
  if (mailstream_flush(s) == -1)
    goto err;
  
  return 0;
  
err:
  return -1;
}
Ejemplo n.º 9
0
LIBETPAN_EXPORT
int mailimap_idle_done(mailimap * session)
{
  int r;
  int error_code;
  struct mailimap_response * response;
  
  r = mailimap_done_send(session);
  if (r != MAILIMAP_NO_ERROR)
	return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
	return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;

  default:
    return MAILIMAP_ERROR_EXTENSION;
  }
}
Ejemplo n.º 10
0
LIBETPAN_EXPORT
int mailimap_idle(mailimap * session)
{
  int r;
  size_t indx;
  struct mailimap_continue_req * cont_req;
  struct mailimap_response * response;
  clist * resp_data_list;
  struct mailimap_parser_context * parser_ctx;
  
  session->imap_selection_info->sel_has_exists = 0;
  session->imap_selection_info->sel_has_recent = 0;
  session->imap_idle_timestamp = time(NULL);
  
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
	return r;
  
  r = mailimap_idle_send(session);
  if (r != MAILIMAP_NO_ERROR)
	return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
	return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  indx = 0;

  parser_ctx = mailimap_parser_context_new(session);
  if (parser_ctx == NULL)
    return MAILIMAP_ERROR_MEMORY;

  r = mailimap_struct_multiple_parse(session->imap_stream,
					session->imap_stream_buffer, parser_ctx,
					&indx,
					&resp_data_list,
					(mailimap_struct_parser *)
					mailimap_response_data_parse,
					(mailimap_struct_destructor *)
					mailimap_response_data_free,
					session->imap_progr_rate, session->imap_progr_fun);
  mailimap_parser_context_free(parser_ctx);
  if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
    return r;
  if (r == MAILIMAP_NO_ERROR) {
    clist_foreach(resp_data_list,
	  (clist_func) mailimap_response_data_free, NULL);
    clist_free(resp_data_list);
  }

  r = mailimap_continue_req_parse(session->imap_stream,
      session->imap_stream_buffer, NULL,
      &indx, &cont_req,
      session->imap_progr_rate, session->imap_progr_fun);
  
  if (r == MAILIMAP_NO_ERROR)
    mailimap_continue_req_free(cont_req);

  if (r == MAILIMAP_ERROR_PARSE) {
    r = mailimap_parse_response(session, &response);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    mailimap_response_free(response);
    
    return MAILIMAP_ERROR_PARSE;
  }
  
  return MAILIMAP_NO_ERROR;
}
Ejemplo n.º 11
0
LIBETPAN_EXPORT
int mailimap_enable(mailimap * session, struct mailimap_capability_data * capabilities,
    struct mailimap_capability_data ** result)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  clistiter * cur;
	struct mailimap_capability_data * cap_data;
  
  if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;
  
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_enable_send(session->imap_stream, capabilities);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
    struct mailimap_extension_data * ext_data;
    struct mailimap_capability_data * cap_data;
    
    ext_data = clist_content(cur);
    if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_ENABLE) {
      continue;
    }
    if (ext_data->ext_type != MAILIMAP_ENABLE_TYPE_ENABLE) {
      continue;
    }
    
    cap_data = ext_data->ext_data;
    ext_data->ext_data = NULL;
		break;
  }
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  
  mailimap_response_free(response);
  
  switch (error_code) {
    case MAILIMAP_RESP_COND_STATE_OK:
  	  * result = cap_data;
      return MAILIMAP_NO_ERROR;
      
    default:
  		mailimap_capability_data_free(cap_data);
      return MAILIMAP_ERROR_EXTENSION;
  }
}
Ejemplo n.º 12
0
LIBETPAN_EXPORT
int
mailimap_sort(mailimap * session, const char * charset,
              struct mailimap_sort_key * key, struct mailimap_search_key * searchkey,
              clist ** result)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  clist * sort_result = NULL;
  clistiter * cur = NULL;
  
  if (session->imap_state != MAILIMAP_STATE_SELECTED)
    return MAILIMAP_ERROR_BAD_STATE;
  
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_sort_send(session->imap_stream, charset, key, searchkey);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  
  for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
       cur != NULL; cur = clist_next(cur)) {
    struct mailimap_extension_data * ext_data;
    
    ext_data = (struct mailimap_extension_data *) clist_content(cur);
    if (ext_data->ext_extension->ext_id == MAILIMAP_EXTENSION_SORT) {
      if (sort_result == NULL) {
        sort_result = ext_data->ext_data;
        ext_data->ext_data = NULL;
        ext_data->ext_type = -1;
      }
    }
  }
  
  clist_foreach(session->imap_response_info->rsp_extension_list,
                (clist_func) mailimap_extension_data_free, NULL);
  clist_free(session->imap_response_info->rsp_extension_list);
  session->imap_response_info->rsp_extension_list = NULL;
  
  if (sort_result == NULL) {
    return MAILIMAP_ERROR_EXTENSION;
  }
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  switch (error_code) {
    case MAILIMAP_RESP_COND_STATE_OK:
      break;
      
    default:
      mailimap_search_result_free(sort_result);
      return MAILIMAP_ERROR_EXTENSION;
  }
  
  mailimap_response_free(response);
  
  * result = sort_result;
  
  return MAILIMAP_NO_ERROR;
}
Ejemplo n.º 13
0
LIBETPAN_EXPORT
int mailimap_xlist(mailimap * session, const char * mb,
                   const char * list_mb, clist ** result)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  clistiter * cur;
  int res;
  clist * result_list;
  
  if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
      (session->imap_state != MAILIMAP_STATE_SELECTED))
    return MAILIMAP_ERROR_BAD_STATE;
  
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_xlist_send(session->imap_stream, mb, list_mb);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  result_list = clist_new();
  if (result_list == NULL) {
    res = MAILIMAP_ERROR_MEMORY;
    goto free_response;
  }
  
  for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
    struct mailimap_extension_data * ext_data;
    struct mailimap_mailbox_list * mailbox_list;
    
    ext_data = clist_content(cur);
    if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_XLIST) {
      continue;
    }
    if (ext_data->ext_type != MAILIMAP_XLIST_TYPE_XLIST) {
      continue;
    }
    
    mailbox_list = ext_data->ext_data;
    r = clist_append(result_list, mailbox_list);
    if (r < 0) {
      res = MAILIMAP_ERROR_MEMORY;
      goto free_list;
    }
    ext_data->ext_data = NULL;
  }
  
  * result = result_list;
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  
  mailimap_response_free(response);
  
  switch (error_code) {
    case MAILIMAP_RESP_COND_STATE_OK:
      return MAILIMAP_NO_ERROR;
      
    default:
      return MAILIMAP_ERROR_LIST;
  }
  
free_list:
  for(cur = clist_begin(result_list) ; cur != NULL ; cur = clist_next(cur)) {
    struct mailimap_mailbox_list * mailbox_list;
    
    mailbox_list = clist_content(cur);
    mailimap_mailbox_list_free(mailbox_list);
  }
  clist_free(result_list);
free_response:
  mailimap_response_free(response);
err:
  return res;
}
Ejemplo n.º 14
0
LIBETPAN_EXPORT
int mailimap_oauth2_authenticate(mailimap * session, const char *auth_user, const char * access_token)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  size_t indx;
  struct mailimap_continue_req * cont_req;
  
  if (session->imap_state != MAILIMAP_STATE_NON_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;
  
  mailstream_set_privacy(session->imap_stream, 0);
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR) {
    mailstream_set_privacy(session->imap_stream, 1);
    return r;
  }
  
  r = mailimap_oauth2_authenticate_send(session, auth_user, access_token);
  if (r != MAILIMAP_NO_ERROR) {
    mailstream_set_privacy(session->imap_stream, 1);
    return r;
  }
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR) {
    mailstream_set_privacy(session->imap_stream, 1);
    return r;
  }
  
  if (mailstream_flush(session->imap_stream) == -1) {
    mailstream_set_privacy(session->imap_stream, 1);
    return MAILIMAP_ERROR_STREAM;
  }
  mailstream_set_privacy(session->imap_stream, 1);
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  indx = 0;
  r = mailimap_continue_req_parse(session->imap_stream,
      session->imap_stream_buffer,
      &indx, &cont_req,
      session->imap_progr_rate, session->imap_progr_fun);
  if (r == MAILIMAP_NO_ERROR) {
    mailimap_continue_req_free(cont_req);
    
    /* There's probably an error, send an empty line as acknowledgement. */
    r = mailimap_crlf_send(session->imap_stream);
    if (r != MAILIMAP_NO_ERROR) {
      return r;
    }
  
    if (mailstream_flush(session->imap_stream) == -1) {
      return MAILIMAP_ERROR_STREAM;
    }
  }
  else if (r == MAILIMAP_ERROR_PARSE) {
    r = MAILIMAP_NO_ERROR;
  }

  if (r != MAILIMAP_NO_ERROR) {
    return r;
  }

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  
  mailimap_response_free(response);
  
  switch (error_code) {
    case MAILIMAP_RESP_COND_STATE_OK:
      session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
      return MAILIMAP_NO_ERROR;
      
    default:
      return MAILIMAP_ERROR_LOGIN;
  }
}
Ejemplo n.º 15
0
int mailimap_uid_fetch_qresync_vanished(mailimap * session,
  struct mailimap_set * set,
  struct mailimap_fetch_type * fetch_type, uint64_t mod_sequence_value, int vanished,
  clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished)
{
  struct mailimap_response * response;
  int r;
  int error_code;

  if (session->imap_state != MAILIMAP_STATE_SELECTED)
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_uid_fetch_send(session->imap_stream, set, fetch_type);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = send_fetch_param(session->imap_stream, mod_sequence_value, vanished);
  if (r != MAILIMAP_NO_ERROR)
    return r;
	
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR) {
    return r;
  }
  
  * fetch_result = session->imap_response_info->rsp_fetch_list;
  session->imap_response_info->rsp_fetch_list = NULL;
  if (p_vanished != NULL) {
    * p_vanished = get_vanished(session);
  }

  if (clist_count(* fetch_result) == 0) {
    error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  }
  else {
    error_code = MAILIMAP_RESP_COND_STATE_OK;
  }
  
  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;

  default:
    if (* fetch_result != NULL) {
      mailimap_fetch_list_free(* fetch_result);
    }
    if (p_vanished != NULL) {
      if (* p_vanished != NULL) {
        mailimap_qresync_vanished_free(* p_vanished);
      }
    }
    return MAILIMAP_ERROR_UID_FETCH;
  }
}
Ejemplo n.º 16
0
int mailimap_select_qresync(mailimap * session, const char * mb,
  uint32_t uidvalidity, uint64_t modseq_value,
  struct mailimap_set * known_uids,
  struct mailimap_set * seq_match_data_sequences,
  struct mailimap_set * seq_match_data_uids,
  clist ** fetch_result, struct mailimap_qresync_vanished ** p_vanished,
  uint64_t * p_mod_sequence_value)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  uint64_t mod_sequence_value;

  if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
      (session->imap_state != MAILIMAP_STATE_SELECTED))
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_select_qresync_send(session->imap_stream, mb, uidvalidity, modseq_value,
    known_uids, seq_match_data_sequences, seq_match_data_uids);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  if (session->imap_selection_info != NULL)
    mailimap_selection_info_free(session->imap_selection_info);
  session->imap_selection_info = mailimap_selection_info_new();

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  * fetch_result = session->imap_response_info->rsp_fetch_list;
  session->imap_response_info->rsp_fetch_list = NULL;
  if (p_vanished != NULL) {
    * p_vanished = get_vanished(session);
  }

  mod_sequence_value = get_mod_sequence_value(session);
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    session->imap_state = MAILIMAP_STATE_SELECTED;
    * p_mod_sequence_value = mod_sequence_value;
    return MAILIMAP_NO_ERROR;

  default:
    mailimap_selection_info_free(session->imap_selection_info);
    session->imap_selection_info = NULL;
    session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
    * p_mod_sequence_value = mod_sequence_value;
    if (* fetch_result != NULL) {
      mailimap_fetch_list_free(* fetch_result);
    }
    if (p_vanished != NULL) {
      if (* p_vanished != NULL) {
        mailimap_qresync_vanished_free(* p_vanished);
      }
    }
    return MAILIMAP_ERROR_SELECT;
  }
}
Ejemplo n.º 17
0
static int search_modseq(mailimap * session, const char * charset,
                         struct mailimap_search_key * key,
                         int uid_enabled, int literalplus_enabled,
                         clist ** result, uint64_t * p_mod_sequence_value)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  struct mailimap_condstore_search * search_data;
  clistiter * cur;
  
  if (session->imap_state != MAILIMAP_STATE_SELECTED)
    return MAILIMAP_ERROR_BAD_STATE;
  
  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (literalplus_enabled) {
    if (uid_enabled) {
      r = mailimap_uid_search_literalplus_send(session->imap_stream, charset, key);
    }
    else {
      r = mailimap_search_literalplus_send(session->imap_stream, charset, key);
    }
  }
  else {
    if (uid_enabled) {
      r = mailimap_uid_search_send(session->imap_stream, charset, key);
    }
    else {
      r = mailimap_search_send(session->imap_stream, charset, key);
    }
  }
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;
  
  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;
  
  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  search_data = NULL;
  for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
    struct mailimap_extension_data * ext_data;
    
    ext_data = clist_content(cur);
    if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
      continue;
    }
    if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA) {
      continue;
    }
    
    search_data = ext_data->ext_data;
    ext_data->ext_data = NULL;
    break;
  }
  
  if (search_data == NULL) {
    * result = session->imap_response_info->rsp_search_result;
    if (p_mod_sequence_value != NULL) {
      * p_mod_sequence_value = 0;
    }
    session->imap_response_info->rsp_search_result = NULL;
  }
  else {
    * result = search_data->cs_search_result;
    * p_mod_sequence_value = search_data->cs_modseq_value;
    search_data->cs_search_result = NULL;
    mailimap_condstore_search_free(search_data);
  }
  
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  
  mailimap_response_free(response);
  
  switch (error_code) {
    case MAILIMAP_RESP_COND_STATE_OK:
      return MAILIMAP_NO_ERROR;
      
    default:
      if (uid_enabled) {
        return MAILIMAP_ERROR_UID_SEARCH;
      }
      else {
        return MAILIMAP_ERROR_SEARCH;
      }
  }
}
Ejemplo n.º 18
0
LIBETPAN_EXPORT
int mailimap_acl_getacl(mailimap * session,
    const char * mailbox,
    clist ** result)
{
  struct mailimap_response * response;
  struct mailimap_extension_data * ext_data;
  clistiter * cur;
  int r;
  int error_code;

  if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_getacl_send(session->imap_stream,
    mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  * result = clist_new();
  if (* result == NULL)
    return MAILIMAP_ERROR_MEMORY;

  /* get all acl_data received and copy it to result */
  for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
    cur != NULL; cur = clist_next(cur)) {
      ext_data = (struct mailimap_extension_data *) clist_content(cur);
      if (
        ext_data->ext_extension->ext_id == MAILIMAP_EXTENSION_ACL &&
        ext_data->ext_type == MAILIMAP_ACL_TYPE_ACL_DATA) {
          r = clist_append((* result), ext_data->ext_data);
          if (r != 0)
            return MAILIMAP_ERROR_MEMORY;

          ext_data->ext_data = NULL;
          ext_data->ext_type = -1;
      }
  }

  clist_foreach(session->imap_response_info->rsp_extension_list,
        (clist_func) mailimap_extension_data_free, NULL);
  clist_free(session->imap_response_info->rsp_extension_list);
  session->imap_response_info->rsp_extension_list = NULL;

  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;

  default:
    return MAILIMAP_ERROR_EXTENSION;
  }
}
Ejemplo n.º 19
0
int mailimap_examine_condstore_optional(mailimap * session, const char * mb,
  int condstore, uint64_t * p_mod_sequence_value)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  uint64_t mod_sequence_value;
  clistiter * cur;

  if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
      (session->imap_state != MAILIMAP_STATE_SELECTED))
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_examine_send(session->imap_stream, mb, condstore);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  if (session->imap_selection_info != NULL)
    mailimap_selection_info_free(session->imap_selection_info);
  session->imap_selection_info = mailimap_selection_info_new();

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  mod_sequence_value = 0;
  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
    struct mailimap_extension_data * ext_data;
    struct mailimap_condstore_resptextcode * resptextcode;
    
    ext_data = clist_content(cur);
    if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
      continue;
    }
    if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_RESP_TEXT_CODE) {
      continue;
    }
    
    resptextcode = ext_data->ext_data;
    switch (resptextcode->cs_type) {
      case MAILIMAP_CONDSTORE_RESPTEXTCODE_HIGHESTMODSEQ:
      mod_sequence_value = resptextcode->cs_data.cs_modseq_value;
      break;
      case MAILIMAP_CONDSTORE_RESPTEXTCODE_NOMODSEQ:
      mod_sequence_value = 0;
      break;
    }
  }

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    session->imap_state = MAILIMAP_STATE_SELECTED;
    * p_mod_sequence_value = mod_sequence_value;
    return MAILIMAP_NO_ERROR;

  default:
    mailimap_selection_info_free(session->imap_selection_info);
    session->imap_selection_info = NULL;
    session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
    * p_mod_sequence_value = mod_sequence_value;
    return MAILIMAP_ERROR_EXAMINE;
  }
}
Ejemplo n.º 20
0
/*
  this is one of the imap commands annotatemore adds. setannotation is
  yet to be implemented.
*/
LIBETPAN_EXPORT
int mailimap_annotatemore_getannotation(mailimap * session,
    const char * list_mb,
    struct mailimap_annotatemore_entry_match_list * entries,
    struct mailimap_annotatemore_attrib_match_list * attribs,
    clist ** result)
{
  struct mailimap_response * response;
  struct mailimap_extension_data * ext_data;
  clistiter * cur;
  int r;
  int error_code;

  if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_annotatemore_getannotation_send(session->imap_stream,
    list_mb, entries, attribs);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  * result = clist_new();
  if (* result == NULL)
    return MAILIMAP_ERROR_MEMORY;

  /* copy all annotate_data to the result-list */
  for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
    cur != NULL; cur = clist_next(cur)) {
      ext_data = (struct mailimap_extension_data *) clist_content(cur);
      if (
        ext_data->ext_extension->ext_id == MAILIMAP_EXTENSION_ANNOTATEMORE &&
        ext_data->ext_type == MAILIMAP_ANNOTATEMORE_TYPE_ANNOTATE_DATA) {
          r = clist_append((* result), ext_data->ext_data);
          if (r != 0)
            return MAILIMAP_ERROR_MEMORY;

          ext_data->ext_data = NULL;
          ext_data->ext_type = -1;
      }
  }

  clist_foreach(session->imap_response_info->rsp_extension_list,
        (clist_func) mailimap_extension_data_free, NULL);
  clist_free(session->imap_response_info->rsp_extension_list);
  session->imap_response_info->rsp_extension_list = NULL;

  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;

  default:
    return MAILIMAP_ERROR_EXTENSION;
  }
}
Ejemplo n.º 21
0
LIBETPAN_EXPORT
int mailimap_annotatemore_setannotation(mailimap * session,
    const char * list_mb,
    struct mailimap_annotatemore_entry_att_list * en_att,
    int * result)
{
  struct mailimap_response * response;
  int r;
  int error_code;
  clistiter * cur;
  struct mailimap_extension_data * ext_data;

  if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_annotatemore_setannotation_send(session->imap_stream,
    list_mb, en_att);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;
    break;
  case MAILIMAP_RESP_COND_STATE_NO:
    * result = MAILIMAP_ANNOTATEMORE_RESP_TEXT_CODE_UNSPECIFIED;
    if (session->imap_response_info->rsp_extension_list != NULL) {
      for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
        cur != NULL; cur = clist_next(cur)) {
          ext_data = clist_content(cur);
          if ((ext_data->ext_extension->ext_id == 
                MAILIMAP_EXTENSION_ANNOTATEMORE) &&
              (ext_data->ext_type ==
                MAILIMAP_ANNOTATEMORE_TYPE_RESP_TEXT_CODE))
          {
        * result = * ((int *)ext_data->ext_data);
          }
      }
    }
    return MAILIMAP_ERROR_EXTENSION;
    break;
  default:
    * result = MAILIMAP_ANNOTATEMORE_RESP_TEXT_CODE_UNSPECIFIED;
    return MAILIMAP_ERROR_EXTENSION;
    break;
  }
}
Ejemplo n.º 22
0
LIBETPAN_EXPORT
int mailimap_acl_myrights(mailimap * session,
    const char * mailbox,
    struct mailimap_acl_myrights_data ** result)
{
  struct mailimap_response * response;
  struct mailimap_extension_data * ext_data;
  clistiter * cur;
  int r;
  int error_code;

  if (session->imap_state != MAILIMAP_STATE_AUTHENTICATED)
    return MAILIMAP_ERROR_BAD_STATE;

  r = mailimap_send_current_tag(session);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_myrights_send(session->imap_stream, mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_crlf_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (mailstream_flush(session->imap_stream) == -1)
    return MAILIMAP_ERROR_STREAM;

  if (mailimap_read_line(session) == NULL)
    return MAILIMAP_ERROR_STREAM;

  r = mailimap_parse_response(session, &response);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  * result = NULL;

  /* in rsp_extension_list there is at most one myrights_data */
  for (cur = clist_begin(session->imap_response_info->rsp_extension_list);
    cur != NULL; cur = clist_next(cur)) {
      ext_data = (struct mailimap_extension_data *) clist_content(cur);
      if (
        ext_data->ext_extension->ext_id == MAILIMAP_EXTENSION_ACL &&
        ext_data->ext_type == MAILIMAP_ACL_TYPE_MYRIGHTS_DATA) {
          * result = (struct mailimap_acl_myrights_data *)ext_data->ext_data;
          ext_data->ext_data = NULL;
          /* remove the element from rsp_extension_list */
          clist_delete(session->imap_response_info->rsp_extension_list, cur);
          mailimap_extension_data_free(ext_data);

          break;
      }
  }

  clist_foreach(session->imap_response_info->rsp_extension_list,
        (clist_func) mailimap_extension_data_free, NULL);
  clist_free(session->imap_response_info->rsp_extension_list);
  session->imap_response_info->rsp_extension_list = NULL;

  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;

  mailimap_response_free(response);

  /* if there is no data to be returned, return MAILIMAP_ERROR_EXTENSION */
  if (* result == NULL)
    return MAILIMAP_ERROR_EXTENSION;

  switch (error_code) {
  case MAILIMAP_RESP_COND_STATE_OK:
    return MAILIMAP_NO_ERROR;

  default:
    return MAILIMAP_ERROR_EXTENSION;
  }
}