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

Diff of /imapfilter/imapfilter.c

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

revision 1.10 by lefcha, Sun Aug 26 19:58:54 2001 UTC revision 1.11 by lefcha, Mon Sep 10 23:43:29 2001 UTC
# Line 2  Line 2 
2  #include <unistd.h>  #include <unistd.h>
3  #include <string.h>  #include <string.h>
4  #include <limits.h>  #include <limits.h>
5    #include <errno.h>
6    
7  #include "config.h"  #include "config.h"
8  #include "imapfilter.h"  #include "imapfilter.h"
9  #include "file.h"  #include "data.h"
 #include "connect.h"  
 #include "imap.h"  
 #include "log.h"  
10    
11    
 extern int sock;  
12  extern account_t *accounts;  extern account_t *accounts;
13    extern filter_t *filters;
14    
15  unsigned int options;           /* Program options. */  unsigned int options;           /* Program options. */
16  char logfile[PATH_MAX];         /* Log file. */  char logfile[PATH_MAX];         /* Log file. */
# Line 24  char logfile[PATH_MAX];                /* Log file. */ Line 22  char logfile[PATH_MAX];                /* Log file. */
22  int main(int argc, char **argv)  int main(int argc, char **argv)
23  {  {
24      int c;      int c;
25      char *cfg = NULL;           /* Configuration file. */      char *confile = NULL;       /* Configuration file. */
26      account_t *ca;      account_t *ca;              /* Current account. */
27        mbox_t *cm;                 /* Current mailbox. */
28      options = OPT_DETAILS_NORMAL;      
29        options = OPTION_DETAILS_NORMAL;
30      logfile[0] = 0;      logfile[0] = 0;
31    
32      while ((c = getopt(argc, argv, "c:hl:qtv")) != -1) {      while ((c = getopt(argc, argv, "c:hl:qv")) != -1) {
33          switch (c) {          switch (c) {
34          case 'c':          case 'c':
35              cfg = optarg;              confile = optarg;
36              break;              break;
37          case 'h':          case 'h':
38              usage();              usage();
# Line 43  int main(int argc, char **argv) Line 42  int main(int argc, char **argv)
42              strncpy(logfile, optarg, PATH_MAX);              strncpy(logfile, optarg, PATH_MAX);
43              break;              break;
44          case 'q':          case 'q':
45              options &= OPT_DETAILS_CLEAR;              options &= OPTION_DETAILS_CLEAR;
46              options |= OPT_DETAILS_QUITE;              options |= OPTION_DETAILS_QUITE;
             break;  
         case 't':  
             options |= OPT_TEST_MODE;  
             options |= OPT_TEST_MODE_STICKY;    /* Override config  
                                                    file's TEST_MODE. */  
47              break;              break;
48          case 'v':          case 'v':
49              options &= OPT_DETAILS_CLEAR;              options &= OPTION_DETAILS_CLEAR;
50              options |= OPT_DETAILS_VERBOSE;              options |= OPTION_DETAILS_VERBOSE;
51              break;              break;
52          default:          default:
53              usage();              usage();
# Line 62  int main(int argc, char **argv) Line 56  int main(int argc, char **argv)
56          }          }
57      }      }
58    
59      if (read_config(cfg) || open_logfile())      if (read_config(confile) || open_logfile())
60          exit(2);          exit(2);
61        
62      for (ca = accounts; ca; ca = ca->next) {      for (ca = accounts; ca; ca = ca->next) {
63    
64            if (init_connection(ca->server, ca->port)) {
         if (init_connection(ca)) {  
65              close_logfile();              close_logfile();
66              exit(3);              exit(3);
67          }          }
68    
69          clear_stream();          server_response();
70    
71  #ifdef DEBUG  #ifdef DEBUG
72          imap_noop();          test();
73  #endif  #endif
74    
75          imap_login(ca);          login(ca->username, ca->password);
76          imap_select();  
77          imap_status();          for (cm = ca->mboxes; cm; cm = cm->next) {
78                if (!*cm->filters)
79                    continue;
80    
81          apply_filters();              examine_mailbox(cm->name);
82    
83          imap_logout();              apply_filters(cm->filters, cm->name);
84    
85                close_mailbox();
86            }
87    
88            logout();
89    
90          close_connection();          close_connection();
91      }      }
92        
93      close_logfile();      close_logfile();
94    
95      exit(0);      exit(0);
# Line 97  int main(int argc, char **argv) Line 97  int main(int argc, char **argv)
97    
98    
99  /*  /*
100   * Searches and deletes any messages (if found and not in test mode) that   * Print a very brief usage message.
  * match the defined filters.  
  */  
 void apply_filters(void)  
 {  
     char res[SEARCH_BUF];  
   
     if (!imap_search(res) && res[0]) {  
         del_messages(res);  
         if (!(options & OPT_TEST_MODE))  
             imap_expunge();  
     }  
 }  
   
   
 /*  
  * Prints a very brief usage message.  
101   */   */
102  void usage(void)  void usage(void)
103  {  {
104      fprintf(stderr,      fprintf(stderr,
105              "usage: imapfilter [-hqtv] [-c configfile] [-l logfile]\n");              "usage: imapfilter [-hqv] [-c configfile] [-l logfile]\n");
106  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26