|
Lines 42-48
Link Here
|
| 42 |
static char sccsid[] = "@(#)from.c 8.1 (Berkeley) 6/6/93"; |
42 |
static char sccsid[] = "@(#)from.c 8.1 (Berkeley) 6/6/93"; |
| 43 |
#endif |
43 |
#endif |
| 44 |
static const char rcsid[] = |
44 |
static const char rcsid[] = |
| 45 |
"$FreeBSD: src/usr.bin/from/from.c,v 1.8 1999/08/28 01:01:22 peter Exp $"; |
45 |
"$FreeBSD: src/usr.bin/from/from.c,v 1.5.2.2 1999/10/30 21:49:05 green Exp $"; |
| 46 |
#endif /* not lint */ |
46 |
#endif /* not lint */ |
| 47 |
|
47 |
|
| 48 |
#include <sys/types.h> |
48 |
#include <sys/types.h> |
|
Lines 57-62
Link Here
|
| 57 |
|
57 |
|
| 58 |
int match __P((char *, char *)); |
58 |
int match __P((char *, char *)); |
| 59 |
static void usage __P((void)); |
59 |
static void usage __P((void)); |
|
|
60 |
char * getbox __P((char *)); |
| 60 |
|
61 |
|
| 61 |
int |
62 |
int |
| 62 |
main(argc, argv) |
63 |
main(argc, argv) |
|
Lines 66-73
Link Here
|
| 66 |
extern char *optarg; |
67 |
extern char *optarg; |
| 67 |
extern int optind; |
68 |
extern int optind; |
| 68 |
struct passwd *pwd; |
69 |
struct passwd *pwd; |
| 69 |
int ch, count, newline; |
70 |
int ch, count, newline, header, deflt; |
| 70 |
char *file, *sender, *p; |
71 |
char *file, *mailenv, *sender, *p; |
| 71 |
#if MAXPATHLEN > BUFSIZ |
72 |
#if MAXPATHLEN > BUFSIZ |
| 72 |
char buf[MAXPATHLEN]; |
73 |
char buf[MAXPATHLEN]; |
| 73 |
#else |
74 |
#else |
|
Lines 76-81
Link Here
|
| 76 |
|
77 |
|
| 77 |
file = sender = NULL; |
78 |
file = sender = NULL; |
| 78 |
count = -1; |
79 |
count = -1; |
|
|
80 |
deflt = -1; |
| 79 |
while ((ch = getopt(argc, argv, "cf:s:")) != -1) |
81 |
while ((ch = getopt(argc, argv, "cf:s:")) != -1) |
| 80 |
switch (ch) { |
82 |
switch (ch) { |
| 81 |
case 'c': |
83 |
case 'c': |
|
Lines 99-105
Link Here
|
| 99 |
if (!file) { |
101 |
if (!file) { |
| 100 |
if (*argv) { |
102 |
if (*argv) { |
| 101 |
(void)sprintf(buf, "%s/%s", _PATH_MAILDIR, *argv); |
103 |
(void)sprintf(buf, "%s/%s", _PATH_MAILDIR, *argv); |
| 102 |
file = buf; |
104 |
file = strdup(buf); deflt=1; |
| 103 |
} else { |
105 |
} else { |
| 104 |
if (!(file = getenv("MAIL"))) { |
106 |
if (!(file = getenv("MAIL"))) { |
| 105 |
if (!(pwd = getpwuid(getuid()))) |
107 |
if (!(pwd = getpwuid(getuid()))) |
|
Lines 107-142
Link Here
|
| 107 |
file = pwd->pw_name; |
109 |
file = pwd->pw_name; |
| 108 |
(void)sprintf(buf, |
110 |
(void)sprintf(buf, |
| 109 |
"%s/%s", _PATH_MAILDIR, file); |
111 |
"%s/%s", _PATH_MAILDIR, file); |
| 110 |
file = buf; |
112 |
file = strdup(buf); deflt=1; |
| 111 |
} |
113 |
} |
| 112 |
} |
114 |
} |
| 113 |
} |
115 |
} |
| 114 |
|
116 |
|
| 115 |
/* read from stdin */ |
117 |
while(((deflt) && (mailenv = getbox(file)) != NULL)) { |
| 116 |
if (strcmp(file, "-") == 0) { |
118 |
|
| 117 |
} |
119 |
/* read from stdin */ |
| 118 |
else if (!freopen(file, "r", stdin)) { |
120 |
if (strcmp(file, "-") == 0) { |
| 119 |
errx(1, "can't read %s", file); |
|
|
| 120 |
} |
| 121 |
for (newline = 1; fgets(buf, sizeof(buf), stdin);) { |
| 122 |
if (*buf == '\n') { |
| 123 |
newline = 1; |
| 124 |
continue; |
| 125 |
} |
121 |
} |
| 126 |
if (newline && !strncmp(buf, "From ", 5) && |
122 |
else { |
| 127 |
(!sender || match(buf + 5, sender))) { |
123 |
if (!freopen(file, "r", stdin)) |
| 128 |
if (count != -1) |
124 |
errx(1, "can't read %s", file); |
| 129 |
count++; |
125 |
} |
| 130 |
else |
126 |
|
| 131 |
printf("%s", buf); |
127 |
header=0; |
|
|
128 |
for (newline = 1; fgets(buf, sizeof(buf), stdin);) { |
| 129 |
if (*buf == '\n') { |
| 130 |
newline = 1; |
| 131 |
continue; |
| 132 |
} |
| 133 |
if (newline && !strncmp(buf, "From ", 5) && |
| 134 |
(!sender || match(buf + 5, sender))) { |
| 135 |
if (count != -1) |
| 136 |
count++; |
| 137 |
else |
| 138 |
if(!header) { |
| 139 |
printf("%s:\n\n",file); |
| 140 |
header++; |
| 141 |
} |
| 142 |
printf("%s", buf); |
| 143 |
fflush(stdout); |
| 144 |
} |
| 145 |
newline = 0; |
| 132 |
} |
146 |
} |
| 133 |
newline = 0; |
147 |
if (count != -1) |
|
|
148 |
printf("There %s %d message%s in your incoming mailbox.\n", |
| 149 |
count == 1 ? "is" : "are", count, count == 1 ? "" : "s"); |
| 150 |
if(deflt == 1) |
| 151 |
deflt--; |
| 152 |
file = mailenv; |
| 134 |
} |
153 |
} |
| 135 |
if (count != -1) |
|
|
| 136 |
printf("There %s %d message%s in your incoming mailbox.\n", |
| 137 |
count == 1 ? "is" : "are", count, count == 1 ? "" : "s"); |
| 138 |
exit(0); |
| 139 |
} |
154 |
} |
|
|
155 |
|
| 156 |
char * |
| 157 |
getbox(str) |
| 158 |
char *str; |
| 159 |
{ |
| 160 |
char *p; |
| 161 |
|
| 162 |
if(*str == '\0') |
| 163 |
return((char *)NULL); |
| 164 |
|
| 165 |
for (p = str;((*str != ':')&&(*str != '\0'));str++) {} |
| 166 |
*str++ = '\0'; |
| 167 |
return(str); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 140 |
|
173 |
|
| 141 |
static void |
174 |
static void |
| 142 |
usage() |
175 |
usage() |