/[imapfilter]/imapfilter/imapfilter.c
ViewVC logotype

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Sun Aug 26 12:26:59 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
Changes since 1.8: +1 -0 lines
File MIME type: text/plain
Exist, recent, unseen messages found in mailbox.

1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <limits.h>
5
6 #include "config.h"
7 #include "imapfilter.h"
8 #include "file.h"
9 #include "connect.h"
10 #include "imap.h"
11 #include "log.h"
12
13
14 extern int sock;
15 extern account_t *accounts;
16
17 int options; /* Program options. */
18 char logfile[PATH_MAX]; /* Log file. */
19
20
21 /*
22 * In the beginning there was main()...
23 */
24 int main(int argc, char **argv)
25 {
26 int c;
27 char *cfg = NULL; /* Configuration file. */
28 account_t *ca;
29
30 options = OPT_DETAILS_NORMAL;
31 logfile[0] = 0;
32
33 while ((c = getopt(argc, argv, "c:hl:qstv")) != -1) {
34 switch (c) {
35 case 'c':
36 cfg = optarg;
37 break;
38 case 'h':
39 usage();
40 exit(1);
41 break;
42 case 'l':
43 strncpy(logfile, optarg, PATH_MAX);
44 break;
45 case 'q':
46 options &= OPT_DETAILS_CLEAR;
47 options |= OPT_DETAILS_QUITE;
48 break;
49 case 's':
50 options |= OPT_SHOW_HEADERS;
51 break;
52 case 't':
53 options |= OPT_TEST_MODE;
54 break;
55 case 'v':
56 options &= OPT_DETAILS_CLEAR;
57 options |= OPT_DETAILS_VERBOSE;
58 break;
59 default:
60 usage();
61 exit(1);
62 break;
63 }
64 }
65
66 if (read_config(cfg) || open_logfile())
67 exit(2);
68
69 for (ca = accounts; ca; ca = ca->next) {
70
71
72 if (init_connection(ca)) {
73 close_logfile();
74 exit(3);
75 }
76
77 clear_stream();
78
79 #ifdef DEBUG
80 imap_noop();
81 #endif
82
83 imap_login(ca);
84 imap_select();
85 imap_status();
86
87 apply_filters();
88
89 imap_logout();
90
91 close_connection();
92 }
93
94 close_logfile();
95
96 exit(0);
97 }
98
99
100 /*
101 * Searches and deletes any messages (if found and not in test mode) that
102 * match the defined filters.
103 */
104 void apply_filters(void)
105 {
106 char res[SEARCH_BUF];
107
108 if (!imap_search(res) && res[0]) {
109 delete_messages(res);
110 if (!(options & OPT_TEST_MODE))
111 imap_expunge();
112 }
113 }
114
115
116 /*
117 * Prints a very brief usage message.
118 */
119 void usage(void)
120 {
121 fprintf(stderr,
122 "usage: imapfilter [-hqstv] [-c configfile] [-l logfile]\n");
123 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26