int mailsmtp_connect(mailsmtp * session, mailstream * s) { int code; session->stream = s; mailstream_set_logger(s, smtp_logger, session); code = read_response(session); switch (code) { case 220: return MAILSMTP_NO_ERROR; case 554: session->stream = NULL; mailstream_close(s); return MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE; case 0: session->stream = NULL; mailstream_close(s); return MAILSMTP_ERROR_STREAM; default: session->stream = NULL; mailstream_close(s); return MAILSMTP_ERROR_UNEXPECTED_CODE; } }
int newsnntp_quit(newsnntp * f) { char command[NNTP_STRING_SIZE]; char * response; int r; int res; if (f->nntp_stream == NULL) return NEWSNNTP_ERROR_BAD_STATE; snprintf(command, NNTP_STRING_SIZE, "QUIT\r\n"); r = send_command(f, command); if (r == -1) { res = NEWSNNTP_ERROR_STREAM; goto close; } response = read_line(f); if (response == NULL) { res = NEWSNNTP_ERROR_STREAM; goto close; } parse_response(f, response); res = NEWSNNTP_NO_ERROR; close: mailstream_close(f->nntp_stream); f->nntp_stream = NULL; return res; }
int mailsmtp_quit(mailsmtp * session) { char command[SMTP_STRING_SIZE]; int r; int res; snprintf(command, SMTP_STRING_SIZE, "QUIT\r\n"); r = send_command(session, command); if (r == -1) { res = MAILSMTP_ERROR_STREAM; goto close; } r = read_response(session); if (r == 0) { res = MAILSMTP_ERROR_STREAM; goto close; } res = MAILSMTP_NO_ERROR; close: mailstream_close(session->stream); session->stream = NULL; return res; }
int mailpop3_quit(mailpop3 * f) { char command[POP3_STRING_SIZE]; char * response; int r; int res; if ((f->pop3_state != POP3_STATE_AUTHORIZATION) && (f->pop3_state != POP3_STATE_TRANSACTION)) { res = MAILPOP3_ERROR_BAD_STATE; goto close; } snprintf(command, POP3_STRING_SIZE, "QUIT\r\n"); r = send_command(f, command); if (r == -1) { res = MAILPOP3_ERROR_STREAM; goto close; } response = read_line(f); if (response == NULL) { res = MAILPOP3_ERROR_STREAM; goto close; } if (parse_response(f, response) == RESPONSE_OK) { res = MAILPOP3_NO_ERROR; } else { res = MAILPOP3_ERROR_QUIT_FAILED; } res = MAILPOP3_NO_ERROR; close: if (f->pop3_stream != NULL) { mailstream_close(f->pop3_stream); f->pop3_stream = NULL; } if (f->pop3_timestamp != NULL) { free(f->pop3_timestamp); f->pop3_timestamp = NULL; } if (f->pop3_msg_tab != NULL) { mailpop3_msg_info_tab_free(f->pop3_msg_tab); f->pop3_msg_tab = NULL; } f->pop3_state = POP3_STATE_DISCONNECTED; return res; }
static void delete_nntp(Folder *folder, newsnntp *nntp) { chashdatum key; key.data = &folder; key.len = sizeof(folder); chash_delete(session_hash, &key, NULL); key.data = &nntp; key.len = sizeof(nntp); if (nntp && nntp->nntp_stream) { /* we don't want libetpan to logout */ mailstream_close(nntp->nntp_stream); nntp->nntp_stream = NULL; } debug_print("removing newsnntp %p\n", nntp); newsnntp_free(nntp); }
static int mailpop3_cfssl_connect_ssl_level(mailpop3 * f, const char * server, uint16_t port, int ssl_level) { mailstream * stream; int r; stream = mailstream_cfstream_open_timeout(server, port, f->pop3_timeout); if (stream == NULL) { return MAILPOP3_ERROR_CONNECTION_REFUSED; } mailstream_cfstream_set_ssl_level(stream, ssl_level); mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_NO_VERIFICATION); r = mailstream_cfstream_set_ssl_enabled(stream, 1); if (r < 0) { mailstream_close(stream); return MAILPOP3_ERROR_SSL; } return mailpop3_connect(f, stream); }
static int newsnntp_cfssl_connect_ssl_level(newsnntp * f, const char * server, uint16_t port, int ssl_level) { mailstream * stream; int r; stream = mailstream_cfstream_open(server, port); if (stream == NULL) { return NEWSNNTP_ERROR_CONNECTION_REFUSED; } mailstream_cfstream_set_ssl_level(stream, ssl_level); mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_NO_VERIFICATION); r = mailstream_cfstream_set_ssl_enabled(stream, 1); if (r < 0) { mailstream_close(stream); return NEWSNNTP_ERROR_SSL; } return newsnntp_connect(f, stream); }
static int mailimap_cfssl_connect_voip_ssl_level(mailimap * f, const char * server, uint16_t port, int voip_enabled, int ssl_level) { mailstream * stream; int r; stream = mailstream_cfstream_open_voip_timeout(server, port, voip_enabled, f->imap_timeout); if (stream == NULL) { return MAILIMAP_ERROR_CONNECTION_REFUSED; } mailstream_cfstream_set_ssl_level(stream, ssl_level); mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_DISABLE_VALIDATES_CERTIFICATE_CHAIN); r = mailstream_cfstream_set_ssl_enabled(stream, 1); if (r < 0) { mailstream_close(stream); return MAILIMAP_ERROR_SSL; } return mailimap_connect(f, stream); }
static int mailsmtp_cfssl_connect(mailsmtp * session, const char * server, uint16_t port) { mailstream * stream; int r; stream = mailstream_cfstream_open(server, port); if (stream == NULL) { return MAILSMTP_ERROR_CONNECTION_REFUSED; } mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_NO_VERIFICATION); r = mailstream_cfstream_set_ssl_enabled(stream, 1); if (r < 0) { mailstream_close(stream); return MAILSMTP_ERROR_SSL; } return mailsmtp_connect(session, stream); }
int mailsmtp_data_message_quit(mailsmtp * session, const char * message, size_t size) { int r; r = send_data(session, message, size); if (r == -1) return MAILSMTP_ERROR_STREAM; r = send_quit(session); r = read_response(session); mailstream_close(session->stream); session->stream = NULL; switch(r) { case 250: return MAILSMTP_NO_ERROR; case 552: return MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION; case 554: return MAILSMTP_ERROR_TRANSACTION_FAILED; case 451: return MAILSMTP_ERROR_IN_PROCESSING; case 452: return MAILSMTP_ERROR_INSUFFICIENT_SYSTEM_STORAGE; case 0: return MAILSMTP_ERROR_STREAM; default: return MAILSMTP_ERROR_UNEXPECTED_CODE; } }
int mailsmtp_quit(mailsmtp * session) { int r; int res; if (session->stream == NULL) return MAILSMTP_NO_ERROR; r = send_quit(session); if (r != MAILSMTP_NO_ERROR) { res = r; goto close; } res = MAILSMTP_NO_ERROR; close: mailstream_close(session->stream); session->stream = NULL; return res; }
int mailstorage_generic_connect_with_local_address(mailsession_driver * driver, char * servername, uint16_t port, char * local_address, uint16_t local_port, char * command, int connection_type, int cache_function_id, char * cache_directory, int flags_function_id, char * flags_directory, mailsession ** result) { int r; int res; mailstream * stream; int fd; mailsession * session; int connect_result; switch (connection_type) { case CONNECTION_TYPE_PLAIN: case CONNECTION_TYPE_TRY_STARTTLS: case CONNECTION_TYPE_STARTTLS: case CONNECTION_TYPE_TLS: fd = mail_tcp_connect_with_local_address(servername, port, local_address, local_port); if (fd == -1) { res = MAIL_ERROR_CONNECT; goto err; } break; case CONNECTION_TYPE_COMMAND: case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: case CONNECTION_TYPE_COMMAND_STARTTLS: case CONNECTION_TYPE_COMMAND_TLS: fd = subcommand_connect(command, servername, port); break; default: fd = -1; break; } if (fd == -1) { res = MAIL_ERROR_INVAL; goto err; } switch (connection_type) { case CONNECTION_TYPE_PLAIN: case CONNECTION_TYPE_TRY_STARTTLS: case CONNECTION_TYPE_STARTTLS: case CONNECTION_TYPE_COMMAND: case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: case CONNECTION_TYPE_COMMAND_STARTTLS: stream = mailstream_socket_open(fd); break; case CONNECTION_TYPE_TLS: case CONNECTION_TYPE_COMMAND_TLS: stream = mailstream_ssl_open(fd); break; default: stream = NULL; break; } if (stream == NULL) { res = MAIL_ERROR_STREAM; close(fd); goto err; } session = mailsession_new(driver); if (session == NULL) { res = MAIL_ERROR_MEMORY; goto close_stream; } if (cache_directory != NULL) { char cache_directory_server[PATH_MAX]; snprintf(cache_directory_server, PATH_MAX, "%s/%s", cache_directory, servername); r = mailsession_parameters(session, cache_function_id, cache_directory_server); if (r != MAIL_NO_ERROR) { res = r; goto close_stream; } } if (flags_directory != NULL) { char flags_directory_server[PATH_MAX]; snprintf(flags_directory_server, PATH_MAX, "%s/%s", flags_directory, servername); r = mailsession_parameters(session, flags_function_id, flags_directory_server); if (r != MAIL_NO_ERROR) { res = r; goto close_stream; } } r = mailsession_connect_stream(session, stream); switch (r) { case MAIL_NO_ERROR_NON_AUTHENTICATED: case MAIL_NO_ERROR_AUTHENTICATED: case MAIL_NO_ERROR: break; default: res = r; goto free; } connect_result = r; switch (connection_type) { case CONNECTION_TYPE_TRY_STARTTLS: case CONNECTION_TYPE_COMMAND_TRY_STARTTLS: r = mailsession_starttls(session); if ((r != MAIL_NO_ERROR) && (r != MAIL_ERROR_NO_TLS)) { res = r; goto free; } break; case CONNECTION_TYPE_STARTTLS: case CONNECTION_TYPE_COMMAND_STARTTLS: r = mailsession_starttls(session); if (r != MAIL_NO_ERROR) { res = r; goto free; } } * result = session; return connect_result; close_stream: mailstream_close(stream); free: mailsession_free(session); err: return res; }