/*
- * $Id$
- *
* This module is an SMTP and ESMTP implementation for the Citadel system.
* It is compliant with all of the following:
*
#include "config.h"
#include "control.h"
#include "user_ops.h"
-#include "policy.h"
#include "database.h"
#include "msgbase.h"
#include "internet_addressing.h"
int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */
-citthread_mutex_t smtp_send_lock;
-
/*****************************************************************************/
/* SMTP SERVER (INBOUND) STUFF */
*/
void smtp_get_pass(char *argbuf) {
char password[SIZ];
+ long len;
memset(password, 0, sizeof(password));
- CtdlDecodeBase64(password, argbuf, SIZ);
+ len = CtdlDecodeBase64(password, argbuf, SIZ);
/* CtdlLogPrintf(CTDL_DEBUG, "Trying <%s>\n", password); */
- if (CtdlTryPassword(password) == pass_ok) {
+ if (CtdlTryPassword(password, len) == pass_ok) {
smtp_auth_greeting();
}
else {
char user[256];
char pass[256];
int result;
+ long len;
CtdlDecodeBase64(decoded_authstring, encoded_authstring, strlen(encoded_authstring) );
safestrncpy(ident, decoded_authstring, sizeof ident);
safestrncpy(user, &decoded_authstring[strlen(ident) + 1], sizeof user);
- safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
+ len = safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
+ if (len == -1)
+ len = sizeof(pass) - 1;
SMTP->command_state = smtp_command;
}
if (result == login_ok) {
- if (CtdlTryPassword(pass) == pass_ok) {
+ if (CtdlTryPassword(pass, len) == pass_ok) {
smtp_auth_greeting();
return;
}
/* Load the message out of the database */
CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
- CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, ESC_DOT);
+ CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL, (ESC_DOT|SUPPRESS_ENV_TO) );
msg_size = StrLength(CC->redirect_buffer);
msgtext = SmashStrBuf(&CC->redirect_buffer);
scan_done = 0;
ptr = msgtext;
do {
- if (ptr = memreadline(ptr, buf, sizeof buf), *ptr == 0) {
+ if (ptr = cmemreadline(ptr, buf, sizeof buf), *ptr == 0) {
scan_done = 1;
}
if (!strncasecmp(buf, "From:", 5)) {
strcpy(mx_port, "25");
}
CtdlLogPrintf(CTDL_DEBUG, "SMTP client: connecting to %s : %s ...\n", mx_host, mx_port);
- sock = sock_connect(mx_host, mx_port, "tcp");
+ sock = sock_connect(mx_host, mx_port);
snprintf(dsn, SIZ, "Could not connect: %s", strerror(errno));
if (sock >= 0) CtdlLogPrintf(CTDL_DEBUG, "SMTP client: connected!\n");
if (sock < 0) {
/*
- * smtp_do_queue()
+ * smtp_queue_thread()
*
* Run through the queue sending out messages.
*/
-void *smtp_do_queue(void *arg) {
+void *smtp_queue_thread(void *arg) {
int num_processed = 0;
struct CitContext smtp_queue_CC;
- CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n");
-
CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send");
- citthread_setspecific(MyConKey, (void *)&smtp_queue_CC );
-
- if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
- CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
- }
- else {
- num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL);
- }
-
- citthread_mutex_unlock (&smtp_send_lock);
- CtdlLogPrintf(CTDL_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed);
- return(NULL);
-}
-
+ citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
+ CtdlLogPrintf(CTDL_DEBUG, "smtp_queue_thread() initializing\n");
+ while (!CtdlThreadCheckStop()) {
+
+ CtdlLogPrintf(CTDL_INFO, "SMTP client: processing outbound queue\n");
-/*
- * smtp_queue_thread
- *
- * Create a thread to run the SMTP queue
- *
- * This was created as a response to a situation seen on Uncensored where a bad remote was holding
- * up SMTP sending for long times.
- * Converting to a thread does not fix the problem caused by the bad remote but it does prevent
- * the SMTP sending from stopping housekeeping and the EVT_TIMER event system which in turn prevented
- * other things from happening.
- */
-void smtp_queue_thread (void)
-{
- if (citthread_mutex_trylock (&smtp_send_lock)) {
- CtdlLogPrintf(CTDL_DEBUG, "SMTP queue run already in progress\n");
- }
- else {
- CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_do_queue, NULL);
+ if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
+ CtdlLogPrintf(CTDL_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
+ }
+ else {
+ num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL);
+ }
+ CtdlLogPrintf(CTDL_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed);
+ CtdlThreadSleep(60);
}
-}
-
-
-void smtp_server_going_down (void)
-{
- CtdlLogPrintf(CTDL_DEBUG, "SMTP module clean up for shutdown.\n");
-
- citthread_mutex_destroy (&smtp_send_lock);
+ CtdlClearSystemContext();
+ return(NULL);
}
CitadelServiceSMTP_LMTP_UNF);
smtp_init_spoolout();
- CtdlRegisterSessionHook(smtp_queue_thread, EVT_TIMER);
CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP);
CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
- CtdlRegisterCleanupHook (smtp_server_going_down);
- citthread_mutex_init (&smtp_send_lock, NULL);
+ CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_queue_thread, NULL);
}
/* return our Subversion id for the Log */
- return "$Id$";
+ return "smtp";
}