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



 |The following reply was made to PR bin/47577; it has been noted by GNATS.
 |
 |From: Steffen "Daode" Nurpmeso <sdaoden%gmail.com@localhost>
 |To: christos%zoulas.com@localhost (Christos Zoulas)
 |Cc: gnats-admin%netbsd.org@localhost, gnats-bugs%NetBSD.org@localhost,
 | netbsd-bugs%netbsd.org@localhost
 |Subject: Re: bin/47577: Mail(1)/mail(1)/mailx(1) gets stuck when current
 | folder becomes accessible
 |Date: Mon, 18 Feb 2013 20:07:55 +0100
 |
 | christos%zoulas.com@localhost (Christos Zoulas) wrote:
 ||On Feb 18,  7:19pm, sdaoden%gmail.com@localhost (Steffen "Daode" Nurpmeso) 
wrote:
 ||-- Subject: Re: bin/47577: Mail(1)/mail(1)/mailx(1) gets stuck when \
 |  current \
 ||f
 ||
 ||| Sure; "fi" etc. then always show an absolute path, which is often
 ||| annoying imho, especially on 80 column terminals, though.
 ||
 ||So keep a "displayname" and a "resolvedname" so you always show the
 ||displayname. It is strange that the name will change when the user cds?
 ||Don't you agree?

This seems to work after some testing; the actual display length
can be controlled by adjusting sizeof(displayname).
Forgive if i f..d up something, but don't think so.
Ciao,

--steffen

--- 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-18 17:38:31.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.
@@ -232,11 +271,8 @@ setfile(const char *name)
        shudclob = 1;
        edit = isedit;
        (void)strcpy(prevfile, mailname);
-       if (name != mailname) {
-               (void)strcpy(mailname, name);
-
-               (void)strcpy(mailname, name);
-       }
+       if (name != mailname)
+               _update_mailname(name);
        mailsize = fsize(ibuf);
        (void)snprintf(tempname, sizeof(tempname),
            "%s/mail.RxXXXXXXXXXX", tmpdir);
@@ -975,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
@@ -1019,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