README: omit -i option in examples
[neatmail.git] / mail.c
blob9389f126bc753b6a8206168997689c42075dc716
1 /*
2 * NEATMAIL MAIL CLIENT
4 * Copyright (C) 2009-2020 Ali Gholami Rudi <ali at rudi dot ir>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <ctype.h>
19 #include <fcntl.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <sys/stat.h>
26 #include "mail.h"
28 static int has_mail(char *path)
30 struct stat st;
31 if (stat(path, &st) == -1)
32 return 0;
33 return st.st_mtime > st.st_atime;
36 static int ns(char *argv[])
38 int i;
39 for (i = 0; argv[i]; i++)
40 if (has_mail(argv[i]))
41 printf("%s\n", argv[i]);
42 return 0;
45 static char *usage =
46 "usage: neatmail command [options]\n\n"
47 "commands:\n"
48 " ex \texecute commands on an mbox\n"
49 " mk \tlist the messages in an mbox\n"
50 " pg \tpage a message of an mbox\n"
51 " me \tencode mime message headers\n"
52 " pn \tprune an mbox\n"
53 " ns \tcheck mboxes for new mails\n";
55 int main(int argc, char *argv[])
57 signal(SIGPIPE, SIG_IGN);
58 if (!argv[1])
59 printf("%s", usage);
60 if (argv[1] && !strcmp("mk", argv[1]))
61 return mk(argv + 2);
62 if (argv[1] && !strcmp("ex", argv[1]))
63 return ex(argv + 2);
64 if (argv[1] && !strcmp("pg", argv[1]))
65 return pg(argv + 2);
66 if (argv[1] && !strcmp("me", argv[1]))
67 return me(argv + 2);
68 if (argv[1] && !strcmp("pn", argv[1]))
69 return pn(argv + 2);
70 if (argv[1] && !strcmp("ns", argv[1]))
71 return ns(argv + 2);
72 return 0;