custom headers configuration added
[claws.git] / src / headers.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <glib.h>
25 #include <string.h>
26 #include <strings.h>
27 #include <stdlib.h>
28
29 #include "intl.h"
30 #include "headers.h"
31 #include "utils.h"
32
33
34 gchar * custom_header_get_str(CustomHeader *ch)
35 {
36         return g_strdup_printf
37                 ("%s\t%s: %s", ch->account_name, ch->name, ch->value);
38 }
39  
40 CustomHeader * custom_header_read_str(gchar * buf)
41 {
42         CustomHeader * ch;
43         gchar * account_name;
44         gchar * name;
45         gchar * value;
46         gchar * tmp;
47  
48         Xalloca(tmp, strlen(buf) + 1, return NULL);
49         strcpy(tmp, buf);
50
51         account_name = tmp;
52
53         name = strchr(account_name, '\t');
54         if (!name)
55                 return NULL;
56         else
57                 *name++ = '\0';
58
59         while (*name == ' ')
60                 name ++;
61         
62         ch = g_new0(CustomHeader, 1);
63
64         ch->account_name = *account_name ? g_strdup(account_name) : NULL;
65
66         value = strchr(name, ':');
67         if (!value)
68                 {
69                         g_free(ch->account_name);
70                         g_free(ch);
71                         return NULL;
72                 }
73         else
74                 *value++ = '\0';
75  
76         ch->name = *name ? g_strdup(name) : NULL;
77  
78         while (*value == ' ')
79                 value ++;
80
81         ch->value = *value ? g_strdup(value) : NULL;
82
83         return ch;
84 }
85  
86 void custom_header_free(CustomHeader *ch)
87 {
88         if (!ch) return;
89  
90         if (ch->account_name)
91                 g_free(ch->account_name);
92         if (ch->name)
93                 g_free(ch->name);
94         if (ch->value)
95                 g_free(ch->value);
96  
97         g_free(ch);
98 }