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

Diff of /imapfilter/imap.c

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

revision 1.10 by lefcha, Sun Aug 26 12:26:59 2001 UTC revision 1.11 by lefcha, Sun Aug 26 19:54:54 2001 UTC
# Line 14  Line 14 
14  extern int sock;  extern int sock;
15  extern account_t *accounts;  extern account_t *accounts;
16  extern filter_t *dfilters, *afilters;  extern filter_t *dfilters, *afilters;
17  extern int options;  extern unsigned int options;
18  extern unsigned int dlimit, alimit;  extern unsigned int dlimit, alimit;
19    
20  static int tag = 0xA000;        /* Every IMAP command is prefixed with a  static int tag = 0xA000;        /* Every IMAP command is prefixed with a
# Line 41  int send_command(char *cmd) Line 41  int send_command(char *cmd)
41  }  }
42    
43    
 /*  
  * Calls send_command() and get_response().  
  */  
 int send_command_get_response(char *cmd)  
 {  
     char buf[RESPONSE_BUF];  
   
     if (!send_command(cmd) && !get_response(buf))  
         return 0;  
     else  
         return 1;  
 }  
   
   
44  #ifdef DEBUG  #ifdef DEBUG
45  /*  /*
46   * IMAP NOOP: does nothing always succeeds.   * IMAP NOOP: does nothing always succeeds.
# Line 67  int imap_noop(void) Line 53  int imap_noop(void)
53    
54      snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag++);      snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag++);
55    
56      return send_command_get_response(cmd);      if (!send_command(cmd) && !clear_stream())
57            return 0;
58        else
59            return 1;
60  }  }
61  #endif  #endif
62    
# Line 84  int imap_logout(void) Line 72  int imap_logout(void)
72    
73      snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag++);      snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag++);
74    
75      return send_command_get_response(cmd);      if (!send_command(cmd) && !clear_stream())
76            return 0;
77        else
78            return 1;
79  }  }
80    
81    
# Line 100  int imap_login(account_t * ca) Line 91  int imap_login(account_t * ca)
91      snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n",      snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n",
92               tag++, ca->userid, ca->passwd);               tag++, ca->userid, ca->passwd);
93    
94      return send_command_get_response(cmd);      if (!send_command(cmd) && !clear_stream())
95            return 0;
96        else
97            return 1;
98  }  }
99    
100    
# Line 115  int imap_select(void) Line 109  int imap_select(void)
109    
110      snprintf(cmd, SMALL_CMD, "%X SELECT INBOX\r\n", tag++);      snprintf(cmd, SMALL_CMD, "%X SELECT INBOX\r\n", tag++);
111    
112      return send_command_get_response(cmd);      if (!send_command(cmd) && !clear_stream())
113            return 0;
114        else
115            return 1;
116  }  }
117    
118    
# Line 147  int imap_search(char *res) Line 144  int imap_search(char *res)
144    
145      verbose("Client request:  SEARCH\n");      verbose("Client request:  SEARCH\n");
146    
147      generate_search_filters(cmd);      gen_search_filters(cmd);
148      if (send_command(cmd))      if (send_command(cmd) || search_response(res))
149          return 1;          return 1;
     search_response(res);  
150    
151      verbose("Client request:  SEARCH\n");      verbose("Client request:  SEARCH\n");
152    
153      if (alimit && afilters) {      if (alimit && afilters) {
154          generate_search_limits(cmd);          gen_search_limits(cmd);
155          if (send_command(cmd))          if (send_command(cmd) || search_response(res))
156              return 1;              return 1;
         search_response(res);  
157      }      }
158    
159      return 0;      return 0;
# Line 197  int imap_store(unsigned int msg) Line 192  int imap_store(unsigned int msg)
192      snprintf(cmd, MEDIUM_CMD,      snprintf(cmd, MEDIUM_CMD,
193               "%X STORE %d +FLAGS \\Deleted\r\n", tag++, msg);               "%X STORE %d +FLAGS \\Deleted\r\n", tag++, msg);
194    
195      return send_command_get_response(cmd);      if (!send_command(cmd) && !clear_stream())
196            return 0;
197        else
198            return 1;
199  }  }
200    
201    
# Line 212  int imap_expunge(void) Line 210  int imap_expunge(void)
210    
211      snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag++);      snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag++);
212    
213      return send_command_get_response(cmd);      if (!send_command(cmd) && !clear_stream())
214            return 0;
215        else
216            return 1;
217  }  }
218    
219    
# Line 221  int imap_expunge(void) Line 222  int imap_expunge(void)
222   * command that will be sent.  This command will search for DENY, ALLOW,   * command that will be sent.  This command will search for DENY, ALLOW,
223   * and DENY_LIMIT filters.   * and DENY_LIMIT filters.
224   */   */
225  void generate_search_filters(char *cmd)  void gen_search_filters(char *cmd)
226  {  {
227      int len;      int len;
228    
229      snprintf(cmd, BIG_CMD, "%X SEARCH", tag++);      snprintf(cmd, BIG_CMD, "%X SEARCH", tag++);
230    
231      deny_filters(cmd);      gen_deny_filters(cmd);
232    
233      if (dlimit) {      if (dlimit) {
234          len = strlen(cmd);          len = strlen(cmd);
# Line 238  void generate_search_filters(char *cmd) Line 239  void generate_search_filters(char *cmd)
239          snprintf(cmd + len, BIG_CMD - len, " ALL");          snprintf(cmd + len, BIG_CMD - len, " ALL");
240      }      }
241    
242      allow_filters(cmd, "NOT");      gen_allow_filters(cmd, "NOT");
243    
244        if (options & OPT_UNSEEN_ONLY) {
245            len = strlen(cmd);
246            snprintf(cmd + len, BIG_CMD - len, " UNSEEN");
247        }
248    
249      len = strlen(cmd);      len = strlen(cmd);
250      snprintf(cmd + len, BIG_CMD - len, "\r\n");      snprintf(cmd + len, BIG_CMD - len, "\r\n");
# Line 250  void generate_search_filters(char *cmd) Line 256  void generate_search_filters(char *cmd)
256   * command that will be sent.  This command will search for the ALLOW_LIMIT   * command that will be sent.  This command will search for the ALLOW_LIMIT
257   * filter.   * filter.
258   */   */
259  void generate_search_limits(char *cmd)  void gen_search_limits(char *cmd)
260  {  {
261      int len;      int len;
262    
263      snprintf(cmd, BIG_CMD, "%X SEARCH", tag++);      snprintf(cmd, BIG_CMD, "%X SEARCH", tag++);
264    
265      allow_filters(cmd, "OR");      gen_allow_filters(cmd, "OR");
266    
267      len = strlen(cmd);      len = strlen(cmd);
268      snprintf(cmd + len, BIG_CMD - len, " LARGER %d", alimit);      snprintf(cmd + len, BIG_CMD - len, " LARGER %d", alimit);
269    
270        if (options & OPT_UNSEEN_ONLY) {
271            len = strlen(cmd);
272            snprintf(cmd + len, BIG_CMD - len, " UNSEEN");
273        }
274    
275      len = strlen(cmd);      len = strlen(cmd);
276      snprintf(cmd + len, BIG_CMD - len, "\r\n");      snprintf(cmd + len, BIG_CMD - len, "\r\n");
277    
# Line 270  void generate_search_limits(char *cmd) Line 281  void generate_search_limits(char *cmd)
281  /*  /*
282   * Adds to the IMAP SEARCH command all the DENY type filters.   * Adds to the IMAP SEARCH command all the DENY type filters.
283   */   */
284  void deny_filters(char *cmd)  void gen_deny_filters(char *cmd)
285  {  {
286      int len;      int len;
287      filter_t *cdf;      filter_t *cdf;
# Line 294  void deny_filters(char *cmd) Line 305  void deny_filters(char *cmd)
305  /*  /*
306   * Adds to IMAP SEARCH command all the ALLOW type filters.   * Adds to IMAP SEARCH command all the ALLOW type filters.
307   */   */
308  void allow_filters(char *cmd, char *key)  void gen_allow_filters(char *cmd, char *key)
309  {  {
310      int len;      int len;
311      filter_t *caf;      filter_t *caf;
# Line 320  void allow_filters(char *cmd, char *key) Line 331  void allow_filters(char *cmd, char *key)
331   * integers, sends the appropriate command and optionally prints some   * integers, sends the appropriate command and optionally prints some
332   * headers of the "to be deleted" messages.   * headers of the "to be deleted" messages.
333   */   */
334  void delete_messages(char *msgs)  void del_messages(char *msgs)
335  {  {
336      unsigned long int m;      unsigned long int m;
337      char hdr[HEADERS_MAX];      char hdr[HEADERS_MAX];

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26