OSSP CVS Repository

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

ossp-pkg/lmtp2nntp/msg.c 1.1 -> 1.2

--- msg.c        2001/08/13 06:41:41     1.1
+++ msg.c        2001/08/13 15:16:32     1.2
@@ -127,6 +127,11 @@
     msg->asNewsgroups = 0;
     cp = msg->azHeaders;
     while (cp != NULL) {
+        if (strcasecmp("From", cp) == 0) {
+            argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  name  */
+            argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  value */
+            continue;
+        }
         if (strcasecmp("To:", cp) == 0) {
             argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  name  */
             argz_delete(&msg->azHeaders, &msg->asHeaders, cp);             /* del  value */
@@ -183,6 +188,8 @@
     char        *cpCut;
     char        *cpWrap;
     char        *cpNew;
+    char         c;
+    int          n;
 
     /* verify asNewsgroups */
     if (msg->azNewsgroups == NULL)
@@ -287,13 +294,68 @@
     argz_stringify(msg->azBody, msg->asBody, '\n');
     msg->cpBody = msg->azBody;
 
-    if ((msg->cpMsg = malloc(strlen(msg->cpHeaders) + 1 + strlen(msg->cpBody) + 2 + 1)) == NULL)
+    /********************************************************************
+     * header + CRLF + body + '.' + CRLF + '\0', replacing NL with CRLF *
+     ********************************************************************/
+
+    n = 0;
+    /* count size of headers, reserve space for NL to CRLF conversion */
+    for (i = 0; ((c = msg->cpHeaders[i]) != '\0'); i++) {
+        if (c == '\n')
+            n++;
+        n++;
+    }
+    /* if headers don't end with NL, reserve space for CRLF */
+    if (i >= 0 && msg->cpHeaders[i - 1] != '\n')
+        n+=2;
+    /* reserve space for CRLF between headers and body */
+    n+=2;
+    /* count size of body, reserve space for NL to CRLF conversion */
+    for (i = 0; ((c = msg->cpBody[i]) != '\0'); i++) {
+        if (c == '\n')
+            n++;
+        n++;
+    }
+    /* if body doesn't end with NL, reserve space for CRLF */
+    if (i >= 0 && msg->cpBody[i - 1] != '\n')
+        n+=2;
+    /* reserve space for terminating '.'-CRLF-NUL at the end of the message */
+    n+=4;
+
+    if ((msg->cpMsg = (char *)malloc(n)) == NULL)
         return MSG_ERR_MEM;
-    *msg->cpMsg = '\0';                  /* + 1 in the end */
-    strcat(msg->cpMsg, msg->cpHeaders); 
-    strcat(msg->cpMsg, "\n");            /* + 1 */
-    strcat(msg->cpMsg, msg->cpBody);
-    strcat(msg->cpMsg, ".\n");           /* + 2 */
+
+    n = 0;
+    /* copy headers, do NL to CRLF conversion */
+    for (i = 0; ((c = msg->cpHeaders[i]) != '\0'); i++) {
+        if (c == '\n')
+            msg->cpMsg[n++] = '\r';
+        msg->cpMsg[n++] = c;
+    }
+    /* if headers don't end with NL, append CRLF */
+    if (i >= 0 && msg->cpHeaders[i - 1] != '\n') {
+        msg->cpMsg[n++] = '\r';
+        msg->cpMsg[n++] = '\n';
+    }
+    /* add CRLF between headers and body */
+    msg->cpMsg[n++] = '\r';
+    msg->cpMsg[n++] = '\n';
+    /* copy body, do NL to CRLF conversion */
+    for (i = 0; ((c = msg->cpBody[i]) != '\0'); i++) {
+        if (c == '\n')
+            msg->cpMsg[n++] = '\r';
+        msg->cpMsg[n++] = c;
+    }
+    /* if body doesn't end with NL, append CRLF */
+    if (i >= 0 && msg->cpBody[i - 1] != '\n') {
+        msg->cpMsg[n++] = '\r';
+        msg->cpMsg[n++] = '\n';
+    }
+    /* add terminating '.'-CRLF-NUL at the end of the message */
+    msg->cpMsg[n++] =  '.';
+    msg->cpMsg[n++] = '\r';
+    msg->cpMsg[n++] = '\n';
+    msg->cpMsg[n]   = '\0';
 
     //fprintf(stderr, "DEBUG: Message = ***%s***\n", msg->cpMsg);
 

CVSTrac 2.0.1