[evolution-data-server] Bug #357175 - IMAP alerts still too intrusive



commit d16797bb2103e0561eb5f18a9bd61c447a44e43d
Author: Milan Crha <mcrha redhat com>
Date:   Thu Dec 22 19:43:29 2011 +0100

    Bug #357175 - IMAP alerts still too intrusive

 camel/providers/imap/camel-imap-command.c |   40 ++++++++++++++++++-----------
 camel/providers/imap/camel-imap-journal.c |    2 +-
 camel/providers/imap/camel-imap-store.c   |    5 +++
 camel/providers/imap/camel-imap-store.h   |    2 +
 4 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/camel/providers/imap/camel-imap-command.c b/camel/providers/imap/camel-imap-command.c
index 7ed6061..741db3a 100644
--- a/camel/providers/imap/camel-imap-command.c
+++ b/camel/providers/imap/camel-imap-command.c
@@ -388,21 +388,31 @@ camel_imap_command_response (CamelImapStore *store,
 			store, respbuf, cancellable, error);
 		if (!respbuf)
 			type = CAMEL_IMAP_RESPONSE_ERROR;
-		else if (!g_ascii_strncasecmp (respbuf, "* OK [ALERT]", 12)
-			 || !g_ascii_strncasecmp (respbuf, "* NO [ALERT]", 12)
-			 || !g_ascii_strncasecmp (respbuf, "* BAD [ALERT]", 13)) {
-			gchar *msg;
-
-			/* for imap ALERT codes, account user host */
-			/* we might get a ']' from a BAD response since we +12,
-			 * but who cares? */
-			msg = g_strdup_printf (
-				_("Alert from IMAP server %s %s:\n%s"),
-				user, host, respbuf + 12);
-			camel_session_alert_user (
-				session, CAMEL_SESSION_ALERT_WARNING,
-				msg, FALSE);
-			g_free (msg);
+		else {
+			gboolean ok_alert = g_ascii_strncasecmp (respbuf, "* OK [ALERT]", 12) == 0;
+			gboolean bad_alert = g_ascii_strncasecmp (respbuf, "* BAD [ALERT]", 13) == 0;
+
+			if (ok_alert || bad_alert || g_ascii_strncasecmp (respbuf, "* NO [ALERT]", 12) == 0) {
+				const gchar *alert;
+				gchar *msg;
+
+				alert = respbuf + 12 + (bad_alert ? 1 : 0);
+
+				if (ok_alert) {
+					if (g_hash_table_lookup (store->known_alerts, alert))
+						break;
+
+					g_hash_table_insert (store->known_alerts, g_strdup (alert), GINT_TO_POINTER (1));
+				}
+
+				msg = g_strdup_printf (
+					_("Alert from IMAP server %s %s:\n%s"),
+					user, host, alert);
+				camel_session_alert_user (
+					session, CAMEL_SESSION_ALERT_WARNING,
+					msg, NULL);
+				g_free (msg);
+			}
 		}
 
 		break;
diff --git a/camel/providers/imap/camel-imap-journal.c b/camel/providers/imap/camel-imap-journal.c
index d486197..31bc483 100644
--- a/camel/providers/imap/camel-imap-journal.c
+++ b/camel/providers/imap/camel-imap-journal.c
@@ -312,7 +312,7 @@ journal_decode_folder (CamelIMAPJournal *journal,
 			camel_session_alert_user (
 				camel_service_get_session (CAMEL_SERVICE (parent_store)),
 				CAMEL_SESSION_ALERT_WARNING,
-				msg, FALSE);
+				msg, NULL);
 			g_free (msg);
 		}
 	}
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index ce1caa9..af02ec1 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -745,6 +745,7 @@ imap_store_finalize (GObject *object)
 	camel_service_disconnect_sync (CAMEL_SERVICE (imap_store), TRUE, NULL);
 
 	g_static_rec_mutex_free (&imap_store->command_and_response_lock);
+	g_hash_table_destroy (imap_store->known_alerts);
 
 	/* Chain up to parent's finalize() method. */
 	G_OBJECT_CLASS (camel_imap_store_parent_class)->finalize (object);
@@ -1025,6 +1026,8 @@ imap_store_disconnect_sync (CamelService *service,
 		store->authtypes = NULL;
 	}
 
+	g_hash_table_remove_all (store->known_alerts);
+
 	if (camel_imap_settings_get_use_namespace (imap_settings))
 		camel_imap_settings_set_namespace (imap_settings, NULL);
 
@@ -1527,6 +1530,8 @@ camel_imap_store_init (CamelImapStore *imap_store)
 	if (imap_tag_prefix > 'Z')
 		imap_tag_prefix = 'A';
 
+	imap_store->known_alerts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
 	g_signal_connect (
 		imap_store, "notify::settings",
 		G_CALLBACK (imap_store_update_store_flags), NULL);
diff --git a/camel/providers/imap/camel-imap-store.h b/camel/providers/imap/camel-imap-store.h
index 0295860..d4f8c12 100644
--- a/camel/providers/imap/camel-imap-store.h
+++ b/camel/providers/imap/camel-imap-store.h
@@ -109,6 +109,8 @@ struct _CamelImapStore {
 	GHashTable *authtypes;
 
 	time_t refresh_stamp;
+
+	GHashTable *known_alerts;
 };
 
 struct _CamelImapStoreClass {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]