Skip to content

Commit c1bfab0

Browse files
committed
Test IDN with NLS on GH
1 parent 692a623 commit c1bfab0

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

.github/workflows/windows.yml

+48
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,54 @@ jobs:
3636
with:
3737
name: msmtp-libressl
3838
path: D:\a\msmtp\tmp\
39+
nls:
40+
runs-on: windows-latest
41+
defaults:
42+
run:
43+
shell: msys2 {0}
44+
steps:
45+
- name: Check out repository code
46+
uses: actions/checkout@v4
47+
- name: Install build dependencies
48+
uses: msys2/setup-msys2@v2
49+
with:
50+
msystem: UCRT64
51+
update: true
52+
install: >-
53+
mingw-w64-ucrt-x86_64-gcc
54+
pkgconf
55+
automake
56+
autoconf
57+
make
58+
texinfo
59+
- name: Build
60+
run: |
61+
autoreconf -i
62+
mkdir nls && cd nls
63+
# The only function from libwinpthread is clock_gettime()
64+
../configure --with-tls=sspi LDFLAGS=-Wl,-Bstatic,-lwinpthread CFLAGS=-DFIXME1
65+
make
66+
cd .. && mkdir norm && cd norm
67+
../configure --with-tls=sspi LDFLAGS=-Wl,-Bstatic,-lwinpthread
68+
make
69+
- name: Set locale
70+
shell: pwsh
71+
run: |
72+
Set-WinSystemLocale -SystemLocale ru-RU
73+
- name: Test IDN fixme
74+
continue-on-error: true
75+
run: |
76+
nls/src/msmtp --debug --serverinfo --tls --host=mx3.почта.рус --port=1234 > output.log 2>&1 || true
77+
cat output.log | iconv -f cp1251 -t utf-8
78+
grep -q 'connection refused' output.log && echo 🎉 The host was found successfully but the connection was refused.
79+
- name: Test IDN fixme 2
80+
continue-on-error: true
81+
run: |
82+
nls/src/msmtp --debug --serverinfo --tls --host=mx3.почта.рус --port=1234
83+
- name: Test IDN norm 2
84+
continue-on-error: true
85+
run: |
86+
norm/src/msmtp --debug --serverinfo --tls --host=mx3.почта.рус --port=1234
3987
native:
4088
runs-on: windows-latest
4189
defaults:

src/net.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -761,22 +761,21 @@ int net_open_socket(
761761
size_t conv;
762762
WCHAR hostname_wide[NI_MAXHOST];
763763
/* We rely on a proper setlocale earlier that was NOT "C" as set default by MS C runtime. */
764-
#ifdef ENABLE_NLS
764+
#if defined(ENABLE_NLS) && defined(FIXME1)
765765
/* FIXME: Something messes up locale (at least on MSYS2/UCRT64) and setlocale(LC_ALL, "") won't fix it.
766766
* The commented code below is the way to get proper console output for hostname.
767767
* Otherwise let's make sure we get proper IDN conversion and that is it. */
768-
/*
769768
char locale_name[LOCALE_NAME_MAX_LENGTH * sizeof(WCHAR)];
770769
GetSystemDefaultLocaleName((LPWSTR)locale_name, LOCALE_NAME_MAX_LENGTH);
771770
size_t len = wcsnlen_s((LPWSTR)locale_name, LOCALE_NAME_MAX_LENGTH);
772771
for (int i = 1; i <= len; ++i)
773772
locale_name[i] = locale_name[i * 2];
774773
setlocale(LC_ALL, locale_name);
775-
*/
776774
_locale_t locale = _create_locale(LC_ALL, "");
777775
errno_t err = _mbstowcs_s_l(&conv, hostname_wide, ARRAYSIZE(hostname_wide), hostname, _TRUNCATE, locale);
778776
_free_locale(locale);
779777
#else
778+
setlocale(LC_ALL, "");
780779
errno_t err = mbstowcs_s(&conv, hostname_wide, ARRAYSIZE(hostname_wide), hostname, _TRUNCATE);
781780
#endif
782781
if (!err)

0 commit comments

Comments
 (0)