commit 88a058f0a73d03f049de24f7729c9466f162d0f5
parent 8489f8f0376925e0a425b4b06a9184e57972430f
Author: Ricardo Mones <mones@claws-mail.org>
Date: Fri, 13 Jun 2008 13:56:06 +0000
2008-06-13 [mones] 3.4.0cvs95
* src/Makefile.am
* src/autofaces.c ** NEW FILE **
* src/autofaces.h ** NEW FILE **
* src/compose.c
Allow setting Faces and X-Faces globally and per-account
from configuration files under ~/.claws-mail/autofaces
Diffstat:
7 files changed, 180 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,12 @@
+2008-06-13 [mones] 3.4.0cvs95
+
+ * src/Makefile.am
+ * src/autofaces.c ** NEW FILE **
+ * src/autofaces.h ** NEW FILE **
+ * src/compose.c
+ Allow setting Faces and X-Faces globally and per-account
+ from configuration files under ~/.claws-mail/autofaces
+
2008-06-13 [holger] 3.4.0cvs94
* .cvsignore
diff --git a/PATCHSETS b/PATCHSETS
@@ -3390,3 +3390,4 @@
( cvs diff -u -r 1.1.2.10 -r 1.1.2.11 src/addrduplicates.c; cvs diff -u -r 1.9.2.22 -r 1.9.2.23 src/addressadd.c; cvs diff -u -r 1.60.2.117 -r 1.60.2.118 src/addressbook.c; cvs diff -u -r 1.1.2.10 -r 1.1.2.11 src/addressbook_foldersel.c; cvs diff -u -r 1.11.2.18 -r 1.11.2.19 src/editgroup.c; cvs diff -u -r 1.26.2.35 -r 1.26.2.36 src/foldersel.c; ) > 3.4.0cvs92.patchset
( cvs diff -u -r 1.60.2.118 -r 1.60.2.119 src/addressbook.c; ) > 3.4.0cvs93.patchset
( cvs diff -u -r 1.8.2.6 -r 1.8.2.7 .cvsignore; cvs diff -u -r 1.1.2.56 -r 1.1.2.57 src/imap_gtk.c; cvs diff -u -r 1.2.2.30 -r 1.2.2.31 src/mh_gtk.c; cvs diff -u -r 1.204.2.171 -r 1.204.2.172 src/prefs_common.c; cvs diff -u -r 1.103.2.109 -r 1.103.2.110 src/prefs_common.h; cvs diff -u -r 1.2.2.27 -r 1.2.2.28 src/gtk/inputdialog.c; cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/gtk/inputdialog.h; ) > 3.4.0cvs94.patchset
+( cvs diff -u -r 1.155.2.87 -r 1.155.2.88 src/Makefile.am; diff -u /dev/null src/autofaces.c; diff -u /dev/null src/autofaces.h; cvs diff -u -r 1.382.2.452 -r 1.382.2.453 src/compose.c; ) > 3.4.0cvs95.patchset
diff --git a/configure.ac b/configure.ac
@@ -11,7 +11,7 @@ MINOR_VERSION=4
MICRO_VERSION=0
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=94
+EXTRA_VERSION=95
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
diff --git a/src/Makefile.am b/src/Makefile.am
@@ -171,7 +171,8 @@ claws_mail_SOURCES = \
unmime.c \
uri_opener.c \
vcard.c \
- wizard.c
+ wizard.c \
+ autofaces.c
claws_mailincludedir = $(pkgincludedir)
claws_mailinclude_HEADERS = \
@@ -319,7 +320,8 @@ claws_mailinclude_HEADERS = \
unmime.h \
uri_opener.h \
vcard.h \
- wizard.h
+ wizard.h \
+ autofaces.h
BUILT_SOURCES = \
matcher_parser_parse.h \
diff --git a/src/autofaces.c b/src/autofaces.c
@@ -0,0 +1,118 @@
+
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2008 Ricardo Mones and the Claws Mail team
+ *
+ * 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/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "defs.h"
+
+#include "utils.h"
+#include "autofaces.h"
+
+gint get_content_for_any_face(gchar *buf, gint len, gchar *anyname, gint maxlen)
+{
+ FILE *xfp;
+ gchar *xfile;
+ gint lastc;
+
+ xfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR, AUTOFACES_DIR,
+ G_DIR_SEPARATOR_S, anyname, NULL);
+ buf[0] = '\0';
+ if ((xfp = fopen(xfile, "rb")) == NULL) {
+ g_free(xfile);
+ g_warning("header content file '%s' not found\n", anyname);
+ return -1;
+ }
+ if (fgets(buf, (len < maxlen)? len: maxlen, xfp) == NULL) {
+ fclose(xfp);
+ g_free(xfile);
+ g_warning("header content file '%s' read failure\n", anyname);
+ return -2;
+ }
+ lastc = strlen(buf) - 1; /* remove trailing \n */
+ buf[lastc] = (buf[lastc] == '\n')? '\0': buf[lastc];
+ fclose(xfp);
+ g_free(xfile);
+
+ return 0;
+}
+
+gchar * get_any_face_filename_for_account(gchar *facetype, gchar *accountname)
+{
+ gchar *name = NULL;
+ gchar *what = NULL;
+ if (facetype == NULL || accountname == NULL)
+ return NULL;
+ if (*facetype == '\0' || *accountname == '\0')
+ return NULL;
+ what = name = g_strdup_printf("%s.%s", facetype, accountname);
+ while (*what) {
+ switch (*what) {
+ case '/':
+ case '\\':
+ case '<':
+ case '>':
+ case ':':
+ case '?':
+ case '*':
+ *what = '_';
+ break;
+ default:
+ if (*what <= ' ') {
+ *what = '_';
+ }
+ break;
+ }
+ ++what;
+ }
+ return name;
+}
+
+gint get_default_xface(gchar *buf, gint len) {
+ return get_content_for_any_face(buf, len, "xface", MAX_XFACE_LEN);
+}
+
+gint get_account_xface(gchar *buf, gint len, gchar *name) {
+ gchar *filename = get_any_face_filename_for_account("xface", name);
+ if (filename) {
+ gint result = get_content_for_any_face(buf, len, filename, MAX_XFACE_LEN);
+ g_free(filename);
+ return result;
+ }
+ g_warning("header xface filename invalid\n");
+ return -1;
+}
+
+gint get_default_face(gchar *buf, gint len) {
+ return get_content_for_any_face(buf, len, "face", MAX_FACE_LEN);
+}
+
+gint get_account_face(gchar *buf, gint len, gchar *name) {
+ gchar *filename = get_any_face_filename_for_account("face", name);
+ if (filename) {
+ gint result = get_content_for_any_face(buf, len, filename, MAX_FACE_LEN);
+ g_free(filename);
+ return result;
+ }
+ g_warning("header face filename invalid\n");
+ return -1;
+}
+
diff --git a/src/autofaces.h b/src/autofaces.h
@@ -0,0 +1,32 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2008 Ricardo Mones and the Claws Mail team
+ *
+ * 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 __AUTOFACES_H__
+#define __AUTOFACES_H__
+
+#define MAX_XFACE_LEN 990
+#define MAX_FACE_LEN 990
+#define AUTOFACES_DIR "autofaces"
+
+gint get_default_xface (gchar *buf, gint len);
+gint get_default_face (gchar *buf, gint len);
+gint get_account_xface (gchar *buf, gint len, gchar *name);
+gint get_account_face (gchar *buf, gint len, gchar *name);
+
+#endif /* __AUTOFACES_H__ */
diff --git a/src/compose.c b/src/compose.c
@@ -124,6 +124,7 @@
#include "hooks.h"
#include "privacy.h"
#include "timing.h"
+#include "autofaces.h"
enum
{
@@ -6025,6 +6026,20 @@ static gchar *compose_get_header(Compose *compose)
}
}
+ /* Automatic Faces and X-Faces */
+ if (get_account_xface (buf, sizeof(buf), compose->account->account_name) == 0) {
+ g_string_append_printf(header, "X-Face: %s\n", buf);
+ }
+ else if (get_default_xface (buf, sizeof(buf)) == 0) {
+ g_string_append_printf(header, "X-Face: %s\n", buf);
+ }
+ if (get_account_face (buf, sizeof(buf), compose->account->account_name) == 0) {
+ g_string_append_printf(header, "Face: %s\n", buf);
+ }
+ else if (get_default_face (buf, sizeof(buf)) == 0) {
+ g_string_append_printf(header, "Face: %s\n", buf);
+ }
+
/* PRIORITY */
switch (compose->priority) {
case PRIORITY_HIGHEST: g_string_append_printf(header, "Importance: high\n"