]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_smtp.c
calculate the directories in a central manner.
[citadel.git] / citadel / serv_smtp.c
index c5da74dd3e8352964a3a31fcf7b394f4d5e0e945..3b5ddb9a971564d63656d5cbec01fb8ef89c0f9b 100644 (file)
@@ -31,6 +31,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <syslog.h>
 
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -625,7 +626,7 @@ void smtp_rcpt(char *argbuf) {
        }
 
        valid = validate_recipients(recp);
-       if (valid->num_error > 0) {
+       if (valid->num_error != 0) {
                cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg);
                free(valid);
                return;
@@ -667,7 +668,7 @@ void smtp_rcpt(char *argbuf) {
 void smtp_data(void) {
        char *body;
        struct CtdlMessage *msg;
-       long msgnum;
+       long msgnum = (-1L);
        char nowstamp[SIZ];
        struct recptypes *valid;
        int scan_errors;
@@ -756,7 +757,7 @@ void smtp_data(void) {
        }
        
        else {                  /* Ok, we'll accept this message. */
-               msgnum = CtdlSubmitMsg(msg, valid, NULL, NULL, "");
+               msgnum = CtdlSubmitMsg(msg, valid, "");
                if (msgnum > 0L) {
                        sprintf(result, "250 2.0.0 Message accepted.\r\n");
                }
@@ -780,6 +781,22 @@ void smtp_data(void) {
                cprintf("%s", result);
        }
 
+       /* Write something to the syslog (which may or may not be where the
+        * rest of the Citadel logs are going; some sysadmins want LOG_MAIL).
+        */
+       if (enable_syslog) {
+               syslog((LOG_MAIL | LOG_INFO),
+                       "%ld: from=<%s>, nrcpts=%d, relay=%s [%s], stat=%s",
+                       msgnum,
+                       SMTP->from,
+                       SMTP->number_of_recipients,
+                       CC->cs_host,
+                       CC->cs_addr,
+                       result
+               );
+       }
+
+       /* Clean up */
        CtdlFreeMessage(msg);
        free(valid);
        smtp_data_clear();      /* clear out the buffers now */
@@ -818,7 +835,7 @@ void smtp_command_loop(void) {
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
-               lprintf(CTDL_CRIT, "SMTP socket is broken.  Ending session.\n");
+               lprintf(CTDL_CRIT, "Client disconnected: ending session.\n");
                CC->kill_me = 1;
                return;
        }
@@ -921,9 +938,11 @@ void smtp_try(const char *key, const char *addr, int *status,
        int num_mxhosts;
        int mx;
        int i;
-       char user[SIZ], node[SIZ], name[SIZ];
+       char user[1024], node[1024], name[1024];
        char buf[1024];
        char mailfrom[1024];
+       char mx_host[256];
+       char mx_port[256];
        int lp, rp;
        char *msgtext;
        char *ptr;
@@ -940,7 +959,7 @@ void smtp_try(const char *key, const char *addr, int *status,
        CC->redirect_buffer = malloc(SIZ);
        CC->redirect_len = 0;
        CC->redirect_alloc = SIZ;
-       CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1);
+       CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1, NULL);
        msgtext = CC->redirect_buffer;
        msg_size = CC->redirect_len;
        CC->redirect_buffer = NULL;
@@ -1006,8 +1025,13 @@ void smtp_try(const char *key, const char *addr, int *status,
        sock = (-1);
        for (mx=0; (mx<num_mxhosts && sock < 0); ++mx) {
                extract_token(buf, mxhosts, mx, '|', sizeof buf);
-               lprintf(CTDL_DEBUG, "Trying <%s>\n", buf);
-               sock = sock_connect(buf, "25", "tcp");
+               extract_token(mx_host, buf, 0, ':', sizeof mx_host);
+               extract_token(mx_port, buf, 1, ':', sizeof mx_port);
+               if (!mx_port[0]) {
+                       strcpy(mx_port, "25");
+               }
+               lprintf(CTDL_DEBUG, "Trying %s : %s ...\n", mx_host, mx_port);
+               sock = sock_connect(mx_host, mx_port, "tcp");
                snprintf(dsn, SIZ, "Could not connect: %s", strerror(errno));
                if (sock >= 0) lprintf(CTDL_DEBUG, "Connected!\n");
                if (sock < 0) snprintf(dsn, SIZ, "%s", strerror(errno));
@@ -1172,6 +1196,20 @@ void smtp_try(const char *key, const char *addr, int *status,
 
 bail:  free(msgtext);
        sock_close(sock);
+
+       /* Write something to the syslog (which may or may not be where the
+        * rest of the Citadel logs are going; some sysadmins want LOG_MAIL).
+        */
+       if (enable_syslog) {
+               syslog((LOG_MAIL | LOG_INFO),
+                       "%ld: to=<%s>, relay=%s, stat=%s",
+                       msgnum,
+                       addr,
+                       mx_host,
+                       dsn
+               );
+       }
+
        return;
 }
 
@@ -1309,14 +1347,14 @@ void smtp_do_bounce(char *instr) {
                valid = validate_recipients(bounceto);
                if (valid != NULL) {
                        if (valid->num_error == 0) {
-                               CtdlSubmitMsg(bmsg, valid, NULL, NULL, "");
+                               CtdlSubmitMsg(bmsg, valid, "");
                                successful_bounce = 1;
                        }
                }
 
                /* If not, post it in the Aide> room */
                if (successful_bounce == 0) {
-                       CtdlSubmitMsg(bmsg, NULL, NULL, NULL, config.c_aideroom);
+                       CtdlSubmitMsg(bmsg, NULL, config.c_aideroom);
                }
 
                /* Free up the memory we used */
@@ -1550,7 +1588,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                        "attempted|%ld\n"
                        "retry|%ld\n",
                        SPOOLMIME, instr, (long)time(NULL), (long)retry );
-               CtdlSubmitMsg(msg, NULL, NULL, NULL, SMTP_SPOOLOUT_ROOM);
+               CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM);
                CtdlFreeMessage(msg);
        }
 
@@ -1685,6 +1723,8 @@ void smtp_cleanup_function(void) {
 
 char *serv_smtp_init(void)
 {
+       char filename[256];
+
        CtdlRegisterServiceHook(config.c_smtp_port,     /* SMTP MTA */
                                NULL,
                                smtp_greeting,
@@ -1705,24 +1745,22 @@ char *serv_smtp_init(void)
                                smtp_command_loop,
                                NULL);
 
+       snprintf(filename, 
+                        sizeof filename,
+                        "%s/lmtp.sock",
+                        ctdl_run_dir);
        CtdlRegisterServiceHook(0,                      /* local LMTP */
-#ifndef HAVE_RUN_DIR
-                                                       "."
-#else
-                                                       RUN_DIR
-#endif
-                                                       "/lmtp.socket",
+                                                       filename,
                                                        lmtp_greeting,
                                                        smtp_command_loop,
                                                        NULL);
 
+       snprintf(filename, 
+                        sizeof filename,
+                        "%s/lmtp-unfiltered.sock",
+                        ctdl_run_dir);
        CtdlRegisterServiceHook(0,                      /* local LMTP */
-#ifndef HAVE_RUN_DIR
-                                                       "."
-#else
-                                                       RUN_DIR
-#endif
-                                                       "/lmtp-unfiltered.socket",
+                                                       filename,
                                                        lmtp_unfiltered_greeting,
                                                        smtp_command_loop,
                                                        NULL);