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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations)
Thu Oct 4 15:47:49 2001 UTC (22 years, 5 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 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.13
59 lefcha 1.12 read_config(confile);
60     open_logfile();
61 lefcha 1.13
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.12 server_response("\0");
69 lefcha 1.1
70     #ifdef DEBUG
71 lefcha 1.11 test();
72 lefcha 1.1 #endif
73    
74 lefcha 1.11 login(ca->username, ca->password);
75    
76     for (cm = ca->mboxes; cm; cm = cm->next) {
77     if (!*cm->filters)
78 lefcha 1.13 examine_mailbox(cm->name);
79     else if (!select_mailbox(cm->name))
80     apply_filters(cm->filters, cm->name);
81 lefcha 1.11
82     close_mailbox();
83     }
84    
85     logout();
86 lefcha 1.1
87 lefcha 1.5 close_connection();
88     }
89 lefcha 1.13
90 lefcha 1.1 close_logfile();
91    
92     exit(0);
93     }
94    
95    
96     /*
97 lefcha 1.11 * Print a very brief usage message.
98 lefcha 1.2 */
99     void usage(void)
100     {
101     fprintf(stderr,
102 lefcha 1.11 "usage: imapfilter [-hqv] [-c configfile] [-l logfile]\n");
103 lefcha 1.1 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26