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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations)
Thu Nov 8 17:50:28 2001 UTC (22 years, 4 months ago) by lefcha
Branch: MAIN
Changes since 1.17: +5 -3 lines
File MIME type: text/plain
Checking for PREAUTH server response.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26