git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH RFC] mailinfo: correctly handle multiline 'Subject:' header

From
Kirill Smelkov <kirr@mns.spb.ru>
Date
Dec 26, 2008, 18:38 UTC
Message-ID
<1230316721-14339-1-git-send-email-kirr@mns.spb.ru>

When native language (RU) is in use, subject header usually contains several parts, e.g.

Subject: [Navy-patches] [PATCH]
	=?utf-8?b?0JjQt9C80LXQvdGR0L0g0YHQv9C40YHQvtC6INC/0LA=?=
	=?utf-8?b?0LrQtdGC0L7QsiDQvdC10L7QsdGF0L7QtNC40LzRi9GFINC00LvRjyA=?=
	=?utf-8?b?0YHQsdC+0YDQutC4?=
This exposes several bugs in builtin-mailinfo.c that I try to fix:
1. decode_b_segment: do not append explicit NUL -- explicit NUL was preventing
   correct header construction on parts concatenation via strbuf_addbuf in
   decode_header_bq. Fixes:

-Subject: Изменён список пакетов необходимых для сборки +Subject: Изменён список па

Then
2. (hackish) do not emit '\n' after processing of every header segment. It
   seems we should emit previous part as-is only if it does not end with
   '=?='. Fixes:

-Subject: Изменён список пакетов необходимых для сборки +Subject: Изменён список па кетов необходимых для сборки

Sorry for low-quality patch and description. I did what I could and don't have energy and time dig more into MIME.

Please help.
Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
---
 builtin-mailinfo.c  |   18 ++++++++++++++++-
 t/t5100-mailinfo.sh |    2 +-
 t/t5100/info0012    |    5 ++++
 t/t5100/msg0012     |    7 ++++++
 t/t5100/patch0012   |   30 +++++++++++++++++++++++++++++
 t/t5100/sample.mbox |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 112 insertions(+), 2 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index e890f7a..d138bc3 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -436,6 +436,14 @@ static struct strbuf *decode_b_segment(const struct strbuf *b_seg)
 			 * for now we just trust the data.
 			 */
 			c = 0;
+
+			/* XXX: the following is needed not to output NUL in
+			 * the resulting string
+			 *
+			 * This seems to be ok, but I'm not 100% sure -- that's
+			 * why this is an RFC.
+			 */
+			continue;
 		}
 		else
 			continue; /* garbage */
@@ -513,7 +521,15 @@ static int decode_header_bq(struct strbuf *it)
 		strbuf_reset(&piecebuf);
 		rfc2047 = 1;
 
-		if (in != ep) {
+		/* XXX: the follwoing is needed not to output '\n' on every
+		 * multi-line segment in Subject.
+		 *
+		 * I suspect this is not 100% correct, but I'm not a MIME guy
+		 * -- that's why this is an RFC.
+		 */
+
+		/* if in does not end with '=?=', we emit it as is */
+		if (in <= (ep-2) && !(ep[-1]=='\n' && ep[-2]=='=')) {
 			strbuf_add(&outbuf, in, ep - in);
 			in = ep;
 		}
diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh
index fe14589..6825f99 100755
--- a/t/t5100-mailinfo.sh
+++ b/t/t5100-mailinfo.sh
@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \
 	'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last &&
 	last=`cat last` &&
 	echo total is $last &&
-	test `cat last` = 11'
+	test `cat last` = 12'
 
 for mail in `echo 00*`
 do
diff --git a/t/t5100/info0012 b/t/t5100/info0012
new file mode 100644
index 0000000..ac1216f
--- /dev/null
+++ b/t/t5100/info0012
@@ -0,0 +1,5 @@
+Author: Dmitriy Blinov
+Email: bda@mnsspb.ru
+Subject: Изменён список пакетов необходимых для сборки
+Date: Wed, 12 Nov 2008 17:54:41 +0300
+
diff --git a/t/t5100/msg0012 b/t/t5100/msg0012
new file mode 100644
index 0000000..1dc2bf7
--- /dev/null
+++ b/t/t5100/msg0012
@@ -0,0 +1,7 @@
+textlive-* исправлены на texlive-*
+docutils заменён на python-docutils
+
+Действительно, оказалось, что rest2web вытягивает за собой
+python-docutils. В то время как сам rest2web не нужен.
+
+Signed-off-by: Dmitriy Blinov <bda@mnsspb.ru>
diff --git a/t/t5100/patch0012 b/t/t5100/patch0012
new file mode 100644
index 0000000..36a0b68
--- /dev/null
+++ b/t/t5100/patch0012
@@ -0,0 +1,30 @@
+---
+ howto/build_navy.txt |    6 +++---
+ 1 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/howto/build_navy.txt b/howto/build_navy.txt
+index 3fd3afb..0ee807e 100644
+--- a/howto/build_navy.txt
++++ b/howto/build_navy.txt
+@@ -119,8 +119,8 @@
+    - libxv-dev
+    - libusplash-dev
+    - latex-make
+-   - textlive-lang-cyrillic
+-   - textlive-latex-extra
++   - texlive-lang-cyrillic
++   - texlive-latex-extra
+    - dia
+    - python-pyrex
+    - libtool
+@@ -128,7 +128,7 @@
+    - sox
+    - cython
+    - imagemagick
+-   - docutils
++   - python-docutils
+ 
+ #. на машине dinar: добавить свой открытый ssh-ключ в authorized_keys2 пользователя ddev
+ #. на своей машине: отредактировать /etc/sudoers (команда ``visudo``) примерно следующим образом::
+-- 
+1.5.6.5
diff --git a/t/t5100/sample.mbox b/t/t5100/sample.mbox
index 4bf7947..94da4da 100644
--- a/t/t5100/sample.mbox
+++ b/t/t5100/sample.mbox
@@ -501,3 +501,55 @@ index 3e5fe51..aabfe5c 100644
 
 --=-=-=--
 
+From bda@mnsspb.ru Wed Nov 12 17:54:41 2008
+From: Dmitriy Blinov <bda@mnsspb.ru>
+To: navy-patches@dinar.mns.mnsspb.ru
+Date: Wed, 12 Nov 2008 17:54:41 +0300
+Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>
+X-Mailer: git-send-email 1.5.6.5
+MIME-Version: 1.0
+Content-Type: text/plain;
+  charset=utf-8
+Content-Transfer-Encoding: 8bit
+Subject: [Navy-patches] [PATCH]
+	=?utf-8?b?0JjQt9C80LXQvdGR0L0g0YHQv9C40YHQvtC6INC/0LA=?=
+	=?utf-8?b?0LrQtdGC0L7QsiDQvdC10L7QsdGF0L7QtNC40LzRi9GFINC00LvRjyA=?=
+	=?utf-8?b?0YHQsdC+0YDQutC4?=
+
+textlive-* исправлены на texlive-*
+docutils заменён на python-docutils
+
+Действительно, оказалось, что rest2web вытягивает за собой
+python-docutils. В то время как сам rest2web не нужен.
+
+Signed-off-by: Dmitriy Blinov <bda@mnsspb.ru>
+---
+ howto/build_navy.txt |    6 +++---
+ 1 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/howto/build_navy.txt b/howto/build_navy.txt
+index 3fd3afb..0ee807e 100644
+--- a/howto/build_navy.txt
++++ b/howto/build_navy.txt
+@@ -119,8 +119,8 @@
+    - libxv-dev
+    - libusplash-dev
+    - latex-make
+-   - textlive-lang-cyrillic
+-   - textlive-latex-extra
++   - texlive-lang-cyrillic
++   - texlive-latex-extra
+    - dia
+    - python-pyrex
+    - libtool
+@@ -128,7 +128,7 @@
+    - sox
+    - cython
+    - imagemagick
+-   - docutils
++   - python-docutils
+ 
+ #. на машине dinar: добавить свой открытый ssh-ключ в authorized_keys2 пользователя ddev
+ #. на своей машине: отредактировать /etc/sudoers (команда ``visudo``) примерно следующим образом::
+-- 
+1.5.6.5
-- 
tg: (2292ebd..) t/mailinfo-multiline-subject (depends on: tmp)
Next: Kirill Smelkov
Message 1 of 12 in “mailinfo: correctly handle multiline 'Subject:' header”
  1. mailinfo: correctly handle multiline 'Subject:' headerKirill Smelkov, Dec 26, 2008
  2. Kirill SmelkovJan 7, 2009
  3. Junio C HamanoJan 8, 2009
  4. Junio C HamanoJan 8, 2009
  5. Alexander PotashevJan 8, 2009
  6. Kirill SmelkovJan 8, 2009
  7. Kirill SmelkovJan 10, 2009
  8. Junio C HamanoJan 11, 2009
  9. Kirill SmelkovJan 12, 2009
  10. Junio C HamanoJan 12, 2009
  11. Kirill SmelkovJan 13, 2009
  12. Kirill SmelkovJan 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.