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

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations)
Mon Sep 10 23:43:29 2001 UTC (22 years, 6 months ago) by lefcha
Branch: MAIN
Changes since 1.10: +34 -50 lines
File MIME type: text/plain
New imapfilter.

1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <limits.h>
5 #include <errno.h>
6
7 #include "config.h"
8 #include "imapfilter.h"
9 #include "data.h"
10
11
12 extern account_t *accounts;
13 extern filter_t *filters;
14
15 unsigned int options; /* Program options. */
16 char logfile[PATH_MAX]; /* Log file. */
17
18
19 /*
20 * In the beginning there was main()...
21 */
22 int main(int argc, char **argv)
23 {
24 int c;
25 char *confile = NULL; /* Configuration file. */
26 account_t *ca; /* Current account. */
27 mbox_t *cm; /* Current mailbox. */
28
29 options = OPTION_DETAILS_NORMAL;
30 logfile[0] = 0;
31
32 while ((c = getopt(argc, argv, "c:hl:qv")) != -1) {
33 switch (c) {
34 case 'c':
35 confile = optarg;
36 break;
37 case 'h':
38 usage();
39 exit(1);
40 break;
41 case 'l':
42 strncpy(logfile, optarg, PATH_MAX);
43 break;
44 case 'q':
45 options &= OPTION_DETAILS_CLEAR;
46 options |= OPTION_DETAILS_QUITE;
47 break;
48 case 'v':
49 options &= OPTION_DETAILS_CLEAR;
50 options |= OPTION_DETAILS_VERBOSE;
51 break;
52 default:
53 usage();
54 exit(1);
55 break;
56 }
57 }
58
59 if (read_config(confile) || open_logfile())
60 exit(2);
61
62 for (ca = accounts; ca; ca = ca->next) {
63
64 if (init_connection(ca->server, ca->port)) {
65 close_logfile();
66 exit(3);
67 }
68
69 server_response();
70
71 #ifdef DEBUG
72 test();
73 #endif
74
75 login(ca->username, ca->password);
76
77 for (cm = ca->mboxes; cm; cm = cm->next) {
78 if (!*cm->filters)
79 continue;
80
81 examine_mailbox(cm->name);
82
83 apply_filters(cm->filters, cm->name);
84
85 close_mailbox();
86 }
87
88 logout();
89
90 close_connection();
91 }
92
93 close_logfile();
94
95 exit(0);
96 }
97
98
99 /*
100 * Print a very brief usage message.
101 */
102 void usage(void)
103 {
104 fprintf(stderr,
105 "usage: imapfilter [-hqv] [-c configfile] [-l logfile]\n");
106 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26