NetBSD-Bugs archive

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

Re: bin/47577: Mail(1)/mail(1)/mailx(1) gets stuck when current folder becomes accessible



aaah, i get grazy, wrong lex.c.orig.

--- fio.c.orig  2013-02-19 01:06:53.000000000 +0100
+++ fio.c       2013-02-19 03:00:56.000000000 +0100
@@ -392,14 +392,18 @@ fsize(FILE *iob)
 PUBLIC int
 getfold(char *name, size_t namesize)
 {
+       char unres[PATHSIZE], res[PATHSIZE];
        char *folder;
 
        if ((folder = value(ENAME_FOLDER)) == NULL)
                return -1;
        if (*folder == '/')
-               (void)strlcpy(name, folder, namesize);
+               (void)strlcpy(unres, folder, sizeof unres);
        else
-               (void)snprintf(name, namesize, "%s/%s", homedir, folder);
+               (void)snprintf(unres, sizeof unres, "%s/%s", homedir, folder);
+       if (realpath(unres, res) == NULL)
+               err(EXIT_FAILURE, "Can't canonicalize *folder* `%s'", unres);
+       (void)strlcpy(name, res, namesize);
        return 0;
 }
 
--- glob.h.orig 2013-02-18 17:39:46.000000000 +0100
+++ glob.h      2013-02-19 03:02:37.000000000 +0100
@@ -59,6 +59,7 @@ EXTERN FILE   *otf;                           /* Output temp 
file
 EXTERN int     image;                          /* File descriptor for image of 
msg */
 EXTERN FILE    *input;                         /* Current command input file */
 EXTERN char    mailname[PATHSIZE];             /* Name of current file */
+EXTERN char    displayname[80];                /* Prettyfied for display */
 EXTERN char    prevfile[PATHSIZE];             /* Name of previous file */
 EXTERN char    *tmpdir;                        /* Path name of temp directory 
*/
 EXTERN char    *homedir;                       /* Path name of home directory 
*/
--- lex.c.orig  2013-02-19 03:23:22.000000000 +0100
+++ lex.c       2013-02-19 03:05:58.000000000 +0100
@@ -141,6 +141,45 @@ file_leak_check(void)
 }
 #endif /* DEBUG_FILE_LEAK */
 
+static void
+_update_mailname(char const *name)
+{
+       char tbuf[PATHSIZE];
+       size_t l;
+
+       if (realpath(name, mailname) == NULL)
+               err(EXIT_FAILURE, "Can't canonicalize `%s'", name);
+
+       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);
+                       goto jleave;
+               }
+       }
+
+       l = strlen(mailname);
+       if (l < sizeof displayname)
+               strcpy(displayname, mailname);
+       else {
+               l -= sizeof(displayname) - 4 - sizeof(displayname) / 3;
+               (void)snprintf(displayname, sizeof displayname, "%.*s...%s",
+                       (int)sizeof(displayname) / 3, mailname, mailname + l);
+       }
+jleave:        ;
+}
+
 /*
  * Set the size of the message vector used to construct argument
  * lists to message list functions.
@@ -233,7 +272,7 @@ setfile(const char *name)
        edit = isedit;
        (void)strcpy(prevfile, mailname);
        if (name != mailname)
-               (void)strcpy(mailname, name);
+               _update_mailname(name);
        mailsize = fsize(ibuf);
        (void)snprintf(tempname, sizeof(tempname),
            "%s/mail.RxXXXXXXXXXX", tmpdir);
@@ -972,7 +1011,6 @@ newfileinfo(int omsgCount)
        struct message *mp;
        int d, n, s, t, u, mdot;
        char fname[PATHSIZE];
-       char *ename;
 
        /*
         * Figure out where to set the 'dot'.  Use the first new or
@@ -1016,23 +1054,10 @@ newfileinfo(int omsgCount)
                if (mp->m_flag & MTAGGED)
                        t++;
        }
-       ename = mailname;
-       if (getfold(fname, sizeof(fname)) >= 0) {
-               char zname[PATHSIZE];
-               size_t l;
-               l = strlen(fname);
-               if (l < sizeof(fname) - 1)
-                       fname[l++] = '/';
-               if (strncmp(fname, mailname, l) == 0) {
-                       (void)snprintf(zname, sizeof(zname), "+%s",
-                           mailname + l);
-                       ename = zname;
-               }
-       }
        /*
         * Display the statistics.
         */
-       (void)printf("\"%s\": ", ename);
+       (void)printf("\"%s\": ", displayname);
        {
                int cnt = get_abs_msgCount();
                (void)printf("%d message%s", cnt, cnt == 1 ? "" : "s");


Home | Main Index | Thread Index | Old Index