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

Diff of /imapfilter/filter.c

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

revision 1.4 by lefcha, Fri Aug 8 00:18:45 2003 UTC revision 1.5 by lefcha, Sat Nov 8 14:23:18 2003 UTC
# Line 25  filter_t *cur_fltr = NULL;     /* Current fi Line 25  filter_t *cur_fltr = NULL;     /* Current fi
25  void init_filter(filter_t * node);  void init_filter(filter_t * node);
26    
27  void init_mask(mask_t * node);  void init_mask(mask_t * node);
 void convert_date(mask_t * node);  
28    
29  void link_mbox_filter(filter_t * cf, mboxgrp_t * cg);  void link_mbox_filter(filter_t * cf, mboxgrp_t * cg);
30    
# Line 233  init_mask(mask_t * node) Line 232  init_mask(mask_t * node)
232  int  int
233  set_mask(char *line, regmatch_t * m, int mmt)  set_mask(char *line, regmatch_t * m, int mmt)
234  {  {
235          int n;          int n, len;
236          mask_t *node;          mask_t *node;
237          char *bp;          char *bp;
238    
# Line 271  set_mask(char *line, regmatch_t * m, int Line 270  set_mask(char *line, regmatch_t * m, int
270          *(bp + n) = '\0';          *(bp + n) = '\0';
271          bp += n;          bp += n;
272    
273          if (mmt != MASK_MATCH_1) {          switch (mmt) {
274            case MASK_MATCH_1:
275                    len = bp - node->body;
276    
277                    break;
278    
279            case MASK_MATCH_2:
280                  *(bp++) = ' ';                  *(bp++) = ' ';
281    
282                  if (mmt != MASK_MATCH_4 && *(line + m[5].rm_so) != '"')                  if (*(line + m[5].rm_so) != '"')
283                          *(bp++) = '"';                          *(bp++) = '"';
284                  *bp = '\0';                  *bp = '\0';
285    
# Line 284  set_mask(char *line, regmatch_t * m, int Line 289  set_mask(char *line, regmatch_t * m, int
289                  *(bp + n) = '\0';                  *(bp + n) = '\0';
290                  bp += n;                  bp += n;
291    
292                  if (mmt != MASK_MATCH_4 && *(line + m[5].rm_so) != '"')                  if (*(line + m[5].rm_so) != '"')
293                          *(bp++) = '"';                          *(bp++) = '"';
294                  *bp = '\0';                  *bp = '\0';
295    
296                  if (mmt == MASK_MATCH_3) {                  len = bp - node->body;
                         *(bp++) = ' ';  
297    
298                          if (*(line + m[6].rm_so) != '"')                  break;
                                 *(bp++) = '"';  
                         *bp = '\0';  
   
                         n = min(m[6].rm_eo - m[6].rm_so,  
                             MASK_BODY_LEN - (bp - node->body) - 2);  
                         xstrncpy(bp, line + m[6].rm_so, n);  
                         *(bp + n) = '\0';  
                         bp += n;  
   
                         if (*(line + m[6].rm_so) != '"')  
                                 *(bp++) = '"';  
                         *bp = '\0';  
                 }  
                 if (mmt == MASK_MATCH_4 && (strstr(node->body, "OLDER") ||  
                         strstr(node->body, "NEWER"))) {  
                         convert_date(node);  
                         bp = node->body + strlen(node->body);  
                 }  
         }  
         APPEND_LINKED_LIST(cur_fltr->masks, node, mask);  
299    
300          cur_fltr->masknum++;          case MASK_MATCH_3:
301          cur_fltr->masklen += (bp - node->body);                  *(bp++) = ' ';
302    
303  #ifdef DEBUG                  if (*(line + m[5].rm_so) != '"')
304          fprintf(stderr, "debug: MASK: '%s'\n", node->body);                          *(bp++) = '"';
305  #endif                  *bp = '\0';
306    
307          return 0;                  n = min(m[5].rm_eo - m[5].rm_so,
308  }                      MASK_BODY_LEN - (bp - node->body) - 2);
309                    xstrncpy(bp, line + m[5].rm_so, n);
310                    *(bp + n) = '\0';
311                    bp += n;
312    
313                    if (*(line + m[5].rm_so) != '"')
314                            *(bp++) = '"';
315                    *bp = '\0';
316    
317  /*                  *(bp++) = ' ';
  * Converts masks related to date filtering, because IMAP servers do not  
  * understand for example "OLDER 3", but "BEFORE 18-Oct-2001" (if  
  * hypothetically current date was 21-Oct-2001).  
  */  
 void  
 convert_date(mask_t * node)  
 {  
         char *cp, *c;  
         char s[16];  
         time_t te;  
         struct tm *tl;  
318    
319          cp = xstrdup(node->body);                  if (*(line + m[6].rm_so) != '"')
320          node->body[0] = '\0';                          *(bp++) = '"';
321                    *bp = '\0';
322    
323                    n = min(m[6].rm_eo - m[6].rm_so,
324                        MASK_BODY_LEN - (bp - node->body) - 2);
325                    xstrncpy(bp, line + m[6].rm_so, n);
326                    *(bp + n) = '\0';
327                    bp += n;
328    
329                    if (*(line + m[6].rm_so) != '"')
330                            *(bp++) = '"';
331                    *bp = '\0';
332    
333                    len = bp - node->body;
334    
335                    break;
336    
337            case MASK_MATCH_4:
338                    *(bp++) = ' ';
339    
340                    n = min(m[5].rm_eo - m[5].rm_so,
341                        MASK_BODY_LEN - (bp - node->body) - 2);
342                    xstrncpy(bp, line + m[5].rm_so, n);
343                    *(bp + n) = '\0';
344                    bp += n;
345                    *bp = '\0';
346    
347          if (strstr(cp, "NOT"))                  if (strstr(node->body, "OLDER"))
348                  strncat(node->body, "NOT ", 4);                          len = strlen("NOT BEFORE DD-MMM-YYYY");
349                    else if (strstr(node->body, "NEWER"))
350                            len = strlen("NOT SINCE DD-MMM-YYYY");
351                    else
352                            len = bp - node->body;
353    
354          if ((c = strstr(cp, "OLDER")))                  break;
355                  strncat(node->body, "BEFORE ", 7);          default:
356          else if ((c = strstr(cp, "NEWER")))                  break;
357                  strncat(node->body, "SINCE ", 6);          }
358    
359          c += 6;          APPEND_LINKED_LIST(cur_fltr->masks, node, mask);
360    
361          te = time(NULL) - (time_t) (strtoul(c, NULL, 10) * 24 * 60 * 60);          cur_fltr->masknum++;
362          tl = localtime(&te);          cur_fltr->masklen += len;
363    
364          if (strftime(s, 15, "%d-%b-%Y", tl))  #ifdef DEBUG
365                  strncat(node->body, s, 15);          fprintf(stderr, "debug: MASK: '%s'\n", node->body);
366    #endif
367    
368          xfree(cp);          return 0;
369  }  }
370    
371    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26