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

Contents of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (show annotations)
Wed Jan 30 13:14:58 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.26: +0 -2 lines
File MIME type: text/plain
Corefile restor settings not needed.

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <limits.h>
6 #include <errno.h>
7
8 #include "config.h"
9 #include "imapfilter.h"
10 #include "data.h"
11
12
13 extern account_t *accounts;
14 extern filter_t *filters;
15
16 unsigned int options; /* Program options. */
17 unsigned int capabilities; /* Capabilities of mail server. */
18 char logfile[PATH_MAX]; /* Log file. */
19 char *home = NULL; /* User's home directory. */
20 uid_t ruid, euid; /* Real and effective UID. */
21
22
23 /*
24 * In the beginning there was main()...
25 */
26 int main(int argc, char *argv[])
27 {
28 int c, r;
29 char *confile = NULL; /* Configuration file. */
30 account_t *ca; /* Current account. */
31 mbox_t *cm; /* Current mailbox. */
32
33 ruid = getuid();
34 euid = geteuid();
35 seteuid(ruid); /* Drop root privileges. */
36
37 corefile_disable();
38
39 options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE);
40 *logfile = 0;
41 home = getenv("HOME");
42
43 #ifndef ENCRYPTED_PASSWORDS
44 while ((c = getopt(argc, argv, "c:hl:qv")) != -1) {
45 #else
46 while ((c = getopt(argc, argv, "c:hl:pqv")) != -1) {
47 #endif
48 switch (c) {
49 case 'c':
50 confile = optarg;
51 break;
52 case 'h':
53 usage();
54 exit(ERROR_UNDEFINED);
55 break;
56 case 'l':
57 strncat(logfile, optarg, PATH_MAX - 1);
58 break;
59 #ifdef ENCRYPTED_PASSWORDS
60 case 'p':
61 options |= OPTION_PASSWORD_EDITOR;
62 break;
63 #endif
64 case 'q':
65 options &= OPTION_DETAILS_CLEAR;
66 options |= OPTION_DETAILS_QUIET;
67 break;
68 case 'v':
69 options &= OPTION_DETAILS_CLEAR;
70 options |= OPTION_DETAILS_VERBOSE;
71 break;
72 default:
73 usage();
74 exit(ERROR_UNDEFINED);
75 break;
76 }
77 }
78
79 tty_store();
80 catch_signals();
81
82 create_homedir();
83
84 read_config(confile);
85 open_logfile();
86
87 #ifdef ENCRYPTED_PASSWORDS
88 read_passwords();
89
90 if ((options & OPTION_PASSWORD_EDITOR))
91 password_editor();
92 #endif
93
94 setuid(ruid); /* Capability to regain root privileges
95 will not be needed any more. */
96
97
98 for (ca = accounts; ca; ca = ca->next) {
99
100 #ifndef SSL_TLS
101 if (init_connection(ca->server, ca->port))
102 #else
103 if (init_connection(ca->server, ca->port, ca->ssl))
104 #endif
105 continue;
106
107 r = greeting_response();
108
109 if (r == RESPONSE_BYE || check_capabilities())
110 continue;
111
112 #ifdef DEBUG
113 test();
114 #endif
115
116 if (r != RESPONSE_PREAUTH) {
117 if (ca->passwdattr == PASSWORD_NONE) {
118 printf("Enter password for %s@%s: ", ca->username, ca->server);
119 get_password(ca->password, PASSWORD_LEN);
120 }
121 if (login(ca->username, ca->password))
122 continue;
123 }
124 check_namespace();
125
126 for (cm = ca->mboxes; cm; cm = cm->next)
127 if (!*cm->filters)
128 mailbox_status(cm->name);
129 else if (!select_mailbox(cm->name)) {
130 apply_filters(cm->filters);
131 close_mailbox();
132 }
133 logout();
134
135 close_connection();
136 }
137
138 secmem_clear();
139 close_logfile();
140
141 exit(0);
142 }
143
144
145 /*
146 * Print a very brief usage message.
147 */
148 void usage(void)
149 {
150 fprintf(stderr,
151 "usage: imapfilter [-h"
152 #ifdef ENCRYPTED_PASSWORDS
153 "p"
154 #endif
155 "qv] [-c configfile] [-l logfile]\n");
156 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26