header.c
5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/error.h>
#include <mailutils/sys/header.h>
int
header_ref (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->ref (header);
}
void
header_destroy (header_t *pheader)
{
if (pheader && *pheader)
{
header_t header = *pheader;
if (header->vtable && header->vtable->destroy)
header->vtable->destroy (pheader);
*pheader = NULL;
}
}
int
header_is_modified (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->is_modified == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->is_modified (header);
}
int
header_clear_modified (header_t header)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->clear_modified == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->clear_modified (header);
}
int
header_set_value (header_t header, const char *fn, const char *fv, int replace)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->set_value == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->set_value (header, fn, fv, replace);
}
int
header_get_value (header_t header, const char *name, char *buffer,
size_t buflen, size_t *pn)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_value == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_value (header, name, buffer, buflen, pn);
}
int
header_aget_value (header_t header, const char *name, char **pvalue)
{
char *value;
size_t n = 0;
int status = header_get_value (header, name, NULL, 0, &n);
if (status == 0)
{
value = calloc (n + 1, 1);
if (value == NULL)
return MU_ERROR_NO_MEMORY;
header_get_value (header, name, value, n + 1, NULL);
*pvalue = value;
}
return status;
}
int
header_get_field_count (header_t header, size_t *pcount)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_field_count == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_field_count (header, pcount);
}
int
header_get_field_name (header_t header, size_t num, char *buf,
size_t buflen, size_t *pn)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_field_name == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_field_name (header, num, buf, buflen, pn);
}
int
header_aget_field_name (header_t header, size_t num, char **pvalue)
{
char *value;
size_t n = 0;
int status = header_get_field_name (header, num, NULL, 0, &n);
if (status == 0)
{
value = calloc (n + 1, 1);
if (value == NULL)
return MU_ERROR_NO_MEMORY;
header_get_field_name (header, num, value, n + 1, NULL);
*pvalue = value;
}
return status;
}
int
header_get_field_value (header_t header, size_t num, char *buf,
size_t buflen, size_t *pn)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_field_value == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_field_value (header, num, buf, buflen, pn);
}
int
header_aget_field_value (header_t header, size_t num, char **pvalue)
{
char *value;
size_t n = 0;
int status = header_get_field_value (header, num, NULL, 0, &n);
if (status == 0)
{
value = calloc (n + 1, 1);
if (value == NULL)
return MU_ERROR_NO_MEMORY;
header_get_field_value (header, num, value, n + 1, NULL);
*pvalue = value;
}
return status;
}
int
header_get_lines (header_t header, size_t *plines)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_lines == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_lines (header, plines);
}
int
header_get_size (header_t header, size_t *psize)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_size == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_size (header, psize);
}
int
header_get_stream (header_t header, stream_t *pstream)
{
if (header == NULL || header->vtable == NULL
|| header->vtable->get_stream == NULL)
return MU_ERROR_NOT_SUPPORTED;
return header->vtable->get_stream (header, pstream);
}