From c1bfab0125286f8cc3f0b562ecf5b910fb890def Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Mon, 23 Sep 2024 14:51:55 -0500 Subject: [PATCH] Test IDN with NLS on GH --- .github/workflows/windows.yml | 48 +++++++++++++++++++++++++++++++++++ src/net.c | 5 ++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 620b834..7c81020 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -36,6 +36,54 @@ jobs: with: name: msmtp-libressl path: D:\a\msmtp\tmp\ + nls: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Install build dependencies + uses: msys2/setup-msys2@v2 + with: + msystem: UCRT64 + update: true + install: >- + mingw-w64-ucrt-x86_64-gcc + pkgconf + automake + autoconf + make + texinfo + - name: Build + run: | + autoreconf -i + mkdir nls && cd nls + # The only function from libwinpthread is clock_gettime() + ../configure --with-tls=sspi LDFLAGS=-Wl,-Bstatic,-lwinpthread CFLAGS=-DFIXME1 + make + cd .. && mkdir norm && cd norm + ../configure --with-tls=sspi LDFLAGS=-Wl,-Bstatic,-lwinpthread + make + - name: Set locale + shell: pwsh + run: | + Set-WinSystemLocale -SystemLocale ru-RU + - name: Test IDN fixme + continue-on-error: true + run: | + nls/src/msmtp --debug --serverinfo --tls --host=mx3.почта.рус --port=1234 > output.log 2>&1 || true + cat output.log | iconv -f cp1251 -t utf-8 + grep -q 'connection refused' output.log && echo 🎉 The host was found successfully but the connection was refused. + - name: Test IDN fixme 2 + continue-on-error: true + run: | + nls/src/msmtp --debug --serverinfo --tls --host=mx3.почта.рус --port=1234 + - name: Test IDN norm 2 + continue-on-error: true + run: | + norm/src/msmtp --debug --serverinfo --tls --host=mx3.почта.рус --port=1234 native: runs-on: windows-latest defaults: diff --git a/src/net.c b/src/net.c index e1dedff..0e88ff5 100644 --- a/src/net.c +++ b/src/net.c @@ -761,22 +761,21 @@ int net_open_socket( size_t conv; WCHAR hostname_wide[NI_MAXHOST]; /* We rely on a proper setlocale earlier that was NOT "C" as set default by MS C runtime. */ -#ifdef ENABLE_NLS +#if defined(ENABLE_NLS) && defined(FIXME1) /* FIXME: Something messes up locale (at least on MSYS2/UCRT64) and setlocale(LC_ALL, "") won't fix it. * The commented code below is the way to get proper console output for hostname. * Otherwise let's make sure we get proper IDN conversion and that is it. */ - /* char locale_name[LOCALE_NAME_MAX_LENGTH * sizeof(WCHAR)]; GetSystemDefaultLocaleName((LPWSTR)locale_name, LOCALE_NAME_MAX_LENGTH); size_t len = wcsnlen_s((LPWSTR)locale_name, LOCALE_NAME_MAX_LENGTH); for (int i = 1; i <= len; ++i) locale_name[i] = locale_name[i * 2]; setlocale(LC_ALL, locale_name); - */ _locale_t locale = _create_locale(LC_ALL, ""); errno_t err = _mbstowcs_s_l(&conv, hostname_wide, ARRAYSIZE(hostname_wide), hostname, _TRUNCATE, locale); _free_locale(locale); #else + setlocale(LC_ALL, ""); errno_t err = mbstowcs_s(&conv, hostname_wide, ARRAYSIZE(hostname_wide), hostname, _TRUNCATE); #endif if (!err)