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

Diff of /imapfilter/connect.c

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

revision 1.8 by lefcha, Sun Aug 26 12:26:59 2001 UTC revision 1.9 by lefcha, Sun Aug 26 19:34:29 2001 UTC
# Line 18  Line 18 
18    
19    
20  extern account_t *accounts;  extern account_t *accounts;
21  extern int options;  extern unsigned int options;
22    
23  int sock;  int sock;
24    
# Line 75  int close_connection(void) Line 75  int close_connection(void)
75    
76    
77  /*  /*
78   * Reads (if any) data the server sent.   * Reads data the server sent.
79   */   */
80  int get_response(char *buf)  int recv_response(char *buf)
81  {  {
82      int flags;      int flags;
83      fd_set rfds;      fd_set rfds;
# Line 115  int get_response(char *buf) Line 115  int get_response(char *buf)
115    
116    
117  /*  /*
118   * Clears stream from any data server sent without processing them.   * Clears stream from any data server sent.
119   */   */
120  int clear_stream(void)  int clear_stream(void)
121  {  {
     int r;  
     unsigned int orig;  
122      char buf[RESPONSE_BUF];      char buf[RESPONSE_BUF];
123    
124      orig = options;             /* Needed so response won't be analyzed. */      return recv_response(buf);
     options &= OPT_DETAILS_CLEAR;  
   
     r = get_response(buf);  
   
     options = orig;  
   
     return r;  
125  }  }
126    
127    
128  /*  /*
129   * Processes the data that server sent due to IMAP SELSECT client request.   * Processes the data that server sent due to IMAP STATUS client request.
130   */   */
131  int status_response(void)  int status_response(void)
132  {  {
133      int r, s;      int r, s;
134      char buf[RESPONSE_BUF];      char buf[RESPONSE_BUF];
135      char exists[STATUS_BUF], recent[STATUS_BUF], unseen[STATUS_BUF];      char exist[STATUS_BUF], recent[STATUS_BUF], unseen[STATUS_BUF];
136      regex_t creg;      regex_t creg;
137      regmatch_t match[4];      regmatch_t match[4];
138      const char *reg =      const char *reg =
139          "\\* STATUS INBOX \\(MESSAGES ([[:digit:]]+) RECENT ([[:digit:]]+) UNSEEN ([[:digit:]]+)\\)";          "\\* STATUS INBOX \\(MESSAGES ([[:digit:]]+) RECENT ([[:digit:]]+) UNSEEN ([[:digit:]]+)\\)";
140    
141      exists[0] = recent[0] = unseen[0] = 0;      exist[0] = recent[0] = unseen[0] = 0;
142    
143      r = get_response(buf);      r = recv_response(buf);
144    
145      regcomp(&creg, reg, REG_EXTENDED);      regcomp(&creg, reg, REG_EXTENDED);
146    
147      if (!regexec(&creg, buf, 4, match, 0)) {      if (!regexec(&creg, buf, 4, match, 0)) {
148          s = min(match[1].rm_eo - match[1].rm_so, STATUS_BUF - 1);          s = min(match[1].rm_eo - match[1].rm_so, STATUS_BUF - 1);
149          strncpy(exists, buf + match[1].rm_so, s);          strncpy(exist, buf + match[1].rm_so, s);
150          exists[s] = 0;          exist[s] = 0;
151    
152          s = min(match[2].rm_eo - match[2].rm_so, STATUS_BUF - 1);          s = min(match[2].rm_eo - match[2].rm_so, STATUS_BUF - 1);
153          strncpy(recent, buf + match[2].rm_so, s);          strncpy(recent, buf + match[2].rm_so, s);
# Line 166  int status_response(void) Line 157  int status_response(void)
157          strncpy(unseen, buf + match[3].rm_so, s);          strncpy(unseen, buf + match[3].rm_so, s);
158          unseen[s] = 0;          unseen[s] = 0;
159    
160          info("%s messages exist, %s recent, %s unseen.\n", exists, recent,          info("%s messages exist, %s recent, %s unseen.\n", exist, recent,
161               unseen);               unseen);
162      }      }
163    
# Line 187  int search_response(char *res) Line 178  int search_response(char *res)
178    
179      len = strlen(res);      len = strlen(res);
180    
181      r = get_response(buf);      r = recv_response(buf);
182    
183      regcomp(&creg, reg, REG_EXTENDED);      regcomp(&creg, reg, REG_EXTENDED);
184    
# Line 215  int fetch_response(char *res) Line 206  int fetch_response(char *res)
206          "Subject: [[:print:]]*"          "Subject: [[:print:]]*"
207      };      };
208    
209      r = get_response(buf);      r = recv_response(buf);
210    
211      for (i = 0; i < 3; i++) {      for (i = 0; i < 3; i++) {
212          regcomp(&creg[i], reg[i], REG_EXTENDED);          regcomp(&creg[i], reg[i], REG_EXTENDED);
# Line 243  void analyze_response(char *buf) Line 234  void analyze_response(char *buf)
234      int s;      int s;
235      regex_t creg;      regex_t creg;
236      regmatch_t match[2];      regmatch_t match[2];
237      const char *reg = "[[:xdigit:]]{4,4} ([[:print:]]*)";      const char *reg = "[[:xdigit:]]{4,4} ((OK|NO|BAD) [[:print:]]*)";
238      char res[RESULTS_BUF];      char res[RESULTS_BUF];
239    
240      regcomp(&creg, reg, REG_EXTENDED);      regcomp(&creg, reg, REG_EXTENDED);

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26