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

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations)
Thu Oct 4 15:47:49 2001 UTC (22 years, 6 months ago) by lefcha
Branch: MAIN
Changes since 1.12: +6 -9 lines
File MIME type: text/plain
Use imap_examine() if no filters  to apply.

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;
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(ERROR_UNDEFINED);
40 break;
41 case 'l':
42 strncat(logfile, optarg, PATH_MAX - 1);
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(ERROR_UNDEFINED);
55 break;
56 }
57 }
58
59 read_config(confile);
60 open_logfile();
61
62 for (ca = accounts; ca; ca = ca->next) {
63
64 if (init_connection(ca->server, ca->port)) {
65 close_logfile();
66 exit(ERROR_NETWORK);
67 }
68 server_response("\0");
69
70 #ifdef DEBUG
71 test();
72 #endif
73
74 login(ca->username, ca->password);
75
76 for (cm = ca->mboxes; cm; cm = cm->next) {
77 if (!*cm->filters)
78 examine_mailbox(cm->name);
79 else if (!select_mailbox(cm->name))
80 apply_filters(cm->filters, cm->name);
81
82 close_mailbox();
83 }
84
85 logout();
86
87 close_connection();
88 }
89
90 close_logfile();
91
92 exit(0);
93 }
94
95
96 /*
97 * Print a very brief usage message.
98 */
99 void usage(void)
100 {
101 fprintf(stderr,
102 "usage: imapfilter [-hqv] [-c configfile] [-l logfile]\n");
103 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26