2007-08-27 [colin] 2.10.0cvs179
[claws.git] / src / customheader.c
blobfb03a8455049447f2cb9ad6f75f30e47b08329c1
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 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 #endif
24 #include <glib.h>
25 #include <string.h>
26 #include <stdlib.h>
28 #include "customheader.h"
29 #include "utils.h"
32 gchar *custom_header_get_str(CustomHeader *ch)
34 return g_strdup_printf("%i:%s: %s",
35 ch->account_id, ch->name,
36 ch->value ? ch->value : "");
39 CustomHeader *custom_header_read_str(const gchar *buf)
41 CustomHeader *ch;
42 gchar *account_id_str;
43 gint id;
44 gchar *name;
45 gchar *value;
46 gchar *tmp;
48 Xstrdup_a(tmp, buf, return NULL);
50 account_id_str = tmp;
52 name = strchr(account_id_str, ':');
53 if (!name)
54 return NULL;
55 else {
56 gchar *endp;
58 *name++ = '\0';
59 id = strtol(account_id_str, &endp, 10);
60 if (*endp != '\0') return NULL;
63 value = strchr(name, ':');
64 if (!value) return NULL;
66 *value++ = '\0';
68 g_strstrip(name);
69 g_strstrip(value);
71 ch = g_new0(CustomHeader, 1);
72 ch->account_id = id;
73 ch->name = *name ? g_strdup(name) : NULL;
74 ch->value = *value ? g_strdup(value) : NULL;
76 return ch;
79 CustomHeader *custom_header_find(GSList *header_list, const gchar *header)
81 GSList *cur;
82 CustomHeader *chdr;
84 for (cur = header_list; cur != NULL; cur = cur->next) {
85 chdr = (CustomHeader *)cur->data;
86 if (!g_utf8_collate(chdr->name, header))
87 return chdr;
90 return NULL;
93 void custom_header_free(CustomHeader *ch)
95 if (!ch) return;
97 g_free(ch->name);
98 g_free(ch->value);
99 g_free(ch);
102 gboolean custom_header_is_allowed(const gchar *header)
104 g_return_val_if_fail(header != NULL, FALSE);
106 if (g_ascii_strcasecmp(header, "Date") != 0 &&
107 g_ascii_strcasecmp(header, "From") != 0 &&
108 g_ascii_strcasecmp(header, "To") != 0 &&
109 /* g_ascii_strcasecmp(header, "Sender") != 0 && */
110 g_ascii_strcasecmp(header, "Message-ID") != 0 &&
111 g_ascii_strcasecmp(header, "In-Reply-To") != 0 &&
112 g_ascii_strcasecmp(header, "References") != 0 &&
113 g_ascii_strcasecmp(header, "Mime-Version") != 0 &&
114 g_ascii_strcasecmp(header, "Content-Type") != 0 &&
115 g_ascii_strcasecmp(header, "Content-Transfer-Encoding")
116 != 0)
117 return TRUE;
119 return FALSE;