NUL characters in messages

Chris Stromsoe cbs at cts.ucla.edu
Fri Sep 6 18:32:11 EDT 2002


On Fri, 6 Sep 2002, Chris Stromsoe wrote:

> Hrm.  Would there be any CMU objection to a patch to translate embedded
> NULs to an alternate character?  Specifically, the case of "\r\0".  I
> plan to do an in place modification in lmtp_engine.c to convert to
> "\r\n\0" and add a header indicating that conversion has taken place.

The attached patch adds a switch to imapd.conf named "mungecrnull".  If
mungecrnull is true, lmtpd will convert strings of "\r\0" to "\r\n\0".
Anything else implements the old behavior.  I'm running with various other
patches, so the line numbers may be off.

At least one version of Mac Eudora incorrectly terminates lines with
"\r\0" in some instances.  This should work around that problem.


-Chris
-------------- next part --------------
--- lmtpengine.c.orig	Fri Sep  6 14:24:21 2002
+++ lmtpengine.c	Fri Sep  6 14:49:34 2002
@@ -633,6 +633,7 @@
 {
     char buf[8192], *p;
     int r = 0;
+    int mungecrnull = config_getswitch("mungecrnull", 0);
 
     while (prot_fgets(buf, sizeof(buf)-1, fin)) {
 	p = buf + strlen(buf) - 1;
@@ -643,8 +644,14 @@
 	}
 	else if (buf[0] == '\r' && buf[1] == '\0') {
 	    /* The message contained \r\0, and fgets is confusing us. */
-	    r = IMAP_MESSAGE_CONTAINSNULL;
-	    continue; /* need to eat the rest of the message */
+	    if (mungecrnull) {	/* convert to crlf */
+		buf[0] = '\r';
+		buf[1] = '\n';
+		buf[2] = '\0';
+	    } else {		/* default */
+		r = IMAP_MESSAGE_CONTAINSNULL;
+		continue; /* need to eat the rest of the message */
+	    }
 	}
 	else if (p[0] == '\r') {
 	    /*


More information about the Info-cyrus mailing list