|
|
1.1 ! root 1: # ! 2: #include "rcv.h" ! 3: #include <sys/stat.h> ! 4: ! 5: /* ! 6: * Mail -- a mail program ! 7: * ! 8: * User commands. ! 9: */ ! 10: ! 11: /* ! 12: * Print the current active headings. ! 13: */ ! 14: ! 15: static int screen; ! 16: ! 17: headers(msgvec) ! 18: int *msgvec; ! 19: { ! 20: register int n, mesg, flag; ! 21: register struct message *mp; ! 22: ! 23: n = msgvec[0]; ! 24: if (n != 0) ! 25: screen = (n-1)/SCREEN; ! 26: if (screen < 0) ! 27: screen = 0; ! 28: mp = &message[screen * SCREEN]; ! 29: if (mp >= &message[msgCount]) ! 30: mp = &message[msgCount - SCREEN]; ! 31: if (mp < &message[0]) ! 32: mp = &message[0]; ! 33: flag = 0; ! 34: mesg = mp - &message[0]; ! 35: dot = mp; ! 36: for (; mp < &message[msgCount]; mp++) { ! 37: mesg++; ! 38: if (mp->m_flag & MDELETED) ! 39: continue; ! 40: if (flag++ >= SCREEN) ! 41: break; ! 42: printhead(mesg); ! 43: sreset(); ! 44: } ! 45: if (flag == 0) { ! 46: printf("No more mail.\n"); ! 47: return(1); ! 48: } ! 49: return(0); ! 50: } ! 51: ! 52: /* ! 53: * Scroll to the next/previous screen ! 54: */ ! 55: ! 56: scroll(arg) ! 57: char arg[]; ! 58: { ! 59: register int s; ! 60: int cur[1]; ! 61: ! 62: cur[0] = 0; ! 63: s = screen; ! 64: switch (*arg) { ! 65: case 0: ! 66: case '+': ! 67: s++; ! 68: if (s*SCREEN > msgCount) { ! 69: printf("On last screenful of messages\n"); ! 70: return(0); ! 71: } ! 72: screen = s; ! 73: break; ! 74: ! 75: case '-': ! 76: if (--s < 0) { ! 77: printf("On first screenful of messages\n"); ! 78: return(0); ! 79: } ! 80: screen = s; ! 81: break; ! 82: ! 83: default: ! 84: printf("Unrecognized scrolling command \"%s\"\n", arg); ! 85: return(1); ! 86: } ! 87: return(headers(cur)); ! 88: } ! 89: ! 90: ! 91: /* ! 92: * Print out the headlines for each message ! 93: * in the passed message list. ! 94: */ ! 95: ! 96: from(msgvec) ! 97: int *msgvec; ! 98: { ! 99: register int *ip; ! 100: ! 101: for (ip = msgvec; *ip != NULL; ip++) { ! 102: printhead(*ip); ! 103: sreset(); ! 104: } ! 105: if (--ip >= msgvec) ! 106: dot = &message[*ip - 1]; ! 107: return(0); ! 108: } ! 109: ! 110: /* ! 111: * Print out the header of a specific message. ! 112: * This is a slight improvement to the standard one. ! 113: */ ! 114: ! 115: printhead(mesg) ! 116: { ! 117: struct message *mp; ! 118: FILE *ibuf; ! 119: char headline[LINESIZE], wcount[10], *subjline, dispc; ! 120: char pbuf[BUFSIZ]; ! 121: int s; ! 122: struct headline hl; ! 123: register char *cp; ! 124: ! 125: mp = &message[mesg-1]; ! 126: ibuf = setinput(mp); ! 127: readline(ibuf, headline); ! 128: subjline = hfield("subject", mp); ! 129: if (subjline == NOSTR) ! 130: subjline = hfield("subj", mp); ! 131: ! 132: /* ! 133: * Bletch! ! 134: */ ! 135: ! 136: if (subjline != NOSTR && strlen(subjline) > 28) ! 137: subjline[29] = '\0'; ! 138: dispc = ' '; ! 139: if (mp->m_flag & MSAVED) ! 140: dispc = '*'; ! 141: if (mp->m_flag & MPRESERVE) ! 142: dispc = 'P'; ! 143: parse(headline, &hl, pbuf); ! 144: sprintf(wcount, " %d/%d", mp->m_lines, mp->m_size); ! 145: s = strlen(wcount); ! 146: cp = wcount + s; ! 147: while (s < 7) ! 148: s++, *cp++ = ' '; ! 149: *cp = '\0'; ! 150: if (subjline != NOSTR) ! 151: printf("%c%3d %-8s %16.16s %s \"%s\"\n", dispc, mesg, ! 152: nameof(mp), hl.l_date, wcount, subjline); ! 153: else ! 154: printf("%c%3d %-8s %16.16s %s\n", dispc, mesg, ! 155: nameof(mp), hl.l_date, wcount); ! 156: } ! 157: ! 158: /* ! 159: * Print out the value of dot. ! 160: */ ! 161: ! 162: pdot() ! 163: { ! 164: printf("%d\n", dot - &message[0] + 1); ! 165: return(0); ! 166: } ! 167: ! 168: /* ! 169: * Print out all the possible commands. ! 170: */ ! 171: ! 172: pcmdlist() ! 173: { ! 174: register struct cmd *cp; ! 175: register int cc; ! 176: extern struct cmd cmdtab[]; ! 177: ! 178: printf("Commands are:\n"); ! 179: for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) { ! 180: cc += strlen(cp->c_name) + 2; ! 181: if (cc > 72) { ! 182: printf("\n"); ! 183: cc = strlen(cp->c_name) + 2; ! 184: } ! 185: if ((cp+1)->c_name != NOSTR) ! 186: printf("%s, ", cp->c_name); ! 187: else ! 188: printf("%s\n", cp->c_name); ! 189: } ! 190: return(0); ! 191: } ! 192: ! 193: /* ! 194: * Type out the messages requested. ! 195: */ ! 196: ! 197: type(msgvec) ! 198: int *msgvec; ! 199: { ! 200: register *ip; ! 201: register struct message *mp; ! 202: register int mesg; ! 203: int c; ! 204: FILE *ibuf; ! 205: ! 206: for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { ! 207: mesg = *ip; ! 208: touch(mesg); ! 209: mp = &message[mesg-1]; ! 210: dot = mp; ! 211: print(mp); ! 212: } ! 213: return(0); ! 214: } ! 215: ! 216: /* ! 217: * Print the indicated message on standard output. ! 218: */ ! 219: ! 220: print(mp) ! 221: register struct message *mp; ! 222: { ! 223: ! 224: if (value("quiet") == NOSTR) ! 225: printf("Message %2d:\n", mp - &message[0] + 1); ! 226: touch(mp - &message[0] + 1); ! 227: send(mp, stdout); ! 228: } ! 229: ! 230: /* ! 231: * Print the top so many lines of each desired message. ! 232: * The number of lines is taken from the variable "toplines" ! 233: * and defaults to 5. ! 234: */ ! 235: ! 236: top(msgvec) ! 237: int *msgvec; ! 238: { ! 239: register int *ip; ! 240: register struct message *mp; ! 241: register int mesg; ! 242: int c, topl, lines, lineb; ! 243: char *valtop, linebuf[LINESIZE]; ! 244: FILE *ibuf; ! 245: ! 246: topl = 5; ! 247: valtop = value("toplines"); ! 248: if (valtop != NOSTR) { ! 249: topl = atoi(valtop); ! 250: if (topl < 0 || topl > 10000) ! 251: topl = 5; ! 252: } ! 253: lineb = 1; ! 254: for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { ! 255: mesg = *ip; ! 256: touch(mesg); ! 257: mp = &message[mesg-1]; ! 258: dot = mp; ! 259: if (value("quiet") == NOSTR) ! 260: printf("Message %2d:\n", mesg); ! 261: ibuf = setinput(mp); ! 262: c = mp->m_lines; ! 263: if (!lineb) ! 264: printf("\n"); ! 265: for (lines = 0; lines < c && lines <= topl; lines++) { ! 266: if (readline(ibuf, linebuf) <= 0) ! 267: break; ! 268: puts(linebuf); ! 269: lineb = blankline(linebuf); ! 270: } ! 271: } ! 272: return(0); ! 273: } ! 274: ! 275: /* ! 276: * Touch all the given messages so that they will ! 277: * get mboxed. ! 278: */ ! 279: ! 280: stouch(msgvec) ! 281: int msgvec[]; ! 282: { ! 283: register int *ip; ! 284: ! 285: for (ip = msgvec; *ip != 0; ip++) { ! 286: touch(*ip); ! 287: dot = &message[*ip-1]; ! 288: dot->m_flag &= ~MPRESERVE; ! 289: } ! 290: return(0); ! 291: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.