On Sat, Aug 20, 2016 at 07:21:15AM -0700, Kevin J. McCarthy wrote:
> I'll post a patch for this (based on your patch) later on today, so you
> can see more concretely what I'm proposing.

I need to clean up and test these more, but just to show concretely what
I'm proposing, here are two patches.

The first is based on your patch, Derek, but instead it completely
removes the $locale setting.

The second patch adds $attribution_locale and wrappers around the two
places where attribution strings are generated.

Note that the default $date_format used by %d in $attribution has a "!",
so you'll need to remove that to test it.

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
# HG changeset patch
# User Kevin McCarthy <ke...@8t8.us>
# Date 1471730492 25200
#      Sat Aug 20 15:01:32 2016 -0700
# Node ID 373f55f55cadff4567d4d5aca3c820af69d1789f
# Parent  e5fcfc5f9c2e711339ceaf2fdc1faf91fec6a6c6
Remove the $locale setting.

Instead, use the locale as specified by the users environment, except
when overridden by "!" in $date_format, ${}, etc.

The next commit will introduce $attribution_locale, which can be used
to customize the attribution date format using hooks.

Thanks to Derek Martin for the original patch!

diff --git a/browser.c b/browser.c
--- a/browser.c
+++ b/browser.c
@@ -171,21 +171,22 @@
          if (*t_fmt == '!') {
            ++t_fmt;
            do_locales = FALSE;
          }
        } else {
          tnow = time (NULL);
          t_fmt = tnow - folder->ff->mtime < 31536000 ? "%b %d %H:%M" : "%b %d  
%Y";
        }
-       if (do_locales)
-         setlocale(LC_TIME, NONULL (Locale)); /* use environment if $locale is 
not set */
-       else
-         setlocale(LC_TIME, "C");
-       strftime (date, sizeof (date), t_fmt, localtime (&folder->ff->mtime));
+
+        if (!do_locales)
+          setlocale (LC_TIME, "C");
+        strftime (date, sizeof (date), t_fmt, localtime (&folder->ff->mtime));
+        if (!do_locales)
+          setlocale (LC_TIME, "");
 
        mutt_format_s (dest, destlen, fmt, date);
       }
       else
        mutt_format_s (dest, destlen, fmt, "");
       break;
       
     case 'f':
diff --git a/crypt-gpgme.c b/crypt-gpgme.c
--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -864,23 +864,21 @@
 
   return *buf? 0:-1;
 }
 
 static void print_time(time_t t, STATE *s)
 {
   char p[STRING];
 
-  setlocale (LC_TIME, "");
 #ifdef HAVE_LANGINFO_D_T_FMT
   strftime (p, sizeof (p), nl_langinfo (D_T_FMT), localtime (&t));
 #else
   strftime (p, sizeof (p), "%c", localtime (&t));
 #endif
-  setlocale (LC_TIME, "C");
   state_attach_puts (p, s);
 }
 
 /* 
  * Implementation of `sign_message'.
  */
 
 /* Sign the MESSAGE in body A either using OpenPGP or S/MIME when
@@ -2810,32 +2808,31 @@
          else
          {
            *p++ = *cp++;
            len--;
          }
        }
        *p = 0;
 
-       if (do_locales && Locale)
-         setlocale (LC_TIME, Locale);
-        
         {
          time_t tt = 0;
 
          if (key->kobj->subkeys && (key->kobj->subkeys->timestamp > 0))
            tt = key->kobj->subkeys->timestamp;
 
           tm = localtime (&tt);
         }
-       strftime (buf2, sizeof (buf2), dest, tm);
-
-       if (do_locales)
-         setlocale (LC_TIME, "C");
-        
+
+        if (!do_locales)
+          setlocale (LC_TIME, "C");
+        strftime (buf2, sizeof (buf2), dest, tm);
+        if (!do_locales)
+          setlocale (LC_TIME, "");
+
        snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
        snprintf (dest, destlen, fmt, buf2);
        if (len > 0)
          src = cp + 1;
       }
       break;
     case 'n':
       if (!optional)
@@ -3366,19 +3363,16 @@
   struct tm *tm;
   char shortbuf[SHORT_STRING];
   unsigned long aval = 0;
   const char *delim;
   int is_pgp = 0;
   int i;
   gpgme_user_id_t uid = NULL;
 
-  if (Locale)
-    setlocale (LC_TIME, Locale);
-
   is_pgp = key->protocol == GPGME_PROTOCOL_OpenPGP;
 
   for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
     {
       if (uid->revoked)
         continue;
 
       s = uid->uid;
@@ -3608,19 +3602,16 @@
           if (subkey->can_certify)
             {
               fprintf (fp, "%s%s", delim, _("certification"));
               delim = _(", ");
             }
           putc ('\n', fp);
         }
     }
-
-  if (Locale)
-    setlocale (LC_TIME, "C");
 }
 
 
 /* Show detailed information about the selected key */
 static void 
 verify_key (crypt_key_t *key)
 {
   FILE *fp;
diff --git a/crypt.c b/crypt.c
--- a/crypt.c
+++ b/crypt.c
@@ -59,19 +59,17 @@
   char p[STRING], tmp[STRING];
 
   if (!WithCrypto)
     return;
 
   if (option (OPTCRYPTTIMESTAMP))
   {
     t = time(NULL);
-    setlocale (LC_TIME, "");
     strftime (p, sizeof (p), _(" (current time: %c)"), localtime (&t));
-    setlocale (LC_TIME, "C");
   }
   else
     *p = '\0';
 
   snprintf (tmp, sizeof (tmp), _("[-- %s output follows%s --]\n"), 
NONULL(app_name), p);
   state_attach_puts (tmp, s);
 }
 
diff --git a/globals.h b/globals.h
--- a/globals.h
+++ b/globals.h
@@ -61,17 +61,16 @@
 WHERE char *ImapDelimChars INITVAL (NULL);
 WHERE char *ImapHeaders;
 WHERE char *ImapLogin INITVAL (NULL);
 WHERE char *ImapPass INITVAL (NULL);
 WHERE char *ImapUser INITVAL (NULL);
 #endif
 WHERE char *Inbox;
 WHERE char *Ispell;
-WHERE char *Locale;
 WHERE char *MailcapPath;
 WHERE char *Maildir;
 #if defined(USE_IMAP) || defined(USE_POP)
 WHERE char *MessageCachedir;
 #endif
 #if USE_HCACHE
 WHERE char *HeaderCache;
 #if HAVE_GDBM || HAVE_DB4
diff --git a/hdrline.c b/hdrline.c
--- a/hdrline.c
+++ b/hdrline.c
@@ -378,19 +378,16 @@
          else
          {
            *p++ = *cp++;
            len--;
          }
        }
        *p = 0;
 
-       if (do_locales && Locale)
-         setlocale (LC_TIME, Locale);
-
        if (op == '[' || op == 'D')
          tm = localtime (&hdr->date_sent);
        else if (op == '(')
          tm = localtime (&hdr->received);
        else if (op == '<')
        {
          T = time (NULL);
          tm = localtime (&T);
@@ -401,20 +398,21 @@
          T = hdr->date_sent;
          if (hdr->zoccident)
            T -= (hdr->zhours * 3600 + hdr->zminutes * 60);
          else
            T += (hdr->zhours * 3600 + hdr->zminutes * 60);
          tm = gmtime (&T);
        }
 
-       strftime (buf2, sizeof (buf2), dest, tm);
-
-       if (do_locales)
-         setlocale (LC_TIME, "C");
+        if (!do_locales)
+          setlocale (LC_TIME, "C");
+        strftime (buf2, sizeof (buf2), dest, tm);
+        if (!do_locales)
+          setlocale (LC_TIME, "");
 
        mutt_format_s (dest, destlen, prefix, buf2);
        if (len > 0 && op != 'd' && op != 'D') /* Skip ending op */
          src = cp + 1;
       }
       break;
 
     case 'e':
diff --git a/init.h b/init.h
--- a/init.h
+++ b/init.h
@@ -1390,22 +1390,16 @@
   */
   { "keep_flagged", DT_BOOL, R_NONE, OPTKEEPFLAGGED, 0 },
   /*
   ** .pp
   ** If \fIset\fP, read messages marked as flagged will not be moved
   ** from your spool mailbox to your $$mbox mailbox, or as a result of
   ** a ``$mbox-hook'' command.
   */
-  { "locale",          DT_STR,  R_BOTH, UL &Locale, UL "C" },
-  /*
-  ** .pp
-  ** The locale used by \fCstrftime(3)\fP to format dates. Legal values are
-  ** the strings your system accepts for the locale environment variable 
\fC$$$LC_TIME\fP.
-  */
   { "mail_check",      DT_NUM,  R_NONE, UL &BuffyTimeout, 5 },
   /*
   ** .pp
   ** This variable configures how often (in seconds) mutt should look for
   ** new mail. Also see the $$timeout variable.
   */
   { "mail_check_recent",DT_BOOL, R_NONE, OPTMAILCHECKRECENT, 1 },
   /*
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -592,25 +592,24 @@
   
   if(getegid() != getgid())
   {
     fprintf(stderr, "%s: I don't want to run with privileges!\n",
            argv[0]);
     exit(1);
   }
 
+  setlocale (LC_ALL, "");
+
 #ifdef ENABLE_NLS
   /* FIXME what about init.c:1439 ? */
-  setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, MUTTLOCALEDIR);
   textdomain (PACKAGE);
 #endif
 
-  setlocale (LC_CTYPE, "");
-
   mutt_error = mutt_nocurses_error;
   mutt_message = mutt_nocurses_error;
   SRAND (time (NULL));
   umask (077);
 
   memset (Options, 0, sizeof (Options));
   memset (QuadOptions, 0, sizeof (QuadOptions));
 
diff --git a/pgpkey.c b/pgpkey.c
--- a/pgpkey.c
+++ b/pgpkey.c
@@ -190,25 +190,24 @@
          else
          {
            *p++ = *cp++;
            len--;
          }
        }
        *p = 0;
 
-       if (do_locales && Locale)
-         setlocale (LC_TIME, Locale);
 
        tm = localtime (&key->gen_time);
 
-       strftime (buf2, sizeof (buf2), dest, tm);
-
-       if (do_locales)
-         setlocale (LC_TIME, "C");
+        if (!do_locales)
+          setlocale (LC_TIME, "C");
+        strftime (buf2, sizeof (buf2), dest, tm);
+        if (!do_locales)
+          setlocale (LC_TIME, "");
 
        snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
        snprintf (dest, destlen, fmt, buf2);
        if (len > 0)
          src = cp + 1;
       }
       break;
     case 'n':
# HG changeset patch
# User Kevin McCarthy <ke...@8t8.us>
# Date 1471730498 25200
#      Sat Aug 20 15:01:38 2016 -0700
# Node ID 3098488f18a9937b068b43e6e2fbc60b3b56b979
# Parent  373f55f55cadff4567d4d5aca3c820af69d1789f
Add $attribution_locale setting.

This allows the attribution date format to be customized, using folder
or send-hooks.

diff --git a/doc/manual.xml.head b/doc/manual.xml.head
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -3619,18 +3619,18 @@
 <para>
 Example: <literal><command>send-hook</command> mutt
 "<command>set</command> mime_forward signature=''"</literal>
 </para>
 
 <para>
 Another typical use for this command is to change the values of the
 <link linkend="attribution">$attribution</link>, <link
-linkend="signature">$signature</link> and <link
-linkend="locale">$locale</link> variables in order to change the
+linkend="attribution-locale">$attribution_locale</link>, and <link
+linkend="signature">$signature</link> variables in order to change the
 language of the attributions and signatures based upon the recipients.
 </para>
 
 <note>
 <para>
 <command>send-hook</command>'s are only executed once after getting the
 initial list of recipients.  Adding a recipient after replying or
 editing the message will not cause any <command>send-hook</command> to
diff --git a/edit.c b/edit.c
--- a/edit.c
+++ b/edit.c
@@ -155,17 +155,19 @@
   {
     if (mutt_atoi (msg, &n) == 0 && n > 0 && n <= Context->msgcount)
     {
       n--;
 
       /* add the attribution */
       if (Attribution)
       {
+        setlocale (LC_TIME, NONULL (AttributionLocale));
        mutt_make_string (tmp, sizeof (tmp) - 1, Attribution, Context, 
Context->hdrs[n]);
+        setlocale (LC_TIME, "");
        strcat (tmp, "\n");     /* __STRCAT_CHECKED__ */
       }
 
       if (*bufmax == *buflen)
        safe_realloc ( &buf, sizeof (char *) * (*bufmax += 25));
       buf[(*buflen)++] = safe_strdup (tmp);
 
       bytes = Context->hdrs[n]->content->length;
diff --git a/globals.h b/globals.h
--- a/globals.h
+++ b/globals.h
@@ -31,16 +31,17 @@
 WHERE ADDRESS *EnvFrom;
 WHERE ADDRESS *From;
 
 WHERE char *AliasFile;
 WHERE char *AliasFmt;
 WHERE char *AssumedCharset;
 WHERE char *AttachSep;
 WHERE char *Attribution;
+WHERE char *AttributionLocale;
 WHERE char *AttachCharset;
 WHERE char *AttachFormat;
 WHERE char *Charset;
 WHERE char *ComposeFormat;
 WHERE char *ConfigCharset;
 WHERE char *ContentType;
 WHERE char *DefaultHook;
 WHERE char *DateFmt;
diff --git a/init.h b/init.h
--- a/init.h
+++ b/init.h
@@ -261,16 +261,28 @@
   */
   { "attribution",     DT_STR,  R_NONE, UL &Attribution, UL "On %d, %n wrote:" 
},
   /*
   ** .pp
   ** This is the string that will precede a message which has been included
   ** in a reply.  For a full listing of defined \fCprintf(3)\fP-like sequences 
see
   ** the section on $$index_format.
   */
+  { "attribution_locale", DT_STR, R_NONE, UL &AttributionLocale, UL "" },
+  /*
+  ** .pp
+  ** The locale used by \fCstrftime(3)\fP to format dates in the
+  ** $attribution string.  Legal values are the strings your system
+  ** accepts for the locale environment variable \fC$$$LC_TIME\fP.
+  ** .pp
+  ** This setting is to allow the attribution date format to be
+  ** customized by recipient or folder using hooks.  By default, Mutt
+  ** will use your locale environment, so there is not need to set
+  ** this except to override that default.
+  */
   { "auto_tag",                DT_BOOL, R_NONE, OPTAUTOTAG, 0 },
   /*
   ** .pp
   ** When \fIset\fP, functions in the \fIindex\fP menu which affect a message
   ** will be applied to all tagged messages (if there are any).  When
   ** unset, you must first use the \fC<tag-prefix>\fP function (bound to ``;''
   ** by default) to make the next function apply to all tagged messages.
   */
@@ -594,18 +606,18 @@
   { "date_format",     DT_STR,  R_BOTH, UL &DateFmt, UL "!%a, %b %d, %Y at 
%I:%M:%S%p %Z" },
   /*
   ** .pp
   ** This variable controls the format of the date printed by the ``%d''
   ** sequence in $$index_format.  This is passed to the \fCstrftime(3)\fP
   ** function to process the date, see the man page for the proper syntax.
   ** .pp
   ** Unless the first character in the string is a bang (``!''), the month
-  ** and week day names are expanded according to the locale specified in
-  ** the variable $$locale. If the first character in the string is a
+  ** and week day names are expanded according to the locale.
+  ** If the first character in the string is a
   ** bang, the bang is discarded, and the month and week day names in the
   ** rest of the string are expanded in the \fIC\fP locale (that is in US
   ** English).
   */
   { "default_hook",    DT_STR,  R_NONE, UL &DefaultHook, UL "~f %s !~P | (~P 
~C %s)" },
   /*
   ** .pp
   ** This variable controls how ``$message-hook'', ``$reply-hook'', 
``$send-hook'',
diff --git a/send.c b/send.c
--- a/send.c
+++ b/send.c
@@ -396,17 +396,19 @@
   return 0;
 }
 
 void mutt_make_attribution (CONTEXT *ctx, HEADER *cur, FILE *out)
 {
   char buffer[LONG_STRING];
   if (Attribution)
   {
+    setlocale (LC_TIME, NONULL (AttributionLocale));
     mutt_make_string (buffer, sizeof (buffer), Attribution, ctx, cur);
+    setlocale (LC_TIME, "");
     fputs (buffer, out);
     fputc ('\n', out);
   }
 }
 
 void mutt_make_post_indent (CONTEXT *ctx, HEADER *cur, FILE *out)
 {
   char buffer[STRING];

Attachment: signature.asc
Description: PGP signature

Reply via email to