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

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Sun Aug 26 01:18:24 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
Changes since 1.6: +27 -22 lines
File MIME type: text/plain
Structural changes

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 begining 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
86 apply_filters();
87
88 imap_logout();
89
90 close_connection();
91 }
92
93 close_logfile();
94
95 exit(0);
96 }
97
98
99 /*
100 * Searches and deletes any messages (if found and not in test mode) that
101 * match the defined filters.
102 */
103 void apply_filters(void)
104 {
105 char res[SEARCH_BUF];
106
107 if (!imap_search(res) && res[0]) {
108 delete_messages(res);
109 if (!(options & OPT_TEST_MODE))
110 imap_expunge();
111 }
112 }
113
114
115 /*
116 * Prints a very brief usage message.
117 */
118 void usage(void)
119 {
120 fprintf(stderr,
121 "usage: imapfilter [-hqstv] [-c configfile] [-l logfile]\n");
122 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26