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

Annotation of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (hide annotations)
Mon Jan 14 18:12:38 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.24: +29 -3 lines
File MIME type: text/plain
Added encrypted passwords support.

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.24 unsigned int capabilities; /* Capabilities of mail server. */
18 lefcha 1.5 char logfile[PATH_MAX]; /* Log file. */
19 lefcha 1.25 char *home = NULL; /* User's home directory. */
20 lefcha 1.7
21 lefcha 1.1
22 lefcha 1.2 /*
23 lefcha 1.8 * In the beginning there was main()...
24 lefcha 1.2 */
25 lefcha 1.16 int main(int argc, char *argv[])
26 lefcha 1.1 {
27 lefcha 1.18 int c, r;
28 lefcha 1.11 char *confile = NULL; /* Configuration file. */
29     account_t *ca; /* Current account. */
30     mbox_t *cm; /* Current mailbox. */
31 lefcha 1.12
32 lefcha 1.24 options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE);
33 lefcha 1.12 *logfile = 0;
34 lefcha 1.25 home = getenv("HOME");
35 lefcha 1.1
36 lefcha 1.25 #ifndef ENCRYPTED_PASSWORDS
37 lefcha 1.11 while ((c = getopt(argc, argv, "c:hl:qv")) != -1) {
38 lefcha 1.25 #else
39     while ((c = getopt(argc, argv, "c:hl:pqv")) != -1) {
40     #endif
41 lefcha 1.1 switch (c) {
42 lefcha 1.3 case 'c':
43 lefcha 1.11 confile = optarg;
44 lefcha 1.3 break;
45 lefcha 1.2 case 'h':
46     usage();
47 lefcha 1.12 exit(ERROR_UNDEFINED);
48 lefcha 1.2 break;
49 lefcha 1.1 case 'l':
50 lefcha 1.12 strncat(logfile, optarg, PATH_MAX - 1);
51 lefcha 1.1 break;
52 lefcha 1.25 #ifdef ENCRYPTED_PASSWORDS
53     case 'p':
54     options |= OPTION_PASSWORD_EDITOR;
55     break;
56     #endif
57 lefcha 1.1 case 'q':
58 lefcha 1.11 options &= OPTION_DETAILS_CLEAR;
59 lefcha 1.15 options |= OPTION_DETAILS_QUIET;
60 lefcha 1.1 break;
61     case 'v':
62 lefcha 1.11 options &= OPTION_DETAILS_CLEAR;
63     options |= OPTION_DETAILS_VERBOSE;
64 lefcha 1.1 break;
65     default:
66 lefcha 1.2 usage();
67 lefcha 1.12 exit(ERROR_UNDEFINED);
68 lefcha 1.1 break;
69     }
70     }
71 lefcha 1.13
72 lefcha 1.24 catch_signals();
73    
74 lefcha 1.25 create_homedir();
75    
76 lefcha 1.12 read_config(confile);
77     open_logfile();
78 lefcha 1.21
79 lefcha 1.25 #ifdef ENCRYPTED_PASSWORDS
80     read_passwords();
81    
82     if ((options & OPTION_PASSWORD_EDITOR))
83     password_editor();
84     #endif
85    
86 lefcha 1.7 for (ca = accounts; ca; ca = ca->next) {
87    
88 lefcha 1.16 #ifndef SSL_TLS
89 lefcha 1.19 if (init_connection(ca->server, ca->port))
90 lefcha 1.16 #else
91 lefcha 1.19 if (init_connection(ca->server, ca->port, ca->ssl))
92 lefcha 1.16 #endif
93 lefcha 1.19 continue;
94 lefcha 1.21
95 lefcha 1.18 r = greeting_response();
96    
97     if (r == RESPONSE_BYE || check_capabilities())
98 lefcha 1.15 continue;
99 lefcha 1.1
100     #ifdef DEBUG
101 lefcha 1.11 test();
102 lefcha 1.1 #endif
103    
104 lefcha 1.24 if (r != RESPONSE_PREAUTH) {
105 lefcha 1.25 if (ca->passwdattr == PASSWORD_NONE) {
106     printf("Enter password for %s@%s: ", ca->username, ca->server);
107     get_password(ca->password, PASSWORD_LEN);
108     }
109 lefcha 1.24 if (login(ca->username, ca->password))
110     continue;
111     }
112     check_namespace();
113 lefcha 1.11
114 lefcha 1.14 for (cm = ca->mboxes; cm; cm = cm->next)
115 lefcha 1.15 if (!*cm->filters)
116     mailbox_status(cm->name);
117     else if (!select_mailbox(cm->name)) {
118     apply_filters(cm->filters);
119 lefcha 1.14 close_mailbox();
120     }
121 lefcha 1.11 logout();
122 lefcha 1.1
123 lefcha 1.5 close_connection();
124 lefcha 1.22 }
125 lefcha 1.17
126 lefcha 1.22 overwrite_passwords();
127 lefcha 1.13
128 lefcha 1.1 close_logfile();
129    
130     exit(0);
131     }
132    
133    
134     /*
135 lefcha 1.11 * Print a very brief usage message.
136 lefcha 1.2 */
137     void usage(void)
138     {
139 lefcha 1.25 #ifndef ENCRYPTED_PASSWORDS
140     fprintf(stderr,
141     "usage: imapfilter [-hpqv] [-c configfile] [-l logfile]\n");
142     #else
143 lefcha 1.2 fprintf(stderr,
144 lefcha 1.11 "usage: imapfilter [-hqv] [-c configfile] [-l logfile]\n");
145 lefcha 1.25 #endif
146 lefcha 1.1 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26