]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_smtp.c
Removed some outdated cruft from the SMTP queue handler:
[citadel.git] / citadel / serv_smtp.c
index fdc1a217b4dc0e1a403a86501001c560762288c5..e8fcf69bc56074c294cfa13cc4a71149651e0bbb 100644 (file)
@@ -106,14 +106,7 @@ enum {                             /* Command states for login authentication */
        smtp_plain
 };
 
-enum {                         /* Delivery modes */
-       smtp_deliver_local,
-       smtp_deliver_remote
-};
-
 #define SMTP           CC->SMTP
-#define SMTP_RECPS     CC->SMTP_RECPS
-#define SMTP_ROOMS     CC->SMTP_ROOMS
 
 
 int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */
@@ -128,7 +121,7 @@ int run_queue_now = 0;      /* Set to 1 to ignore SMTP send retry times */
 /*
  * Here's where our SMTP session begins its happy day.
  */
-void smtp_greeting(void)
+void smtp_greeting(int is_msa)
 {
        char message_to_spammer[1024];
 
@@ -136,20 +129,17 @@ void smtp_greeting(void)
        CC->internal_pgm = 1;
        CC->cs_flags |= CS_STEALTH;
        SMTP = malloc(sizeof(struct citsmtp));
-       SMTP_RECPS = malloc(SIZ);
-       SMTP_ROOMS = malloc(SIZ);
        memset(SMTP, 0, sizeof(struct citsmtp));
-       memset(SMTP_RECPS, 0, SIZ);
-       memset(SMTP_ROOMS, 0, SIZ);
+       SMTP->is_msa = is_msa;
 
        /* If this config option is set, reject connections from problem
         * addresses immediately instead of after they execute a RCPT
         */
-       if (config.c_rbl_at_greeting) {
+       if ( (config.c_rbl_at_greeting) && (SMTP->is_msa == 0) ) {
                if (rbl_check(message_to_spammer)) {
                        cprintf("550 %s\r\n", message_to_spammer);
                        CC->kill_me = 1;
-                       /* no need to free(valid), it's not allocated yet */
+                       /* no need to free_recipients(valid), it's not allocated yet */
                        return;
                }
        }
@@ -161,7 +151,7 @@ void smtp_greeting(void)
                        config.c_maxsessions
                );
                CC->kill_me = 1;
-               /* no need to free(valid), it's not allocated yet */
+               /* no need to free_recipients(valid), it's not allocated yet */
                return;
        }
 
@@ -175,7 +165,7 @@ void smtp_greeting(void)
 #ifdef HAVE_OPENSSL
 void smtps_greeting(void) {
        CtdlStartTLS(NULL, NULL, NULL);
-       smtp_greeting();
+       smtp_greeting(0);
 }
 #endif
 
@@ -184,8 +174,7 @@ void smtps_greeting(void) {
  * SMTP MSA port requires authentication.
  */
 void smtp_msa_greeting(void) {
-       smtp_greeting();
-       SMTP->is_msa = 1;
+       smtp_greeting(1);
 }
 
 
@@ -193,16 +182,24 @@ void smtp_msa_greeting(void) {
  * LMTP is like SMTP but with some extra bonus footage added.
  */
 void lmtp_greeting(void) {
-       smtp_greeting();
+       smtp_greeting(0);
        SMTP->is_lmtp = 1;
 }
 
 
+/* 
+ * Generic SMTP MTA greeting
+ */
+void smtp_mta_greeting(void) {
+       smtp_greeting(0);
+}
+
+
 /*
  * We also have an unfiltered LMTP socket that bypasses spam filters.
  */
 void lmtp_unfiltered_greeting(void) {
-       smtp_greeting();
+       smtp_greeting(0);
        SMTP->is_lmtp = 1;
        SMTP->is_unfiltered = 1;
 }
@@ -667,7 +664,7 @@ void smtp_rcpt(char *argbuf) {
                if (config.c_rbl_at_greeting == 0) {    /* Don't RBL again if we already did it */
                        if (rbl_check(message_to_spammer)) {
                                cprintf("550 %s\r\n", message_to_spammer);
-                               /* no need to free(valid), it's not allocated yet */
+                               /* no need to free_recipients(valid), it's not allocated yet */
                                return;
                        }
                }
@@ -676,7 +673,7 @@ void smtp_rcpt(char *argbuf) {
        valid = validate_recipients(recp);
        if (valid->num_error != 0) {
                cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg);
-               free(valid);
+               free_recipients(valid);
                return;
        }
 
@@ -684,7 +681,7 @@ void smtp_rcpt(char *argbuf) {
                if (CC->logged_in) {
                         if (CtdlCheckInternetMailPermission(&CC->user)==0) {
                                cprintf("551 5.7.1 <%s> - you do not have permission to send Internet mail\r\n", recp);
-                                free(valid);
+                                free_recipients(valid);
                                 return;
                         }
                 }
@@ -694,7 +691,7 @@ void smtp_rcpt(char *argbuf) {
                if ( (SMTP->message_originated_locally == 0)
                   && (SMTP->is_lmtp == 0) ) {
                        cprintf("551 5.7.1 <%s> - relaying denied\r\n", recp);
-                       free(valid);
+                       free_recipients(valid);
                        return;
                }
        }
@@ -706,7 +703,7 @@ void smtp_rcpt(char *argbuf) {
        strcat(SMTP->recipients, recp);
        SMTP->number_of_recipients += 1;
        if (valid != NULL) 
-               free(valid);
+               free_recipients(valid);
 }
 
 
@@ -860,7 +857,7 @@ void smtp_data(void) {
 
        /* Clean up */
        CtdlFreeMessage(msg);
-       free(valid);
+       free_recipients(valid);
        smtp_data_clear();      /* clear out the buffers now */
 }
 
@@ -1370,6 +1367,9 @@ void smtp_do_bounce(char *instr) {
        struct recptypes *valid;
        int successful_bounce = 0;
        static int seq = 0;
+       char *omsgtext;
+       size_t omsgsize;
+       long omsgid = (-1);
 
        lprintf(CTDL_DEBUG, "smtp_do_bounce() called\n");
        strcpy(bounceto, "");
@@ -1390,6 +1390,8 @@ void smtp_do_bounce(char *instr) {
                give_up = 1;
        }
 
+       /* Start building our bounce message */
+
        bmsg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
        if (bmsg == NULL) return;
        memset(bmsg, 0, sizeof(struct CtdlMessage));
@@ -1403,7 +1405,6 @@ void smtp_do_bounce(char *instr) {
         bmsg->cm_fields['U'] = strdup("Delivery Status Notification (Failure)");
        bmsg->cm_fields['M'] = malloc(1024);
 
-
         strcpy(bmsg->cm_fields['M'], "Content-type: multipart/mixed; boundary=\"");
         strcat(bmsg->cm_fields['M'], boundary);
         strcat(bmsg->cm_fields['M'], "\"\r\n");
@@ -1444,12 +1445,11 @@ void smtp_do_bounce(char *instr) {
                        strcpy(bounceto, addr);
                }
 
-               if (
-                  (!strcasecmp(key, "local"))
-                  || (!strcasecmp(key, "remote"))
-                  || (!strcasecmp(key, "ignet"))
-                  || (!strcasecmp(key, "room"))
-               ) {
+               if (!strcasecmp(key, "msgid")) {
+                       omsgid = atol(addr);
+               }
+
+               if (!strcasecmp(key, "remote")) {
                        if (status == 5) bounce_this = 1;
                        if (give_up) bounce_this = 1;
                }
@@ -1475,14 +1475,32 @@ void smtp_do_bounce(char *instr) {
                }
        }
 
-       /* Attach the original message 
-        strcat(bmsg->cm_fields['M'], "--");
-        strcat(bmsg->cm_fields['M'], boundary);
-        strcat(bmsg->cm_fields['M'], "\r\n");
-        strcat(bmsg->cm_fields['M'], "Content-type: application/octet-stream\r\n\r\n");
-        strcat(bmsg->cm_fields['M'], "all your message are belong to FIXME\r\n");
-       */
-
+       /* Attach the original message */
+       if (omsgid >= 0) {
+               strcat(bmsg->cm_fields['M'], "--");
+               strcat(bmsg->cm_fields['M'], boundary);
+               strcat(bmsg->cm_fields['M'], "\r\n");
+               strcat(bmsg->cm_fields['M'], "Content-type: message/rfc822\r\n");
+               strcat(bmsg->cm_fields['M'], "Content-Transfer-Encoding: 7bit\r\n");
+               strcat(bmsg->cm_fields['M'], "Content-Disposition: inline\r\n");
+               strcat(bmsg->cm_fields['M'], "\r\n");
+       
+               CC->redirect_buffer = malloc(SIZ);
+               CC->redirect_len = 0;
+               CC->redirect_alloc = SIZ;
+               CtdlOutputMsg(omsgid, MT_RFC822, HEADERS_ALL, 0, 1, NULL);
+               omsgtext = CC->redirect_buffer;
+               omsgsize = CC->redirect_len;
+               CC->redirect_buffer = NULL;
+               CC->redirect_len = 0;
+               CC->redirect_alloc = 0;
+               bmsg->cm_fields['M'] = realloc(bmsg->cm_fields['M'],
+                               (strlen(bmsg->cm_fields['M']) + omsgsize + 1024) );
+               strcat(bmsg->cm_fields['M'], omsgtext);
+               free(omsgtext);
+       }
+
+       /* Close the multipart MIME scope */
         strcat(bmsg->cm_fields['M'], "--");
         strcat(bmsg->cm_fields['M'], boundary);
         strcat(bmsg->cm_fields['M'], "--\r\n");
@@ -1514,7 +1532,7 @@ void smtp_do_bounce(char *instr) {
 
                /* Free up the memory we used */
                if (valid != NULL) {
-                       free(valid);
+                       free_recipients(valid);
                }
        }
 
@@ -1550,12 +1568,7 @@ int smtp_purge_completed_deliveries(char *instr) {
 
                completed = 0;
 
-               if (
-                  (!strcasecmp(key, "local"))
-                  || (!strcasecmp(key, "remote"))
-                  || (!strcasecmp(key, "ignet"))
-                  || (!strcasecmp(key, "room"))
-               ) {
+               if (!strcasecmp(key, "remote")) {
                        if (status == 2) completed = 1;
                        else ++incomplete;
                }
@@ -1869,8 +1882,6 @@ void smtp_cleanup_function(void) {
 
        lprintf(CTDL_DEBUG, "Performing SMTP cleanup hook\n");
        free(SMTP);
-       free(SMTP_ROOMS);
-       free(SMTP_RECPS);
 }
 
 
@@ -1882,7 +1893,7 @@ char *serv_smtp_init(void)
 
        CtdlRegisterServiceHook(config.c_smtp_port,     /* SMTP MTA */
                                NULL,
-                               smtp_greeting,
+                               smtp_mta_greeting,
                                smtp_command_loop,
                                NULL);