Added a check button for NNTP authentication to account preferences.
[claws.git] / src / customheader.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 "customheader.h"
31 #include "utils.h"
32
33
34 gchar * custom_header_get_str(CustomHeader *ch)
35 {
36         return g_strdup_printf
37                 ("%i:%s: %s", ch->account_id, ch->name, ch->value);
38 }
39  
40 CustomHeader * custom_header_read_str(gchar * buf)
41 {
42         CustomHeader * ch;
43         gchar * account_id_str;
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_id_str = tmp;
52
53         name = strchr(account_id_str, ':');
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_id = atoi(account_id_str);
65         if (ch->account_id == 0) {
66                 g_free(ch);
67                 return NULL;
68         }
69
70         value = strchr(name, ':');
71         if (!value)
72                 {
73                         g_free(ch);
74                         return NULL;
75                 }
76         else
77                 *value++ = '\0';
78  
79         ch->name = *name ? g_strdup(name) : NULL;
80  
81         while (*value == ' ')
82                 value ++;
83
84         ch->value = *value ? g_strdup(value) : NULL;
85
86         return ch;
87 }
88  
89 void custom_header_free(CustomHeader *ch)
90 {
91         if (!ch) return;
92  
93         if (ch->name)
94                 g_free(ch->name);
95         if (ch->value)
96                 g_free(ch->value);
97  
98         g_free(ch);
99 }