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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Thu Aug 23 19:13:15 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
Changes since 1.4: +18 -16 lines
File MIME type: text/plain
Added support for more than one accounts

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 lefcha 1.5 char logfile[PATH_MAX]; /* Log file. */
15 lefcha 1.1 extern int sock;
16 lefcha 1.5 int curacc; /* Current account being proccessed. */
17     extern int acccnt;
18 lefcha 1.1
19 lefcha 1.2 /*
20     * In the begining there was main()...
21     */
22 lefcha 1.1 int main(int argc, char **argv)
23     {
24     char *config = NULL; /* Configuration file. */
25     int c;
26    
27     options = OPTION_DETAILS_NORMAL;
28 lefcha 1.5 logfile[0] = 0;
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 lefcha 1.5 strncpy(logfile, optarg, FILENAME_MAX);
41 lefcha 1.1 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 lefcha 1.5 for (curacc = 0; curacc <= acccnt; curacc++) {
67     if (establish_connection()) {
68     close_logfile();
69     exit(3);
70     }
71 lefcha 1.1
72 lefcha 1.5 clear_stream();
73 lefcha 1.1
74     #ifdef DEBUG
75 lefcha 1.5 imap_noop();
76 lefcha 1.1 #endif
77    
78 lefcha 1.5 imap_login();
79     imap_select();
80 lefcha 1.1
81 lefcha 1.5 apply_filters();
82 lefcha 1.1
83 lefcha 1.5 imap_logout();
84 lefcha 1.1
85 lefcha 1.5 close_connection();
86     }
87 lefcha 1.1
88     close_logfile();
89    
90     exit(0);
91     }
92    
93    
94     /*
95     * Search and if found (and not in test mode) delete any messages
96     * that match the defined filters.
97     */
98     void apply_filters(void)
99     {
100     char results[SEARCH_RESULTS_MAX];
101    
102 lefcha 1.4 if (!imap_search(results) && results[0]) {
103 lefcha 1.1 delete_messages(results);
104     if (!(options & OPTION_TEST_MODE))
105     imap_expunge();
106     }
107 lefcha 1.2 }
108    
109    
110     /*
111 lefcha 1.3 * Prints a very brief usage message.
112 lefcha 1.2 */
113     void usage(void)
114     {
115     fprintf(stderr,
116 lefcha 1.3 "usage: imapfilter [-hqstv] [-c configfile] [-l logfile]\n");
117 lefcha 1.1 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26