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

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sat Aug 11 15:52:52 2001 UTC (22 years, 8 months ago) by lefcha
Branch: lefcha
CVS Tags: start
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
Initial import into CVS

1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4
5 #include "config.h"
6 #include "imapfilter.h"
7 #include "file.h"
8 #include "connect.h"
9 #include "imap.h"
10 #include "log.h"
11
12
13 int options; /* Program options. */
14 extern int sock;
15 extern account_data account;
16
17
18
19 int main(int argc, char **argv)
20 {
21 char *config = NULL; /* Configuration file. */
22 int c;
23
24 options = OPTION_DETAILS_NORMAL;
25 account.logfile[0] = 0;
26
27 while ((c = getopt(argc, argv, "l:qtvc:L")) != -1) {
28 switch (c) {
29 case 'l':
30 strncpy(account.logfile, optarg, FILENAME_MAX);
31 break;
32 case 'q':
33 options &= OPTION_DETAILS_CLEAR;
34 options |= OPTION_DETAILS_QUITE;
35 break;
36 case 't':
37 options |= OPTION_TEST_MODE;
38 break;
39 case 'v':
40 options &= OPTION_DETAILS_CLEAR;
41 options |= OPTION_DETAILS_VERBOSE;
42 break;
43 case 'c':
44 config = optarg;
45 break;
46 case 'L':
47 options |= OPTION_LOGGING_DISABLED;
48 break;
49 default:
50 fprintf(stderr,
51 "usage: imapfilter [-hqtvL] [-c configfile] [-l logfile]\n");
52 exit(1);
53 break;
54 }
55 }
56
57 if (read_config(config) || open_logfile())
58 exit(1);
59
60 if (establish_connection()) {
61 close_logfile();
62 exit(2);
63 }
64
65 clear_stream();
66
67 #ifdef DEBUG
68 imap_noop();
69 #endif
70
71 imap_login();
72 imap_select();
73
74 apply_filters();
75
76 imap_logout();
77
78 close_connection();
79
80 close_logfile();
81
82 exit(0);
83 }
84
85
86 /*
87 * Search and if found (and not in test mode) delete any messages
88 * that match the defined filters.
89 */
90 void apply_filters(void)
91 {
92 char results[SEARCH_RESULTS_MAX];
93
94 imap_search();
95
96 if (!search_response(results)) {
97 delete_messages(results);
98 if (!(options & OPTION_TEST_MODE))
99 imap_expunge();
100 }
101 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26