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

Diff of /imapfilter/imapfilter.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.63 by lefcha, Mon Feb 9 20:39:23 2004 UTC revision 1.64 by lefcha, Tue Feb 10 22:21:09 2004 UTC
# Line 26  extern account_t *accounts; Line 26  extern account_t *accounts;
26  extern filter_t *filters;  extern filter_t *filters;
27  extern buffer_t ibuf, obuf;  extern buffer_t ibuf, obuf;
28    
29  unsigned int options;           /* Program options. */  opts_t opts;                    /* Program opts. */
 int verbosity;                  /* Program verbosity level (-2..2). */  
30  unsigned int flags = 0;         /* Program flags. */  unsigned int flags = 0;         /* Program flags. */
31  unsigned int interval = 0;      /* Poll at the specified interval. */  
32  conn_t connpri, connaux;        /* Primary and auxiliary IMAP connection. */  conn_t connpri, connaux;        /* Primary and auxiliary IMAP connection. */
33    
 char logfile[PATH_MAX];         /* Log file. */  
34  char *home = NULL;              /* User's home directory. */  char *home = NULL;              /* User's home directory. */
 char charset[CHARSET_LEN];      /* Charset for IMAP SEARCH requests. */  
35    
36  jmp_buf acctloop;               /* Non-local exit in case of network error. */  jmp_buf acctloop;               /* Non-local exit in case of network error. */
37    
# Line 50  int Line 47  int
47  main(int argc, char *argv[])  main(int argc, char *argv[])
48  {  {
49          int c, r;          int c, r;
50          char *conffile;         /* Configuration file. */          char *cf;               /* Configuration file. */
51          account_t *ca;          /* Current account. */          account_t *ca;          /* Current account. */
52          mbox_t *cm;             /* Current mailbox. */          mbox_t *cm;             /* Current mailbox. */
53    
54          setlocale(LC_ALL, "");          setlocale(LC_ALL, "");
55    
56            opts.debug = 0;
57            opts.verbosity = 0;
58            opts.timeout = -1;
59            opts.daemon = 0;
60            opts.headers = 0;
61            opts.errors = 0;
62            opts.namespace = 1;
63            opts.expunge = 0;
64            opts.subscribe = 0;
65            opts.peek = 1;
66            opts.passwd_editor = 0;
67            opts.charset[0] = '\0';
68            opts.logfile[0] = '\0';
69    
70          home = getenv("HOME");          home = getenv("HOME");
71          options = (OPTION_NAMESPACE | OPTION_PEEK);          cf = NULL;
         verbosity = 0;  
         *charset = 0;  
         *logfile = 0;  
         conffile = NULL;  
72          connpri.sock = connaux.sock = -1;          connpri.sock = connaux.sock = -1;
73    
74          while ((c = getopt(argc, argv, "DVc:d:kl:"          while ((c = getopt(argc, argv, "DVc:d:kl:"
# Line 71  main(int argc, char *argv[]) Line 78  main(int argc, char *argv[])
78                      "qv")) != -1) {                      "qv")) != -1) {
79                  switch (c) {                  switch (c) {
80                  case 'D':                  case 'D':
81                          options |= OPTION_DEBUG;                          if (opts.debug < 2)
82                                    opts.debug++;
83                          break;                          break;
84                  case 'V':                  case 'V':
85                          version();                          version();
86                          /* NOTREACHED */                          /* NOTREACHED */
87                  case 'c':                  case 'c':
88                          conffile = optarg;                          cf = optarg;
89                          break;                          break;
90                  case 'd':                  case 'd':
                         options |= OPTION_DAEMON_MODE;  
91                          errno = 0;                          errno = 0;
92                          interval = strtoul(optarg, NULL, 10);                          opts.daemon = strtoul(optarg, NULL, 10);
93                          if (errno)                          if (errno)
94                                  interval = 0;                                  opts.daemon = 0;
95                          break;                          break;
96                  case 'k':                  case 'k':
97                          kill_imapfilter();                          kill_imapfilter();
98                          break;                          break;
99                  case 'l':                  case 'l':
100                          strncat(logfile, optarg, PATH_MAX - 1);                          strncat(opts.logfile, optarg, PATH_MAX - 1);
101                          break;                          break;
102  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
103                  case 'p':                  case 'p':
104                          options |= OPTION_PASSWORD_EDITOR;                          opts.passwd_editor = 1;
105                          break;                          break;
106  #endif  #endif
107                  case 'q':                  case 'q':
108                          if (verbosity > -2)                          if (opts.verbosity > -2)
109                                  verbosity--;                                  opts.verbosity--;
110                          break;                          break;
111                  case 'v':                  case 'v':
112                          if (verbosity < 2)                          if (opts.verbosity < 2)
113                                  verbosity++;                                  opts.verbosity++;
114                          break;                          break;
115                  default:                  default:
116                  case '?':                  case '?':
# Line 119  main(int argc, char *argv[]) Line 126  main(int argc, char *argv[])
126          lockfile_check();          lockfile_check();
127          lockfile_create();          lockfile_create();
128    
129          if (!(options & OPTION_DEBUG))          if (!opts.debug)
130                  corefile_disable();                  corefile_disable();
131    
132          tty_store();          tty_store();
133          catch_signals();          catch_signals();
134    
135          read_config(conffile);          read_config(cf);
136    
137  #ifdef ENCRYPTED_PASSWORDS  #ifdef ENCRYPTED_PASSWORDS
138          read_passwords();          read_passwords();
139    
140          if ((options & OPTION_PASSWORD_EDITOR)) {          if (opts.passwd_editor) {
141                  password_editor();                  password_editor();
142    
143                  secmem_clear();                  secmem_clear();
# Line 145  main(int argc, char *argv[]) Line 152  main(int argc, char *argv[])
152          init_buffer(&ibuf);          init_buffer(&ibuf);
153          init_buffer(&obuf);          init_buffer(&obuf);
154    
155          if (options & OPTION_DAEMON_MODE)          if (opts.daemon)
156                  verbosity = -2;                  opts.verbosity = -2;
157    
158          do {          do {
159                  for (ca = accounts; ca != NULL; ca = ca->next) {                  for (ca = accounts; ca != NULL; ca = ca->next) {
# Line 160  main(int argc, char *argv[]) Line 167  main(int argc, char *argv[])
167    
168                          r = greeting_response(&connpri);                          r = greeting_response(&connpri);
169    
170                          if (options & OPTION_DEBUG)                          if (opts.debug)
171                                  test(&connpri);                                  test(&connpri);
172    
173                          if (check_capabilities(&connpri))                          if (check_capabilities(&connpri))
# Line 212  main(int argc, char *argv[]) Line 219  main(int argc, char *argv[])
219                  }                  }
220    
221                  /* Fork if in daemon mode. */                  /* Fork if in daemon mode. */
222                  if (options & OPTION_DAEMON_MODE &&                  if (opts.daemon && !(flags & FLAG_DAEMON_MODE)) {
                     !(flags & FLAG_DAEMON_MODE)) {  
   
223                          switch (fork()) {                          switch (fork()) {
224                          case -1:                          case -1:
225                                  fatal(ERROR_FORK, "forking; %s\n",                                  fatal(ERROR_FORK, "forking; %s\n",
# Line 261  main(int argc, char *argv[]) Line 266  main(int argc, char *argv[])
266    
267                          flags |= FLAG_DAEMON_MODE;                          flags |= FLAG_DAEMON_MODE;
268                  }                  }
269                  if (options & OPTION_DAEMON_MODE &&                  if (opts.daemon && flags & FLAG_SIGUSR1_RECEIVED) {
270                      flags & FLAG_SIGUSR1_RECEIVED) {                          reread_config(cf);
                         reread_config(conffile);  
271                          continue;                          continue;
272                  }                  }
273                  if (interval)                  if (opts.daemon)
274                          sleep(interval);                          sleep(opts.daemon);
275          } while (options & OPTION_DAEMON_MODE && interval);          } while (opts.daemon);
276    
277          log_stop();          log_stop();
278          secmem_clear();          secmem_clear();

Legend:
Removed from v.1.63  
changed lines
  Added in v.1.64

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26