-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.c
207 lines (190 loc) · 7.44 KB
/
help.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Copyright (c) 1995-2019 Peter Simons <simons@cryp.to>
* Copyright (c) 2000-2001 Cable & Wireless GmbH
* Copyright (c) 1999-2000 CyberSolutions GmbH
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "libtext/text.h"
#include "petidomo.h"
int
SendHelp(struct Mail * MailStruct,
const char * param1,
const char * param2,
const char * defaultlist)
{
const struct PD_Config * MasterConfig;
const struct List_Config * ListConfig = NULL;
FILE * fh;
char * originator;
char * p;
char envelope[1024];
char * buffer;
/* Find out who is who and what to send. */
MasterConfig = getMasterConfig();
if (defaultlist != NULL) {
ListConfig = getListConfig(defaultlist);
sprintf(envelope, "%s-owner@%s", defaultlist, ListConfig->fqdn);
}
else
sprintf(envelope, "petidomo-manager@%s", MasterConfig->fqdn);
originator = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
if (param1 != NULL) {
if (isValidListName(param1) == TRUE) {
/* Send list's description back. */
ListConfig = getListConfig(param1);
sprintf(envelope, "%s-owner@%s", param1, MasterConfig->fqdn);
fh = vOpenMailer(envelope, originator, NULL);
if (fh == NULL) {
syslog(LOG_ERR, "Failed to send mail to \"%s\" regarding this request.",
originator);
return -1;
}
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
param1, ListConfig->fqdn);
fprintf(fh, "To: %s\n", originator);
fprintf(fh, "Subject: Petidomo: Your request \"help %s\"\n", param1);
if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n");
fprintf(fh, "Description of list \"%s\":\n\n", param1);
p = loadfile(ListConfig->desc_file);
if (p != NULL) {
fprintf(fh, "%s\n", p);
free(p);
}
else {
syslog(LOG_INFO, "List \"%s\" doesn't have a description.", param1);
fprintf(fh, "No description available.\n");
}
CloseMailer(fh);
}
else {
/* List does not exist, I am afraid. */
fh = vOpenMailer(envelope, originator, NULL);
if (fh == NULL) {
syslog(LOG_ERR, "Failed to send mail to \"%s\" regarding this request.",
originator);
return -1;
}
if (defaultlist != NULL)
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
defaultlist, ListConfig->fqdn);
else
fprintf(fh, "From: petidomo@%s (Petidomo Mailing List Server)\n",
MasterConfig->fqdn);
fprintf(fh, "To: %s\n", originator);
fprintf(fh, "Subject: Petidomo: Your request \"help %s\"\n", param1);
if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n");
buffer = text_easy_sprintf(
"There is no mailing list \"%s\" on this machine, I am afraid. Please check " \
"whether you spelled the name of the list correctly, or whether you have been " \
"sending this request to the wrong address.\n\nYou can receive a list of all " \
"mailing lists available here by sending the command \"INDEX\" to the " \
"mailing list server.", param1);
text_wordwrap(buffer, 70);
fprintf(fh, "%s\n", buffer);
CloseMailer(fh);
}
}
else {
/* Send help text to the originator. */
fh = vOpenMailer(envelope, originator, NULL);
if (fh == NULL) {
syslog(LOG_ERR, "Failed to send mail to \"%s\" regarding this request.",
originator);
return -1;
}
if (defaultlist != NULL)
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
defaultlist, ListConfig->fqdn);
else
fprintf(fh, "From: petidomo@%s (Petidomo Mailing List Server)\n",
MasterConfig->fqdn);
fprintf(fh, "To: %s\n", originator);
fprintf(fh, "Subject: Petidomo: Your request \"help\"\n");
if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n");
p = loadfile(MasterConfig->help_file);
if (p != NULL) {
fprintf(fh, "%s\n", p);
free(p);
}
else {
syslog(LOG_ERR, "There is no help file for Petidomo!");
fprintf(fh, "No help text available.\n");
}
CloseMailer(fh);
}
return 0;
}
int
Indecipherable(struct Mail * MailStruct, const char * defaultlist)
{
const struct PD_Config * MasterConfig;
const struct List_Config * ListConfig = NULL;
FILE * fh;
char * replyto;
char * p;
char envelope[1024];
/* Find out who is who and what to send. */
MasterConfig = getMasterConfig();
if (defaultlist != NULL) {
ListConfig = getListConfig(defaultlist);
sprintf(envelope, "%s-owner@%s", defaultlist, ListConfig->fqdn);
}
else
sprintf(envelope, "petidomo-manager@%s", MasterConfig->fqdn);
replyto = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
/* Send the help file out. */
fh = vOpenMailer(envelope, replyto, NULL);
if (fh == NULL) {
syslog(LOG_ERR, "Failed to send mail to \"%s\" regarding this request.", replyto);
return -1;
}
if (defaultlist != NULL)
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
defaultlist, ListConfig->fqdn);
else
fprintf(fh, "From: petidomo@%s (Petidomo Mailing List Server)\n",
MasterConfig->fqdn);
fprintf(fh, "To: %s\n", replyto);
fprintf(fh, "Subject: Petidomo: Your request \"indecipherable\"\n");
if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n");
p = loadfile(MasterConfig->help_file);
if (p != NULL) {
fprintf(fh, "%s\n", p);
free(p);
}
else {
syslog(LOG_ERR, "There is no help file for Petidomo!");
fprintf(fh, "No help text available.\n");
}
CloseMailer(fh);
return 0;
}