15#include "../../sysdep.h"
31#include <sys/socket.h>
32#include <netinet/in.h>
34#include <libcitadel.h>
35#include "../../citadel.h"
36#include "../../server.h"
37#include "../../citserver.h"
38#include "../../support.h"
39#include "../../config.h"
40#include "../../control.h"
41#include "../../user_ops.h"
42#include "../../database.h"
43#include "../../msgbase.h"
44#include "../../internet_addressing.h"
45#include "../../genstamp.h"
46#include "../../domain.h"
47#include "../../clientsocket.h"
48#include "../../locate_host.h"
49#include "../../citadel_dirs.h"
50#include "../../ctdl_module.h"
58 else return ChrPtr(sSMTP->
from);
86 int successful_bounce = 0;
91 syslog(LOG_DEBUG,
"smtp_do_bounce() called");
93 boundary = NewStrBufPlain(HKEY(
"=_Citadel_Multipart_"));
95 StrBufAppendPrintf(boundary,
"%s_%04x%04x",
CtdlGetConfigStr(
"c_fqdn"), getpid(), ++seq);
100 if (bmsg == NULL)
return;
102 BounceMB = NewStrBufPlain(NULL, 1024);
110 StrBufAppendBufPlain(BounceMB, HKEY(
"Content-type: multipart/mixed; boundary=\""), 0);
111 StrBufAppendBuf(BounceMB, boundary, 0);
112 StrBufAppendBufPlain(BounceMB, HKEY(
"\"\r\n"), 0);
113 StrBufAppendBufPlain(BounceMB, HKEY(
"MIME-Version: 1.0\r\n"), 0);
114 StrBufAppendBufPlain(BounceMB, HKEY(
"X-Mailer: " CITADEL "\r\n"), 0);
115 StrBufAppendBufPlain(BounceMB, HKEY(
"\r\nThis is a multipart message in MIME format.\r\n\r\n"), 0);
116 StrBufAppendBufPlain(BounceMB, HKEY(
"--"), 0);
117 StrBufAppendBuf(BounceMB, boundary, 0);
118 StrBufAppendBufPlain(BounceMB, HKEY(
"\r\n"), 0);
119 StrBufAppendBufPlain(BounceMB, HKEY(
"Content-type: text/plain\r\n\r\n"), 0);
122 StrBufAppendBufPlain(
124 HKEY(
"A message you sent could not be delivered "
125 "to some or all of its recipients\ndue to "
126 "prolonged unavailability of its destination(s).\n"
127 "Giving up on the following addresses:\n\n"),
131 StrBufAppendBufPlain(
133 HKEY(
"A message you sent could not be delivered "
134 "to some or all of its recipients.\n"
135 "The following addresses were undeliverable:\n\n"),
139 StrBufAppendBufPlain(
141 HKEY(
"A message you sent has not been delivered "
142 "to some or all of its recipients.\n"
143 "Citadel will continue attempting delivery for five days.\n"
144 "The following addresses were undeliverable:\n\n"),
148 StrBufAppendBufPlain(BounceMB, HKEY(
"This message should never occur.\n\n"), 0);
154 lines = num_tokens(instr,
'\n');
155 for (i=0; i<lines; ++i) {
158 extract_token(buf, instr, i,
'\n',
sizeof buf);
159 extract_token(key, buf, 0,
'|',
sizeof key);
160 addrlen = extract_token(addr, buf, 1,
'|',
sizeof addr);
161 status = extract_int(buf, 2);
162 dsnlen = extract_token(dsn, buf, 3,
'|',
sizeof dsn);
165 syslog(LOG_DEBUG,
"key=<%s> addr=<%s> status=%d dsn=<%s>", key, addr, status, dsn);
167 if (!strcasecmp(key,
"bounceto")) {
168 strcpy(bounceto, addr);
171 if (!strcasecmp(key,
"msgid")) {
175 if (!strcasecmp(key,
"remote")) {
177 if ((is_final ==
SDB_BOUNCE_ALL) && (status != 2)) bounce_this = 1;
178 if ((is_final ==
SDB_WARN) && (status == 4)) bounce_this = 1;
183 StrBufAppendBufPlain(BounceMB, addr, addrlen, 0);
184 StrBufAppendBufPlain(BounceMB, HKEY(
": "), 0);
185 StrBufAppendBufPlain(BounceMB, dsn, dsnlen, 0);
186 StrBufAppendBufPlain(BounceMB, HKEY(
"\r\n"), 0);
192 StrBufAppendBufPlain(BounceMB, HKEY(
"--"), 0);
193 StrBufAppendBuf(BounceMB, boundary, 0);
194 StrBufAppendBufPlain(BounceMB, HKEY(
"\r\n"), 0);
195 StrBufAppendBufPlain(BounceMB, HKEY(
"Content-type: message/rfc822\r\n"), 0);
196 StrBufAppendBufPlain(BounceMB, HKEY(
"Content-Transfer-Encoding: 7bit\r\n"), 0);
197 StrBufAppendBufPlain(BounceMB, HKEY(
"Content-Disposition: inline\r\n"), 0);
198 StrBufAppendBufPlain(BounceMB, HKEY(
"\r\n"), 0);
200 CC->redirect_buffer = NewStrBufPlain(NULL,
SIZ);
207 StrBufAppendBuf(BounceMB,
CC->redirect_buffer, 0);
208 FreeStrBuf(&
CC->redirect_buffer);
212 StrBufAppendBufPlain(BounceMB, HKEY(
"--"), 0);
213 StrBufAppendBuf(BounceMB, boundary, 0);
214 StrBufAppendBufPlain(BounceMB, HKEY(
"--\r\n"), 0);
218 syslog(LOG_DEBUG,
"num_bounces = %d", num_bounces);
219 if (num_bounces > 0) {
222 if (IsEmptyStr(bounceto)) {
223 syslog(LOG_ERR,
"No bounce address specified");
226 syslog(LOG_DEBUG,
"bounce to user <%s>", bounceto);
233 successful_bounce = 1;
238 if (successful_bounce == 0) {
247 FreeStrBuf(&boundary);
249 syslog(LOG_DEBUG,
"Done processing bounces");
254 {
"211 - System status / system help reply" },
255 {
"214",
"Help message" },
256 {
"220",
"Domain service ready" },
257 {
"221",
"Domain service closing transmission channel" },
258 {
"250",
"Requested mail action completed and OK" },
259 {
"251",
"Not Local User, forward email to forward path" },
260 {
"252",
"Cannot Verify user, will attempt delivery later" },
261 {
"253",
"Pending messages for node started" },
262 {
"354",
"Start mail input; end with ." },
263 {
"355",
"Octet-offset is the transaction offset" },
264 {
"421",
"Domain service not available, closing transmission channel" },
265 {
"432",
"Domain service not available, closing transmission channel" },
266 {
"450",
"Requested mail action not taken: mailbox unavailable. request refused" },
267 {
"451",
"Requested action aborted: local error in processing Request is unable to be processed, try again" },
268 {
"452",
"Requested action not taken: insufficient system storage" },
269 {
"453",
"No mail" },
270 {
"454",
"TLS not available due to temporary reason. Encryption required for requested authentication mechanism" },
271 {
"458",
"Unable to queue messages for node" },
272 {
"459",
"Node not allowed: reason" },
273 {
"500",
"Syntax error, command unrecognized" },
274 {
"501",
"Syntax error in parameters or arguments" },
275 {
"502",
"Command not implemented" },
276 {
"503",
"Bad sequence of commands" },
277 {
"504",
"Command parameter not implemented" },
278 {
"510",
"Check the recipient address" },
279 {
"512",
"Domain can not be found. Unknown host." },
280 {
"515",
"Destination mailbox address invalid" },
281 {
"517",
"Problem with senders mail attribute, check properties" },
282 {
"521",
"Domain does not accept mail" },
283 {
"522",
"Recipient has exceeded mailbox limit" },
284 {
"523",
"Server limit exceeded. Message too large" },
285 {
"530",
"Access Denied. Authentication required" },
286 {
"531",
"Mail system Full" },
287 {
"533",
"Remote ../../server.has insufficient disk space to hold email" },
288 {
"534",
"Authentication mechanism is too weak. Message too big" },
289 {
"535",
"Multiple servers using same IP. Required Authentication" },
290 {
"538",
"Encryption required for requested authentication mechanism" },
291 {
"540",
"Email address has no DNS Server" },
292 {
"541",
"No response from host" },
293 {
"542",
"Bad Connection" },
294 {
"543",
"Routing server failure. No available route" },
295 {
"546",
"Email looping" },
296 {
"547",
"Delivery time-out" },
297 {
"550",
"Requested action not taken: mailbox unavailable or relaying denied" },
298 {
"551",
"User not local; please try forward path" },
299 {
"552",
"Requested mail action aborted: exceeded storage allocation" },
300 {
"553",
"Requested action not taken: mailbox name not allowed" },
301 {
"554",
"Transaction failed" }
308 for (i=0; i<(
sizeof(
smtpcodes)/
sizeof(
char *)/2); ++i) {
314 return(
"Unknown or other SMTP status");
char * CtdlGetConfigStr(char *key)
struct recptypes * validate_recipients(char *supplied_recipients, const char *RemoteIdentifier, int Flags)
void free_recipients(struct recptypes *valid)
void CM_Free(struct CtdlMessage *msg)
int CtdlOutputMsg(long msg_num, int mode, int headers_only, int do_proto, int crlf, char *section, int flags, char **Author, char **Address, char **MessageID)
long CtdlSubmitMsg(struct CtdlMessage *msg, struct recptypes *recps, const char *force)
void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length)
void CM_SetAsFieldSB(struct CtdlMessage *Msg, eMsgField which, StrBuf **buf)
#define CTDLMESSAGE_MAGIC
const char * smtp_get_Recipients(void)
char * smtpstatus(int code)
void smtp_do_bounce(const char *instr, int is_final)