[Commits] [SCM] claws branch, master, updated. 3.9.3-108-g2c8ed95

mones at claws-mail.org mones at claws-mail.org
Mon Apr 28 02:01:33 CEST 2014


The branch master of project "claws" (Claws Mail) has been updated
       via  2c8ed95f7080187c10adb816d4d5d60fcd355fd4 (commit)
       via  e33f136772170acc1d4cd8c370f355bea67cf3b0 (commit)
       via  5d33b9375ad270c0b9bb40afaf3967b60c57d183 (commit)
       via  9a8c64d48a0dcacffcfafb1d9759614516cb28cb (commit)
      from  a9aae8f1aded116587af78fa7882b213dd9908fb (commit)


- Log -----------------------------------------------------------------
commit 2c8ed95f7080187c10adb816d4d5d60fcd355fd4
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Apr 27 03:10:22 2014 +0200

    Add libravatar plugin to documentation

diff --git a/manual/plugins.xml b/manual/plugins.xml
index 9778a96..5d8346b 100644
--- a/manual/plugins.xml
+++ b/manual/plugins.xml
@@ -166,6 +166,18 @@
 	</listitem>
       </varlistentry>
       <varlistentry>
+	<term>Libravatar</term>
+	<listitem>
+	  <para>
+	Enables displaying avatar images associated to user profiles in
+	libravatar.org or user's avatar enabled domains.
+	More information: <ulink
+	url="http://www.claws-mail.org/plugin.php?plugin=libravatar"
+	>www.claws-mail.org/plugin.php?plugin=libravatar</ulink>
+	  </para>
+	</listitem>
+      </varlistentry>
+      <varlistentry>
 	<term>Mail Archiver</term>
 	<listitem>
 	  <para>

commit e33f136772170acc1d4cd8c370f355bea67cf3b0
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Apr 27 02:51:39 2014 +0200

    Implement support for federated avatars

diff --git a/src/plugins/libravatar/TODO b/src/plugins/libravatar/TODO
index 581c4f1..f64281f 100644
--- a/src/plugins/libravatar/TODO
+++ b/src/plugins/libravatar/TODO
@@ -1,13 +1,8 @@
 Enhancements, possibilities and random ideas
 --------------------------------------------
 
-- Retrieve federated domain records (!)
 - Support federated IDN domains (??) (Claws Mail itself doesn't support it
   http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id=1670)
-- Domain validation when searching for federated avatars, or at least
-  exclude some domains (eg.: localhost) (???)
-- Check box to enable/disable domain validation (?)
-  http://data.iana.org/TLD/tlds-alpha-by-domain.txt may be useful.
 - Button for checking custom default URL is not 404 (!) check on apply (?)
 - Make it run in cache-less mode if cache dir cannot be created (??)
 - Only cache "mystery man" once for all hashes (what if changes) (?)
diff --git a/src/plugins/libravatar/libravatar.c b/src/plugins/libravatar/libravatar.c
index abb2d9a..48d3bf3 100644
--- a/src/plugins/libravatar/libravatar.c
+++ b/src/plugins/libravatar/libravatar.c
@@ -31,6 +31,7 @@
 #include "libravatar.h"
 #include "libravatar_prefs.h"
 #include "libravatar_missing.h"
+#include "libravatar_federation.h"
 #include "prefs_common.h"
 #include "procheader.h"
 #include "procmsg.h"
@@ -76,10 +77,21 @@ static gboolean libravatar_header_update_hook(gpointer source, gpointer data)
 
 static gchar *federated_base_url_from_address(const gchar *address)
 {
-	/*
-	   TODO: no federation supported right now
-	   Details on http://wiki.libravatar.org/running_your_own/
-	 */
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	gchar *base_url = NULL;
+
+	if (!libravatarprefs.allow_federated) {
+		debug_print("federated domains disabled by configuration\n");
+		goto default_url;
+	}
+
+	base_url = federated_url_for_address(address);
+	if (base_url != NULL) {
+		return base_url;
+	}
+
+default_url:
+#endif
 	return g_strdup(libravatarprefs.base_url);
 }
 

commit 5d33b9375ad270c0b9bb40afaf3967b60c57d183
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Apr 27 02:47:54 2014 +0200

    Allow disabling federated domains

diff --git a/src/plugins/libravatar/libravatar_prefs.c b/src/plugins/libravatar/libravatar_prefs.c
index d72ba93..b85cfa4 100644
--- a/src/plugins/libravatar/libravatar_prefs.c
+++ b/src/plugins/libravatar/libravatar_prefs.c
@@ -53,6 +53,9 @@ struct LibravatarPrefsPage
 	GtkWidget *defm_radio[NUM_DEF_BUTTONS];
 	GtkWidget *defm_url_text;
 	GtkWidget *allow_redirects_check;
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	GtkWidget *allow_federated_check;
+#endif
 };
 
 struct LibravatarPrefsPage libravatarprefs_page;
@@ -76,6 +79,11 @@ static PrefParam param[] = {
 	{ "allow_redirects", "TRUE",
 	  &libravatarprefs.allow_redirects,
           P_BOOL, NULL, NULL, NULL },
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	{ "allow_federated", "TRUE",
+	  &libravatarprefs.allow_federated,
+          P_BOOL, NULL, NULL, NULL },
+#endif
 	{NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
@@ -175,7 +183,6 @@ static GtkWidget *p_create_frame_missing(struct LibravatarPrefsPage *page)
 	GtkWidget *vbox, *radio[NUM_DEF_BUTTONS], *hbox, *label, *entry;
 	gboolean enable = FALSE;
 	int i, e = 0;
-	
 	gchar *radio_label[] = {
 		_("None"),
 		_("Mystery man"),
@@ -239,19 +246,31 @@ static GtkWidget *p_create_frame_missing(struct LibravatarPrefsPage *page)
 
 static GtkWidget *p_create_frame_network(struct LibravatarPrefsPage *page)
 {
-	GtkWidget *vbox, *checkbox;
+	GtkWidget *vbox, *chk_redirects;
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	GtkWidget *chk_federated;
+#endif
 
 	vbox =  gtk_vbox_new(FALSE, 6);
 
-	checkbox = create_checkbox(_("_Allow redirects to other sites"),
+	chk_redirects = create_checkbox(_("_Allow redirects to other sites"),
 				   _("Follow redirect responses received from "
 				     "libravatar server to other avatar "
 				     "services like gravatar.com"));
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox),
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_redirects),
 				     libravatarprefs.allow_redirects);
-	page->allow_redirects_check = checkbox;
-
-	gtk_box_pack_start(GTK_BOX(vbox), checkbox, FALSE, FALSE, 0);
+	page->allow_redirects_check = chk_redirects;
+	gtk_box_pack_start(GTK_BOX(vbox), chk_redirects, FALSE, FALSE, 0);
+
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	chk_federated = create_checkbox(_("_Enable federated servers"),
+				_("Try to get avatar from sender's domain "
+				  "libravatar server"));
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_federated),
+				     libravatarprefs.allow_federated);
+	page->allow_federated_check = chk_federated;
+	gtk_box_pack_start(GTK_BOX(vbox), chk_federated, FALSE, FALSE, 0);
+#endif
 
 	return vbox;
 }
@@ -273,6 +292,7 @@ static GtkWidget *p_create_frame_network(struct LibravatarPrefsPage *page)
   └──────────────────────────────────────────────────────┘
   ┌─Network──────────────────────────────────────────────┐
   │ [✔] Allow redirects                                  │
+  │ [✔] Federated servers                                │
   └──────────────────────────────────────────────────────┘
  */
 static void libravatar_prefs_create_widget_func(PrefsPage * _page,
@@ -362,6 +382,11 @@ static void libravatar_prefs_save_func(PrefsPage * _page)
 	/* redirects */
 	libravatarprefs.allow_redirects = gtk_toggle_button_get_active(
 		GTK_TOGGLE_BUTTON(page->allow_redirects_check));
+	/* federation */
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	libravatarprefs.allow_federated = gtk_toggle_button_get_active(
+		GTK_TOGGLE_BUTTON(page->allow_federated_check));
+#endif
 
 	libravatar_save_config();
 }
diff --git a/src/plugins/libravatar/libravatar_prefs.h b/src/plugins/libravatar/libravatar_prefs.h
index 791c440..84985ea 100644
--- a/src/plugins/libravatar/libravatar_prefs.h
+++ b/src/plugins/libravatar/libravatar_prefs.h
@@ -45,6 +45,9 @@ struct _LibravatarPrefs
 	guint		default_mode;
 	gchar		*default_mode_url;
 	gboolean	allow_redirects;
+#if (defined USE_GNUTLS && GLIB_CHECK_VERSION(2,22,0))
+	gboolean	allow_federated;
+#endif
 };
 
 extern LibravatarPrefs libravatarprefs;

commit 9a8c64d48a0dcacffcfafb1d9759614516cb28cb
Author: Ricardo Mones <ricardo at mones.org>
Date:   Sun Apr 27 02:45:18 2014 +0200

    Retrieve avatar service URL from address

diff --git a/src/plugins/libravatar/Makefile.am b/src/plugins/libravatar/Makefile.am
index 8d8d4db..0e64236 100644
--- a/src/plugins/libravatar/Makefile.am
+++ b/src/plugins/libravatar/Makefile.am
@@ -73,5 +73,6 @@ libravatar_la_CPPFLAGS = \
 libravatar_la_SOURCES = \
 	libravatar.c libravatar.h \
 	libravatar_prefs.c libravatar_prefs.h \
-	libravatar_missing.c libravatar_missing.h
+	libravatar_missing.c libravatar_missing.h \
+	libravatar_federation.c libravatar_federation.h
 
diff --git a/src/plugins/libravatar/libravatar_federation.c b/src/plugins/libravatar/libravatar_federation.c
new file mode 100644
index 0000000..106fdfb
--- /dev/null
+++ b/src/plugins/libravatar/libravatar_federation.c
@@ -0,0 +1,147 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2014 Ricardo Mones
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include "libravatar_federation.h"
+#include "libravatar_prefs.h"
+#include "utils.h"
+
+#define MISSING "x"
+
+static GHashTable *federated = NULL;
+
+/**
+ * Get the associated avatar URL for a domain.
+ *
+ * @param domain Domain to get the URL for.
+ *
+ * @return The avatar URL for the domain or NULL if not found.
+ */
+static gchar *get_federated_url_for_domain(const gchar *domain)
+{
+	gchar *found;
+
+	if (federated == NULL) {
+		return NULL;
+	}
+
+	found = (gchar *) g_hash_table_lookup(federated, domain);
+
+	if (found != NULL)
+		debug_print("cached avatar url for domain %s found: %s\n", domain, found);
+	else	
+		debug_print("cached avatar url for domain %s not found\n", domain);
+
+	return found;
+}
+
+/**
+ * Adds a URL for a domain.
+ *
+ * @param url  The computed avatar URL.
+ * @param domain  Associated domain.
+ */
+static void add_federated_url_for_domain(const gchar *url, const gchar *domain)
+{
+	if (url == NULL)
+		return;
+
+	if (federated == NULL)
+		federated = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+	debug_print("new cached avatar url for domain %s: %s\n", domain, url);
+	g_hash_table_insert(federated, g_strdup(domain), g_strdup(url)); 
+}
+
+/**
+ * Retrieves the federated URL for a given email address.
+ *
+ * @param address  The email address.
+ *
+ * @return The avatar URL for the domain of the address. 
+ */
+gchar *federated_url_for_address(const gchar *address)
+{
+	gchar *domain = NULL, *last = NULL, *addr = NULL, *url = NULL;
+	gchar *host = NULL;
+	guint16 port = 0;
+
+	if (address == NULL || *address == '\0')
+		goto invalid_addr;
+
+	addr = g_strdup(address);
+        domain = strchr(addr, '@');
+	if (domain == NULL)
+		goto invalid_addr;
+ 
+	++domain;
+   	if (strlen(domain) < 5)
+		goto invalid_addr;
+
+	last = domain;
+	while (*last != '\0' && *last != ' ' && *last != '\t' && *last != '>')
+		++last;
+	*last = '\0';
+
+	/* try cached domains */
+	url = get_federated_url_for_domain(domain);
+	if (url != NULL) {
+		g_free(addr);
+		if (!strcmp(url, MISSING)) {
+			return g_strdup(libravatarprefs.base_url);
+		}
+		return g_strdup(url);
+	}
+
+	/* not cached, try secure service first */
+	if (auto_configure_service("avatars-sec", domain, &host, &port)) {
+		if (port != 443) {
+			url = g_strdup_printf("https://%s:%d/avatar", host, port);
+		} else {
+			url = g_strdup_printf("https://%s/avatar", host);
+		}
+	} else { /* try standard one if no secure service available */
+		if (auto_configure_service("avatars", domain, &host, &port)) {
+			if (port != 80) {
+				url = g_strdup_printf("http://%s:%d/avatar", host, port);
+			} else {
+				url = g_strdup_printf("http://%s/avatar", host);
+			}
+		} else {
+			debug_print("libravatar federated domain for %s not found\n", domain);
+		}
+	}
+	if (url != NULL) {
+		add_federated_url_for_domain(url, domain);
+	} else {
+		add_federated_url_for_domain(MISSING, domain);
+	}
+
+	g_free(addr);
+	return url;
+
+invalid_addr:
+	if (addr != NULL)
+		g_free(addr);
+
+	debug_print("invalid address for libravatar federated domain\n");
+	return NULL;
+}
+
diff --git a/src/plugins/libravatar/libravatar_federation.h b/src/plugins/libravatar/libravatar_federation.h
new file mode 100644
index 0000000..e34015d
--- /dev/null
+++ b/src/plugins/libravatar/libravatar_federation.h
@@ -0,0 +1,27 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail Team
+ * Copyright (C) 2014 Ricardo Mones
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIBRAVATAR_FEDERATION_H
+#define __LIBRAVATAR_FEDERATION_H
+
+#include <glib.h>
+
+gchar *federated_url_for_address	(const gchar *address);
+
+#endif

-----------------------------------------------------------------------

Summary of changes:
 manual/plugins.xml                                 |   12 ++
 src/plugins/libravatar/Makefile.am                 |    3 +-
 src/plugins/libravatar/TODO                        |    5 -
 src/plugins/libravatar/libravatar.c                |   20 ++-
 src/plugins/libravatar/libravatar_federation.c     |  147 ++++++++++++++++++++
 ...ibravatar_missing.h => libravatar_federation.h} |   16 +--
 src/plugins/libravatar/libravatar_prefs.c          |   39 +++++-
 src/plugins/libravatar/libravatar_prefs.h          |    3 +
 8 files changed, 215 insertions(+), 30 deletions(-)
 create mode 100644 src/plugins/libravatar/libravatar_federation.c
 copy src/plugins/libravatar/{libravatar_missing.h => libravatar_federation.h} (62%)


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list