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

Diff of /imapfilter/data.c

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

revision 1.24 by lefcha, Fri Feb 8 22:15:43 2002 UTC revision 1.25 by lefcha, Tue Jun 18 20:56:23 2002 UTC
# Line 33  static filter_t *cur_fltr = NULL;      /* Cur Line 33  static filter_t *cur_fltr = NULL;      /* Cur
33  void init_account(account_t * node)  void init_account(account_t * node)
34  {  {
35      node->next = NULL;      node->next = NULL;
36      node->server[0] = node->username[0] = node->password[0] = 0;      node->key[0] = node->server[0] = node->username[0] = node->password[0] = 0;
37      node->passwdattr = PASSWORD_NONE;      node->passwdattr = PASSWORD_NONE;
38      node->port = 143;      node->port = 143;
39      node->ssl = SSL_DISABLED;      node->ssl = SSL_DISABLED;
# Line 68  int set_account(char *line, regmatch_t * Line 68  int set_account(char *line, regmatch_t *
68    
69      init_account(node);      init_account(node);
70    
71      if (match[2].rm_so != -1) {      strncat(node->key, line + match[1].rm_so,
72          strncat(node->username, line + match[2].rm_so,              min(match[1].rm_eo - match[1].rm_so, KEY_LEN - 1));
73                  min(match[2].rm_eo - match[2].rm_so, USERNAME_LEN - 1));  #ifdef DEBUG
74        printf("debug: ACCOUNT: '%s'\n", node->key);
75    #endif
76    
77        if (match[3].rm_so != -1) {
78            strncat(node->username, line + match[3].rm_so,
79                    min(match[3].rm_eo - match[3].rm_so, USERNAME_LEN - 1));
80      } else {      } else {
81          strncat(node->username, line + match[4].rm_so,          strncat(node->username, line + match[5].rm_so,
82                  min(match[4].rm_eo - match[4].rm_so, USERNAME_LEN - 1));                  min(match[5].rm_eo - match[5].rm_so, USERNAME_LEN - 1));
83      }      }
84      if (strchr(node->username, '%'))      if (strchr(node->username, '%'))
85          if (string_decode(node->username))          if (string_decode(node->username))
# Line 82  int set_account(char *line, regmatch_t * Line 88  int set_account(char *line, regmatch_t *
88      printf("debug: USERNAME: '%s'\n", node->username);      printf("debug: USERNAME: '%s'\n", node->username);
89  #endif  #endif
90    
91      if (match[3].rm_so != -1) {      if (match[4].rm_so != -1) {
92          strncat(node->password, line + match[3].rm_so,          strncat(node->password, line + match[4].rm_so,
93                  min(match[3].rm_eo - match[3].rm_so, PASSWORD_LEN - 1));                  min(match[4].rm_eo - match[4].rm_so, PASSWORD_LEN - 1));
94          if (strchr(node->password, '%'))          if (strchr(node->password, '%'))
95              if (string_decode(node->password))              if (string_decode(node->password))
96                  return ERROR_CONFIG_PARSE;                  return ERROR_CONFIG_PARSE;
# Line 95  int set_account(char *line, regmatch_t * Line 101  int set_account(char *line, regmatch_t *
101      printf("debug: PASSWORD: '%s'\n", node->password);      printf("debug: PASSWORD: '%s'\n", node->password);
102  #endif  #endif
103    
104      strncat(node->server, line + match[5].rm_so,      strncat(node->server, line + match[6].rm_so,
105              min(match[5].rm_eo - match[5].rm_so, SERVER_LEN - 1));              min(match[6].rm_eo - match[6].rm_so, SERVER_LEN - 1));
106  #ifdef DEBUG  #ifdef DEBUG
107      printf("debug: SERVER: '%s'\n", node->server);      printf("debug: SERVER: '%s'\n", node->server);
108  #endif  #endif
109    
110      if (match[6].rm_so != -1) {      if (match[7].rm_so != -1) {
111          n = min(match[6].rm_eo - match[6].rm_so - 1, 5);          n = min(match[7].rm_eo - match[7].rm_so - 1, 5);
112          xstrncpy(p, line + match[6].rm_so + 1, n);          xstrncpy(p, line + match[7].rm_so + 1, n);
113          p[n] = 0;          p[n] = 0;
114          node->port = strtoul(p, NULL, 10);          node->port = strtoul(p, NULL, 10);
115  #ifdef DEBUG  #ifdef DEBUG
116          printf("debug: PORT: %d\n", node->port);          printf("debug: PORT: %d\n", node->port);
117  #endif  #endif
118      }      }
119      if (match[7].rm_so != -1) {      if (match[8].rm_so != -1) {
120          if (match[6].rm_so == -1)          if (match[7].rm_so == -1)
121              node->port = 993;              node->port = 993;
122    
123          if (strcasestr(line + match[7].rm_so, "ssl3"))          if (strcasestr(line + match[8].rm_so, "ssl3"))
124              node->ssl = SSL_SSL_V3;              node->ssl = SSL_SSL_V3;
125          else if (strcasestr(line + match[7].rm_so, "tls1"))          else if (strcasestr(line + match[8].rm_so, "tls1"))
126              node->ssl = SSL_TLS_V1;              node->ssl = SSL_TLS_V1;
127          else          else
128              node->ssl = SSL_SSL_V2;              node->ssl = SSL_SSL_V2;
# Line 213  int set_mboxgrp(char *line, regmatch_t * Line 219  int set_mboxgrp(char *line, regmatch_t *
219  void process_mboxgrp(mboxgrp_t * node, char *mboxs)  void process_mboxgrp(mboxgrp_t * node, char *mboxs)
220  {  {
221      unsigned int i = 0;      unsigned int i = 0;
     const char *delim = ",";  
222      char *tok;      char *tok;
223    
224      while (i < MBOXGRP_MBOXES_MAX - 1 && (tok = strsep(&mboxs, delim))) {      while (i < MBOXGRP_MBOXES_MAX - 1 && (tok = strsep(&mboxs, ","))) {
225          node->mboxes[i] = (mbox_t *) set_mbox(tok);          node->mboxes[i] = (mbox_t *) set_mbox(tok);
226          node->mboxes[++i] = NULL;          node->mboxes[++i] = NULL;
227      }      }
# Line 294  void init_filter(filter_t * node) Line 299  void init_filter(filter_t * node)
299      node->key[0] = 0;      node->key[0] = 0;
300      node->mode = FILTER_MODE_AND;      node->mode = FILTER_MODE_AND;
301      node->action.type = 0;      node->action.type = 0;
302        node->action.raccount = NULL;
303      node->action.destmbox[0] = node->action.args[0] = 0;      node->action.destmbox[0] = node->action.args[0] = 0;
304      node->masks = NULL;      node->masks = NULL;
305      node->masknum = node->masklen = 0;      node->masknum = node->ormasknum = node->masklen = 0;
306  }  }
307    
308    
# Line 366  filter_t *find_filter(char *key) Line 372  filter_t *find_filter(char *key)
372   */   */
373  int set_action(char *line, regmatch_t * match)  int set_action(char *line, regmatch_t * match)
374  {  {
375        char *c;
376        account_t *a;
377        
378      if (!cur_fltr)      if (!cur_fltr)
379          return ERROR_CONFIG_PARSE;          return ERROR_CONFIG_PARSE;
380    
# Line 387  int set_action(char *line, regmatch_t * Line 396  int set_action(char *line, regmatch_t *
396          else          else
397              strncat(cur_fltr->action.destmbox, line + match[3].rm_so,              strncat(cur_fltr->action.destmbox, line + match[3].rm_so,
398                      min(match[3].rm_eo - match[3].rm_so, MBOX_NAME_LEN - 1));                      min(match[3].rm_eo - match[3].rm_so, MBOX_NAME_LEN - 1));
399        } else if (!strncasecmp(line + match[1].rm_so, "rcopy", 5)) {
400            cur_fltr->action.type = FILTER_ACTION_RCOPY;
401            for (a = accounts; a; a = a->next)
402                if (!strncasecmp(line + match[4].rm_so, a->key, strlen(a->key)))
403                    cur_fltr->action.raccount = a;
404            if (!cur_fltr->action.raccount)
405                return ERROR_CONFIG_PARSE;
406    
407            if (*(line + match[5].rm_so) == '"' && *(line + match[5].rm_eo - 1) == '"')
408                strncat(cur_fltr->action.destmbox, line + match[5].rm_so + 1,
409                        min(match[5].rm_eo - match[5].rm_so - 2, MBOX_NAME_LEN - 1));
410            else
411                strncat(cur_fltr->action.destmbox, line + match[5].rm_so,
412                        min(match[5].rm_eo - match[5].rm_so, MBOX_NAME_LEN - 1));
413        } else if (!strncasecmp(line + match[1].rm_so, "rmove", 5)) {
414            cur_fltr->action.type = FILTER_ACTION_RMOVE;
415            for (a = accounts; a; a = a->next)
416                if (!strncasecmp(line + match[6].rm_so, a->key, strlen(a->key)))
417                    cur_fltr->action.raccount = a;
418            if (!cur_fltr->action.raccount)
419                return ERROR_CONFIG_PARSE;
420    
421            if (*(line + match[7].rm_so) == '"' && *(line + match[7].rm_eo - 1) == '"')
422                strncat(cur_fltr->action.destmbox, line + match[7].rm_so + 1,
423                        min(match[7].rm_eo - match[7].rm_so - 2, MBOX_NAME_LEN - 1));
424            else
425                strncat(cur_fltr->action.destmbox, line + match[7].rm_so,
426                        min(match[7].rm_eo - match[7].rm_so, MBOX_NAME_LEN - 1));
427      } else if (!strncasecmp(line + match[1].rm_so, "list", 4))      } else if (!strncasecmp(line + match[1].rm_so, "list", 4))
428          cur_fltr->action.type = FILTER_ACTION_LIST;          cur_fltr->action.type = FILTER_ACTION_LIST;
429    
430      if (match[4].rm_so != -1)      if (match[8].rm_so != -1) {
431          strncat(cur_fltr->action.args, line + match[4].rm_so,          strncat(cur_fltr->action.args, line + match[8].rm_so,
432                  min(match[4].rm_eo - match[4].rm_so, ARGS_LEN - 1));                  min(match[8].rm_eo - match[8].rm_so, ARGS_LEN - 2));
433            while ((c = strchr(cur_fltr->action.args, ',')))
434                *c = ' ';
435        }
436    
437    #ifdef DEBUG
438        printf("debug: ACTION: %d '%s' '%s' '%s'\n", cur_fltr->action.type,
439               cur_fltr->action.raccount->key, cur_fltr->action.destmbox,
440               cur_fltr->action.args);
441    #endif
442      return 0;      return 0;
443    
444  }  }
# Line 443  int set_mask(char *line, regmatch_t * ma Line 488  int set_mask(char *line, regmatch_t * ma
488    
489      /* If specified set mask's type. */      /* If specified set mask's type. */
490      if (match[2].rm_so != -1 && cur_fltr->masks) {      if (match[2].rm_so != -1 && cur_fltr->masks) {
491          if (!strncasecmp(line + match[2].rm_so, "or", 2))          if (!strncasecmp(line + match[2].rm_so, "or", 2)) {
492              node->type = MASK_TYPE_OR;              node->type = MASK_TYPE_OR;
493          else              if ((cur_fltr->mode = FILTER_MODE_OR))
494                    cur_fltr->ormasknum++;
495            } else
496              node->type = MASK_TYPE_AND;              node->type = MASK_TYPE_AND;
497      }      }
498      /* Add NOT if specified. */      /* Add NOT if specified. */
# Line 552  void convert_date(mask_t * node) Line 599  void convert_date(mask_t * node)
599  int set_job(char *line, regmatch_t * match)  int set_job(char *line, regmatch_t * match)
600  {  {
601      int n;      int n;
     const char *delim = ",";  
602      char *ftok, *gtok, *fltr, *mbgrp, *f, *g;      char *ftok, *gtok, *fltr, *mbgrp, *f, *g;
603      filter_t *cf;      filter_t *cf;
604      mboxgrp_t *cg;      mboxgrp_t *cg;
# Line 570  int set_job(char *line, regmatch_t * mat Line 616  int set_job(char *line, regmatch_t * mat
616      mbgrp = (char *) xmalloc(n + 1);      mbgrp = (char *) xmalloc(n + 1);
617    
618      /* Go through filters. */      /* Go through filters. */
619      while ((ftok = strsep(&f, delim))) {      while ((ftok = strsep(&f, ","))) {
620          cf = (filter_t *) find_filter(ftok);          cf = (filter_t *) find_filter(ftok);
621          if (!cf)          if (!cf)
622              return ERROR_CONFIG_PARSE;              return ERROR_CONFIG_PARSE;
# Line 579  int set_job(char *line, regmatch_t * mat Line 625  int set_job(char *line, regmatch_t * mat
625          g[n] = 0;          g[n] = 0;
626    
627          /* Go through mailbox groups. */          /* Go through mailbox groups. */
628          while ((gtok = strsep(&g, delim))) {          while ((gtok = strsep(&g, ","))) {
629              cg = (mboxgrp_t *) find_mboxgrp(gtok);              cg = (mboxgrp_t *) find_mboxgrp(gtok);
630              if (!cg)              if (!cg)
631                  return ERROR_CONFIG_PARSE;                  return ERROR_CONFIG_PARSE;

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26