1: #ifndef lint
   2: static char sccsid[] = "@(#)xget.c	4.4 6/30/83";
   3: #endif
   4: 
   5: #include "xmail.h"
   6: #include <sys/types.h>
   7: #include <sys/dir.h>
   8: #include <ctype.h>
   9: #include <pwd.h>
  10: #include <sys/stat.h>
  11: char *myname;
  12: int uid;
  13: struct direct *dbuf;
  14: char *maildir = "/usr/spool/secretmail/";
  15: FILE *kf, *mf;
  16: DIR *df;
  17: MINT *x, *b, *one, *t45, *z, *q, *r;
  18: MINT *two, *t15, *mbuf;
  19: char buf[256], line[128];
  20: #define MXF 100
  21: int fnum[MXF], fcnt;
  22: struct stat stbuf;
  23: main()
  24: {   int i;
  25:     char *p;
  26: 
  27:     uid = getuid();
  28:     myname = (char *)getlogin();
  29:     if(myname == NULL)
  30:         myname = getpwuid(uid)->pw_name;
  31:     comminit();
  32:     mbuf = itom(0);
  33:     files();
  34:     setup(getpass("Key: "));
  35:     mkb();
  36:     mkx();
  37: #ifndef debug
  38:     invert(x, b, x);
  39: #else
  40:     invert(x, b, z);
  41:     mult(x, z, z);
  42:     mdiv(z, b, q, z);
  43:     omout(z);
  44:     invert(x, b, x);
  45: #endif
  46:     for(i=0; i<fcnt; i++)
  47:     {   sprintf(line, "%s%s.%d", maildir, myname, fnum[i]);
  48:         if(stat(line, &stbuf)<0)
  49:         {   perror(line);
  50:             continue;
  51:         }
  52:         if(stbuf.st_size == 0)
  53:         {   printf("zero length mail file\n");
  54:             unlink(line);
  55:             continue;
  56:         }
  57:         if((mf = fopen(line, "r"))==NULL)
  58:         {   perror(line);
  59:             continue;
  60:         }
  61:         decipher(mf, stdout);
  62:     cmnd:
  63:         printf("? ");
  64:         fgets(buf, sizeof(buf), stdin);
  65:         if(feof(stdin)) exit(0);
  66:         switch(buf[0])
  67:         {
  68:         case 'q':
  69:             exit(0);
  70:         case 'n':
  71:         case 'd':
  72:         case '\n':
  73:             fclose(mf);
  74:             unlink(line);
  75:             break;
  76:         case '!':
  77:             system(buf+1);
  78:             printf("!\n");
  79:             goto cmnd;
  80:         case 's':
  81:         case 'w':
  82:             rewind(mf);
  83:             if(buf[1] == '\n' || buf[1] == '\0')
  84:                 strcpy(buf, "s mbox\n");
  85:             for(p = buf+1; isspace(*p); p++);
  86:             p[strlen(p)-1] = 0;
  87:             kf = fopen(p, "a");
  88:             if(kf == NULL)
  89:             {   perror(p);
  90:                 goto cmnd;
  91:             }
  92:             decipher(mf, kf);
  93:             fclose(mf);
  94:             fclose(kf);
  95:             unlink(line);
  96:             break;
  97:         default:
  98:             printf("Commands are:\n");
  99:             printf("q	quit, leaving unread messages\n");
 100:             printf("n	delete current message and goto next\n");
 101:             printf("d	same as above\n");
 102:             printf("\\n	same as above\n");
 103:             printf("!	execute shell command\n");
 104:             printf("s	save message in the named file or mbox\n");
 105:             printf("w	same as above\n");
 106:             printf("?	prints this list\n");
 107:             goto cmnd;
 108:         }
 109:     }
 110:     exit(0);
 111: }
 112: icmp(a, b) int *a, *b;
 113: {
 114:     return(*a - *b);
 115: }
 116: files()
 117: {   int i;
 118:     if((df = opendir(maildir)) == NULL)
 119:     {   perror(maildir);
 120:         exit(1);
 121:     }
 122:     strcpy(line, myname);
 123:     strcat(line, ".%d");
 124:     while ((dbuf = readdir(df)) != NULL)
 125:     {
 126:         if(sscanf(dbuf->d_name, line, &i) != 1)
 127:             continue;
 128:         if(fcnt >= MXF)
 129:             break;
 130:         fnum[fcnt++] = i;
 131:     }
 132:     closedir(df);
 133:     if(fcnt == 0)
 134:     {   printf("no secret mail\n");
 135:         exit(0);
 136:     }
 137:     qsort(fnum, fcnt, sizeof(int), icmp);
 138: }
 139: decipher(u, w) FILE *u, *w;
 140: {   int i;
 141:     short a;
 142:     for(;;)
 143:     {   nin(mbuf, u);
 144:         if(feof(u)) break;
 145:         mult(mbuf, x, mbuf);
 146:         mdiv(mbuf, b, q, mbuf);
 147:         for(i=1; i<=3; i++)
 148:         {   a = mbuf->val[i];
 149:             putc(a&0177, w);
 150:             a >>= 8;
 151:             putc(a&0177, w);
 152:         }
 153:     }
 154: }

Defined functions

decipher defined in line 139; used 2 times
files defined in line 116; used 1 times
  • in line 33
icmp defined in line 112; used 1 times
main defined in line 23; never used

Defined variables

buf defined in line 19; used 16 times
dbuf defined in line 13; used 2 times
fcnt defined in line 21; used 5 times
fnum defined in line 21; used 3 times
line defined in line 19; used 11 times
maildir defined in line 14; used 3 times
myname defined in line 11; used 5 times
sccsid defined in line 2; never used
stbuf defined in line 22; used 2 times
uid defined in line 12; used 2 times

Defined macros

MXF defined in line 20; used 2 times
Last modified: 1983-06-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1583
Valid CSS Valid XHTML 1.0 Strict