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