talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 94b24847bf5cf842c388a710d59b85d256054e87
parent ddf3aca80e577ae0131b0e034ee080810b1fa996
Author: Colin Leroy <colin@colino.net>
Date:   Wed, 28 Nov 2012 11:01:24 +0000

2012-11-28 [colin]	3.9.0cvs27

	* src/imap.c
	* src/news.c
	* src/common/session.c
	* src/common/session.h
		Add keep-alive pings on IMAP and NNTP

Diffstat:
MChangeLog | 8++++++++
MPATCHSETS | 1+
Mconfigure.ac | 2+-
Msrc/common/session.c | 23+++++++++++++++++++++++
Msrc/common/session.h | 3+++
Msrc/imap.c | 30++++++++++++++++++++++++------
Msrc/news.c | 51+++++++++++++++++++++++++++++++++++----------------
7 files changed, 95 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,11 @@ +2012-11-28 [colin] 3.9.0cvs27 + + * src/imap.c + * src/news.c + * src/common/session.c + * src/common/session.h + Add keep-alive pings on IMAP and NNTP + 2012-11-28 [colin] 3.9.0cvs26 * src/imap.c diff --git a/PATCHSETS b/PATCHSETS @@ -4524,3 +4524,4 @@ ( cvs diff -u -r 1.9.2.58 -r 1.9.2.59 src/common/ssl.c; ) > 3.9.0cvs24.patchset ( cvs diff -u -r 1.115.2.264 -r 1.115.2.265 src/main.c; ) > 3.9.0cvs25.patchset ( cvs diff -u -r 1.179.2.268 -r 1.179.2.269 src/imap.c; cvs diff -u -r 1.1.4.126 -r 1.1.4.127 src/etpan/imap-thread.c; cvs diff -u -r 1.1.4.30 -r 1.1.4.31 src/etpan/imap-thread.h; ) > 3.9.0cvs26.patchset +( cvs diff -u -r 1.179.2.269 -r 1.179.2.270 src/imap.c; cvs diff -u -r 1.101.2.73 -r 1.101.2.74 src/news.c; cvs diff -u -r 1.23.2.28 -r 1.23.2.29 src/common/session.c; cvs diff -u -r 1.8.2.21 -r 1.8.2.22 src/common/session.h; ) > 3.9.0cvs27.patchset diff --git a/configure.ac b/configure.ac @@ -12,7 +12,7 @@ MINOR_VERSION=9 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=26 +EXTRA_VERSION=27 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/common/session.c b/src/common/session.c @@ -100,6 +100,8 @@ void session_init(Session *session, const void *prefs_account, gboolean is_smtp) session->data = NULL; session->account = prefs_account; session->is_smtp = is_smtp; + + session->ping_tag = -1; } /*! @@ -215,6 +217,8 @@ void session_destroy(Session *session) cm_return_if_fail(session != NULL); cm_return_if_fail(session->destroy != NULL); + session_register_ping(session, NULL); + session_close(session); session->destroy(session); g_free(session->server); @@ -867,3 +871,22 @@ static gboolean session_write_data_cb(SockInfo *source, return FALSE; } + +void session_register_ping(Session *session, gboolean (*ping_cb)(gpointer data)) +{ + if (!session) + return; + if (session->ping_tag > -1) + g_source_remove(session->ping_tag); + + session->ping_tag = -1; + + if (ping_cb != NULL) +#if GLIB_CHECK_VERSION(2,14,0) + session->ping_tag = + g_timeout_add_seconds(60, ping_cb, session); +#else + session->ping_tag = + g_timeout_add(60*1000, ping_cb, session); +#endif +} diff --git a/src/common/session.h b/src/common/session.h @@ -154,6 +154,8 @@ struct _Session const void *account; gboolean is_smtp; + gint ping_tag; + #ifdef USE_GNUTLS SSLType ssl_type; #endif @@ -207,5 +209,6 @@ gint session_send_data (Session *session, gint session_recv_data (Session *session, guint size, const gchar *terminator); +void session_register_ping(Session *session, gboolean (*ping_cb)(gpointer data)); #endif /* __SESSION_H__ */ diff --git a/src/imap.c b/src/imap.c @@ -544,6 +544,24 @@ static void unlock_session(IMAPSession *session) } } +static gboolean imap_ping(gpointer data) +{ + Session *session = (Session *)data; + IMAPSession *imap_session = IMAP_SESSION(session); + int r; + + if (session->state != SESSION_READY) + return FALSE; + if (imap_session->busy || !imap_session->authenticated) + return TRUE; + + lock_session(imap_session); + r = imap_cmd_noop(imap_session); + unlock_session(imap_session); + + return r == MAILIMAP_NO_ERROR; +} + static void imap_disc_session_destroy(IMAPSession *session) { RemoteFolder *rfolder = NULL; @@ -752,7 +770,7 @@ static void imap_folder_init(Folder *folder, const gchar *name, folder_remote_folder_init((Folder *)folder, name, path); IMAP_FOLDER(folder)->max_set_size = IMAP_SET_MAX_COUNT; IMAP_FOLDER(folder)->search_charset_supported = TRUE; - IMAP_FOLDER(folder)->search_charset = "UTF-8"; + IMAP_FOLDER(folder)->search_charset = conv_get_locale_charset_str_no_utf8(); } static FolderItem *imap_folder_item_new(Folder *folder) @@ -1183,6 +1201,8 @@ static IMAPSession *imap_session_new(Folder * folder, log_message(LOG_PROTOCOL, "IMAP connection is %s-authenticated\n", (session->authenticated) ? "pre" : "un"); + session_register_ping(SESSION(session), imap_ping); + return session; } @@ -2177,9 +2197,9 @@ static void imap_change_search_charset(IMAPFolder *folder) */ if (folder->search_charset_supported) { - if (folder->search_charset && !strcmp(folder->search_charset, "UTF-8")) - folder->search_charset = conv_get_locale_charset_str_no_utf8(); - else if (folder->search_charset && !strcmp(folder->search_charset, conv_get_locale_charset_str_no_utf8())) + if (folder->search_charset && !strcmp(folder->search_charset, conv_get_locale_charset_str_no_utf8())) + folder->search_charset = "UTF-8"; + else if (folder->search_charset && !strcmp(folder->search_charset, "UTF-8")) folder->search_charset = "UTF-7"; else { folder->search_charset = NULL; @@ -3992,8 +4012,6 @@ static gint imap_cmd_noop(IMAPSession *session) return r; } - session->folder_content_changed = FALSE; - if ((exists && exists != session->exists) || (recent && recent != session->recent) || (expunge && expunge != session->expunge) diff --git a/src/news.c b/src/news.c @@ -83,7 +83,7 @@ struct _NewsFolder struct _NewsSession { Session session; - + Folder *folder; gchar *group; }; @@ -282,6 +282,34 @@ static void news_session_destroy(Session *session) g_free(news_session->group); } +static gboolean nntp_ping(gpointer data) +{ + Session *session = (Session *)data; + NewsSession *news_session = NEWS_SESSION(session); + int r; + struct tm lt; + + if (session->state != SESSION_READY || news_folder_locked(news_session->folder)) + return FALSE; + + if ((r = nntp_threaded_date(news_session->folder, &lt)) != NEWSNNTP_NO_ERROR) { + if (r != NEWSNNTP_ERROR_COMMAND_NOT_SUPPORTED && + r != NEWSNNTP_ERROR_COMMAND_NOT_UNDERSTOOD) { + log_warning(LOG_PROTOCOL, _("NNTP connection to %s:%d has been" + " disconnected.\n"), + news_session->folder->account->nntp_server, + news_session->folder->account->set_nntpport ? + news_session->folder->account->nntpport : NNTP_PORT); + REMOTE_FOLDER(news_session->folder)->session = NULL; + session_destroy(session); + return FALSE; + } + } + session_set_access_time(session); + return TRUE; +} + + #ifdef USE_GNUTLS static Session *news_session_new(Folder *folder, const gchar *server, gushort port, const gchar *userid, const gchar *passwd, @@ -320,7 +348,10 @@ static Session *news_session_new(Folder *folder, const gchar *server, gushort po session_destroy(SESSION(session)); return NULL; } - + + session->folder = folder; + + session_register_ping(SESSION(session), nntp_ping); return SESSION(session); } @@ -437,8 +468,6 @@ static Session *news_session_new_for_folder(Folder *folder) static NewsSession *news_session_get(Folder *folder) { RemoteFolder *rfolder = REMOTE_FOLDER(folder); - struct tm lt; - int r; cm_return_val_if_fail(folder != NULL, NULL); cm_return_val_if_fail(FOLDER_CLASS(folder) == &news_class, NULL); @@ -469,18 +498,8 @@ static NewsSession *news_session_get(Folder *folder) return NEWS_SESSION(rfolder->session); } - if ((r = nntp_threaded_date(folder, &lt)) != NEWSNNTP_NO_ERROR) { - if (r != NEWSNNTP_ERROR_COMMAND_NOT_SUPPORTED && - r != NEWSNNTP_ERROR_COMMAND_NOT_UNDERSTOOD) { - log_warning(LOG_PROTOCOL, _("NNTP connection to %s:%d has been" - " disconnected. Reconnecting...\n"), - folder->account->nntp_server, - folder->account->set_nntpport ? - folder->account->nntpport : NNTP_PORT); - session_destroy(rfolder->session); - rfolder->session = news_session_new_for_folder(folder); - } - } + if (!nntp_ping(rfolder->session)) + rfolder->session = news_session_new_for_folder(folder); newsession: if (rfolder->session)