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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations)
Sun Sep 30 20:19:12 2001 UTC (22 years, 6 months ago) by lefcha
Branch: MAIN
Changes since 1.11: +12 -12 lines
File MIME type: text/plain
Error codes.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26