Home | History | Annotate | Line # | Download | only in mail
cmd1.c revision 1.28.8.1
      1  1.28.8.1      matt /*	$NetBSD: cmd1.c,v 1.28.8.1 2007/11/06 23:35:48 matt Exp $	*/
      2       1.5  christos 
      3       1.1       cgd /*-
      4       1.3   deraadt  * Copyright (c) 1980, 1993
      5       1.3   deraadt  *	The Regents of the University of California.  All rights reserved.
      6       1.1       cgd  *
      7       1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8       1.1       cgd  * modification, are permitted provided that the following conditions
      9       1.1       cgd  * are met:
     10       1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11       1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12       1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14       1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15      1.21       agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.1       cgd  *    may be used to endorse or promote products derived from this software
     17       1.1       cgd  *    without specific prior written permission.
     18       1.1       cgd  *
     19       1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1       cgd  * SUCH DAMAGE.
     30       1.1       cgd  */
     31       1.1       cgd 
     32      1.10     lukem #include <sys/cdefs.h>
     33       1.1       cgd #ifndef lint
     34       1.5  christos #if 0
     35       1.6       tls static char sccsid[] = "@(#)cmd1.c	8.2 (Berkeley) 4/20/95";
     36       1.5  christos #else
     37  1.28.8.1      matt __RCSID("$NetBSD: cmd1.c,v 1.28.8.1 2007/11/06 23:35:48 matt Exp $");
     38       1.5  christos #endif
     39       1.1       cgd #endif /* not lint */
     40       1.1       cgd 
     41      1.28  christos #include <assert.h>
     42      1.28  christos 
     43       1.1       cgd #include "rcv.h"
     44       1.3   deraadt #include "extern.h"
     45      1.27  christos #include "format.h"
     46      1.26  christos #ifdef MIME_SUPPORT
     47      1.26  christos #include "mime.h"
     48      1.26  christos #endif
     49      1.28  christos #include "thread.h"
     50      1.28  christos 
     51       1.1       cgd 
     52       1.1       cgd /*
     53       1.1       cgd  * Mail -- a mail program
     54       1.1       cgd  *
     55       1.1       cgd  * User commands.
     56       1.1       cgd  */
     57       1.1       cgd 
     58      1.28  christos static int screen;
     59      1.28  christos 
     60      1.28  christos /*
     61      1.28  christos  * Compute screen size.
     62      1.28  christos  */
     63      1.28  christos static int
     64      1.28  christos screensize(void)
     65      1.28  christos {
     66      1.28  christos 	int s;
     67      1.28  christos 	char *cp;
     68      1.28  christos 
     69      1.28  christos 	if ((cp = value(ENAME_SCREEN)) != NULL && (s = atoi(cp)) > 0)
     70      1.28  christos 		return s;
     71      1.28  christos 	return screenheight - 4;
     72      1.28  christos }
     73      1.28  christos 
     74      1.28  christos /*
     75      1.28  christos  * Print out the header of a specific message.
     76      1.28  christos  * This is a slight improvement to the standard one.
     77      1.28  christos  */
     78      1.28  christos PUBLIC void
     79      1.28  christos printhead(int mesg)
     80      1.28  christos {
     81      1.28  christos 	const char *fmtstr;
     82      1.28  christos 	char *msgline;
     83      1.28  christos 
     84      1.28  christos 	fmtstr = value(ENAME_HEADER_FORMAT);
     85      1.28  christos 	if (fmtstr == NULL)
     86      1.28  christos 		fmtstr = DEFAULT_HEADER_FORMAT;
     87      1.28  christos 	msgline = smsgprintf(fmtstr, get_message(mesg));
     88      1.28  christos 	if (screenwidth > 0)
     89      1.28  christos 		msgline[screenwidth] = '\0';
     90      1.28  christos 	(void)printf("%s\n", msgline);
     91      1.28  christos }
     92      1.28  christos 
     93       1.1       cgd /*
     94       1.1       cgd  * Print the current active headings.
     95       1.1       cgd  * Don't change dot if invoker didn't give an argument.
     96       1.1       cgd  */
     97      1.28  christos PUBLIC int
     98      1.15       wiz headers(void *v)
     99       1.1       cgd {
    100       1.5  christos 	int *msgvec = v;
    101      1.28  christos 	int n, flag;
    102      1.10     lukem 	struct message *mp;
    103       1.1       cgd 	int size;
    104       1.1       cgd 
    105       1.1       cgd 	size = screensize();
    106       1.1       cgd 	n = msgvec[0];
    107       1.1       cgd 	if (n != 0)
    108      1.28  christos 		screen = (n - 1)/size;
    109       1.1       cgd 	if (screen < 0)
    110       1.1       cgd 		screen = 0;
    111      1.28  christos 
    112      1.28  christos 	if ((mp = get_message(screen * size + 1)) == NULL) {
    113      1.28  christos 		int msgCount;
    114      1.28  christos 		msgCount = get_msgCount();
    115      1.28  christos 		if (screen * size + 1 > msgCount)
    116      1.28  christos 			mp = get_message(msgCount - size + 1);
    117      1.28  christos 		if (mp == NULL)
    118      1.28  christos 			mp = get_message(1);
    119      1.28  christos 	}
    120       1.1       cgd 	flag = 0;
    121      1.28  christos 	if (dot != get_message(n))
    122       1.1       cgd 		dot = mp;
    123      1.28  christos 	for (/*EMPTY*/; mp; mp = next_message(mp)) {
    124       1.1       cgd 		if (mp->m_flag & MDELETED)
    125       1.1       cgd 			continue;
    126       1.1       cgd 		if (flag++ >= size)
    127       1.1       cgd 			break;
    128      1.28  christos 		printhead(get_msgnum(mp));
    129       1.1       cgd 	}
    130       1.1       cgd 	if (flag == 0) {
    131      1.23  christos 		(void)printf("No more mail.\n");
    132      1.28  christos 		return 1;
    133       1.1       cgd 	}
    134      1.28  christos 	return 0;
    135       1.1       cgd }
    136       1.1       cgd 
    137       1.1       cgd /*
    138       1.1       cgd  * Scroll to the next/previous screen
    139       1.1       cgd  */
    140      1.28  christos PUBLIC int
    141      1.15       wiz scroll(void *v)
    142       1.1       cgd {
    143       1.5  christos 	char *arg = v;
    144      1.10     lukem 	int s, size;
    145       1.1       cgd 	int cur[1];
    146       1.1       cgd 
    147       1.1       cgd 	cur[0] = 0;
    148       1.1       cgd 	size = screensize();
    149       1.1       cgd 	s = screen;
    150       1.1       cgd 	switch (*arg) {
    151       1.1       cgd 	case 0:
    152       1.1       cgd 	case '+':
    153       1.1       cgd 		s++;
    154      1.28  christos 		if (s * size >= get_msgCount()) {
    155      1.23  christos 			(void)printf("On last screenful of messages\n");
    156      1.28  christos 			return 0;
    157       1.1       cgd 		}
    158       1.1       cgd 		screen = s;
    159       1.1       cgd 		break;
    160       1.1       cgd 
    161       1.1       cgd 	case '-':
    162       1.1       cgd 		if (--s < 0) {
    163      1.23  christos 			(void)printf("On first screenful of messages\n");
    164      1.28  christos 			return 0;
    165       1.1       cgd 		}
    166       1.1       cgd 		screen = s;
    167       1.1       cgd 		break;
    168       1.1       cgd 
    169       1.1       cgd 	default:
    170      1.23  christos 		(void)printf("Unrecognized scrolling command \"%s\"\n", arg);
    171      1.28  christos 		return 1;
    172       1.1       cgd 	}
    173      1.28  christos 	return headers(cur);
    174       1.1       cgd }
    175       1.1       cgd 
    176       1.1       cgd /*
    177       1.1       cgd  * Print out the headlines for each message
    178       1.1       cgd  * in the passed message list.
    179       1.1       cgd  */
    180      1.28  christos PUBLIC int
    181      1.15       wiz from(void *v)
    182       1.1       cgd {
    183       1.5  christos 	int *msgvec = v;
    184      1.10     lukem 	int *ip;
    185       1.1       cgd 
    186       1.8        pk 	for (ip = msgvec; *ip != 0; ip++)
    187       1.1       cgd 		printhead(*ip);
    188       1.1       cgd 	if (--ip >= msgvec)
    189      1.28  christos 		dot = get_message(*ip);
    190      1.28  christos 	return 0;
    191       1.1       cgd }
    192       1.1       cgd 
    193       1.1       cgd /*
    194      1.28  christos  * Print out the value of dot.
    195       1.1       cgd  */
    196      1.28  christos /*ARGSUSED*/
    197      1.28  christos PUBLIC int
    198      1.28  christos pdot(void *v)
    199       1.1       cgd {
    200      1.28  christos 	int *msgvec;
    201      1.26  christos 
    202      1.28  christos 	msgvec = v;
    203      1.28  christos 	dot = get_message(msgvec[0]);
    204       1.1       cgd 
    205      1.28  christos 	(void)printf("%d\n", get_msgnum(dot));
    206      1.28  christos 	return 0;
    207       1.1       cgd }
    208       1.1       cgd 
    209       1.1       cgd /*
    210       1.1       cgd  * Print out all the possible commands.
    211       1.1       cgd  */
    212      1.23  christos /*ARGSUSED*/
    213      1.28  christos PUBLIC int
    214      1.26  christos pcmdlist(void *v __unused)
    215       1.1       cgd {
    216      1.10     lukem 	const struct cmd *cp;
    217      1.10     lukem 	int cc;
    218       1.1       cgd 
    219      1.23  christos 	(void)printf("Commands are:\n");
    220       1.1       cgd 	for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) {
    221       1.1       cgd 		cc += strlen(cp->c_name) + 2;
    222       1.1       cgd 		if (cc > 72) {
    223      1.23  christos 			(void)printf("\n");
    224       1.1       cgd 			cc = strlen(cp->c_name) + 2;
    225       1.1       cgd 		}
    226      1.26  christos 		if ((cp + 1)->c_name != NULL)
    227      1.23  christos 			(void)printf("%s, ", cp->c_name);
    228       1.1       cgd 		else
    229      1.23  christos 			(void)printf("%s\n", cp->c_name);
    230       1.1       cgd 	}
    231      1.28  christos 	return 0;
    232       1.1       cgd }
    233       1.1       cgd 
    234      1.28  christos 
    235      1.28  christos PUBLIC char *
    236      1.28  christos sget_msgnum(struct message *mp, struct message *parent)
    237      1.26  christos {
    238      1.28  christos 	char *p;
    239      1.28  christos 	if (parent == NULL || parent == mp) {
    240      1.28  christos 		(void)sasprintf(&p, "%d", mp->m_index);
    241      1.28  christos 		return p;
    242      1.28  christos 	}
    243      1.28  christos 	p = sget_msgnum(mp->m_plink, parent);
    244      1.26  christos 
    245      1.28  christos 	(void)sasprintf(&p, "%s.%d", p, mp->m_index);
    246      1.28  christos 	return p;
    247      1.26  christos }
    248      1.26  christos 
    249      1.28  christos PUBLIC void
    250      1.28  christos show_msgnum(FILE *obuf, struct message *mp, struct message *parent)
    251       1.1       cgd {
    252      1.28  christos 	if (value(ENAME_QUIET) == NULL)
    253      1.28  christos 		(void)fprintf(obuf, "Message %s:\n", sget_msgnum(mp, parent));
    254       1.1       cgd }
    255       1.1       cgd 
    256      1.28  christos struct type1_core_args_s {
    257      1.28  christos 	FILE *obuf;
    258      1.28  christos 	struct message *parent;
    259      1.28  christos 	struct ignoretab *igtab;
    260      1.28  christos 	struct mime_info **mip;
    261      1.28  christos };
    262      1.28  christos static int
    263      1.28  christos type1_core(struct message *mp, void *v)
    264       1.1       cgd {
    265      1.28  christos 	struct type1_core_args_s *args;
    266       1.1       cgd 
    267      1.28  christos 	args = v;
    268      1.28  christos 	touch(mp);
    269      1.28  christos 	show_msgnum(args->obuf, mp, args->parent);
    270      1.26  christos #ifdef MIME_SUPPORT
    271      1.28  christos 	if (args->mip == NULL)
    272      1.28  christos 		(void)mime_sendmessage(mp, args->obuf, args->igtab, NULL, NULL);
    273      1.28  christos 	else {
    274      1.28  christos 		*args->mip = mime_decode_open(mp);
    275      1.28  christos 		(void)mime_sendmessage(mp, args->obuf, args->igtab, NULL, *args->mip);
    276      1.28  christos 		mime_decode_close(*args->mip);
    277      1.28  christos 	}
    278      1.26  christos #else
    279      1.28  christos 	(void)sendmessage(mp, args->obuf, args->igtab, NULL, NULL);
    280      1.26  christos #endif
    281      1.28  christos 	return 0;
    282       1.1       cgd }
    283       1.1       cgd 
    284       1.1       cgd /*
    285      1.28  christos  * Respond to a broken pipe signal --
    286      1.28  christos  * probably caused by quitting more.
    287       1.1       cgd  */
    288      1.28  christos static jmp_buf	pipestop;
    289      1.28  christos 
    290      1.28  christos /*ARGSUSED*/
    291      1.28  christos static void
    292      1.28  christos brokpipe(int signo __unused)
    293       1.1       cgd {
    294      1.28  christos 	longjmp(pipestop, 1);
    295       1.1       cgd }
    296       1.1       cgd 
    297       1.1       cgd /*
    298      1.28  christos  * Type out the messages requested.
    299       1.1       cgd  */
    300      1.28  christos #ifndef MIME_SUPPORT
    301      1.28  christos # define type1(a,b,c)		legacy_type1(a,b)
    302      1.28  christos #endif
    303      1.28  christos static int
    304      1.28  christos type1(int *msgvec, int doign, int mime_decode)
    305       1.1       cgd {
    306      1.28  christos 	int recursive;
    307      1.28  christos 	int *ip;
    308      1.28  christos 	int msgCount;
    309      1.28  christos 	/*
    310      1.28  christos 	 * Some volatile variables so longjmp will get the current not
    311      1.28  christos 	 * starting values.  Note it is the variable that is volatile,
    312      1.28  christos 	 * not what it is pointing at!
    313      1.28  christos 	 */
    314      1.28  christos 	FILE *volatile obuf;		/* avoid longjmp clobbering? */
    315      1.26  christos #ifdef MIME_SUPPORT
    316      1.28  christos 	sig_t volatile oldsigpipe;	/* XXX - is volatile needed? */
    317      1.28  christos 	struct mime_info *volatile mip; /* avoid longjmp clobbering - needed */
    318      1.26  christos #endif
    319      1.26  christos 
    320      1.28  christos 	if ((obuf = last_registered_file(0)) == NULL)
    321      1.28  christos 		obuf = stdout;
    322      1.26  christos 
    323      1.26  christos #ifdef MIME_SUPPORT
    324      1.28  christos 	mip = NULL;
    325      1.28  christos 
    326      1.28  christos 	oldsigpipe = signal(SIGPIPE, SIG_IGN);
    327  1.28.8.1      matt 
    328      1.28  christos 	if (setjmp(pipestop))
    329      1.28  christos 		goto close_pipe;
    330      1.28  christos 
    331      1.28  christos 	(void)signal(SIGPIPE, brokpipe);
    332      1.26  christos #endif
    333      1.28  christos 	msgCount = get_msgCount();
    334      1.26  christos 
    335      1.28  christos 	recursive = do_recursion();
    336      1.28  christos 	for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
    337      1.28  christos 		struct type1_core_args_s args;
    338      1.28  christos 		struct message *mp;
    339      1.26  christos 
    340      1.28  christos 		mp = get_message(*ip);
    341      1.28  christos 		dot = mp;
    342      1.28  christos 		args.obuf = obuf;
    343      1.28  christos 		args.parent = recursive ? mp : NULL;
    344      1.28  christos 		args.igtab = doign ? ignore : 0;
    345      1.26  christos #ifdef MIME_SUPPORT
    346      1.28  christos 		args.mip = mime_decode ? __UNVOLATILE(&mip) : NULL;
    347      1.26  christos #else
    348      1.28  christos 		args.mip = NULL;
    349      1.26  christos #endif
    350      1.28  christos 		(void)thread_recursion(mp, type1_core, &args);
    351      1.28  christos 	}
    352      1.26  christos #ifdef MIME_SUPPORT
    353      1.28  christos close_pipe:
    354      1.28  christos 	if (mip != NULL) {
    355      1.28  christos 		/*
    356      1.28  christos 		 * Ignore SIGPIPE so it can't cause a duplicate close.
    357      1.28  christos 		 */
    358      1.28  christos 		(void)signal(SIGPIPE, SIG_IGN);
    359      1.28  christos 		mime_decode_close(mip);
    360      1.28  christos 		(void)signal(SIGPIPE, oldsigpipe);
    361      1.28  christos 	}
    362      1.26  christos #endif
    363      1.28  christos 	return 0;
    364      1.26  christos }
    365      1.26  christos 
    366      1.28  christos #ifdef MIME_SUPPORT
    367      1.28  christos static int
    368      1.28  christos de_mime(void)
    369      1.26  christos {
    370      1.28  christos 	return value(ENAME_MIME_DECODE_MSG) != NULL;
    371      1.26  christos }
    372      1.26  christos 
    373      1.26  christos /*
    374      1.26  christos  * Identical to type(), but with opposite mime behavior.
    375      1.26  christos  */
    376      1.28  christos PUBLIC int
    377      1.26  christos view(void *v)
    378      1.26  christos {
    379      1.26  christos 	int *msgvec = v;
    380      1.28  christos 	return type1(msgvec, 1, !de_mime());
    381      1.26  christos }
    382      1.26  christos 
    383      1.26  christos /*
    384      1.26  christos  * Identical to Type(), but with opposite mime behavior.
    385      1.26  christos  */
    386      1.28  christos PUBLIC int
    387      1.26  christos View(void *v)
    388      1.26  christos {
    389      1.26  christos 	int *msgvec = v;
    390      1.26  christos 
    391      1.28  christos 	return type1(msgvec, 0, !de_mime());
    392       1.1       cgd }
    393      1.26  christos #endif /* MIME_SUPPORT */
    394       1.1       cgd 
    395       1.1       cgd /*
    396      1.28  christos  * Type out messages, honor ignored fields.
    397       1.1       cgd  */
    398      1.28  christos PUBLIC int
    399      1.28  christos type(void *v)
    400       1.1       cgd {
    401      1.28  christos 	int *msgvec = v;
    402      1.26  christos 
    403      1.28  christos 	return type1(msgvec, 1, de_mime());
    404       1.1       cgd }
    405       1.1       cgd 
    406       1.1       cgd /*
    407      1.28  christos  * Type out messages, even printing ignored fields.
    408       1.1       cgd  */
    409      1.28  christos PUBLIC int
    410      1.28  christos Type(void *v)
    411       1.1       cgd {
    412      1.28  christos 	int *msgvec = v;
    413      1.28  christos 
    414      1.28  christos 	return type1(msgvec, 0, de_mime());
    415       1.1       cgd }
    416       1.1       cgd 
    417       1.1       cgd /*
    418      1.24  christos  * Pipe the current message buffer to a command.
    419      1.24  christos  */
    420      1.28  christos PUBLIC int
    421      1.24  christos pipecmd(void *v)
    422      1.24  christos {
    423      1.24  christos 	char *cmd = v;
    424      1.26  christos 	FILE *volatile obuf;	/* void longjmp clobbering - we want
    425      1.26  christos 				   the current value not start value */
    426      1.24  christos 	if (dot == NULL) {
    427      1.24  christos 		warn("pipcmd: no current message");
    428      1.24  christos 		return 1;
    429      1.24  christos 	}
    430      1.24  christos 
    431      1.24  christos 	obuf = stdout;
    432      1.24  christos 	if (setjmp(pipestop))
    433      1.24  christos 		goto close_pipe;
    434      1.24  christos 
    435      1.24  christos 	obuf = Popen(cmd, "w");
    436      1.24  christos 	if (obuf == NULL) {
    437      1.24  christos 		warn("pipecmd: Popen failed: %s", cmd);
    438      1.24  christos 		return 1;
    439      1.24  christos 	} else
    440      1.24  christos 		(void)signal(SIGPIPE, brokpipe);
    441      1.24  christos 
    442      1.26  christos 	(void)sendmessage(dot, obuf, ignoreall, NULL, NULL);
    443      1.24  christos  close_pipe:
    444      1.24  christos 	if (obuf != stdout) {
    445      1.24  christos 		/*
    446      1.24  christos 		 * Ignore SIGPIPE so it can't cause a duplicate close.
    447      1.24  christos 		 */
    448      1.24  christos 		(void)signal(SIGPIPE, SIG_IGN);
    449      1.26  christos 		(void)Pclose(obuf);
    450      1.24  christos 		(void)signal(SIGPIPE, SIG_DFL);
    451      1.24  christos 	}
    452      1.24  christos 	return 0;
    453      1.24  christos }
    454      1.24  christos 
    455      1.28  christos 
    456      1.28  christos struct top_core_args_s {
    457      1.28  christos 	int lineb;
    458      1.28  christos 	int topl;
    459      1.28  christos 	struct message *parent;
    460      1.28  christos };
    461      1.28  christos static int
    462      1.28  christos top_core(struct message *mp, void *v)
    463      1.28  christos {
    464      1.28  christos 	char buffer[LINESIZE];
    465      1.28  christos 	struct top_core_args_s *args;
    466      1.28  christos 	FILE *ibuf;
    467      1.28  christos 	int lines;
    468      1.28  christos 	int c;
    469      1.28  christos 
    470      1.28  christos 	args = v;
    471      1.28  christos 	touch(mp);
    472      1.28  christos 	if (!args->lineb)
    473      1.28  christos 		(void)printf("\n");
    474      1.28  christos 	show_msgnum(stdout, mp, args->parent);
    475      1.28  christos 	ibuf = setinput(mp);
    476      1.28  christos 	c = mp->m_lines;
    477      1.28  christos 	for (lines = 0; lines < c && lines <= args->topl; lines++) {
    478      1.28  christos 		if (mail_readline(ibuf, buffer, sizeof(buffer)) < 0)
    479      1.28  christos 			break;
    480      1.28  christos 		(void)puts(buffer);
    481      1.28  christos 		args->lineb = blankline(buffer);
    482      1.28  christos 	}
    483      1.28  christos 	return 0;
    484      1.28  christos }
    485      1.28  christos 
    486      1.24  christos /*
    487       1.1       cgd  * Print the top so many lines of each desired message.
    488       1.1       cgd  * The number of lines is taken from the variable "toplines"
    489       1.1       cgd  * and defaults to 5.
    490       1.1       cgd  */
    491      1.28  christos PUBLIC int
    492      1.15       wiz top(void *v)
    493       1.1       cgd {
    494      1.28  christos 	struct top_core_args_s args;
    495      1.28  christos 	int recursive;
    496      1.28  christos 	int msgCount;
    497       1.5  christos 	int *msgvec = v;
    498      1.10     lukem 	int *ip;
    499      1.28  christos 	int topl;
    500      1.28  christos 	char *valtop;
    501       1.1       cgd 
    502       1.1       cgd 	topl = 5;
    503      1.28  christos 	valtop = value(ENAME_TOPLINES);
    504      1.16       wiz 	if (valtop != NULL) {
    505       1.1       cgd 		topl = atoi(valtop);
    506       1.1       cgd 		if (topl < 0 || topl > 10000)
    507       1.1       cgd 			topl = 5;
    508       1.1       cgd 	}
    509      1.28  christos 	args.topl = topl;
    510      1.28  christos 	args.lineb = 1;
    511      1.28  christos 	recursive = do_recursion();
    512      1.28  christos 	msgCount = get_msgCount();
    513      1.28  christos 	for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
    514      1.28  christos 		struct message *mp;
    515      1.28  christos 
    516      1.28  christos 		mp = get_message(*ip);
    517       1.1       cgd 		dot = mp;
    518      1.28  christos 		args.parent = recursive ? mp : NULL;
    519      1.28  christos 		(void)thread_recursion(mp, top_core, &args);
    520       1.1       cgd 	}
    521      1.28  christos 	return 0;
    522       1.1       cgd }
    523       1.1       cgd 
    524       1.1       cgd /*
    525       1.1       cgd  * Touch all the given messages so that they will
    526       1.1       cgd  * get mboxed.
    527       1.1       cgd  */
    528      1.28  christos PUBLIC int
    529      1.15       wiz stouch(void *v)
    530       1.1       cgd {
    531       1.5  christos 	int *msgvec = v;
    532      1.10     lukem 	int *ip;
    533       1.1       cgd 
    534      1.28  christos 	for (ip = msgvec; *ip != 0; ip++)
    535      1.28  christos 		dot = set_m_flag(*ip, ~(MPRESERVE | MTOUCH), MTOUCH);
    536      1.28  christos 
    537      1.28  christos 	return 0;
    538       1.1       cgd }
    539       1.1       cgd 
    540       1.1       cgd /*
    541       1.1       cgd  * Make sure all passed messages get mboxed.
    542       1.1       cgd  */
    543      1.28  christos PUBLIC int
    544      1.15       wiz mboxit(void *v)
    545       1.1       cgd {
    546       1.5  christos 	int *msgvec = v;
    547      1.10     lukem 	int *ip;
    548       1.1       cgd 
    549      1.28  christos 	for (ip = msgvec; *ip != 0; ip++)
    550      1.28  christos 		dot = set_m_flag(*ip,
    551      1.28  christos 		    ~(MPRESERVE | MTOUCH | MBOX), MTOUCH | MBOX);
    552      1.28  christos 
    553      1.28  christos 	return 0;
    554       1.1       cgd }
    555       1.1       cgd 
    556       1.1       cgd /*
    557       1.1       cgd  * List the folders the user currently has.
    558       1.1       cgd  */
    559      1.23  christos /*ARGSUSED*/
    560      1.28  christos PUBLIC int
    561      1.26  christos folders(void *v __unused)
    562       1.1       cgd {
    563       1.7     mikel 	char dirname[PATHSIZE];
    564      1.22  christos 	const char *cmd;
    565       1.1       cgd 
    566      1.28  christos 	if (getfold(dirname, sizeof(dirname)) < 0) {
    567      1.23  christos 		(void)printf("No value set for \"folder\"\n");
    568       1.1       cgd 		return 1;
    569       1.1       cgd 	}
    570      1.28  christos 	if ((cmd = value(ENAME_LISTER)) == NULL)
    571       1.1       cgd 		cmd = "ls";
    572      1.20  christos 	(void)run_command(cmd, 0, -1, -1, dirname, NULL);
    573       1.6       tls 	return 0;
    574       1.6       tls }
    575       1.6       tls 
    576       1.6       tls /*
    577       1.6       tls  * Update the mail file with any new messages that have
    578       1.6       tls  * come in since we started reading mail.
    579       1.6       tls  */
    580      1.23  christos /*ARGSUSED*/
    581      1.28  christos PUBLIC int
    582      1.26  christos inc(void *v __unused)
    583       1.6       tls {
    584       1.6       tls 	int nmsg, mdot;
    585       1.6       tls 
    586       1.6       tls 	nmsg = incfile();
    587       1.6       tls 
    588       1.6       tls 	if (nmsg == 0) {
    589      1.28  christos 		(void)printf("No new mail.\n");
    590       1.6       tls 	} else if (nmsg > 0) {
    591      1.28  christos 		struct message *mp;
    592      1.28  christos 		mdot = newfileinfo(get_abs_msgCount() - nmsg);
    593      1.28  christos 		if ((mp = get_message(mdot)) != NULL)
    594      1.28  christos 			dot = mp;
    595       1.6       tls 	} else {
    596      1.28  christos 		(void)printf("\"inc\" command failed...\n");
    597       1.6       tls 	}
    598       1.6       tls 
    599       1.1       cgd 	return 0;
    600       1.1       cgd }
    601