From 8773776ff0ac39c7ab700719bba3b93d4ef2da1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Fri, 12 Feb 1999 14:21:57 +0100
Subject: [PATCH] pem_msg->init: Handle strings without terminating newline.

Rev: lib/modules/Tools.pmod/PEM.pmod:1.4
---
 lib/modules/Tools.pmod/PEM.pmod | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/modules/Tools.pmod/PEM.pmod b/lib/modules/Tools.pmod/PEM.pmod
index 0f56a5db08..2975832882 100644
--- a/lib/modules/Tools.pmod/PEM.pmod
+++ b/lib/modules/Tools.pmod/PEM.pmod
@@ -98,6 +98,9 @@ class rfc934 {
 
     for(; i < sizeof(parts); i++)
       {
+#ifdef PEM_DEBUG
+	werror(sprintf("parts[%d] = '%s'\n", i, parts[i]));
+#endif
 	if (sizeof(parts[i]) && (parts[i][0] == ' '))
 	  {
 	    /* Escape, just remove the "- " prefix */
@@ -123,10 +126,24 @@ class rfc934 {
 
 	int end = search(parts[i], "\n");
 	if (end >= 0)
-	  {
-	    boundary = "-" + parts[i][..end-1];
-	    current = parts[i][end..];
-	  }
+	{
+	  boundary = "-" + parts[i][..end-1];
+	  current = parts[i][end..];
+	} else {
+	  /* This is a special case that happens if the input data had
+	   * no terminating newline after the final boundary. */
+#ifdef PEM_DEBUG
+	  werror(sprintf("Final boundary, with no terminating newline.\n"
+			 "  boundary='%s'\n", boundary));
+#endif
+
+#if 0
+	  encapsulated 
+	    += ({ encapsulated_message()->init(boundary, current) });
+#endif
+	  boundary = "-" + parts[i];
+	  break;
+	}
       }
     final_text = current;
     final_boundary = boundary;
-- 
GitLab