]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtp.c
Changed the behavior introduced in commit fb862a2894f01c5fb6144ec781f188445c13c7f1...
[citadel.git] / citadel / modules / smtp / serv_smtp.c
index d6f8e2a30e72ace82cfa10d1287a976d684a8a6a..2ebcc4bc12440a88e14dd1a3927376a1fb25a606 100644 (file)
@@ -691,6 +691,32 @@ void smtp_data(void) {
         * is read with a Citadel client.
         */
        if ( (CC->logged_in) && (config.c_rfc822_strict_from == 0) ) {
+
+#ifdef SMTP_REJECT_INVALID_SENDER
+               int validemail = 0;
+
+               if (!IsEmptyStr(CC->cs_inet_email) && 
+                   !IsEmptyStr(msg->cm_fields['F']))
+                       validemail = strcmp(CC->cs_inet_email, msg->cm_fields['F']) == 0;
+               if ((!validemail) && 
+                   (!IsEmptyStr(CC->cs_inet_other_emails)))
+               {
+                       int num_secondary_emails = 0;
+                       int i;
+                       num_secondary_emails = num_tokens(CC->cs_inet_other_emails, '|');
+                       for (i=0; i<num_secondary_emails && !validemail; ++i) {
+                               char buf[256];
+                               extract_token(buf, CC->cs_inet_other_emails,i,'|',sizeof CC->cs_inet_other_emails);
+                               validemail = strcmp(buf, msg->cm_fields['F']) == 0;
+                       }
+               }
+               if (!validemail) {
+                       syslog(LOG_ERR, "invalid sender '%s' - rejecting this message", msg->cm_fields['F']);
+                       cprintf("550 Invalid sender '%s' - rejecting this message.\r\n", msg->cm_fields['F']);
+                       return;
+               }
+#endif /* SMTP_REJECT_INVALID_SENDER */
+
                if (msg->cm_fields['A'] != NULL) free(msg->cm_fields['A']);
                if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']);
                if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']);
@@ -961,7 +987,7 @@ CTDL_MODULE_INIT(smtp)
                                        NULL,
                                        CitadelServiceSMTP_LMTP_UNF);
 
-               CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP);
+               CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP, PRIO_STOP + 250);
        }
        
        /* return our module name for the log */