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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide 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 lefcha 1.1 #include <stdio.h>
2     #include <unistd.h>
3     #include <string.h>
4 lefcha 1.7 #include <limits.h>
5 lefcha 1.1
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 lefcha 1.7 extern int sock;
15     extern account_t *accounts;
16    
17 lefcha 1.1 int options; /* Program options. */
18 lefcha 1.5 char logfile[PATH_MAX]; /* Log file. */
19 lefcha 1.7
20 lefcha 1.1
21 lefcha 1.2 /*
22     * In the begining there was main()...
23     */
24 lefcha 1.1 int main(int argc, char **argv)
25     {
26     int c;
27 lefcha 1.7 char *cfg = NULL; /* Configuration file. */
28     account_t *ca;
29 lefcha 1.1
30 lefcha 1.7 options = OPT_DETAILS_NORMAL;
31 lefcha 1.5 logfile[0] = 0;
32 lefcha 1.1
33 lefcha 1.3 while ((c = getopt(argc, argv, "c:hl:qstv")) != -1) {
34 lefcha 1.1 switch (c) {
35 lefcha 1.3 case 'c':
36 lefcha 1.7 cfg = optarg;
37 lefcha 1.3 break;
38 lefcha 1.2 case 'h':
39     usage();
40     exit(1);
41     break;
42 lefcha 1.1 case 'l':
43 lefcha 1.6 strncpy(logfile, optarg, PATH_MAX);
44 lefcha 1.1 break;
45     case 'q':
46 lefcha 1.7 options &= OPT_DETAILS_CLEAR;
47     options |= OPT_DETAILS_QUITE;
48 lefcha 1.1 break;
49 lefcha 1.3 case 's':
50 lefcha 1.7 options |= OPT_SHOW_HEADERS;
51 lefcha 1.3 break;
52 lefcha 1.1 case 't':
53 lefcha 1.7 options |= OPT_TEST_MODE;
54 lefcha 1.1 break;
55     case 'v':
56 lefcha 1.7 options &= OPT_DETAILS_CLEAR;
57     options |= OPT_DETAILS_VERBOSE;
58 lefcha 1.1 break;
59     default:
60 lefcha 1.2 usage();
61 lefcha 1.1 exit(1);
62     break;
63     }
64     }
65    
66 lefcha 1.7 if (read_config(cfg) || open_logfile())
67 lefcha 1.2 exit(2);
68 lefcha 1.1
69 lefcha 1.7 for (ca = accounts; ca; ca = ca->next) {
70    
71    
72     if (init_connection(ca)) {
73 lefcha 1.5 close_logfile();
74     exit(3);
75     }
76 lefcha 1.1
77 lefcha 1.5 clear_stream();
78 lefcha 1.1
79     #ifdef DEBUG
80 lefcha 1.5 imap_noop();
81 lefcha 1.1 #endif
82    
83 lefcha 1.7 imap_login(ca);
84 lefcha 1.5 imap_select();
85 lefcha 1.1
86 lefcha 1.5 apply_filters();
87 lefcha 1.1
88 lefcha 1.5 imap_logout();
89 lefcha 1.1
90 lefcha 1.5 close_connection();
91     }
92 lefcha 1.1
93     close_logfile();
94    
95     exit(0);
96     }
97    
98    
99     /*
100 lefcha 1.7 * Searches and deletes any messages (if found and not in test mode) that
101     * match the defined filters.
102 lefcha 1.1 */
103     void apply_filters(void)
104     {
105 lefcha 1.7 char res[SEARCH_BUF];
106 lefcha 1.1
107 lefcha 1.7 if (!imap_search(res) && res[0]) {
108     delete_messages(res);
109     if (!(options & OPT_TEST_MODE))
110 lefcha 1.1 imap_expunge();
111     }
112 lefcha 1.2 }
113    
114    
115     /*
116 lefcha 1.3 * Prints a very brief usage message.
117 lefcha 1.2 */
118     void usage(void)
119     {
120     fprintf(stderr,
121 lefcha 1.3 "usage: imapfilter [-hqstv] [-c configfile] [-l logfile]\n");
122 lefcha 1.1 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26