forked from virtadpt/eBBS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnetmail.c
165 lines (133 loc) · 3.85 KB
/
netmail.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
Eagles Bulletin Board System
Copyright (C) 1995, Ray Rocker, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "server.h"
#include <ctype.h>
#define MAILERFILE "etc/mailers"
/* For the bbs name and tempfile */
extern SERVERDATA server;
is_valid_address(addr)
char *addr;
{
if (*addr == '\0') return 0; /* blank */
if (*addr == '-') return 0; /* cannot begin with '-' */
while (*addr) {
if (!isalnum(*addr) && strchr(".%!@:;-_+[]", *addr) == NULL)
return 0;
addr++;
}
return 1;
}
spec_to_mailer(rec, mailer)
char *rec;
char *mailer;
{
NAME prefix;
rec = _extract_quoted(rec, prefix, sizeof(prefix));
rec = _extract_quoted(rec, mailer, sizeof(ADDR));
return S_OK;
}
char *
lookup_mailer(addr, mailer)
char *addr;
char *mailer;
{
char *colon;
int rc;
if ((colon = strchr(addr, ':')) == NULL) return NULL;
*colon = '\0';
rc = _record_find(MAILERFILE, _match_first, addr, spec_to_mailer, mailer);
if (rc != S_OK) return NULL;
return colon+1;
}
ok_for_from_header(str)
char *str;
{
for (; str && *str; str++)
if (strchr("<>;\"'\\|[]{}()%@!", *str)) return 0;
return 1;
}
LONG
mail_file_to_outside(fname, subject, addrspec, is_forward, is_binary)
char *fname;
char *subject;
char *addrspec;
int is_forward;
int is_binary;
{
FILE *fp;
ACCOUNT acct;
ADDR addrbuf;
PATH execbuf;
PATH mailer;
int rc;
char *address;
char *base;
if ((fp = fopen(fname, "r")) == NULL) return S_NOSUCHFILE;
fclose(fp);
if (local_bbs_owninfo(&acct) != S_OK) return S_SYSERR;
if (addrspec == NULL) {
sprintf(addrbuf, "%s:%s", MAILER_PREFIX, acct.email);
}
else {
strncpy(addrbuf, addrspec, sizeof addrbuf);
}
if ((address = lookup_mailer(addrbuf, mailer)) == NULL) return S_BADADDRESS;
if ((fp = fopen(server.tempfile, "w")) == NULL) return S_SYSERR;
/* Write headers! */
if (ok_for_from_header(acct.username))
fprintf(fp, "From: %s.bbs (%s)\n", acct.userid, acct.username);
else fprintf(fp, "From: %s.bbs (%s)\n", acct.userid, acct.userid);
if (is_forward) fprintf(fp, "Subject: %s (fwd)\n", subject);
else fprintf(fp, "Subject: %s\n", subject);
fprintf(fp, "To: %s\n", address);
fprintf(fp, "X-Disclaimer: %s is not responsible for the contents of this message.\n", server.name);
fprintf(fp, "\n");
if (is_forward) fprintf(fp, "*** Forwarded file follows ***\n\n");
fflush(fp);
if (is_binary) {
fclose(fp);
base = strrchr(fname, '/');
if (base) base++;
else base = fname;
strcpy(execbuf, server.encodebin);
strcat(execbuf, " ");
strcat(execbuf, base);
rc = execute(execbuf, NULL, fname, server.tempfile, "/dev/null", NULL, 1);
}
else {
rc = append_file(fileno(fp), fname);
fclose(fp);
}
if (rc != 0) {
unlink(server.tempfile);
return S_SYSERR;
}
sprintf(execbuf, "%s %s", mailer, address);
bbslog(3, "FORWARD '%s' to %s by %s\n", subject, address, acct.userid);
rc = execute(execbuf, NULL, server.tempfile, "/dev/null", "/dev/null", NULL);
unlink(server.tempfile);
return (rc == 0 ? S_OK : S_SYSERR);
}
LONG
forward_file_to_outside(fname, title, is_binary)
char *fname;
char *title;
int is_binary;
{
LONG rc;
rc = mail_file_to_outside(fname, title, NULL, 1, is_binary);
return rc;
}