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

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22.2.1 - (show annotations)
Wed Dec 5 09:55:12 2001 UTC (22 years, 3 months ago) by lefcha
Branch: release-0_7-patches
Changes since 1.22: +6 -3 lines
File MIME type: text/plain
Take into consideration namespace.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26