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

Diff of /imapfilter/connect.c

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

revision 1.7 by lefcha, Sun Aug 26 10:02:46 2001 UTC revision 1.8 by lefcha, Sun Aug 26 12:26:59 2001 UTC
# Line 137  int clear_stream(void) Line 137  int clear_stream(void)
137  /*  /*
138   * Processes the data that server sent due to IMAP SELSECT client request.   * Processes the data that server sent due to IMAP SELSECT client request.
139   */   */
140  int select_response(void)  int status_response(void)
141  {  {
142      int r, i, s;      int r, s;
143      char buf[RESPONSE_BUF];      char buf[RESPONSE_BUF];
144      char exists[SELECT_BUF], recent[SELECT_BUF];      char exists[STATUS_BUF], recent[STATUS_BUF], unseen[STATUS_BUF];
145      regex_t creg[2];      regex_t creg;
146      regmatch_t match[2];      regmatch_t match[4];
147      const char *reg[2] = {      const char *reg =
148          "\\* ([[:digit:]]+) EXISTS",          "\\* STATUS INBOX \\(MESSAGES ([[:digit:]]+) RECENT ([[:digit:]]+) UNSEEN ([[:digit:]]+)\\)";
         "\\* ([[:digit:]]+) RECENT"  
     };  
149    
150      exists[0] = recent[0] = 0;      exists[0] = recent[0] = unseen[0] = 0;
151    
152      r = get_response(buf);      r = get_response(buf);
153    
154      for (i = 0; i < 2; i++)      regcomp(&creg, reg, REG_EXTENDED);
         regcomp(&creg[i], reg[i], REG_EXTENDED);  
155    
156      if (!regexec(&creg[0], buf, 2, match, 0)) {      if (!regexec(&creg, buf, 4, match, 0)) {
157          s = min(match[1].rm_eo - match[1].rm_so, SELECT_BUF - 1);          s = min(match[1].rm_eo - match[1].rm_so, STATUS_BUF - 1);
158          strncpy(exists, buf + match[1].rm_so, s);          strncpy(exists, buf + match[1].rm_so, s);
159          exists[s] = 0;          exists[s] = 0;
     }  
160    
161      if (!regexec(&creg[1], buf, 2, match, 0)) {          s = min(match[2].rm_eo - match[2].rm_so, STATUS_BUF - 1);
162          s = min(match[1].rm_eo - match[1].rm_so, SELECT_BUF - 1);          strncpy(recent, buf + match[2].rm_so, s);
         strncpy(recent, buf + match[1].rm_so, s);  
163          recent[s] = 0;          recent[s] = 0;
164    
165            s = min(match[3].rm_eo - match[3].rm_so, STATUS_BUF - 1);
166            strncpy(unseen, buf + match[3].rm_so, s);
167            unseen[s] = 0;
168    
169            info("%s messages exist, %s recent, %s unseen.\n", exists, recent,
170                 unseen);
171      }      }
       
     if (!strncmp(exists, "0", 1))  
         info("No messages found.\n");  
     else  
         info("%s messages exist, %s of which recent.\n", exists, recent);  
172    
173      return r;      return r;
174  }  }

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26