Module Name:    src
Committed By:   christos
Date:           Tue Feb 19 17:43:33 UTC 2013

Modified Files:
        src/usr.bin/mail: fio.c glob.h lex.c

Log Message:
PR/47577: Steffen "Daode" Nurpmeso: Keep a resolved folder name together
with a display name in order to keep track of current state when the directory
is changed.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/mail/fio.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/mail/glob.h
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/mail/lex.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/mail/fio.c
diff -u src/usr.bin/mail/fio.c:1.36 src/usr.bin/mail/fio.c:1.37
--- src/usr.bin/mail/fio.c:1.36	Sat Oct 20 21:10:22 2012
+++ src/usr.bin/mail/fio.c	Tue Feb 19 12:43:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fio.c,v 1.36 2012/10/21 01:10:22 christos Exp $	*/
+/*	$NetBSD: fio.c,v 1.37 2013/02/19 17:43:32 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)fio.c	8.2 (Berkeley) 4/20/95";
 #else
-__RCSID("$NetBSD: fio.c,v 1.36 2012/10/21 01:10:22 christos Exp $");
+__RCSID("$NetBSD: fio.c,v 1.37 2013/02/19 17:43:32 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -392,14 +392,20 @@ 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) {
+		warn("Can't canonicalize folder `%s'", unres);
+		(void)strlcpy(name, unres, namesize);
+	} else
+		(void)strlcpy(name, res, namesize);
 	return 0;
 }
 

Index: src/usr.bin/mail/glob.h
diff -u src/usr.bin/mail/glob.h:1.12 src/usr.bin/mail/glob.h:1.13
--- src/usr.bin/mail/glob.h:1.12	Fri Apr 10 09:08:25 2009
+++ src/usr.bin/mail/glob.h	Tue Feb 19 12:43:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: glob.h,v 1.12 2009/04/10 13:08:25 christos Exp $	*/
+/*	$NetBSD: glob.h,v 1.13 2013/02/19 17:43:32 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -29,7 +29,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)glob.h	8.1 (Berkeley) 6/6/93
- *	$NetBSD: glob.h,v 1.12 2009/04/10 13:08:25 christos Exp $
+ *	$NetBSD: glob.h,v 1.13 2013/02/19 17:43:32 christos Exp $
  */
 
 /*
@@ -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 */

Index: src/usr.bin/mail/lex.c
diff -u src/usr.bin/mail/lex.c:1.41 src/usr.bin/mail/lex.c:1.42
--- src/usr.bin/mail/lex.c:1.41	Sun Apr 29 19:50:22 2012
+++ src/usr.bin/mail/lex.c	Tue Feb 19 12:43:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: lex.c,v 1.41 2012/04/29 23:50:22 christos Exp $	*/
+/*	$NetBSD: lex.c,v 1.42 2013/02/19 17:43:32 christos Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)lex.c	8.2 (Berkeley) 4/20/95";
 #else
-__RCSID("$NetBSD: lex.c,v 1.41 2012/04/29 23:50:22 christos Exp $");
+__RCSID("$NetBSD: lex.c,v 1.42 2013/02/19 17:43:32 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -141,6 +141,46 @@ file_leak_check(void)
 }
 #endif /* DEBUG_FILE_LEAK */
 
+static void
+update_mailname(const char *name)
+{
+	char tbuf[PATHSIZE];
+	size_t l;
+
+	if (realpath(name, mailname) == NULL) {
+		warn("Can't canonicalize `%s'", name);
+		return;
+	}
+
+	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;
+		}
+	}
+
+	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);
+	}
+}
+
 /*
  * Set the size of the message vector used to construct argument
  * lists to message list functions.
@@ -233,7 +273,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);
@@ -971,8 +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");

Reply via email to