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

Diff of /imapfilter/imapfilter.c

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

revision 1.6 by lefcha, Fri Aug 24 17:42:49 2001 UTC revision 1.7 by lefcha, Sun Aug 26 01:18:24 2001 UTC
# Line 1  Line 1 
1  #include <stdio.h>  #include <stdio.h>
2  #include <unistd.h>  #include <unistd.h>
3  #include <string.h>  #include <string.h>
4    #include <limits.h>
5    
6  #include "config.h"  #include "config.h"
7  #include "imapfilter.h"  #include "imapfilter.h"
# Line 10  Line 11 
11  #include "log.h"  #include "log.h"
12    
13    
14    extern int sock;
15    extern account_t *accounts;
16    
17  int options;                    /* Program options. */  int options;                    /* Program options. */
18  char logfile[PATH_MAX];         /* Log file. */  char logfile[PATH_MAX];         /* Log file. */
19  extern int sock;  
 int curacc;                     /* Current account being proccessed. */  
 extern int acccnt;  
20    
21  /*  /*
22   * In the begining there was main()...   * In the begining there was main()...
23   */   */
24  int main(int argc, char **argv)  int main(int argc, char **argv)
25  {  {
     char *config = NULL;        /* Configuration file. */  
26      int c;      int c;
27        char *cfg = NULL;           /* Configuration file. */
28        account_t *ca;
29    
30      options = OPTION_DETAILS_NORMAL;      options = OPT_DETAILS_NORMAL;
31      logfile[0] = 0;      logfile[0] = 0;
32    
33      while ((c = getopt(argc, argv, "c:hl:qstv")) != -1) {      while ((c = getopt(argc, argv, "c:hl:qstv")) != -1) {
34          switch (c) {          switch (c) {
35          case 'c':          case 'c':
36              config = optarg;              cfg = optarg;
37              break;              break;
38          case 'h':          case 'h':
39              usage();              usage();
# Line 40  int main(int argc, char **argv) Line 43  int main(int argc, char **argv)
43              strncpy(logfile, optarg, PATH_MAX);              strncpy(logfile, optarg, PATH_MAX);
44              break;              break;
45          case 'q':          case 'q':
46              options &= OPTION_DETAILS_CLEAR;              options &= OPT_DETAILS_CLEAR;
47              options |= OPTION_DETAILS_QUITE;              options |= OPT_DETAILS_QUITE;
48              break;              break;
49          case 's':          case 's':
50              options |= OPTION_SHOW_HEADERS;              options |= OPT_SHOW_HEADERS;
51              break;              break;
52          case 't':          case 't':
53              options |= OPTION_TEST_MODE;              options |= OPT_TEST_MODE;
54              break;              break;
55          case 'v':          case 'v':
56              options &= OPTION_DETAILS_CLEAR;              options &= OPT_DETAILS_CLEAR;
57              options |= OPTION_DETAILS_VERBOSE;              options |= OPT_DETAILS_VERBOSE;
58              break;              break;
59          default:          default:
60              usage();              usage();
# Line 60  int main(int argc, char **argv) Line 63  int main(int argc, char **argv)
63          }          }
64      }      }
65    
66      if (read_config(config) || open_logfile())      if (read_config(cfg) || open_logfile())
67          exit(2);          exit(2);
68    
69      for (curacc = 0; curacc <= acccnt; curacc++) {      for (ca = accounts; ca; ca = ca->next) {
70          if (establish_connection()) {  
71    
72            if (init_connection(ca)) {
73              close_logfile();              close_logfile();
74              exit(3);              exit(3);
75          }          }
# Line 75  int main(int argc, char **argv) Line 80  int main(int argc, char **argv)
80          imap_noop();          imap_noop();
81  #endif  #endif
82    
83          imap_login();          imap_login(ca);
84          imap_select();          imap_select();
85    
86          apply_filters();          apply_filters();
# Line 92  int main(int argc, char **argv) Line 97  int main(int argc, char **argv)
97    
98    
99  /*  /*
100   * Search and if found (and not in test mode) delete any messages   * Searches and deletes any messages (if found and not in test mode) that
101   * that match the defined filters.   * match the defined filters.
102   */   */
103  void apply_filters(void)  void apply_filters(void)
104  {  {
105      char results[SEARCH_RESULTS_MAX];      char res[SEARCH_BUF];
106    
107      if (!imap_search(results) && results[0]) {      if (!imap_search(res) && res[0]) {
108          delete_messages(results);          delete_messages(res);
109          if (!(options & OPTION_TEST_MODE))          if (!(options & OPT_TEST_MODE))
110              imap_expunge();              imap_expunge();
111      }      }
112  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26