Fix bug #3574: Template addressing
[claws.git] / src / customheader.c
blob554fb7d858b461cc0c8f85e9c1fa29c2da93dd26
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include <glib.h>
26 #include <string.h>
27 #include <stdlib.h>
29 #include "customheader.h"
30 #include "utils.h"
33 gchar *custom_header_get_str(CustomHeader *ch)
35 return g_strdup_printf("%i:%s: %s",
36 ch->account_id, ch->name,
37 ch->value ? ch->value : "");
40 CustomHeader *custom_header_read_str(const gchar *buf)
42 CustomHeader *ch;
43 gchar *account_id_str;
44 gint id;
45 gchar *name;
46 gchar *value;
47 gchar *tmp;
49 Xstrdup_a(tmp, buf, return NULL);
51 account_id_str = tmp;
53 name = strchr(account_id_str, ':');
54 if (!name)
55 return NULL;
56 else {
57 gchar *endp;
59 *name++ = '\0';
60 id = strtol(account_id_str, &endp, 10);
61 if (*endp != '\0') return NULL;
64 value = strchr(name, ':');
65 if (!value) return NULL;
67 *value++ = '\0';
69 g_strstrip(name);
70 g_strstrip(value);
72 ch = g_new0(CustomHeader, 1);
73 ch->account_id = id;
74 ch->name = *name ? g_strdup(name) : NULL;
75 ch->value = *value ? g_strdup(value) : NULL;
77 return ch;
80 CustomHeader *custom_header_find(GSList *header_list, const gchar *header)
82 GSList *cur;
83 CustomHeader *chdr;
85 for (cur = header_list; cur != NULL; cur = cur->next) {
86 chdr = (CustomHeader *)cur->data;
87 if (!g_utf8_collate(chdr->name, header))
88 return chdr;
91 return NULL;
94 void custom_header_free(CustomHeader *ch)
96 if (!ch) return;
98 g_free(ch->name);
99 g_free(ch->value);
100 g_free(ch);
103 gboolean custom_header_is_allowed(const gchar *header)
105 cm_return_val_if_fail(header != NULL, FALSE);
107 if (g_ascii_strcasecmp(header, "Date") != 0 &&
108 g_ascii_strcasecmp(header, "From") != 0 &&
109 g_ascii_strcasecmp(header, "To") != 0 &&
110 /* g_ascii_strcasecmp(header, "Sender") != 0 && */
111 g_ascii_strcasecmp(header, "Message-ID") != 0 &&
112 g_ascii_strcasecmp(header, "In-Reply-To") != 0 &&
113 g_ascii_strcasecmp(header, "References") != 0 &&
114 g_ascii_strcasecmp(header, "MIME-Version") != 0 &&
115 g_ascii_strcasecmp(header, "Content-Type") != 0 &&
116 g_ascii_strcasecmp(header, "Content-Transfer-Encoding")
117 != 0)
118 return TRUE;
120 return FALSE;