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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Sun Aug 12 16:06:45 2001 UTC (22 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.2: +9 -9 lines
File MIME type: text/plain
Merged small changes from v0.1.1

1 lefcha 1.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 lefcha 1.2 /*
19     * In the begining there was main()...
20     */
21 lefcha 1.1 int main(int argc, char **argv)
22     {
23     char *config = NULL; /* Configuration file. */
24     int c;
25    
26     options = OPTION_DETAILS_NORMAL;
27     account.logfile[0] = 0;
28    
29 lefcha 1.3 while ((c = getopt(argc, argv, "c:hl:qstv")) != -1) {
30 lefcha 1.1 switch (c) {
31 lefcha 1.3 case 'c':
32     config = optarg;
33     break;
34 lefcha 1.2 case 'h':
35     usage();
36     exit(1);
37     break;
38 lefcha 1.1 case 'l':
39     strncpy(account.logfile, optarg, FILENAME_MAX);
40     break;
41     case 'q':
42     options &= OPTION_DETAILS_CLEAR;
43     options |= OPTION_DETAILS_QUITE;
44     break;
45 lefcha 1.3 case 's':
46     options |= OPTION_SHOW_HEADERS;
47     break;
48 lefcha 1.1 case 't':
49     options |= OPTION_TEST_MODE;
50     break;
51     case 'v':
52     options &= OPTION_DETAILS_CLEAR;
53     options |= OPTION_DETAILS_VERBOSE;
54     break;
55     default:
56 lefcha 1.2 usage();
57 lefcha 1.1 exit(1);
58     break;
59     }
60     }
61    
62     if (read_config(config) || open_logfile())
63 lefcha 1.2 exit(2);
64 lefcha 1.1
65     if (establish_connection()) {
66     close_logfile();
67 lefcha 1.2 exit(3);
68 lefcha 1.1 }
69    
70     clear_stream();
71    
72     #ifdef DEBUG
73     imap_noop();
74     #endif
75    
76     imap_login();
77     imap_select();
78    
79     apply_filters();
80    
81     imap_logout();
82    
83     close_connection();
84    
85     close_logfile();
86    
87     exit(0);
88     }
89    
90    
91     /*
92     * Search and if found (and not in test mode) delete any messages
93     * that match the defined filters.
94     */
95     void apply_filters(void)
96     {
97     char results[SEARCH_RESULTS_MAX];
98    
99     imap_search();
100    
101     if (!search_response(results)) {
102     delete_messages(results);
103     if (!(options & OPTION_TEST_MODE))
104     imap_expunge();
105     }
106 lefcha 1.2 }
107    
108    
109     /*
110 lefcha 1.3 * Prints a very brief usage message.
111 lefcha 1.2 */
112     void usage(void)
113     {
114     fprintf(stderr,
115 lefcha 1.3 "usage: imapfilter [-hqstv] [-c configfile] [-l logfile]\n");
116 lefcha 1.1 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26