annotate src/spool.c @ 434:f2a7271746d1 default tip

Removes Freshmeat.net from the docs The site, which was later renamed to freecode.com, is no longer maintained (contains only a static copy).
author markus schnalke <meillo@marmaro.de>
date Sat, 07 Feb 2015 11:45:07 +0100
parents bdbedce60247
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
1 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
2 ** MasqMail
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
3 ** Copyright (C) 1999-2001 Oliver Kurth
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
4 ** Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
5 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
6 ** This program is free software; you can redistribute it and/or modify
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
7 ** it under the terms of the GNU General Public License as published by
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
8 ** the Free Software Foundation; either version 2 of the License, or
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
9 ** (at your option) any later version.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
10 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
11 ** This program is distributed in the hope that it will be useful,
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
14 ** GNU General Public License for more details.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
15 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
16 ** You should have received a copy of the GNU General Public License
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
17 ** along with this program; if not, write to the Free Software
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
21 #include <sys/stat.h>
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
22
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
23 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
24 #include "dotlock.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
26 static gint
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
27 read_line(FILE *in, gchar *buf, gint buf_len)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
28 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
29 gint p = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
30 gint c;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
31
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
32 while ((c = getc(in)) != '\n' && (c != EOF)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
33 if (p >= buf_len - 1) {
75
257a9e6d1a8e fixed correct processing of mails with data lines longer 4096 chars
meillo@marmaro.de
parents: 43
diff changeset
34 buf[buf_len-1] = '\0';
257a9e6d1a8e fixed correct processing of mails with data lines longer 4096 chars
meillo@marmaro.de
parents: 43
diff changeset
35 ungetc(c, in);
257a9e6d1a8e fixed correct processing of mails with data lines longer 4096 chars
meillo@marmaro.de
parents: 43
diff changeset
36 return buf_len;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
37 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
38 buf[p++] = c;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
39 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
40
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
41 if (c == EOF) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
42 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
43 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
44 if ((p > 0) && (buf[p - 1] == '\r'))
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
45 p--;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
46 buf[p++] = '\n';
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
47 buf[p] = '\0';
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 return p;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
50 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
51
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
52 static void
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
53 spool_write_rcpt(FILE *out, address *rcpt)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
54 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
55 gchar dlvrd_char = addr_is_delivered(rcpt) ? 'X' : (addr_is_failed(rcpt) ? 'F' : ' ');
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
56
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 if (rcpt->local_part[0] != '|') {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 /* this is a paranoid check, in case it slipped through: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
59 /* if this happens, it is a bug */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 if (rcpt->domain == NULL) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 logwrite(LOG_WARNING, "BUG: null domain for address %s, setting to %s\n", rcpt->local_part, conf.host_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
62 logwrite(LOG_WARNING, "please report this bug.\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 rcpt->domain = g_strdup(conf.host_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
65 fprintf(out, "RT:%c%s\n", dlvrd_char, addr_string(rcpt));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
67 fprintf(out, "RT:%c%s\n", dlvrd_char, rcpt->local_part);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
69 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
70
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
71 static address*
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
72 spool_scan_rcpt(gchar *line)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
73 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
74 address *rcpt = NULL;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
75
414
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
76 if (!line[3]) {
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
77 return NULL;
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
78 }
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
79 if (line[4] == '|') {
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
80 rcpt = create_address_pipe(line+4);
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
81 } else {
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
82 rcpt = create_address(line+4, TRUE);
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
83 }
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
84 if (line[3] == 'X') {
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
85 addr_mark_delivered(rcpt);
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
86 } else if (line[3] == 'F') {
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
87 addr_mark_failed(rcpt);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
89 return rcpt;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
90 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
91
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
93 spool_read_data(message *msg)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
94 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 FILE *in;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 gchar *spool_file;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
97
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 DEBUG(5) debugf("spool_read_data entered\n");
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
99 spool_file = g_strdup_printf("%s/%s-D", conf.spool_dir, msg->uid);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
100 DEBUG(5) debugf("reading data spool file '%s'\n", spool_file);
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
101 in = fopen(spool_file, "r");
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
102 if (!in) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
103 logwrite(LOG_ALERT, "could not open spool data file %s: %s\n", spool_file, strerror(errno));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
104 return FALSE;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
105 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
106
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
107 char buf[MAX_DATALINE];
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
108 int len;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
109
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
110 /* msg uid */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
111 read_line(in, buf, MAX_DATALINE);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
112
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
113 /* data */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
114 msg->data_list = NULL;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
115 while ((len = read_line(in, buf, MAX_DATALINE)) > 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
116 msg->data_list = g_list_prepend(msg->data_list, g_strdup(buf));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
117 }
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
118 msg->data_list = g_list_reverse(msg->data_list);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
119 fclose(in);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
120 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
121 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
122
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
123 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
124 spool_read_header(message *msg)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
125 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 FILE *in;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
127 gchar *spool_file;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
128
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
129 /* header spool: */
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
130 spool_file = g_strdup_printf("%s/%s-H", conf.spool_dir, msg->uid);
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
131 in = fopen(spool_file, "r");
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
132 if (!in) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
133 logwrite(LOG_ALERT, "could not open spool header file %s: %s\n",
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
134 spool_file, strerror(errno));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
135 return FALSE;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
136 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
137
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
138 header *hdr = NULL;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
139 char buf[MAX_DATALINE];
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
140 int len;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
141
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
142 /* msg uid */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
143 read_line(in, buf, MAX_DATALINE);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
144
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
145 /* envelope header */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
146 while ((len = read_line(in, buf, MAX_DATALINE)) > 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
147 if (buf[0] == '\n') {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
148 break;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
149 } else if (strncasecmp(buf, "MF:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
150 msg->return_path = create_address(&(buf[3]), TRUE);
414
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
151 DEBUG(3) debugf("spool_read: MAIL FROM: %s\n",
309935f59820 Minor refactoring and added a newline to the debug output.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
152 msg->return_path->address);
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
153 } else if (strncasecmp(buf, "RT:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
154 address *addr;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
155 addr = spool_scan_rcpt(buf);
108
46f407c0727a exchange of the if parts to simplify the condition
meillo@marmaro.de
parents: 82
diff changeset
156 if (addr_is_delivered(addr) || addr_is_failed(addr)) {
46f407c0727a exchange of the if parts to simplify the condition
meillo@marmaro.de
parents: 82
diff changeset
157 msg->non_rcpt_list = g_list_append(msg->non_rcpt_list, addr);
46f407c0727a exchange of the if parts to simplify the condition
meillo@marmaro.de
parents: 82
diff changeset
158 } else {
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
159 msg->rcpt_list = g_list_append(msg->rcpt_list, addr);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
160 }
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
161 } else if (strncasecmp(buf, "PR:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
162 prot_id i;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
163 for (i = 0; i < PROT_NUM; i++) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
164 if (strncasecmp(prot_names[i], &(buf[3]), strlen(prot_names[i])) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
165 break;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
166 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
167 }
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
168 msg->received_prot = i;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
169 } else if (strncasecmp(buf, "RH:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
170 g_strchomp(buf);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
171 msg->received_host = g_strdup(&(buf[3]));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
172 } else if (strncasecmp(buf, "ID:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
173 g_strchomp(buf);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
174 msg->ident = g_strdup(&(buf[3]));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
175 } else if (strncasecmp(buf, "DS:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
176 msg->data_size = atoi(&(buf[3]));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
177 } else if (strncasecmp(buf, "TR:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
178 msg->received_time = (time_t) (atoi(&(buf[3])));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
179 } else if (strncasecmp(buf, "TW:", 3) == 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
180 msg->warned_time = (time_t) (atoi(&(buf[3])));
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
181 }
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
182 /* so far ignore other tags */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
183 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
184
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
185 /* mail headers */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
186 while ((len = read_line(in, buf, MAX_DATALINE)) > 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
187 if (strncasecmp(buf, "HD:", 3) == 0) {
300
d04894d0fc64 free memory in spool read for continuation header lines
markus schnalke <meillo@marmaro.de>
parents: 236
diff changeset
188 DEBUG(6) debugf("spool_read_header(): hdr start\n");
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
189 hdr = get_header(&(buf[3]));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
190 msg->hdr_list = g_list_append(msg->hdr_list, hdr);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
191 } else if ((buf[0] == ' ' || buf[0] == '\t') && hdr) {
300
d04894d0fc64 free memory in spool read for continuation header lines
markus schnalke <meillo@marmaro.de>
parents: 236
diff changeset
192 DEBUG(6) debugf("spool_read_header(): hdr continuation\n");
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
193 char *tmp = hdr->header;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
194 /* header continuation */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
195 hdr->header = g_strconcat(hdr->header, buf, NULL);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
196 hdr->value = hdr->header + (hdr->value - tmp);
300
d04894d0fc64 free memory in spool read for continuation header lines
markus schnalke <meillo@marmaro.de>
parents: 236
diff changeset
197 free(tmp); /* because g_strconcat() allocs and copies */
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
198 } else {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
199 break;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
200 }
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
201 }
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
202 fclose(in);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
203 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
204 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
205
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
206 message*
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
207 msg_spool_read(gchar *uid)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
208 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
209 message *msg;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
210 gboolean ok = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
211
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
212 msg = create_message();
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
213 msg->uid = g_strdup(uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214
114
a80ebfa16cd5 better debugging output (thanks to Paolo)
meillo@marmaro.de
parents: 108
diff changeset
215 DEBUG(4) debugf("msg_spool_read():\n");
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
216 /* header spool: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
217 ok = spool_read_header(msg);
415
0430194f7ef8 Debug message cosmetic.
markus schnalke <meillo@marmaro.de>
parents: 414
diff changeset
218 DEBUG(4) debugf("spool_read_header() returned: %d\n", ok);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 return msg;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
220 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
221
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
222 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
223 ** write header. uid and gid should already be set to the
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
224 ** mail ids. Better call spool_write(msg, FALSE).
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
225 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
226 static gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
227 spool_write_header(message *msg)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
228 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
229 GList *node;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
230 gchar *spool_file, *tmp_file;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
231 FILE *out;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
232 gboolean ok = TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
233
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
234 /* header spool: */
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
235 tmp_file = g_strdup_printf("%s/%d-H.tmp", conf.spool_dir, getpid());
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
236 DEBUG(4) debugf("tmp_file = %s\n", tmp_file);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
237
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
238 if ((out = fopen(tmp_file, "w"))) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
239 DEBUG(6) debugf("opened tmp_file %s\n", tmp_file);
0
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 fprintf(out, "%s\n", msg->uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
242 fprintf(out, "MF:%s\n", addr_string(msg->return_path));
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 DEBUG(6) debugf("after MF\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
245 foreach(msg->rcpt_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
246 address *rcpt = (address *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
247 spool_write_rcpt(out, rcpt);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
248 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
249 foreach(msg->non_rcpt_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
250 address *rcpt = (address *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
251 spool_write_rcpt(out, rcpt);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
252 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
253 DEBUG(6) debugf("after RT\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
254 fprintf(out, "PR:%s\n", prot_names[msg->received_prot]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
255 if (msg->received_host != NULL)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
256 fprintf(out, "RH:%s\n", msg->received_host);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
257
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
258 if (msg->ident != NULL)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
259 fprintf(out, "ID:%s\n", msg->ident);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
260
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
261 if (msg->data_size >= 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
262 fprintf(out, "DS: %d\n", msg->data_size);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
263
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
264 if (msg->received_time > 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
265 fprintf(out, "TR: %u\n", (int) (msg->received_time));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
266
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
267 if (msg->warned_time > 0)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
268 fprintf(out, "TW: %u\n", (int) (msg->warned_time));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
269
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
270 DEBUG(6) debugf("after RH\n");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
271 fprintf(out, "\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
272
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
273 foreach(msg->hdr_list, node) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
274 header *hdr = (header *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
275 fprintf(out, "HD:%s", hdr->header);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
276 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
277 if (fflush(out) == EOF)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
278 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
279 else if (fdatasync(fileno(out)) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
280 if (errno != EINVAL) /* some fs do not support this.. I hope this also means that it is not necessary */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
281 ok = FALSE;
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 fclose(out);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
284 if (ok) {
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
285 spool_file = g_strdup_printf("%s/%s-H", conf.spool_dir, msg->uid);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
286 DEBUG(4) debugf("spool_file = %s\n", spool_file);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
287 ok = (rename(tmp_file, spool_file) != -1);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
288 g_free(spool_file);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
289 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
290 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
291 logwrite(LOG_ALERT, "could not open temporary header spool file '%s': %s\n", tmp_file, strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
292 DEBUG(1) debugf("euid = %d, egid = %d\n", geteuid(), getegid());
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
293 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
294 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
295
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
296 g_free(tmp_file);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
297
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
298 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
299 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
300
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
301 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
302 spool_write(message *msg, gboolean do_write_data)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
303 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
304 GList *list;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
305 gchar *spool_file, *tmp_file;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
306 FILE *out;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
307 gboolean ok = TRUE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
308 uid_t saved_uid, saved_gid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
309 /* user can read/write, group can read, others cannot do anything: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
310 mode_t saved_mode = saved_mode = umask(026);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
311
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
312 /* set uid and gid to the mail ids */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
313 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
314 set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
315 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
316
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
317 /* header spool: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
318 ok = spool_write_header(msg);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
319
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
320 if (ok && do_write_data) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
321 /* data spool: */
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
322 tmp_file = g_strdup_printf("%s/%d-D.tmp", conf.spool_dir, getpid());
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
323 DEBUG(4) debugf("tmp_file = %s\n", tmp_file);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
324
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
325 if ((out = fopen(tmp_file, "w"))) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
326 fprintf(out, "%s\n", msg->uid);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
327 for (list = g_list_first(msg->data_list); list != NULL; list = g_list_next(list)) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
328 fprintf(out, "%s", (gchar *) (list->data));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
329 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
330
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
331 /* possibly paranoid ;-) */
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
332 if (fflush(out) == EOF) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
333 ok = FALSE;
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
334 } else if (fdatasync(fileno(out)) != 0) {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
335 if (errno != EINVAL) { /* some fs do not support this.. I hope this also means that it is not necessary */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
336 ok = FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
337 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
338 }
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
339 fclose(out);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
340 if (ok) {
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
341 spool_file = g_strdup_printf("%s/%s-D", conf.spool_dir, msg->uid);
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
342 DEBUG(4) debugf("spool_file = %s\n", spool_file);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
343 ok = (rename(tmp_file, spool_file) != -1);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
344 g_free(spool_file);
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
345 }
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
346 } else {
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
347 logwrite(LOG_ALERT, "could not open temporary data spool file: %s\n",
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
348 strerror(errno));
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
349 ok = FALSE;
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
350 }
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
351 g_free(tmp_file);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
352 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
353
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
354 /* set uid and gid back */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
355 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
356 set_euidgid(saved_uid, saved_gid, NULL, NULL);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
357 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
358
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
359 umask(saved_mode);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
360
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
361 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
362 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
363
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
364 #define MAX_LOCKAGE 300
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
365
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
366 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
367 spool_lock(gchar *uid)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
368 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
369 uid_t saved_uid, saved_gid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
370 gchar *hitch_name;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
371 gchar *lock_name;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
372 gboolean ok = FALSE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
373
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
374 hitch_name = g_strdup_printf("%s/%s-%d.lock", conf.lock_dir, uid, getpid());
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
375 lock_name = g_strdup_printf("%s/%s.lock", conf.lock_dir, uid);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
376
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
377 /* set uid and gid to the mail ids */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
378 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
379 set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
380 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
381
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
382 ok = dot_lock(lock_name, hitch_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
383 if (!ok)
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
384 logwrite(LOG_WARNING, "spool file %s is locked\n", uid);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
385
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
386 /* set uid and gid back */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
387 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
388 set_euidgid(saved_uid, saved_gid, NULL, NULL);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
389 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
390
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
391 g_free(lock_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
392 g_free(hitch_name);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
393
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
394 return ok;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
395 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
396
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
397 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
398 spool_unlock(gchar *uid)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
399 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
400 uid_t saved_uid, saved_gid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
401 gchar *lock_name;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
402
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
403 /* set uid and gid to the mail ids */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
404 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
405 set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
406 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
407
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
408 lock_name = g_strdup_printf("%s/%s.lock", conf.lock_dir, uid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
409 dot_unlock(lock_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
410 g_free(lock_name);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
411
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
412 /* set uid and gid back */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
413 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
414 set_euidgid(saved_uid, saved_gid, NULL, NULL);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
415 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
416 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
417 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
418
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
419 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 349
diff changeset
420 spool_delete_all(message *msg)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
421 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
422 uid_t saved_uid, saved_gid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
423 gchar *spool_file;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
424
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
425 /* set uid and gid to the mail ids */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
426 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
427 set_euidgid(conf.mail_uid, conf.mail_gid, &saved_uid, &saved_gid);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
428 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
429
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
430 /* header spool: */
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
431 spool_file = g_strdup_printf("%s/%s-H", conf.spool_dir, msg->uid);
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
432 if (unlink(spool_file) != 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
433 logwrite(LOG_ALERT, "could not delete spool file %s: %s\n", spool_file, strerror(errno));
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
434 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
435 g_free(spool_file);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
436
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
437 /* data spool: */
422
bdbedce60247 Remove `input' dir in spool dir. Spooled files are in spool dir directly now.
markus schnalke <meillo@marmaro.de>
parents: 415
diff changeset
438 spool_file = g_strdup_printf("%s/%s-D", conf.spool_dir, msg->uid);
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
439 if (unlink(spool_file) != 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
440 logwrite(LOG_ALERT, "could not delete spool file %s: %s\n", spool_file, strerror(errno));
82
83a182793503 refactoring
meillo@marmaro.de
parents: 76
diff changeset
441 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
442 g_free(spool_file);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
443
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
444 /* set uid and gid back */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
445 if (!conf.run_as_user) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
446 set_euidgid(saved_uid, saved_gid, NULL, NULL);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
447 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
448 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
449 }