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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Mon Aug 20 21:40:57 2001 UTC (22 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.3: +3 -4 lines
File MIME type: text/plain
Added message size limits support

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26