* Added a new message function hook type EVT_SMTPSCAN which permits modules to
authorArt Cancro <ajc@citadel.org>
Fri, 7 Jun 2002 22:10:51 +0000 (22:10 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 7 Jun 2002 22:10:51 +0000 (22:10 +0000)
  register hooks that can scan incoming SMTP messages and elect to reject them
  (due to virus or spam content, for example).

citadel/ChangeLog
citadel/serv_smtp.c
citadel/server.h
citadel/techdoc/hack.txt

index 2768183f4dc85ebd4fd3477f42564eac5a045df4..0a8ba560f28e7211916af4be05cb3d9d61213b2d 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 591.36  2002/06/07 22:10:51  ajc
+ * Added a new message function hook type EVT_SMTPSCAN which permits modules to
+   register hooks that can scan incoming SMTP messages and elect to reject them
+   (due to virus or spam content, for example).
+
  Revision 591.35  2002/06/07 03:22:13  ajc
  * Added a module "serv_mrtg" which allows activity reporting to MRTG
    (http://www.mrtg.org) -- this will replace our stats program.
@@ -3692,3 +3697,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 6617cc2c4e465376e6e29afd4586ba190fb42624..43896c28092e0f89180028ffc68e0623751c961e 100644 (file)
@@ -457,6 +457,7 @@ void smtp_data(void) {
        long msgnum;
        char nowstamp[SIZ];
        struct recptypes *valid;
+       int scan_errors;
 
        if (strlen(SMTP->from) == 0) {
                cprintf("503 Need MAIL command first.\r\n");
@@ -508,17 +509,35 @@ void smtp_data(void) {
 
        /* 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 */
 }
 
index c8cb8925444f7f3885ee5993ab45170dbb2f5e29..127be4c9572fdfeb016ee487c81ed088c0a9b60d 100644 (file)
@@ -338,6 +338,7 @@ extern DLEXP struct MessageFunctionHook *MessageHookTable;
 #define EVT_BEFOREREAD 200
 #define EVT_BEFORESAVE 201
 #define EVT_AFTERSAVE  202
+#define EVT_SMTPSCAN   203     /* called before submitting a msg from SMTP */
 
 
 
index 90bbe404adc93d9f3453f27771ac62035071a8f5..af5ce2cd13742ad82f9afa470156d3177bb41cc0 100644 (file)
@@ -117,6 +117,11 @@ T  Date/Time       A 32-bit integer containing the date and time of
 U       Subject         Optional.  Developers may choose whether they wish to
                         generate or display subject fields.  Citadel/UX does
                         not generate them, but it does print them when found.
+0      Error           This field is typically never found in a message on
+                       disk or in transit.  Message scanning modules are
+                       expected to fill in this field when rejecting a message
+                       with an explanation as to what happened (virus found,
+                       message looks like spam, etc.)
   
                        EXAMPLE