#include "support.h"
#include "config.h"
#include "control.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
#include "room_ops.h"
#include "user_ops.h"
#include "policy.h"
char buf[SIZ];
char username[SIZ];
- decode_base64(username, argbuf, SIZ);
+ CtdlDecodeBase64(username, argbuf, SIZ);
lprintf(9, "Trying <%s>\n", username);
if (CtdlLoginExistingUser(username) == login_ok) {
- encode_base64(buf, "Password:");
+ CtdlEncodeBase64(buf, "Password:", 9);
cprintf("334 %s\r\n", buf);
SMTP->command_state = smtp_password;
}
void smtp_get_pass(char *argbuf) {
char password[SIZ];
- decode_base64(password, argbuf, SIZ);
+ CtdlDecodeBase64(password, argbuf, SIZ);
lprintf(9, "Trying <%s>\n", password);
if (CtdlTryPassword(password) == pass_ok) {
cprintf("235 Hello, %s\r\n", CC->usersupp.fullname);
}
else {
- encode_base64(buf, "Username:");
+ CtdlEncodeBase64(buf, "Username:", 9);
cprintf("334 %s\r\n", buf);
SMTP->command_state = smtp_user;
}
long msgnum;
char nowstamp[SIZ];
struct recptypes *valid;
+ int scan_errors;
if (strlen(SMTP->from) == 0) {
cprintf("503 Need MAIL command first.\r\n");
/* Submit the message into the Citadel system. */
valid = validate_recipients(SMTP->recipients);
- msgnum = CtdlSubmitMsg(msg, valid, "");
- CtdlFreeMessage(msg);
- phree(valid);
- if (msgnum > 0L) {
- cprintf("250 Message accepted.\r\n");
+ /* If there are modules that want to scan this message before final
+ * submission (such as virus checkers or spam filters), call them now
+ * and give them an opportunity to reject the message.
+ */
+ scan_errors = PerformMessageHooks(msg, EVT_SMTPSCAN);
+
+ if (scan_errors > 0) { /* We don't want this message! */
+
+ if (msg->cm_fields['0'] == NULL) {
+ msg->cm_fields['0'] = strdoop(
+ "Message rejected by filter");
+ }
+
+ cprintf("552 %s\r\n", msg->cm_fields['0']);
}
- else {
- cprintf("550 Internal delivery error\r\n");
+
+ else { /* Ok, we'll accept this message. */
+ msgnum = CtdlSubmitMsg(msg, valid, "");
+ if (msgnum > 0L) {
+ cprintf("250 Message accepted.\r\n");
+ }
+ else {
+ cprintf("550 Internal delivery error\r\n");
+ }
}
+ CtdlFreeMessage(msg);
+ phree(valid);
smtp_data_clear(); /* clear out the buffers now */
}
}
else {
CtdlRedirectOutput(msg_fp, -1);
- CtdlOutputMsg(msgnum, MT_RFC822, 0, 0, 1);
+ CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
CtdlRedirectOutput(NULL, -1);
fseek(msg_fp, 0L, SEEK_END);
msg_size = ftell(msg_fp);
/* If not, post it in the Aide> room */
if (successful_bounce == 0) {
- CtdlSubmitMsg(bmsg, NULL, AIDEROOM);
+ CtdlSubmitMsg(bmsg, NULL, config.c_aideroom);
}
/* Free up the memory we used */
lprintf(3, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
return;
}
- CtdlForEachMessage(MSGS_ALL, 0L, (-127),
+ CtdlForEachMessage(MSGS_ALL, 0L,
SPOOLMIME, NULL, smtp_do_procmsg, NULL);
lprintf(7, "SMTP: queue run completed\n");
}
+/*
+ * Initialize the SMTP outbound queue
+ */
+void smtp_init_spoolout(void) {
+ struct quickroom qrbuf;
+
+ /*
+ * Create the room. This will silently fail if the room already
+ * exists, and that's perfectly ok, because we want it to exist.
+ */
+ create_room(SMTP_SPOOLOUT_ROOM, 3, "", 0, 1, 0);
+
+ /*
+ * Make sure it's set to be a "system room" so it doesn't show up
+ * in the <K>nown rooms list for Aides.
+ */
+ if (lgetroom(&qrbuf, SMTP_SPOOLOUT_ROOM) == 0) {
+ qrbuf.QRflags2 |= QR2_SYSTEM;
+ lputroom(&qrbuf);
+ }
+}
+
+
/*****************************************************************************/
/*****************************************************************************/
-char *Dynamic_Module_Init(void)
+char *serv_smtp_init(void)
{
SYM_SMTP = CtdlGetDynamicSymbol();
smtp_greeting,
smtp_command_loop);
- create_room(SMTP_SPOOLOUT_ROOM, 3, "", 0, 1);
+ smtp_init_spoolout();
CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
return "$Id$";