public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Mamoru TASAKA <mtasaka@fedoraproject.org>
To: git-commits@fedoraproject.org
Subject: [rpms/libetpan] rawhide: Backport upstream patch to use ICU for Japanese charset conversion
Date: Fri, 26 Jun 2026 15:10:42 GMT	[thread overview]
Message-ID: <178248664246.1.10393408443722660382.rpms-libetpan-437373945b14@fedoraproject.org> (raw)

A new commit has been pushed.

Repo   : rpms/libetpan
Branch : rawhide
Commit : 437373945b14671f1150d1f2fba30e781bb66b6e
Author : Mamoru TASAKA <mtasaka@fedoraproject.org>
Date   : 2026-06-27T00:10:30+09:00
Stats  : +334/-13 in 3 file(s)
URL    : https://src.fedoraproject.org/rpms/libetpan/c/437373945b14671f1150d1f2fba30e781bb66b6e?branch=rawhide

Log:
Backport upstream patch to use ICU for Japanese charset conversion

---
diff --git a/libetpan-1.10.1-unittext-plaintext-rendering-fix-build.patch b/libetpan-1.10.1-unittext-plaintext-rendering-fix-build.patch
new file mode 100644
index 0000000..8b1d4d4
--- /dev/null
+++ b/libetpan-1.10.1-unittext-plaintext-rendering-fix-build.patch
@@ -0,0 +1,78 @@
+From d3c9bd49e681660bafce6fc193650f0de5ad908f Mon Sep 17 00:00:00 2001
+From: Hoa Dinh <dinh.viet.hoa@gmail.com>
+Date: Mon, 22 Jun 2026 02:22:04 -0700
+Subject: [PATCH] Fix plaintext rendering test build
+
+---
+ unittest/Makefile                             | 14 ++++++++------
+ unittest/plaintext-rendering/html_flattener.c | 14 +++++++++++---
+ 2 files changed, 19 insertions(+), 9 deletions(-)
+
+diff --git a/unittest/Makefile b/unittest/Makefile
+index a2f23525..42dff3c3 100644
+--- a/unittest/Makefile
++++ b/unittest/Makefile
+@@ -12,11 +12,12 @@ CPPFLAGS += \
+ 	-Icommon
+ 
+ CFLAGS += -Wall -Wextra -Werror -g
+-LDLIBS += $(TOP)/src/.libs/libetpan.a -lz -liconv -lsasl2 -lpthread
++LDLIBS += $(TOP)/src/.libs/libetpan.a -lz -lsasl2 -lpthread
+ XML2_CPPFLAGS := -I$(shell xcrun --show-sdk-path)/usr/include/libxml2
+ XML2_LDLIBS := -lxml2
+-TIDY_CPPFLAGS := $(shell pkg-config --cflags tidy 2>/dev/null || printf '%s' "-I$$(brew --prefix tidy-html5)/include")
++TIDY_CPPFLAGS := $(shell pkg-config --cflags tidy 2>/dev/null || printf '%s' "-I$$(brew --prefix tidy-html5)/include") -I /usr/include/tidy
+ TIDY_LDLIBS := $(shell pkg-config --libs tidy 2>/dev/null || printf '%s' "-L$$(brew --prefix tidy-html5)/lib -ltidy")
++MATH_LDLIBS := -lm
+ 
+ IMAP_TEST = imap/imap_test
+ IMF_TEST = imf/imf_test
+@@ -133,7 +135,7 @@ $(CHARSET_DETECTION_TEST): $(CHARSET_DETECTION_TEST_DEPS) libetpan
+ 	$(CC) $(CPPFLAGS) $(CFLAGS) $(CHARSET_DETECTION_TEST_SRCS) $(LDLIBS) -o $@
+ 
+ $(PLAINTEXT_RENDERING_TEST): $(PLAINTEXT_RENDERING_TEST_DEPS) libetpan
+-	$(CC) $(CPPFLAGS) $(XML2_CPPFLAGS) $(TIDY_CPPFLAGS) $(CFLAGS) $(PLAINTEXT_RENDERING_TEST_SRCS) $(LDLIBS) $(XML2_LDLIBS) $(TIDY_LDLIBS) -o $@
++	$(CC) $(CPPFLAGS) $(XML2_CPPFLAGS) $(TIDY_CPPFLAGS) $(CFLAGS) $(PLAINTEXT_RENDERING_TEST_SRCS) $(LDLIBS) $(XML2_LDLIBS) $(TIDY_LDLIBS) $(MATH_LDLIBS) -o $@
+ 
+ $(IMAP_UTF7_TEST): $(IMAP_UTF7_TEST_DEPS) libetpan
+ 	$(CC) $(CPPFLAGS) $(CFLAGS) $(IMAP_UTF7_TEST_SRCS) $(LDLIBS) -o $@
+diff --git a/unittest/plaintext-rendering/html_flattener.c b/unittest/plaintext-rendering/html_flattener.c
+index 50d91272..23e3eb85 100644
+--- a/unittest/plaintext-rendering/html_flattener.c
++++ b/unittest/plaintext-rendering/html_flattener.c
+@@ -366,7 +366,7 @@ static void comment_parsed(void * ctx, const xmlChar * value)
+   (void) value;
+ }
+ 
+-static void structured_error(void * user_data, xmlErrorPtr error)
++static void structured_error(void * user_data, const xmlError * error)
+ {
+   (void) user_data;
+   (void) error;
+@@ -375,6 +375,8 @@ static void structured_error(void * user_data, xmlErrorPtr error)
+ char * plaintext_rendering_flatten_html(const char * html)
+ {
+   xmlSAXHandler handler;
++  htmlParserCtxtPtr parser_context;
++  htmlDocPtr parsed_doc;
+   struct flatten_state state;
+   char * cleaned_html;
+   unsigned int i;
+@@ -391,9 +393,15 @@ char * plaintext_rendering_flatten_html(const char * html)
+   state.show_blockquote = 1;
+   state.show_link = 1;
+   state.last_char_is_whitespace = 1;
+-  xmlSetStructuredErrorFunc(xmlGenericErrorContext, structured_error);
++  parser_context = htmlNewSAXParserCtxt(&handler, &state);
++  assert(parser_context != NULL);
++  xmlCtxtSetErrorHandler(parser_context, structured_error, NULL);
+   cleaned_html = plaintext_rendering_cleaned_html(html);
+-  htmlSAXParseDoc((xmlChar *) cleaned_html, "utf-8", &handler, &state);
++  parsed_doc = htmlCtxtReadDoc(parser_context, (xmlChar *) cleaned_html, NULL,
++      "utf-8", 0);
++  if (parsed_doc != NULL)
++    xmlFreeDoc(parsed_doc);
++  htmlFreeParserCtxt(parser_context);
+   free(cleaned_html);
+   clean_terminal_space(state.result);
+   for (i = 0; i < state.link_count; i++)

diff --git a/libetpan-1.10.1-use-icu-for-japanese-conversion.patch b/libetpan-1.10.1-use-icu-for-japanese-conversion.patch
new file mode 100644
index 0000000..79ecd53
--- /dev/null
+++ b/libetpan-1.10.1-use-icu-for-japanese-conversion.patch
@@ -0,0 +1,235 @@
+From 0141aba7e56d0ae4450a94cc3e261567fbc47683 Mon Sep 17 00:00:00 2001
+From: Hoa Dinh <dinh.viet.hoa@gmail.com>
+Date: Wed, 24 Jun 2026 23:43:31 -0700
+Subject: [PATCH] Use ICU for Japanese charset conversion
+
+---
+ configure.ac               |  38 ++++++++++++++
+ src/Makefile.am            |   3 +-
+ src/data-types/Makefile.am |   2 +-
+ src/data-types/charconv.c  | 105 +++++++++++++++++++++++++++++++++++++
+ unittest/Makefile          |   1 +
+ 5 files changed, 146 insertions(+), 3 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 0c8de6fe..c9600e07 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -348,6 +348,44 @@ if test x$enable_iconv = xyes; then
+ fi
+ AC_SUBST(LIBICONV)
+ 
++dnl ICU
++ICULIB=""
++ICUCPPFLAGS=""
++
++AC_ARG_WITH(icu, [AS_HELP_STRING([--with-icu], [use ICU for charset conversion before iconv (default=auto)])],
++            [], [with_icu=auto])
++if test "x$with_icu" != "xno"; then
++  PKG_CHECK_MODULES([ICU], [icu-uc],
++    [with_icu=yes],
++    [if test "x$with_icu" = "xyes"; then
++       AC_MSG_ERROR([ICU support requested but icu-uc was not found])
++     else
++       with_icu=no
++     fi])
++  if test "x$with_icu" = "xyes"; then
++    SAVED_CPPFLAGS="$CPPFLAGS"
++    SAVED_LIBS="$LIBS"
++    CPPFLAGS="$CPPFLAGS $ICU_CFLAGS"
++    LIBS="$LIBS $ICU_LIBS"
++    AC_CHECK_HEADERS([unicode/ucnv.h unicode/ustring.h],
++      [],
++      [AC_MSG_ERROR([ICU headers are missing])])
++    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <unicode/ucnv.h>]],
++      [[UErrorCode err = U_ZERO_ERROR;
++        UConverter * conv = ucnv_open("UTF-8", &err);
++        if (conv != NULL) ucnv_close(conv);
++        return U_FAILURE(err);]])],
++      [AC_DEFINE(HAVE_ICU, 1, [Define if you have ICU charset conversion.])
++       ICUCPPFLAGS="$ICU_CFLAGS"
++       ICULIB="$ICU_LIBS"],
++      [AC_MSG_ERROR([ICU libraries are missing])])
++    CPPFLAGS="$SAVED_CPPFLAGS"
++    LIBS="$SAVED_LIBS"
++  fi
++fi
++AC_SUBST(ICUCPPFLAGS)
++AC_SUBST(ICULIB)
++
+ dnl Berkeley DB
+ 
+ DBVERS=0
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 1847099f..03b33448 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -81,5 +81,4 @@ libetpan@LIBSUFFIX@_la_LIBADD = \
+ 	main/libmain.la \
+ 	engine/libengine.la \
+         $(arch_lib) \
+-	@LIBS@ @SSLLIBS@ @LIBICONV@ @DBLIB@ @GNUTLSLIB@ @SASLLIBS@
+-
++	@LIBS@ @SSLLIBS@ @LIBICONV@ @ICULIB@ @DBLIB@ @GNUTLSLIB@ @SASLLIBS@
+diff --git a/src/data-types/Makefile.am b/src/data-types/Makefile.am
+index d2f00301..99f9141d 100644
+--- a/src/data-types/Makefile.am
++++ b/src/data-types/Makefile.am
+@@ -38,7 +38,7 @@ etpaninclude_HEADERS = \
+ 	carray.h clist.h chash.h \
+ 	charconv.h mailsem.h maillock.h
+ 
+-AM_CPPFLAGS = -I$(top_builddir)/include
++AM_CPPFLAGS = -I$(top_builddir)/include @ICUCPPFLAGS@
+ 
+ noinst_LTLIBRARIES = libdata-types.la
+ 
+diff --git a/src/data-types/charconv.c b/src/data-types/charconv.c
+index bf716f84..6f719f8e 100644
+--- a/src/data-types/charconv.c
++++ b/src/data-types/charconv.c
+@@ -42,6 +42,9 @@
+ #ifdef HAVE_ICONV
+ #include <iconv.h>
+ #endif
++#ifdef HAVE_ICU
++#include <unicode/ucnv.h>
++#endif
+ #include <stdlib.h>
+ #include <string.h>
+ #include <stdio.h>
+@@ -567,6 +570,45 @@ static size_t mail_iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft,
+ }
+ #endif
+ 
++#ifdef HAVE_ICU
++static int icu_should_try_charset(const char * fromcode)
++{
++  return strcasecmp(fromcode, "iso-2022-jp") == 0 ||
++      strcasecmp(fromcode, "iso-2022-jp-2") == 0 ||
++      strcasecmp(fromcode, "shift_jis") == 0 ||
++      strcasecmp(fromcode, "shift-jis") == 0 ||
++      strcasecmp(fromcode, "euc-jp") == 0 ||
++      strcasecmp(fromcode, "eucjp") == 0;
++}
++
++static int icu_charconv(const char * tocode, const char * fromcode,
++    const char * str, size_t length, char * result, size_t * result_len)
++{
++  UErrorCode err = U_ZERO_ERROR;
++  int32_t converted_len;
++
++  if (length > (size_t) 0x7fffffff || *result_len > (size_t) 0x7fffffff)
++    return MAIL_CHARCONV_ERROR_MEMORY;
++
++  converted_len = ucnv_convert(tocode, fromcode, result, (int32_t) *result_len,
++      str, (int32_t) length, &err);
++  if (err == U_BUFFER_OVERFLOW_ERROR)
++    return MAIL_CHARCONV_ERROR_MEMORY;
++  if (U_FAILURE(err)) {
++    if (err == U_FILE_ACCESS_ERROR || err == U_MISSING_RESOURCE_ERROR ||
++        err == U_INVALID_TABLE_FORMAT)
++      return MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET;
++    return MAIL_CHARCONV_ERROR_CONV;
++  }
++  if (converted_len < 0)
++    return MAIL_CHARCONV_ERROR_CONV;
++
++  result[converted_len] = '\0';
++  *result_len = (size_t) converted_len;
++  return MAIL_CHARCONV_NO_ERROR;
++}
++#endif
++
+ static const char * get_valid_charset(const char * fromcode)
+ {
+   if ((strcasecmp(fromcode, "GB2312") == 0) || (strcasecmp(fromcode, "GB_2312-80") == 0)) {
+@@ -639,6 +681,34 @@ int charconv(const char * tocode, const char * fromcode,
+ 		/* else, let's try with iconv, if available */
+ 	}
+ 
++#ifdef HAVE_ICU
++	if (icu_should_try_charset(fromcode))
++	{
++		size_t allocated_length;
++		size_t result_length;
++
++		res = charconv_get_output_size(length, &allocated_length);
++		if (res != MAIL_CHARCONV_NO_ERROR)
++			return res;
++		result_length = allocated_length;
++		*result = malloc(allocated_length + 1);
++		if (*result == NULL)
++			return MAIL_CHARCONV_ERROR_MEMORY;
++		res = icu_charconv(tocode, fromcode, str, length, *result,
++		    &result_length);
++		if (res == MAIL_CHARCONV_NO_ERROR) {
++			out = realloc(*result, result_length + 1);
++			if (out != NULL)
++				*result = out;
++			return MAIL_CHARCONV_NO_ERROR;
++		}
++		free(*result);
++		*result = NULL;
++		if (res != MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET)
++			return res;
++	}
++#endif
++
+ #ifndef HAVE_ICONV
+   return MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET;
+ #else
+@@ -752,6 +822,41 @@ int charconv_buffer(const char * tocode, const char * fromcode,
+ 		/* else, let's try with iconv, if available */
+ 	}
+ 
++#ifdef HAVE_ICU
++	if (icu_should_try_charset(fromcode))
++	{
++		size_t allocated_length;
++		size_t result_length;
++
++		res = charconv_get_output_size(length, &allocated_length);
++		if (res != MAIL_CHARCONV_NO_ERROR)
++			return res;
++		result_length = allocated_length;
++		mmapstr = mmap_string_sized_new(allocated_length + 1);
++		*result_len = 0;
++		if (mmapstr == NULL)
++			return MAIL_CHARCONV_ERROR_MEMORY;
++		res = icu_charconv(tocode, fromcode, str, length, mmapstr->str,
++		    &result_length);
++		if (res == MAIL_CHARCONV_NO_ERROR) {
++			int r;
++
++			*result = mmapstr->str;
++			r = mmap_string_ref(mmapstr);
++			if (r < 0) {
++				mmap_string_free(mmapstr);
++				return MAIL_CHARCONV_ERROR_MEMORY;
++			}
++			mmap_string_set_size(mmapstr, result_length);
++			*result_len = result_length;
++			return MAIL_CHARCONV_NO_ERROR;
++		}
++		mmap_string_free(mmapstr);
++		if (res != MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET)
++			return res;
++	}
++#endif
++
+ #ifndef HAVE_ICONV
+   return MAIL_CHARCONV_ERROR_UNKNOWN_CHARSET;
+ #else
+diff --git a/unittest/Makefile b/unittest/Makefile
+index 42dff3c3..c954d402 100644
+--- a/unittest/Makefile
++++ b/unittest/Makefile
+@@ -13,6 +13,7 @@ CPPFLAGS += \
+ 
+ CFLAGS += -Wall -Wextra -Werror -g
+ LDLIBS += $(TOP)/src/.libs/libetpan.a -lz -lsasl2 -lpthread
++LDLIBS += $(shell pkg-config --libs icu-uc 2>/dev/null)
+ XML2_CPPFLAGS := -I$(shell xcrun --show-sdk-path)/usr/include/libxml2
+ XML2_LDLIBS := -lxml2
+ TIDY_CPPFLAGS := $(shell pkg-config --cflags tidy 2>/dev/null || printf '%s' "-I$$(brew --prefix tidy-html5)/include") -I /usr/include/tidy

diff --git a/libetpan.spec b/libetpan.spec
index e91f0ad..a7dab10 100644
--- a/libetpan.spec
+++ b/libetpan.spec
@@ -1,6 +1,6 @@
 Name:           libetpan
 Version:        1.10.1
-Release:        1%{?dist}
+Release:        2%{?dist}
 Summary:        Portable, efficient middle-ware for different kinds of mail access
 
 # src/bsd/getopt.c BSD-4-Clause (not used)
@@ -11,19 +11,23 @@ URL:            http://www.etpan.org/
 Source0:        https://github.com/dinhviethoa/%{name}/archive/%{version}/%{name}-%{version}.tar.gz
 # system crypto policy (see rhbz#1179310)
 Patch10:        libetpan-1.9.2-cryptopolicy.patch
-# xmlError constness
-Patch11:        libetpan-1.10-xmlError-constness.patch
 # Upstream patches
-#
+# https://github.com/dinhvh/libetpan/commit/d3c9bd49e681660bafce6fc193650f0de5ad908f
+Patch101:		libetpan-1.10.1-unittext-plaintext-rendering-fix-build.patch
+# https://github.com/dinhvh/libetpan/commit/0141aba7e56d0ae4450a94cc3e261567fbc47683
+Patch102:		libetpan-1.10.1-use-icu-for-japanese-conversion.patch
 
-BuildRequires:  gcc-c++
-BuildRequires:  liblockfile-devel
-BuildRequires:  libdb-devel < 5.4
 BuildRequires:  cyrus-sasl-devel
 BuildRequires:  gnutls-devel
-BuildRequires:  libtool
+BuildRequires:  libdb-devel < 5.4
+BuildRequires:  liblockfile-devel
+BuildRequires:  pkgconfig(icu-uc)
 BuildRequires:  zlib-devel
-BuildRequires:  autoconf automake
+
+BuildRequires:  autoconf
+BuildRequires:  automake
+BuildRequires:  gcc-c++
+BuildRequires:  libtool
 BuildRequires:  make
 # disabled by default in configure.ac accidentally
 # https://github.com/dinhviethoa/libetpan/issues/221
@@ -56,7 +60,8 @@ find . -name \*.gz -delete
 sed -i.flags libetpan.pc.in \
     -e 's|-letpan@LIBSUFFIX@.*$|-letpan@LIBSUFFIX@|'
 %patch -P10 -p1 -b .crypto-policy
-%patch -P11 -p1 -b .const
+%patch -P101 -p1 -b .plaintext
+%patch -P102 -p1 -b .jp_icu
 
 # 2013-08-05 F20 development, bz 992070: The configure scripts adds some
 # extra libs to the GnuTLS link options, which cause rebuilds to fail, since
@@ -98,7 +103,6 @@ sed -i.shared Makefile \
 	-e 's|libetpan.a|libetpan.so|' \
 	-e 's|-liconv ||' \
 	-e 's|-Werror |-Werror -Wno-error=deprecated-declarations |' \
-	-e 's|\$(TIDY_LDLIBS) |$(TIDY_LDLIBS) -lm |' \
 	%{nil}
 
 # plaintext_rendering_test: needs TZ (PDT)
@@ -106,8 +110,9 @@ sed -i.shared Makefile \
 export TZ="America/Los_Angeles"
 pushd plaintext-rendering/data
 if [ ! -d input-fail ] ; then
-	mkdir input-fail
-	mv input/5231-emoji.eml input-fail/
+	true
+#	mkdir input-fail
+#	mv input/5231-emoji.eml input-fail/
 fi
 popd
 
@@ -130,6 +135,9 @@ popd
 %{_libdir}/%{name}.so
 
 %changelog
+* Fri Jun 26 2026 Mamoru TASAKA <mtasaka@fedoraproject.org> - 1.10.1-2
+- Backport upstream patch to use ICU for Japanese charset conversion
+
 * Wed Jun 17 2026 Mamoru TASAKA <mtasaka@fedoraproject.org> - 1.10.1-1
 - 1.10.1
 

                 reply	other threads:[~2026-06-26 15:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178248664246.1.10393408443722660382.rpms-libetpan-437373945b14@fedoraproject.org \
    --to=mtasaka@fedoraproject.org \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox