Beispiel #1
0
static int mailimap_xlist_send(mailstream * fd,
                               const char * mb, const char * list_mb)
{
  int r;
  
  r = mailimap_token_send(fd, "XLIST");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_mailbox_send(fd, mb);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_list_mailbox_send(fd, list_mb);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  return MAILIMAP_NO_ERROR;
}
Beispiel #2
0
int mailimap_acl_deleteacl_send(mailstream * fd,
        const char * mailbox,
        const char * identifier)
{
  int r;

  r = mailimap_token_send(fd, "DELETEACL");
  if (r != MAILIMAP_NO_ERROR)
	  return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_mailbox_send(fd, mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_identifier_send(fd, identifier);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  return MAILIMAP_NO_ERROR;
}
Beispiel #3
0
int mailimap_acl_listrights_send(mailstream * fd,
        const char * mailbox,
        const char * identifier)
{
  int r;

  r = mailimap_token_send(fd, "LISTRIGHTS");
  if (r != MAILIMAP_NO_ERROR)
	  return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_mailbox_send(fd, mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_identifier_send(fd, identifier);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  return MAILIMAP_NO_ERROR;
}
Beispiel #4
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;
    }
}
Beispiel #5
0
static int mailimap_store_xgmlabels_send(mailstream * fd, struct mailimap_set * set,
                                         int fl_sign, int fl_silent,
                                         struct mailimap_msg_att_xgmlabels * labels)
{
  int r;
  
  r = mailimap_token_send(fd, "STORE");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_set_send(fd, set);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  switch (fl_sign) {
    case 1:
      r = mailimap_char_send(fd, '+');
      if (r != MAILIMAP_NO_ERROR)
        return r;
      break;
    case -1:
      r = mailimap_char_send(fd, '-');
      if (r != MAILIMAP_NO_ERROR)
        return r;
      break;
  }
  
  r = mailimap_token_send(fd, "X-GM-LABELS");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (fl_silent) {
    r = mailimap_token_send(fd, ".SILENT");
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_msg_att_xgmlabels_send(fd, labels);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  return MAILIMAP_NO_ERROR;
}
Beispiel #6
0
int
mailimap_sort_send(mailstream * fd, const char * charset,
                   struct mailimap_sort_key * key, struct mailimap_search_key * searchkey)
{
  int r;
  
  r = mailimap_token_send(fd, "SORT");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_oparenth_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_sort_key_send(fd, key);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_cparenth_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (charset != NULL) {
    r = mailimap_space_send(fd);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    r = mailimap_astring_send(fd, charset);
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (searchkey != NULL) {
    r = mailimap_search_key_send(fd, searchkey);
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  
  
  return MAILIMAP_NO_ERROR;
}
Beispiel #7
0
static int mailimap_id_param_send(mailstream * fd, struct mailimap_id_param * param)
{
  int r;
  
  r = mailimap_astring_send(fd, param->idpa_name);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  if (param->idpa_value == NULL) {
    r = mailimap_token_send(fd, "NIL");
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  else {
    r = mailimap_astring_send(fd, param->idpa_value);
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  
  return MAILIMAP_NO_ERROR;
}
Beispiel #8
0
static int send_fetch_param(mailstream * fd, uint64_t mod_sequence_value, int vanished)
{
  int r;
  
  if (mod_sequence_value == 0)
    return MAILIMAP_NO_ERROR;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_oparenth_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_token_send(fd, "CHANGEDSINCE");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_mod_sequence_value_send(fd, mod_sequence_value);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  if (vanished) {
    r = mailimap_space_send(fd);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    r = mailimap_token_send(fd, "VANISHED");
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  
  r = mailimap_cparenth_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  return MAILIMAP_NO_ERROR;
}
Beispiel #9
0
int mailimap_acl_setacl_send(mailstream * fd,
        const char * mailbox,
        const char * identifier,
        const char * mod_rights)
{
  int r;

  r = mailimap_token_send(fd, "SETACL");
  if (r != MAILIMAP_NO_ERROR)
	  return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_mailbox_send(fd, mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_identifier_send(fd, identifier);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_acl_mod_rights_send(fd, mod_rights);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  return MAILIMAP_NO_ERROR;
}
Beispiel #10
0
static int mailimap_uid_store_xgmlabels_send(mailstream * fd, struct mailimap_set * set,
                                             int fl_sign, int fl_silent,
                                             struct mailimap_msg_att_xgmlabels * labels)
{
  int r;
  
  r = mailimap_token_send(fd, "UID");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  return mailimap_store_xgmlabels_send(fd, set, fl_sign, fl_silent, labels);
}
Beispiel #11
0
int
mailimap_uid_sort_send(mailstream * fd, const char * charset,
                       struct mailimap_sort_key * key, struct mailimap_search_key * searchkey)

{
  int r;
  
  r = mailimap_token_send(fd, "UID");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  return mailimap_sort_send(fd, charset, key, searchkey);
}
Beispiel #12
0
int mailimap_id_send(mailstream * fd, struct mailimap_id_params_list * client_identification)
{
  int r;

  r = mailimap_token_send(fd, "ID");
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_id_params_list_send(fd, client_identification);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  return MAILIMAP_NO_ERROR;
}
Beispiel #13
0
static int mailimap_enable_send(mailstream * fd, struct mailimap_capability_data * capabilities)
{
  int r;
  
  r = mailimap_token_send(fd, "ENABLE");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  r = mailimap_capability_data_send(fd, capabilities);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  
  return MAILIMAP_NO_ERROR;
}
Beispiel #14
0
int mailimap_acl_myrights_send(mailstream * fd,
        const char * mailbox)
{
  int r;

  r = mailimap_token_send(fd, "MYRIGHTS");
  if (r != MAILIMAP_NO_ERROR)
	  return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_mailbox_send(fd, mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  return MAILIMAP_NO_ERROR;
}
Beispiel #15
0
int mailimap_acl_getacl_send(mailstream * fd,
        const char * mailbox)
{
  int r;

  r = mailimap_token_send(fd, "GETACL");
  if (r != MAILIMAP_NO_ERROR)
	  return r;

  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  r = mailimap_mailbox_send(fd, mailbox);
  if (r != MAILIMAP_NO_ERROR)
    return r;

  return MAILIMAP_NO_ERROR;
}
Beispiel #16
0
int mailimap_sort_key_send(mailstream * fd,
                                  struct mailimap_sort_key * key)
{
  int r;
  
  if (key->sortk_is_reverse) {
    r = mailimap_token_send(fd, "REVERSE");
    if (r != MAILIMAP_NO_ERROR)
      return r;
    r = mailimap_space_send(fd);
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  
  switch (key->sortk_type) {
      
    case MAILIMAP_SORT_KEY_ARRIVAL:
      return mailimap_token_send(fd, "ARRIVAL");
    case MAILIMAP_SORT_KEY_CC:
      return mailimap_token_send(fd, "CC");
    case MAILIMAP_SORT_KEY_DATE:
      return mailimap_token_send(fd, "DATE");
    case MAILIMAP_SORT_KEY_FROM:
      return mailimap_token_send(fd, "FROM");
    case MAILIMAP_SORT_KEY_SIZE:
      return mailimap_token_send(fd, "SIZE");
    case MAILIMAP_SORT_KEY_SUBJECT:
      return mailimap_token_send(fd, "SUBJECT");
    case MAILIMAP_SORT_KEY_TO:
      return mailimap_token_send(fd, "TO");
      
    case MAILIMAP_SORT_KEY_MULTIPLE:
      r = mailimap_struct_spaced_list_send(fd, key->sortk_multiple,
                                           (mailimap_struct_sender *)
                                           mailimap_sort_key_send);
      
      return MAILIMAP_NO_ERROR;
    default:
      /* should not happend */
      return MAILIMAP_ERROR_INVAL;
  }
}
Beispiel #17
0
int mailimap_oauth2_authenticate_send(mailimap * session,
                                      const char * auth_user,
                                      const char * access_token)
{
  int r;
  char * ptr;
  char * full_auth_string;
  char * full_auth_string_b64;
  int auth_user_len;
  int access_token_len;
  int full_auth_string_len;
  int res;
  
  full_auth_string = NULL;
  full_auth_string_b64 = NULL;
  
  /* Build client response string */
  auth_user_len = strlen(auth_user);
  access_token_len = strlen(access_token);
  full_auth_string_len = 5 + auth_user_len + 1 + 12 + access_token_len + 2;
  full_auth_string = malloc(full_auth_string_len + 1);
  if (full_auth_string == NULL) {
    res = MAILIMAP_ERROR_MEMORY;
    goto free;
  }
  
  ptr = memcpy(full_auth_string, "user="******"\1auth=Bearer ", 13);
  ptr = memcpy(ptr + 13, access_token, access_token_len);
  ptr = memcpy(ptr + access_token_len, "\1\1\0", 3);
  
  /* Convert to base64 */
  full_auth_string_b64 = encode_base64(full_auth_string, full_auth_string_len);
  if (full_auth_string_b64 == NULL) {
    res = MAILIMAP_ERROR_MEMORY;
    goto free;
  }
  
  r = mailimap_token_send(session->imap_stream, "AUTHENTICATE");
  if (r != MAILIMAP_NO_ERROR) {
    res = r;
    goto free;
  }
  r = mailimap_space_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR) {
    res = r;
    goto free;
  }
  r = mailimap_token_send(session->imap_stream, "XOAUTH2");
  if (r != MAILIMAP_NO_ERROR) {
    res = r;
    goto free;
  }
  r = mailimap_space_send(session->imap_stream);
  if (r != MAILIMAP_NO_ERROR) {
    res = r;
    goto free;
  }
  r = mailimap_astring_send(session->imap_stream, full_auth_string_b64);
  if (r != MAILIMAP_NO_ERROR) {
    res = r;
    goto free;
  }
  
  res = MAILIMAP_NO_ERROR;
  
 free:
  free(full_auth_string);
  free(full_auth_string_b64);
  return res;
}
Beispiel #18
0
int mailimap_select_qresync_send(mailstream * fd, 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)
{
  int r;
  
  /*
  select-param        =  "QRESYNC" SP "(" uidvalidity SP
  mod-sequence-value [SP known-uids]
  [SP seq-match-data] ")"
  */
  
  r = mailimap_token_send(fd, "SELECT");
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_mailbox_send(fd, mb);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
	r = mailimap_token_send(fd, "QRESYNC");
	if (r != MAILIMAP_NO_ERROR)
		return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
	r = mailimap_oparenth_send(fd);
	if (r != MAILIMAP_NO_ERROR)
		return r;
  r = mailimap_number_send(fd, uidvalidity);
	if (r != MAILIMAP_NO_ERROR)
		return r;
  r = mailimap_space_send(fd);
  if (r != MAILIMAP_NO_ERROR)
    return r;
  r = mailimap_mod_sequence_value_send(fd, modseq_value);
	if (r != MAILIMAP_NO_ERROR)
		return r;
	if (known_uids != NULL) {
    r = mailimap_space_send(fd);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    r = mailimap_set_send(fd, known_uids);
    if (r != MAILIMAP_NO_ERROR)
      return r;
  }
  if ((seq_match_data_sequences != NULL) && (seq_match_data_uids != NULL)) {
    r = mailimap_space_send(fd);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    /* seq-match-data      =  "(" known-sequence-set SP known-uid-set ")" */
  	r = mailimap_oparenth_send(fd);
  	if (r != MAILIMAP_NO_ERROR)
  		return r;
    r = mailimap_set_send(fd, seq_match_data_sequences);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    r = mailimap_space_send(fd);
    if (r != MAILIMAP_NO_ERROR)
      return r;
    r = mailimap_set_send(fd, seq_match_data_uids);
    if (r != MAILIMAP_NO_ERROR)
      return r;
  	r = mailimap_cparenth_send(fd);
  	if (r != MAILIMAP_NO_ERROR)
  		return r;
  }
	r = mailimap_cparenth_send(fd);
	if (r != MAILIMAP_NO_ERROR)
		return r;
	
  return MAILIMAP_NO_ERROR;
}