git: 7767c9dff70c - main - mail/nmh-devel: Fix message corruption

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Fri, 08 Dec 2023 23:42:15 UTC
The branch main has been updated by cy:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7767c9dff70c419bf936b26e8ada6a545dab5817

commit 7767c9dff70c419bf936b26e8ada6a545dab5817
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-12-08 23:39:12 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-12-08 23:42:08 +0000

    mail/nmh-devel: Fix message corruption
    
    Upstream 8f897f65 (2023-03-12) has resulted in data corruption with
    sent emails. This commit removes this upstream commmit and all that
    subsequently "fix" it.
---
 mail/nmh-devel/Makefile                            |  1 +
 mail/nmh-devel/files/patch-test_fakesmtp.c         | 29 +++++++++
 mail/nmh-devel/files/patch-test_mhshow_test-binary | 20 ++++++
 .../files/patch-test_post_test-post-basic          | 74 ++++++++++++++++++++++
 mail/nmh-devel/files/patch-uip_post.c              | 40 ++++++++++++
 5 files changed, 164 insertions(+)

diff --git a/mail/nmh-devel/Makefile b/mail/nmh-devel/Makefile
index f7da515c6556..cdbcf2471fd6 100644
--- a/mail/nmh-devel/Makefile
+++ b/mail/nmh-devel/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	nmh
 PORTVERSION=	${NMH_COMMIT_DATE}
+PORTREVISION=	1
 MASTER_SITES=	#
 CATEGORIES=	mail
 PKGNAMESUFFIX=	-devel
diff --git a/mail/nmh-devel/files/patch-test_fakesmtp.c b/mail/nmh-devel/files/patch-test_fakesmtp.c
new file mode 100644
index 000000000000..65fa3c744d58
--- /dev/null
+++ b/mail/nmh-devel/files/patch-test_fakesmtp.c
@@ -0,0 +1,29 @@
+--- test/fakesmtp.c.orig	2023-12-04 03:00:44 UTC
++++ test/fakesmtp.c
+@@ -35,13 +35,12 @@ enum {
+ 	SMTP_XOAUTH_ERR
+ };
+ 
+-static ssize_t getsmtp(int, char *);
++static int getsmtp(int, char *);
+ 
+ int
+ main(int argc, char *argv[])
+ {
+-	ssize_t rc;
+-	int conn, smtp_state;
++	int rc, conn, smtp_state;
+ 	FILE *f;
+ 	const char *xoauth = getenv("XOAUTH");
+ 	const char *smtputf8 = getenv("SMTPUTF8");
+@@ -74,8 +73,8 @@ main(int argc, char *argv[])
+ 		if (rc == -1)
+ 			break;	/* EOF */
+ 
+-		fwrite(line, rc, 1, f);
+-		fwrite("\n", 1, 1, f);
++                fputs(line, f);
++                putc('\n', f);
+ 
+ 		switch (smtp_state) {
+ 		case SMTP_DATA:
diff --git a/mail/nmh-devel/files/patch-test_mhshow_test-binary b/mail/nmh-devel/files/patch-test_mhshow_test-binary
new file mode 100644
index 000000000000..73aabc7d7060
--- /dev/null
+++ b/mail/nmh-devel/files/patch-test_mhshow_test-binary
@@ -0,0 +1,20 @@
+--- test/mhshow/test-binary.orig	2023-12-04 03:00:44 UTC
++++ test/mhshow/test-binary
+@@ -21,7 +21,7 @@ expected="$MH_TEST_DIR/test-binary$$.expected"
+ 
+ #### Use the printf to output the NUL byte so that this
+ #### file (test-binary) doesn't need to be a binary file.
+-printf '%s\000%s' >"${expected}" \
++printf '%s\x00%s' >"${expected}" \
+ "[ Message inbox:11 ]
+ To:      recipient@example.edu
+ From:    sender@example.edu
+@@ -33,7 +33,7 @@ Here's a null byte: " ".
+ Here's a null byte: " ".
+ "
+ 
+-printf '%s\000%s' >`mhpath new` \
++printf '%s\x00%s' >`mhpath new` \
+ "From: sender@example.edu
+ To: recipient@example.edu
+ Subject: test binary content
diff --git a/mail/nmh-devel/files/patch-test_post_test-post-basic b/mail/nmh-devel/files/patch-test_post_test-post-basic
new file mode 100644
index 000000000000..5ed616ed67ce
--- /dev/null
+++ b/mail/nmh-devel/files/patch-test_post_test-post-basic
@@ -0,0 +1,74 @@
+--- test/post/test-post-basic.orig	2023-12-04 03:00:44 UTC
++++ test/post/test-post-basic
+@@ -143,13 +143,12 @@ check "${testname}.err" "${testname}.err.expected"
+ set +e
+ check "${testname}.err" "${testname}.err.expected"
+ 
+-#### Cheat: SMTPUTF8 enables 8BITMIME in fakestmp.  Set it for each test
+-#### that needs it below.
+-
+ #
+ # 8-bit with 8BITMIME support
+ #
+ start_test '8-bit with 8BITMIME support'
++# Cheat: SMTPUTF8 enables 8BITMIME in fakestmp
++SMTPUTF8=1; export SMTPUTF8
+ cat > "${testname}.expected" <<EOF
+ EHLO nosuchhost.example.com
+ MAIL FROM:<nobody@example.com> BODY=8BITMIME
+@@ -168,8 +167,9 @@ EOF
+ .
+ QUIT
+ EOF
+-SMTPUTF8=1 test_post "${testname}.actual" "${testname}.expected"
++test_post "${testname}.actual" "${testname}.expected"
+ 
++
+ #
+ # 8-bit with 8BITMIME support, inferred from content
+ #
+@@ -202,43 +202,7 @@ EOF
+ .
+ QUIT
+ EOF
+-SMTPUTF8=1 test_post "${testname}.actual" "${testname}.expected"
+-
+-#
+-# binary content containing a NUL
+-#
+-start_test "content containing NUL"
+-#### Use the printf to output the NUL byte so that this
+-#### file (test-binary) doesn't need to be a binary file.
+-printf '%s\000%s' > "${MH_TEST_DIR}/Mail/draft" \
+-"From: Mr Nobody <nobody@example.com>
+-To: Somebody Else <somebody@example.com>
+-Subject: Test
+-MIME-Version: 1.0
+-Content-Type: application/octet-stream
+-Content-Transfer-Encoding: binary
+-
+-This is a test, with a NUL character:  " "
+-"
+-
+-printf '%s\000%s' > "${testname}.expected" \
+-"EHLO nosuchhost.example.com
+-MAIL FROM:<nobody@example.com> BODY=8BITMIME
+-RCPT TO:<somebody@example.com>
+-DATA
+-From: Mr Nobody <nobody@example.com>
+-To: Somebody Else <somebody@example.com>
+-Subject: Test
+-MIME-Version: 1.0
+-Content-Type: application/octet-stream
+-Content-Transfer-Encoding: binary
+-Date:
+-
+-This is a test, with a NUL character:  " "
+-.
+-QUIT
+-"
+-SMTPUTF8=1 test_post "${testname}.actual" "${testname}.expected"
++test_post "${testname}.actual" "${testname}.expected"
+ 
+ 
+ finish_test
diff --git a/mail/nmh-devel/files/patch-uip_post.c b/mail/nmh-devel/files/patch-uip_post.c
new file mode 100644
index 000000000000..9284651a3b47
--- /dev/null
+++ b/mail/nmh-devel/files/patch-uip_post.c
@@ -0,0 +1,40 @@
+--- uip/post.c.orig	2023-12-04 03:00:44 UTC
++++ uip/post.c
+@@ -657,34 +657,17 @@ main (int argc, char **argv)
+ 		free (cp);
+ 		continue;
+ 
+-	    case BODY: {
+-		size_t n, n_written;
+-
++	    case BODY: 
+ 		finish_headers (out);
+ 		if (whomsw)
+ 		    break;
+-		if (fwrite ("\n", 1, 1, out) != 1) {
+-		    adios ("write of newline between header and body",
+-			   "failed");
+-		}
+-		/* Don't emit trailing NUL, to not interfere with SMTP
+-		   conversation. */
+-		n = bufsz > 0 && buf[bufsz-1] == '\0' ? bufsz - 1 : bufsz;
+-		if (n > 0  &&  (n_written = fwrite (buf, 1, n, out)) != n) {
+-		    adios ("octets of body", "wrote %ld instead of %ld",
+-			   n_written, n);
+-		}
++		fprintf (out, "\n%s", buf);
+ 		while (state == BODY) {
+ 		    bufsz = sizeof buf;
+ 		    state = m_getfld2(&gstate, name, buf, &bufsz);
+-		    n = bufsz > 0 && buf[bufsz-1] == '\0' ? bufsz - 1 : bufsz;
+-		    if (n > 0  &&  (n_written = fwrite (buf, 1, n, out)) != n) {
+-			adios ("octets of body continuation",
+-			       "wrote %ld instead of %ld", n_written, n);
+-		    }
++		    fputs (buf, out);
+ 		}
+ 		break;
+-	    }
+ 
+ 	    case FILEEOF: 
+ 		finish_headers (out);