OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/msg.c versions 1.16 and 1.17
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/msg.c 1.16 -> 1.17

--- msg.c        2001/09/04 09:46:06     1.16
+++ msg.c        2001/09/11 13:41:22     1.17
@@ -31,6 +31,9 @@
 #include "str.h"
 #include "argz.h"
 
+/* third party */
+#include "l2.h"
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -50,6 +53,7 @@
     msg->cpMsg = NULL;
     msg->azHeaders = NULL;
     msg->asHeaders = 0;
+    msg->cpFid = NULL;
     msg->cpBody = NULL;
     msg->cpMsgid = NULL;
     msg->mail_from = NULL;
@@ -57,6 +61,7 @@
     msg->asRcpt = 0;
     msg->azNewsgroups = NULL;
     msg->asNewsgroups = 0;
+    msg->l2 = NULL; /* this is a copy only */
 
     return msg;
 }
@@ -72,6 +77,8 @@
         free(msg->cpMsg);
     if (msg->azHeaders != NULL)
         free(msg->azHeaders);
+    if (msg->cpFid != NULL)
+        free(msg->cpFid);
     if (msg->cpBody != NULL)
         free(msg->cpBody);
     if (msg->cpMsgid != NULL)
@@ -82,6 +89,7 @@
         free(msg->azRcpt);
     if (msg->azNewsgroups != NULL)
         free(msg->azNewsgroups);
+    msg->l2 = NULL; /* this is a copy only, the "parent" needs to clean this up */
 
     free(msg);
     return;
@@ -126,29 +134,30 @@
      * header information.
      */
 
-    /* split message into header and body */
+    log0(msg, DEBUG, "split message into header and body");
     if (str_parse(msg->cpMsg, "m/((?:.*?)\\n)\\n(.*)$/s", &cpHeaders, &msg->cpBody) <= 0)
         return MSG_ERR_SPLITHEADBODY;
 
     free(msg->cpMsg);
     msg->cpMsg = NULL;
 
-    /* replace envelope From w/o colon by X-F: pseudotag. This eliminates the
-     * special case of having one header, which is really an embedded
-     * envelope, not ending with a colon while all others do. After splitting
-     * headers into name and value pairs this envelope ist stripped off.
+    log0(msg, DEBUG, "replace envelope From w/o colon by X-F: pseudotag");
+    /* This eliminates the special case of having one header, which is really
+     * an embedded envelope, not ending with a colon while all others do.
+     * After splitting headers into name and value pairs this envelope ist
+     * stripped off.
      */
     if (strncasecmp(cpHeaders, "From", 4) == 0)
         memcpy(cpHeaders, "X-F:", 4);
 
-    /* unwrap header lines */
+    log0(msg, DEBUG, "unwrap header lines");
     /* poor man's s///g simulator as current str library doesn't support global substitution */
     while (str_parse(cpHeaders, "s/(.*?)\\n[ \\t]+(.*)/$1 $2/s", &cpRem) > 0) {
         free(cpHeaders);
         cpHeaders = cpRem;
     }
 
-    /* split header lines into names and values */
+    log0(msg, DEBUG, "split header lines into names and values");
     while (str_parse(cpHeaders, "m/^([\\w-]+?:)[ \\t]*([^\\n]*?)[ \\t]*\\n(.*)/s", &cpName, &cpValue, &cpRem) > 0) {
         free(cpHeaders);
         cpHeaders = cpRem;
@@ -156,12 +165,13 @@
         argz_add(&msg->azHeaders, &msg->asHeaders, cpValue);
     }
 
-    /* check for headers we care about and do whatever neccessary */
+    log0(msg, DEBUG, "check for headers we care about and do whatever neccessary");
     msg->cpMsgid = NULL;
     msg->azNewsgroups = NULL;
     msg->asNewsgroups = 0;
     cp = msg->azHeaders;
     while (cp != NULL) {
+        log1(msg, DEBUG, "processing header \"%s\"", cp);
         if (strcasecmp("X-F:", cp) == 0) {
             argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  name  */
             argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  value */
@@ -174,6 +184,9 @@
         }
         if (strcasecmp("Received:", cp) == 0) {
             argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  name  */
+            if ((msg->cpFid == NULL) &&
+                (str_parse(cp, "m/\\sid\\s+<?([\\w\\d]{1,30})/i", &msg->cpFid) > 0))
+                    log1(msg, DEBUG, "found foreign-ID \"%s\" for logging", msg->cpFid);
             argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  value */
             continue;
         }
@@ -210,17 +223,23 @@
         if ((cp = argz_next(msg->azHeaders, msg->asHeaders, cp)) == NULL)  /* next name  */
             break;
     }
+
+    log0(msg, DEBUG, "checking Message-ID");
     if (msg->cpMsgid == NULL)
         return MSG_ERR_SPLITIDNONE;
 
+    log0(msg, DEBUG, "checking Newsgroups");
     if (msg->azNewsgroups != NULL) {
         argz_stringify(msg->azNewsgroups, msg->asNewsgroups, ',');
         if (argz_create_sep(msg->azNewsgroups, ',', &msg->azNewsgroups, &msg->asNewsgroups) != 0)
             return MSG_ERR_MEM;
     }
+
+    log0(msg, DEBUG, "adding mandatory Path: header");
     argz_add(&msg->azHeaders, &msg->asHeaders, "Path:");
     argz_add(&msg->azHeaders, &msg->asHeaders, "not-for-mail");
 
+    log0(msg, DEBUG, "split complete");
     return MSG_OK;
 }
 
@@ -238,7 +257,7 @@
     int          n;
     char        *cpHeaders;
 
-    /* verify asNewsgroups */
+    log0(msg, DEBUG, "verify Newsgroups");
     if (msg->azNewsgroups == NULL)
         return MSG_ERR_JOINGROUPNONE;
     argz_stringify(msg->azNewsgroups, msg->asNewsgroups, ',');
@@ -247,7 +266,7 @@
     argz_add(&msg->azHeaders, &msg->asHeaders, "Newsgroups:");
     argz_add(&msg->azHeaders, &msg->asHeaders, msg->azNewsgroups);
 
-    /* verify Message-ID */
+    log0(msg, DEBUG, "verify Message-ID");
     if (msg->cpMsgid == NULL)
         return MSG_ERR_JOINIDNONE;
     if (strlen(msg->cpMsgid) == 0)
@@ -255,7 +274,7 @@
     argz_add(&msg->azHeaders, &msg->asHeaders, "Message-ID:");
     argz_add(&msg->azHeaders, &msg->asHeaders, msg->cpMsgid);
 
-    /* merge name/value pairs into single string */
+    log0(msg, DEBUG, "merge name/value pairs into single string");
     argz_add(&msg->azHeaders, &msg->asHeaders, ""); /* append empty string */
     if ((aHeaders = (char **)malloc((argz_count(msg->azHeaders, msg->asHeaders) + 1) * sizeof(char *))) == NULL)
         return MSG_ERR_MEM;
@@ -273,9 +292,8 @@
     }
     free(aHeaders);
 
-    /* fold headers
-     *
-     * A logical line is split into one or more physical '\n'-terminated
+    log0(msg, DEBUG, "fold headers");
+    /* A logical line is split into one or more physical '\n'-terminated
      * lines. The physical line is never longer than WRAPAT characters. This
      * includes the folded data and the header name + colon + space for the
      * first line and WRAPUSING string prefix for all other lines. Leading and
@@ -327,6 +345,7 @@
         }
     }
 
+    log0(msg, DEBUG, "strigify headers");
     argz_stringify(msg->azHeaders, msg->asHeaders, '\n');
     cpHeaders = msg->azHeaders;
 
@@ -334,6 +353,7 @@
      * header + CRLF + body + '.' + CRLF + NUL, replacing NL with CRLF *
      ********************************************************************/
 
+    log0(msg, DEBUG, "assemble header and body");
     n = 0;
     /* count size of headers, reserve space for NL to CRLF conversion */
     for (i = 0; ((c = cpHeaders[i]) != NUL); i++) {
@@ -401,6 +421,7 @@
     msg->cpMsg[n++] = '\n';
     msg->cpMsg[n]   = NUL;
 
+    log0(msg, DEBUG, "join complete");
     return MSG_OK;
 }
 

CVSTrac 2.0.1