NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: PR/47577 CVS commit: src/usr.bin/mail



..This may also be sufficient.
(Just scream, i'll stop, then ...)

--steffen

diff -Napru mail.orig/lex.c mail/lex.c
--- mail.orig/lex.c     2013-02-25 14:58:37.000000000 +0100
+++ mail/lex.c  2013-02-25 20:04:28.000000000 +0100
@@ -144,8 +144,8 @@ file_leak_check(void)
 static void
 update_mailname(const char *name)
 {
-       char tbuf[PATHSIZE];
-       size_t l;
+       char tbuf[PATHSIZE], *mailp, *dispp;
+       size_t si, i, j;
 
        /* Don't realpath(3) if it's only an update request */
        if (name != NULL && realpath(name, mailname) == NULL) {
@@ -153,32 +153,37 @@ update_mailname(const char *name)
                return;
        }
 
+       mailp = mailname;
+       dispp = displayname;
+
+       /* Don't display an absolute path but "+FOLDER" if under *folder* */
        if (getfold(tbuf, sizeof(tbuf)) >= 0) {
-               l = strlen(tbuf);
-               if (l < sizeof(tbuf) - 1)
-                       tbuf[l++] = '/';
-               if (strncmp(tbuf, mailname, l) == 0) {
-                       char const *sep = "", *cp = mailname + l;
-
-                       l = strlen(cp);
-                       if (l >= sizeof(displayname)) {
-                               cp += l;
-                               cp -= sizeof(displayname) - 5;
-                               sep = "...";
-                       }
-                       (void)snprintf(displayname, sizeof(displayname),
-                           "+%s%s", sep, cp);
-                       return;
+               i = strlen(tbuf);
+               if (i < sizeof(tbuf) - 1)
+                       tbuf[i++] = '/';
+               if (strncmp(tbuf, mailp, i) == 0) {
+                       mailp += i;
+                       *dispp++ = '+';
                }
        }
 
-       l = strlen(mailname);
-       if (l < sizeof(displayname))
-               strcpy(displayname, mailname);
+       /* We want to see the name of the folder .. on the screen */
+       i = strlen(mailp);
+       if (i < sizeof(displayname) - 1)
+               memcpy(dispp, mailp, i + 1);
        else {
-               l -= sizeof(displayname) - 4 - sizeof(displayname) / 3;
-               (void)snprintf(displayname, sizeof(displayname), "%.*s...%s",
-                       (int)sizeof(displayname) / 3, mailname, mailname + l);
+               j = sizeof(displayname) / 3;
+               si = i;
+               i -= sizeof(displayname) - (1 /* "+" */ + 4) - j;
+               /* Avoid disrupting multibyte sequences */
+               goto jmblen;
+               while (i < si && mblen(mailp + i, si - i) < 0) {
+                       ++i;
+jmblen:
+                       mblen(NULL, 0);
+               }
+               (void)snprintf(dispp, sizeof(displayname) - 1, "%.*s...%s",
+                       (int)j, mailp, mailp + i);
        }
 }
 


Home | Main Index | Thread Index | Old Index