show-rcpt added
[unix-history] / usr / src / usr.bin / mail / list.c
index 451bd51..c658e62 100644 (file)
@@ -2,21 +2,11 @@
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)list.c     5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)list.c     5.14 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -42,13 +32,17 @@ getmsglist(buf, vector, flags)
        register int *ip;
        register struct message *mp;
 
        register int *ip;
        register struct message *mp;
 
+       if (msgCount == 0) {
+               *vector = 0;
+               return 0;
+       }
        if (markall(buf, flags) < 0)
                return(-1);
        ip = vector;
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if (mp->m_flag & MMARK)
                        *ip++ = mp - &message[0] + 1;
        if (markall(buf, flags) < 0)
                return(-1);
        ip = vector;
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if (mp->m_flag & MMARK)
                        *ip++ = mp - &message[0] + 1;
-       *ip = NULL;
+       *ip = 0;
        return(ip - vector);
 }
 
        return(ip - vector);
 }
 
@@ -124,7 +118,7 @@ number:
                                if (check(lexnumber, f))
                                        return(-1);
                                for (i = beg; i <= lexnumber; i++)
                                if (check(lexnumber, f))
                                        return(-1);
                                for (i = beg; i <= lexnumber; i++)
-                                       if ((message[i - 1].m_flag & MDELETED) == f)
+                                       if (f == MDELETED || (message[i - 1].m_flag & MDELETED) == 0)
                                                mark(i);
                                beg = 0;
                                break;
                                                mark(i);
                                beg = 0;
                                break;
@@ -333,8 +327,9 @@ evalcol(col)
 
 /*
  * Check the passed message number for legality and proper flags.
 
 /*
  * Check the passed message number for legality and proper flags.
+ * If f is MDELETED, then either kind will do.  Otherwise, the message
+ * has to be undeleted.
  */
  */
-
 check(mesg, f)
 {
        register struct message *mp;
 check(mesg, f)
 {
        register struct message *mp;
@@ -344,7 +339,7 @@ check(mesg, f)
                return(-1);
        }
        mp = &message[mesg-1];
                return(-1);
        }
        mp = &message[mesg-1];
-       if ((mp->m_flag & MDELETED) != f) {
+       if (f != MDELETED && (mp->m_flag & MDELETED) != 0) {
                printf("%d: Inappropriate message\n", mesg);
                return(-1);
        }
                printf("%d: Inappropriate message\n", mesg);
                return(-1);
        }
@@ -593,24 +588,19 @@ scaninit()
 
 first(f, m)
 {
 
 first(f, m)
 {
-       register int mesg;
        register struct message *mp;
 
        register struct message *mp;
 
-       mesg = dot - &message[0] + 1;
+       if (msgCount == 0)
+               return 0;
        f &= MDELETED;
        m &= MDELETED;
        f &= MDELETED;
        m &= MDELETED;
-       for (mp = dot; mp < &message[msgCount]; mp++) {
+       for (mp = dot; mp < &message[msgCount]; mp++)
                if ((mp->m_flag & m) == f)
                if ((mp->m_flag & m) == f)
-                       return(mesg);
-               mesg++;
-       }
-       mesg = dot - &message[0];
-       for (mp = dot-1; mp >= &message[0]; mp--) {
+                       return mp - message + 1;
+       for (mp = dot-1; mp >= &message[0]; mp--)
                if ((mp->m_flag & m) == f)
                if ((mp->m_flag & m) == f)
-                       return(mesg);
-               mesg--;
-       }
-       return(NULL);
+                       return mp - message + 1;
+       return 0;
 }
 
 /*
 }
 
 /*