From bed6327e0962c95394b530b7b1ebc40e2af28320 Mon Sep 17 00:00:00 2001 From: David Levine Date: Wed, 19 Oct 2016 19:53:42 -0400 Subject: [PATCH] Added locale profile component, value is passed to nmh_init(). --- man/mh-profile.man | 21 ++++++++++++++++- sbr/utils.c | 25 +++++++++++++-------- test/mhbuild/test-utf8-body | 45 ++++++++++++++++++++++++++++++++----- test/mhshow/test-charset | 14 +++++++++++- 4 files changed, 89 insertions(+), 16 deletions(-) diff --git a/man/mh-profile.man b/man/mh-profile.man index ae085cc4..0bf8cc84 100644 --- a/man/mh-profile.man +++ b/man/mh-profile.man @@ -1,4 +1,4 @@ -.TH MH-PROFILE %manext5% "September 29, 2016" "%nmhversion%" +.TH MH-PROFILE %manext5% "October 19, 2016" "%nmhversion%" .\" .\" %nmhwarning% .\" @@ -62,6 +62,21 @@ transactions in directory \*(lqMail\*(rq. This is the only mandatory profile entry. (profile, no default) .RE .PP +.BR locale : +locale +.RS 5 +Set the locale for all +.B nmh +programs except +.BR post , +.BR install-mh , +and +.BR slocal . +See the LC_ALL, LC_CTYPE, and LANG variables in the "ENVIRONMENT" +section below for a reference on how the locale is set if this profile +component is not used. +.RE +.PP .BR context : context .RS 5 @@ -800,6 +815,10 @@ variables whose names are all upper-case are user-settable; those whose names are lower-case only are used internally by nmh and should not generally be set by the user. .TP +LC_ALL, LC_CTYPE, and LANG +These variables are used to set the locale, see locale(1). +The \*(lqlocale\*(rq profile entry supersedes these. +.TP MAILDROP This variable tells .B inc diff --git a/sbr/utils.c b/sbr/utils.c index 73061709..fff1aacd 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -383,10 +383,8 @@ void TrimSuffixC(char *s, int c) int nmh_init(const char *argv0, int read_context) { - if (! setlocale(LC_ALL, "")) { - admonish(NULL, "setlocale failed, check your LC_ALL, LC_CTYPE, and " - "LANG environment variables"); - } + int status = OK; + char *locale; invo_name = r1bindex ((char *) argv0, '/'); @@ -439,15 +437,24 @@ nmh_init(const char *argv0, int read_context) { putchar ('\n'); } } - - return OK; } else { - int status = context_foil(NULL); - if (status != OK) { + if ((status = context_foil(NULL)) != OK) { advise("", "failed to create minimal profile/context"); } - return status; } + + /* Allow the user to set a locale in their profile. Otherwise, use the + "" string to pull it from their environment, see setlocale(3). */ + if ((locale = context_find ("locale")) == NULL) { + locale = ""; + } + + if (! setlocale (LC_ALL, locale)) { + admonish (NULL, "setlocale failed, check your LC_ALL, LC_CTYPE, and " + "LANG environment variables"); + } + + return status; } diff --git a/test/mhbuild/test-utf8-body b/test/mhbuild/test-utf8-body index 22de535c..5e1b3256 100755 --- a/test/mhbuild/test-utf8-body +++ b/test/mhbuild/test-utf8-body @@ -40,7 +40,8 @@ test_attachment () # # It's hard to calculate the exact Date: header post is going to # use, so we'll just use sed to remove the actual date so we can easily - # compare it against our "correct" output. And same for charset. + # compare it against our "correct" output. And same for charset, + # because mime_type() can rely on file(1) --mime-encoding. # sed -e 's/^Date:.*/Date:/' -e 's/; charset="[^;]*//' \ "`mhpath cur`" > "${testname}.actual" @@ -59,7 +60,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" < To: Somebody Subject: Test -Attach: $MH_TEST_DIR/attachment.txt +Nmh-Attach: $MH_TEST_DIR/attachment.txt This is a test. EOF @@ -97,7 +98,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" < To: Somebody Subject: Test -Attach: $MH_TEST_DIR/attachment.txt +Nmh-Attach: $MH_TEST_DIR/attachment.txt ¡Ay, caramba! EOF @@ -141,7 +142,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" < To: Somebody Subject: Test -Attach: $MH_TEST_DIR/attachment.txt +Nmh-Attach: $MH_TEST_DIR/attachment.txt EOF cat > "${testname}.expected" < "${MH_TEST_DIR}/Mail/draft" < To: Somebody Subject: Test -Attach: $MH_TEST_DIR/attachment.txt +Nmh-Attach: $MH_TEST_DIR/attachment.txt ¡Ay, caramba! EOF @@ -187,6 +188,40 @@ EOF check "$expected" "$actual" +# previous test, but with locale profile entry +start_test '8-bit body with C locale with locale profile entry' + +printf 'locale: en_US.UTF-8\n' >> "${MH}" + +cat > "${testname}.expected" < +To: Somebody +Subject: Test +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" +Content-Transfer-Encoding: 8bit +Date: + +------- =_aaaaaaaaaa0 +Content-Type: text/plain +Content-Transfer-Encoding: 8bit + +¡Ay, caramba! + +------- =_aaaaaaaaaa0 +Content-Type: text/plain; name="attachment.txt" +Content-Description: attachment.txt +Content-Disposition: attachment; filename="attachment.txt" +Content-Transfer-Encoding: 8bit + +8-bit attachment, ¡Ay, caramba! + +------- =_aaaaaaaaaa0-- +EOF + +test_attachment "${testname}.expected" + + rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt" finish_test diff --git a/test/mhshow/test-charset b/test/mhshow/test-charset index 9039764f..52a75c51 100755 --- a/test/mhshow/test-charset +++ b/test/mhshow/test-charset @@ -26,6 +26,7 @@ actual=$MH_TEST_DIR/$$.actual echo 'mhshow-charset-windows-1252: echo "This is a test"' >> "$MH" # Write message with bogus quoted-printable data. +start_test 'Write message with bogus quoted-printable data' msgfile=`mhpath new` msgnum=`basename $msgfile` cat > $msgfile < $actual 2>&1 -check "$expected" "$actual" : bogus quoted-printable data +check "$expected" "$actual" 'keep first' : bogus quoted-printable data + +start_test 'locale profile component' +#### Used LC_ALL above, now use locale profile component instead. +printf "locale: $LC_ALL\n" >> "${MH}" +unset LC_ALL + +run_prog mhshow $msgnum > $actual 2>&1 +check "$expected" "$actual" : locale profile component + + +finish_test exit $failed -- 2.56.0