Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/mail PR/47577: Steffen "Daode" Nurpmeso: Keep a reso...
details: https://anonhg.NetBSD.org/src/rev/e5aaf1e3503d
branches: trunk
changeset: 785048:e5aaf1e3503d
user: christos <christos%NetBSD.org@localhost>
date: Tue Feb 19 17:43:32 2013 +0000
description:
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.
diffstat:
usr.bin/mail/fio.c | 14 ++++++++---
usr.bin/mail/glob.h | 5 ++-
usr.bin/mail/lex.c | 63 +++++++++++++++++++++++++++++++++++++---------------
3 files changed, 57 insertions(+), 25 deletions(-)
diffs (175 lines):
diff -r 49a9601aaf16 -r e5aaf1e3503d usr.bin/mail/fio.c
--- a/usr.bin/mail/fio.c Tue Feb 19 16:12:36 2013 +0000
+++ b/usr.bin/mail/fio.c Tue Feb 19 17:43:32 2013 +0000
@@ -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 @@
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;
}
diff -r 49a9601aaf16 -r e5aaf1e3503d usr.bin/mail/glob.h
--- a/usr.bin/mail/glob.h Tue Feb 19 16:12:36 2013 +0000
+++ b/usr.bin/mail/glob.h Tue Feb 19 17:43:32 2013 +0000
@@ -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 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 */
diff -r 49a9601aaf16 -r e5aaf1e3503d usr.bin/mail/lex.c
--- a/usr.bin/mail/lex.c Tue Feb 19 16:12:36 2013 +0000
+++ b/usr.bin/mail/lex.c Tue Feb 19 17:43:32 2013 +0000
@@ -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 @@
}
#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 @@
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 @@
{
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 @@
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