Beispiel #1
0
static NewsSession *news_session_get(Folder *folder)
{
	RemoteFolder *rfolder = REMOTE_FOLDER(folder);
	
	cm_return_val_if_fail(folder != NULL, NULL);
	cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL);
	cm_return_val_if_fail(folder->account != NULL, NULL);

	if (prefs_common.work_offline && 
	    !inc_offline_should_override(FALSE,
		_("Claws Mail needs network access in order "
		  "to access the News server."))) {
		return NULL;
	}

	if (!rfolder->session) {
		rfolder->session = news_session_new_for_folder(folder);
		session_register_ping(SESSION(rfolder->session), nntp_ping);
		return NEWS_SESSION(rfolder->session);
	}

	/* Handle port change (also ssl/nossl change) without needing to
	 * restart application. */
	if (rfolder->session->port != folder->account->nntpport) {
		session_destroy(rfolder->session);
		rfolder->session = news_session_new_for_folder(folder);
		session_register_ping(SESSION(rfolder->session), nntp_ping);
		goto newsession;
	}
	
	if (time(NULL) - rfolder->session->last_access_time <
		SESSION_TIMEOUT_INTERVAL) {
		return NEWS_SESSION(rfolder->session);
	}

	if (!nntp_ping(rfolder->session)) {
		rfolder->session = news_session_new_for_folder(folder);
		session_register_ping(SESSION(rfolder->session), nntp_ping);
	}

newsession:
	if (rfolder->session)
		session_set_access_time(rfolder->session);

	return NEWS_SESSION(rfolder->session);
}
Beispiel #2
0
static void sieve_session_reset(SieveSession *session)
{
	PrefsAccount *account = session->account;
	SieveAccountConfig *config = sieve_prefs_account_get_config(account);
	gboolean reuse_auth = (config->auth == SIEVEAUTH_REUSE);

	g_slist_free_full(session->send_queue, (GDestroyNotify)command_abort);

	session_disconnect(SESSION(session));

	SESSION(session)->ssl_cert_auto_accept = account->ssl_certs_auto_accept;
	SESSION(session)->nonblocking = account->use_nonblocking_ssl;
	session->authenticated = FALSE;
	session->current_cmd = NULL;
	session->send_queue = NULL;
	session->state = SIEVE_CAPABILITIES;
#ifdef USE_GNUTLS
	session->tls_init_done = FALSE;
#endif
	session->avail_auth_type = 0;
	session->auth_type = 0;
	session->config = config;
	session->host = config->use_host ? config->host : account->recv_server;
	session->port = config->use_port ? config->port : SIEVE_PORT;
	session->user = reuse_auth ? account->userid : session->config->userid;
	session->forced_auth_type = config->auth_type;
	session_register_ping(SESSION(session), sieve_ping);

	if (session->pass)
		g_free(session->pass);
	if (config->auth == SIEVEAUTH_NONE) {
		session->pass = NULL;
	} else if (reuse_auth && account->passwd) {
		session->pass = g_strdup(account->passwd);
	} else if (config->passwd && config->passwd[0]) {
		session->pass = g_strdup(config->passwd);
	} else if (password_get(session->user, session->host, "sieve",
				session->port, &session->pass)) {
	} else {
		session->pass = input_dialog_query_password_keep(session->host,
				session->user, &(session->pass));
	}
	if (!session->pass) {
		session->pass = g_strdup("");
		session->use_auth = FALSE;
	} else {
		session->use_auth = TRUE;
	}

#ifdef USE_GNUTLS
	SESSION(session)->ssl_type =
		(config->tls_type == SIEVE_TLS_NO) ? SSL_NONE : SSL_STARTTLS;
#endif
}