version 1.19, 2015/06/03 02:35:50 |
version 1.20, 2015/06/03 18:08:54 |
|
|
#include <paths.h> |
#include <paths.h> |
#include <string.h> |
#include <string.h> |
#include <err.h> |
#include <err.h> |
|
#include <errno.h> |
|
|
int match(char *, char *); |
int match(char *, char *); |
FILE *open_mbox(const char *file, const char *user); |
char *mail_spool(char *file, const char *user); |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
int ch, newline; |
int ch, newline, fflag = 0; |
char *file, *line, *sender, *p; |
char *file, *line, *sender, *p; |
size_t linesize = 0; |
size_t linesize = 0; |
ssize_t linelen; |
ssize_t linelen; |
|
|
while ((ch = getopt(argc, argv, "f:s:")) != -1) { |
while ((ch = getopt(argc, argv, "f:s:")) != -1) { |
switch(ch) { |
switch(ch) { |
case 'f': |
case 'f': |
|
fflag = 1; |
file = optarg; |
file = optarg; |
break; |
break; |
case 's': |
case 's': |
|
|
} |
} |
argv += optind; |
argv += optind; |
|
|
if ((fp = open_mbox(file, *argv)) == NULL) |
file = mail_spool(file, *argv); |
exit(1); |
if ((fp = fopen(file, "r")) == NULL) { |
|
if (!fflag && errno == ENOENT) |
|
exit(EXIT_SUCCESS); |
|
err(1, "%s", file); |
|
} |
for (newline = 1; (linelen = getline(&line, &linesize, fp)) != -1;) { |
for (newline = 1; (linelen = getline(&line, &linesize, fp)) != -1;) { |
if (*line == '\n') { |
if (*line == '\n') { |
newline = 1; |
newline = 1; |
|
|
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
} |
} |
|
|
FILE * |
char * |
open_mbox(const char *file, const char *user) |
mail_spool(char *file, const char *user) |
{ |
{ |
struct passwd *pwd; |
struct passwd *pwd; |
char *buf = NULL; |
|
FILE *fp; |
|
|
|
/* |
/* |
* We find the mailbox by: |
* We find the mailbox by: |
|
|
} |
} |
} |
} |
if (file == NULL) { |
if (file == NULL) { |
if (asprintf(&buf, "%s/%s", _PATH_MAILDIR, user) == -1) |
if (asprintf(&file, "%s/%s", _PATH_MAILDIR, user) == -1) |
err(1, NULL); |
err(1, NULL); |
file = buf; |
|
} |
} |
} |
} |
if ((fp = fopen(file, "r")) == NULL) |
return(file); |
warn("%s", file); |
|
free(buf); |
|
return(fp); |
|
} |
} |
|
|
int |
int |