]> diplodocus.org Git - nmh/commitdiff
Added locale profile component, value is passed to nmh_init().
authorDavid Levine <levinedl@acm.org>
Wed, 19 Oct 2016 23:53:42 +0000 (19:53 -0400)
committerDavid Levine <levinedl@acm.org>
Wed, 19 Oct 2016 23:53:51 +0000 (19:53 -0400)
man/mh-profile.man
sbr/utils.c
test/mhbuild/test-utf8-body
test/mhshow/test-charset

index ae085cc..0bf8cc8 100644 (file)
@@ -1,4 +1,4 @@
-.TH MH-PROFILE %manext5% "September 29, 2016" "%nmhversion%"
+.TH MH-PROFILE %manext5% "October 19, 2016" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
 .\"
 .\" %nmhwarning%
 .\"
@@ -62,6 +62,21 @@ transactions in directory \*(lqMail\*(rq.  This is the
 only mandatory profile entry.  (profile, no default)
 .RE
 .PP
 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
 .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
 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
 MAILDROP
 This variable tells
 .B inc
index 7306170..fff1aac 100644 (file)
@@ -383,10 +383,8 @@ void TrimSuffixC(char *s, int c)
 
 int
 nmh_init(const char *argv0, int read_context) {
 
 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, '/');
 
 
     invo_name = r1bindex ((char *) argv0, '/');
 
@@ -439,15 +437,24 @@ nmh_init(const char *argv0, int read_context) {
                 putchar ('\n');
             }
         }
                 putchar ('\n');
             }
         }
-
-        return OK;
     } else {
     } else {
-        int status = context_foil(NULL);
-        if (status != OK) {
+        if ((status = context_foil(NULL)) != OK) {
             advise("", "failed to create minimal profile/context");
         }
             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;
 }
 
 
 }
 
 
index 22de535..5e1b325 100755 (executable)
@@ -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
   #
   # 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"
   #
   sed -e 's/^Date:.*/Date:/' -e 's/; charset="[^;]*//' \
       "`mhpath cur`" > "${testname}.actual"
@@ -59,7 +60,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
-Attach: $MH_TEST_DIR/attachment.txt
+Nmh-Attach: $MH_TEST_DIR/attachment.txt
 
 This is a test.
 EOF
 
 This is a test.
 EOF
@@ -97,7 +98,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
-Attach: $MH_TEST_DIR/attachment.txt
+Nmh-Attach: $MH_TEST_DIR/attachment.txt
 
 ¡Ay, caramba!
 EOF
 
 ¡Ay, caramba!
 EOF
@@ -141,7 +142,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
-Attach: $MH_TEST_DIR/attachment.txt
+Nmh-Attach: $MH_TEST_DIR/attachment.txt
 EOF
 
 cat > "${testname}.expected" <<EOF
 EOF
 
 cat > "${testname}.expected" <<EOF
@@ -168,7 +169,7 @@ cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
 From: Mr Nobody <nobody@example.com>
 To: Somebody <somebody@example.com>
 Subject: Test
-Attach: $MH_TEST_DIR/attachment.txt
+Nmh-Attach: $MH_TEST_DIR/attachment.txt
 
 ¡Ay, caramba!
 EOF
 
 ¡Ay, caramba!
 EOF
@@ -187,6 +188,40 @@ EOF
 check "$expected" "$actual"
 
 
 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" <<EOF
+From: Mr Nobody <nobody@example.com>
+To: Somebody <somebody@example.com>
+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
 rm -f ${MHMTSCONF} "${MH_TEST_DIR}/attachment.txt"
 
 finish_test
index 9039764..52a75c5 100755 (executable)
@@ -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.
 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 <<EOF
 msgfile=`mhpath new`
 msgnum=`basename $msgfile`
 cat > $msgfile <<EOF
@@ -56,6 +57,17 @@ This is a test
 EOF
 
 run_prog mhshow $msgnum > $actual 2>&1
 EOF
 
 run_prog mhshow $msgnum > $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
 exit $failed