annotate src/header.c @ 301:55c530a83d51

refactoring
author markus schnalke <meillo@marmaro.de>
date Thu, 09 Dec 2010 15:42:02 -0300
parents 92063f90f9be
children 2ffcd38ccf53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 Copyright (C) 2000 Oliver Kurth
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
3
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7 (at your option) any later version.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
20 header_name header_names[] = {
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
21 {"From", HEAD_FROM,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
22 {"Sender", HEAD_SENDER,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
23 {"To", HEAD_TO,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
24 {"Cc", HEAD_CC,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
25 {"Bcc", HEAD_BCC,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
26 {"Date", HEAD_DATE,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
27 {"Message-Id", HEAD_MESSAGE_ID,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
28 {"Reply-To", HEAD_REPLY_TO,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
29 {"Subject", HEAD_SUBJECT,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
30 {"Return-Path", HEAD_RETURN_PATH,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
31 {"Envelope-To", HEAD_ENVELOPE_TO,},
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
32 {"Received", HEAD_RECEIVED},
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
33 };
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
34
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
35 /* this was borrowed from exim and slightly changed */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
36 gchar*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
37 rec_timestamp()
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
38 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
39 static gchar buf[64];
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
40 int len;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
41
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
42 time_t now = time(NULL);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
43 struct tm *t = localtime(&now);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
44
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
45 int diff_hour, diff_min;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
46 struct tm local;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 struct tm *gmt;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
48
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
49 memcpy(&local, t, sizeof(struct tm));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 gmt = gmtime(&now);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
51 diff_min = 60 * (local.tm_hour - gmt->tm_hour) + local.tm_min - gmt->tm_min;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
52 if (local.tm_year != gmt->tm_year) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
53 diff_min += (local.tm_year > gmt->tm_year) ? 1440 : -1440;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
54 } else if (local.tm_yday != gmt->tm_yday) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
55 diff_min += (local.tm_yday > gmt->tm_yday) ? 1440 : -1440;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
56 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 diff_hour = diff_min / 60;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 diff_min = abs(diff_min - diff_hour * 60);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
59
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 len = strftime(buf, sizeof(buf), "%a, ", &local);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 g_snprintf(buf + len, sizeof(buf) - len, "%02d ", local.tm_mday);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
62 len += strlen(buf + len);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 len += strftime(buf + len, sizeof(buf) - len, "%b %Y %H:%M:%S", &local);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 g_snprintf(buf + len, sizeof(buf) - len, " %+03d%02d", diff_hour, diff_min);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
65
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 return buf;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
67 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
68
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
69 /* finds list of headers matching id
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
70 if id == HEAD_UNKNOWN and header == NULL finds all unknown headers
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
71 else finds all headers matching header
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
72 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
73 GList*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
74 find_header(GList * hdr_list, header_id id, gchar * hdr_str)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
75 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
76 GList *found_list = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 GList *node;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
78
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
79 if ((id != HEAD_UNKNOWN) || !hdr_str) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 foreach(hdr_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
81 header *hdr = (header *) (node->data);
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
82 if (hdr->id == id) {
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
83 found_list = g_list_append(found_list, hdr);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
84 }
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
85 }
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
86 return found_list;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
87 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
89 foreach(hdr_list, node) {
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
90 header *hdr = (header *) (node->data);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
91 gchar buf[64], *q = buf, *p = hdr->header;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
93 while (*p != ':' && q < buf+sizeof(buf)-1 && *p) {
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
94 *(q++) = *(p++);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
95 }
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
96 *q = '\0';
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
97
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
98 if (strcasecmp(buf, hdr_str) == 0) {
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
99 found_list = g_list_append(found_list, hdr);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
100 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
102 return found_list;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
103 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
104
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
105 void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
106 header_unfold(header * hdr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
107 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
108 gchar *tmp_hdr = g_malloc(strlen(hdr->header));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
109 gchar *p = hdr->header, *q = tmp_hdr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
110 gboolean flag = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
111
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
112 while (*p) {
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
113 if (*p != '\n') {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
114 *(q++) = *p;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
115 } else {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
116 flag = TRUE;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
117 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
118 p++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
119 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
120 *(q++) = '\n';
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
121
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
122 if (flag) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
123 gchar *new_hdr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
124
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
125 g_free(hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 new_hdr = g_strdup(tmp_hdr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
127 g_free(tmp_hdr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
128 hdr->value = new_hdr + (hdr->value - hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
129 hdr->header = new_hdr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
130 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
131 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
132
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
133 #define MAX_HDR_LEN 72
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
134 void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
135 header_fold(header * hdr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
136 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
137 gint len = strlen(hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
138 gchar *p, *q;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
139 gchar *tmp_hdr;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
140 int valueoffset;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
141
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
142 if (len < MAX_HDR_LEN) {
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
143 /* we don't need to do anything */
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
144 return;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
145 }
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
146
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
147 /* the position in hdr->header where the value part starts */
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
148 valueoffset = hdr->value - hdr->header;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
149
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
150 /* TODO: size is only calculated roughly */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
151 /* size is probably overestimated, but so we are on the safe side */
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
152 /* (as much as we already have + chars inserted per break * number
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
153 of breaks + some more) */
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
154 tmp_hdr = g_malloc(len + 2 * (len/MAX_HDR_LEN) + 10);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
155
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
156 p = hdr->header;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
157 q = tmp_hdr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
158
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
159 if (p[len - 1] == '\n') {
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
160 p[len - 1] = '\0';
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
161 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
162
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
163 while (*p) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
164 gint i, l;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
165 gchar *pp;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
166
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
167 /* look forward and find potential break points */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
168 i = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
169 l = -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
170 pp = p;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
171 while (*pp && (i < MAX_HDR_LEN)) {
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
172 if ((*pp == ' ') || (*pp == '\t')) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
173 l = i;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
174 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
175 pp++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
176 i++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
177 }
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
178 if (!*pp) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
179 l = pp - p; /* take rest, if EOS found */
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
180 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
181
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
182 if (l == -1) {
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
183 /* no potential break point was found within
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
184 MAX_HDR_LEN so advance further until the next */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
185 while (*pp && *pp != ' ' && *pp != '\t') {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
186 pp++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
187 i++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
188 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
189 l = i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
190 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
191
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
192 /* copy */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
193 i = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
194 while (i < l) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
195 *(q++) = *(p++);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
196 i++;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
197 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
198 *(q++) = '\n';
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
199 *(q++) = *(p++); /* this is either space, tab or 0 */
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
200 /* *(q++) = '\t'; */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
201 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
202
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
203 g_free(hdr->header);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
204 hdr->header = tmp_hdr;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
205 hdr->value = hdr->header + valueoffset;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
206 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
207
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
208 header*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
209 create_header(header_id id, gchar * fmt, ...)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
210 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
211 gchar *p;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
212 header *hdr;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
213 va_list args;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214 va_start(args, fmt);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
215
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
216 /* g_malloc() calls exit on failure */
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
217 hdr = g_malloc(sizeof(header));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
218
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
219 hdr->id = id;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
220 hdr->header = g_strdup_vprintf(fmt, args);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
221 hdr->value = NULL;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
222
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
223 /* value shall point to the first non-whitespace char in the
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
224 value part of the header line (i.e. after the first colon) */
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
225 p = strchr(hdr->header, ':');
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
226 if (p) {
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
227 p++;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
228 while (*p == ' ' || *p == '\t' || *p == '\n') {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
229 p++;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
230 }
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
231 hdr->value = (*p) ? p : NULL;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
232 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
233
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
234 DEBUG(3) debugf("create_header(): hdr: `%s'\n", hdr->header);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
235 DEBUG(3) debugf("create_header(): val: `%s'\n", hdr->value);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
236
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
237 va_end(args);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
238 return hdr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
239 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
240
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
241 void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
242 destroy_header(header * hdr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
243 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
244 if (hdr) {
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
245 if (hdr->header) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
246 g_free(hdr->header);
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
247 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
248 g_free(hdr);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
250 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
251
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
252 header*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
253 copy_header(header * hdr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
254 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
255 header *new_hdr = NULL;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
256
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
257 if (hdr) {
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
258 new_hdr = g_malloc(sizeof(header));
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
259 new_hdr->id = hdr->id;
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
260 new_hdr->header = g_strdup(hdr->header);
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
261 new_hdr->value = new_hdr->header + (hdr->value - hdr->header);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
262 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
263 return new_hdr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
264 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
265
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
266 header*
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
267 get_header(gchar * line)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
268 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
269 gchar *p = line;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
270 gchar buf[64], *q = buf;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
271 gint i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
272 header *hdr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
273
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
274 while (*p && (*p != ':') && (q < buf+sizeof(buf)-1)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
275 *(q++) = *(p++);
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
276 }
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
277 *q = '\0';
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
278
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
279 if (*p != ':') {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
280 return NULL;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
281 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
282
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
283 hdr = g_malloc(sizeof(header));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
284
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
285 hdr->value = NULL;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
286 p++;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
287
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
288 while (*p && (*p == ' ' || *p == '\t')) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
289 p++;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
290 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
291 hdr->value = p;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
292 /* Note: an empty value can also mean that it's only the first part
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
293 of a folded header line */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
294
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
295 for (i = 0; i < HEAD_NUM_IDS; i++) {
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
296 if (strcasecmp(header_names[i].header, buf) == 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
297 break;
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
298 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
299 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
300 hdr->id = (header_id) i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
301 hdr->header = g_strdup(line);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
302 hdr->value = hdr->header + (hdr->value - line);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
303
235
92063f90f9be removed additional new lines at the end of debug messages
markus schnalke <meillo@marmaro.de>
parents: 208
diff changeset
304 DEBUG(4) debugf("header: %d = %s", hdr->id, hdr->header);
301
55c530a83d51 refactoring
markus schnalke <meillo@marmaro.de>
parents: 235
diff changeset
305 /* Note: This only outputs the first line if the header is folded */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
306
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
307 return hdr;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
308 }