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

Diff of /imapfilter/imap.c

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

revision 1.35 by lefcha, Sun Jul 27 10:08:42 2003 UTC revision 1.36 by lefcha, Sun Jul 27 15:54:49 2003 UTC
# Line 11  Line 11 
11    
12  extern int sockpri;  extern int sockpri;
13    
14  static unsigned int tag = 0xA00000;     /* Every IMAP command is prefixed with  buffer_t obuf;                  /* Output buffer. */
15                                           * a unique [:alnum:] string. */  
16    static unsigned int tag = 0;    /* Every IMAP command is prefixed with a
17                                     * unique [:alnum:] string. */
18    
19  /*  /*
20   * Send to server data; a command.   * Send to server data; a command.
# Line 58  send_command_cont(int *sock, char *cmd) Line 60  send_command_cont(int *sock, char *cmd)
60  int  int
61  imap_noop(int *sock)  imap_noop(int *sock)
62  {  {
63          char cmd[SMALL_CMD];          reset_buffer(&obuf);
64            check_buffer(&obuf, strlen("NOOP") + 12);
65    
66          snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X NOOP\r\n", tag);
67    
68          return send_command(sock, cmd);          return send_command(sock, obuf.data);
69  }  }
70    
71  #endif  #endif
# Line 74  imap_noop(int *sock) Line 77  imap_noop(int *sock)
77  int  int
78  imap_capability(int *sock)  imap_capability(int *sock)
79  {  {
80          char cmd[SMALL_CMD];          reset_buffer(&obuf);
81            check_buffer(&obuf, strlen("CAPABILITY") + 12);
82    
83          snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X CAPABILITY\r\n", tag);
84    
85          return send_command(sock, cmd);          return send_command(sock, obuf.data);
86  }  }
87    
88    
# Line 89  imap_capability(int *sock) Line 93  imap_capability(int *sock)
93  int  int
94  imap_namespace(int *sock)  imap_namespace(int *sock)
95  {  {
96          char cmd[SMALL_CMD];          reset_buffer(&obuf);
97            check_buffer(&obuf, strlen("NAMESPACE") + 12);
98    
99          snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X NAMESPACE\r\n", tag);
100    
101          return send_command(sock, cmd);          return send_command(sock, obuf.data);
102  }  }
103    
104    
# Line 103  imap_namespace(int *sock) Line 108  imap_namespace(int *sock)
108  int  int
109  imap_logout(int *sock)  imap_logout(int *sock)
110  {  {
111          char cmd[SMALL_CMD];          reset_buffer(&obuf);
112            check_buffer(&obuf, strlen("LOGOUT") + 12);
113    
114          snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X LOGOUT\r\n", tag);
115    
116          return send_command(sock, cmd);          return send_command(sock, obuf.data);
117  }  }
118    
119    
# Line 117  imap_logout(int *sock) Line 123  imap_logout(int *sock)
123  int  int
124  imap_starttls(int *sock)  imap_starttls(int *sock)
125  {  {
126          char cmd[SMALL_CMD];          reset_buffer(&obuf);
127            check_buffer(&obuf, strlen("STARTTLS") + 12);
128    
129          snprintf(cmd, SMALL_CMD, "%X STARTTLS\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X STARTTLS\r\n", tag);
130    
131          return send_command(sock, cmd);          return send_command(sock, obuf.data);
132  }  }
133    
134    
# Line 133  imap_starttls(int *sock) Line 140  imap_starttls(int *sock)
140  int  int
141  imap_authenticate(int *sock, char *auth, int cont)  imap_authenticate(int *sock, char *auth, int cont)
142  {  {
143          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
144            check_buffer(&obuf, strlen("AUTHENTICATE") + 12);
145    
146          if (!cont) {          if (!cont) {
147                  snprintf(cmd, MEDIUM_CMD, "%X AUTHENTICATE %s\r\n", tag, auth);                  snprintf(obuf.data, obuf.size, "%08X AUTHENTICATE %s\r\n",
148                  return send_command(sock, cmd);                      tag, auth);
149                    return send_command(sock, obuf.data);
150          } else {          } else {
151                  send_command_cont(sock, auth);                  send_command_cont(sock, auth);
152                  return 0;                  return 0;
# Line 153  imap_authenticate(int *sock, char *auth, Line 162  imap_authenticate(int *sock, char *auth,
162  int  int
163  imap_login(int *sock, char *user, char *pass)  imap_login(int *sock, char *user, char *pass)
164  {  {
165          int r;          int r, n;
166          char *cmd;          char *sbuf;
167    
168          cmd = (char *)smalloc(MEDIUM_CMD);          n = strlen("LOGIN") + strlen(user) + strlen(pass) + 18;
169            sbuf = (char *)smalloc(n);
170    
171          snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,          snprintf(sbuf, n, "%08X LOGIN \"%s\" \"%s\"\r\n", tag, user, pass);
             pass);  
172    
173          r = send_command(sock, cmd);          r = send_command(sock, sbuf);
174    
175          sfree(cmd);          sfree(sbuf);
176    
177          return r;          return r;
178  }  }
# Line 175  imap_login(int *sock, char *user, char * Line 184  imap_login(int *sock, char *user, char *
184   *   *
185  int imap_list(int *sock, char *refer, char *mbox)  int imap_list(int *sock, char *refer, char *mbox)
186  {  {
187      int r;          int r;
188      char cmd[BIG_CMD];          
189            reset_buffer(&obuf);
190      snprintf(cmd, MEDIUM_CMD, "%X LIST \"%s\" \"%s\"\r\n", tag, refer,          check_buffer(&obuf, strlen("LIST") + strlen(refer) + strlen(mbox) + 18);
191               mbox);          
192            snprintf(obuf.data, obuf.size, "%08X LIST \"%s\" \"%s\"\r\n", tag,
193                refer, mbox);
194    
195      r = send_command(sock, cmd);          r = send_command(sock, obuf.data);
196    
197      return r;          return r;
198  }*/  }*/
199    
200    
# Line 194  int imap_list(int *sock, char *refer, ch Line 205  int imap_list(int *sock, char *refer, ch
205  int  int
206  imap_subscribe(int *sock, char *mbox)  imap_subscribe(int *sock, char *mbox)
207  {  {
208          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
209            check_buffer(&obuf, strlen("SUBSCRIBE") + strlen(mbox) + 15);
210    
211          snprintf(cmd, MEDIUM_CMD, "%X SUBSCRIBE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%08X SUBSCRIBE \"%s\"\r\n", tag, mbox);
212    
213          return send_command(sock, cmd);          return send_command(sock, obuf.data);
214  }  }
215    
216    
# Line 208  imap_subscribe(int *sock, char *mbox) Line 220  imap_subscribe(int *sock, char *mbox)
220  int  int
221  imap_examine(int *sock, char *mbox)  imap_examine(int *sock, char *mbox)
222  {  {
223          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
224            check_buffer(&obuf, strlen("EXAMINE") + strlen(mbox) + 15);
225    
226          snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, MEDIUM_CMD, "%08X EXAMINE \"%s\"\r\n", tag, mbox);
227    
228          return send_command(sock, cmd);          return send_command(sock, obuf.data);
229  }*/  }*/
230    
231    
# Line 222  imap_examine(int *sock, char *mbox) Line 235  imap_examine(int *sock, char *mbox)
235  int  int
236  imap_select(int *sock, char *mbox)  imap_select(int *sock, char *mbox)
237  {  {
238          char cmd[SMALL_CMD];          reset_buffer(&obuf);
239            check_buffer(&obuf, strlen("SELECT") + strlen(mbox) + 15);
240    
241          snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%08X SELECT \"%s\"\r\n", tag, mbox);
242    
243          return send_command(sock, cmd);          return send_command(sock, obuf.data);
244  }  }
245    
246    
# Line 236  imap_select(int *sock, char *mbox) Line 250  imap_select(int *sock, char *mbox)
250  int  int
251  imap_status(int *sock, char *mbox, char *items)  imap_status(int *sock, char *mbox, char *items)
252  {  {
253          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
254            check_buffer(&obuf, strlen("STATUS") + strlen(mbox) +
255                strlen(items) + 18);
256    
257          snprintf(cmd, MEDIUM_CMD, "%X STATUS \"%s\" (%s)\r\n", tag, mbox, items);          snprintf(obuf.data, obuf.size, "%08X STATUS \"%s\" (%s)\r\n", tag, mbox, items);
258    
259          return send_command(sock, cmd);          return send_command(sock, obuf.data);
260  }  }
261    
262    
# Line 250  imap_status(int *sock, char *mbox, char Line 266  imap_status(int *sock, char *mbox, char
266  int  int
267  imap_create(int *sock, char *mbox)  imap_create(int *sock, char *mbox)
268  {  {
269          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
270            check_buffer(&obuf, strlen("CREATE") + strlen(mbox) + 14);
271    
272          snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%08X CREATE \"%s\"\r\n", tag, mbox);
273    
274          return send_command(sock, cmd);          return send_command(sock, obuf.data);
275  }  }
276    
277    
# Line 264  imap_create(int *sock, char *mbox) Line 281  imap_create(int *sock, char *mbox)
281  int  int
282  imap_search(int *sock, char *charset, char *search)  imap_search(int *sock, char *charset, char *search)
283  {  {
284          char cmd[BIG_CMD];          reset_buffer(&obuf);
285            check_buffer(&obuf, strlen("SEARCH CHARSET") + strlen(charset) +
286                strlen(search) + 15);
287    
288          if (*charset)          if (*charset)
289                  snprintf(cmd, BIG_CMD, "%X SEARCH CHARSET \"%s\" %s\r\n", tag,                  snprintf(obuf.data, obuf.size, "%08X SEARCH CHARSET \"%s\" %s\r\n",
290                      charset, search);                      tag, charset, search);
291          else          else
292                  snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);                  snprintf(obuf.data, obuf.size, "%08X SEARCH %s\r\n", tag, search);
293    
294          return send_command(sock, cmd);          return send_command(sock, obuf.data);
295  }  }
296    
297    
# Line 282  imap_search(int *sock, char *charset, ch Line 301  imap_search(int *sock, char *charset, ch
301  int  int
302  imap_fetch(int *sock, char *mesg, char *items)  imap_fetch(int *sock, char *mesg, char *items)
303  {  {
304          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
305            check_buffer(&obuf, strlen("FETCH") + strlen(mesg) + strlen(items) + 14);
306    
307          snprintf(cmd, MEDIUM_CMD, "%X FETCH %s %s\r\n", tag, mesg, items);          snprintf(obuf.data, obuf.size, "%08X FETCH %s %s\r\n", tag, mesg, items);
308    
309          return send_command(sock, cmd);          return send_command(sock, obuf.data);
310  }  }
311    
312    
# Line 296  imap_fetch(int *sock, char *mesg, char * Line 316  imap_fetch(int *sock, char *mesg, char *
316  int  int
317  imap_store(int *sock, char *mesg, unsigned int mode, char *flags)  imap_store(int *sock, char *mesg, unsigned int mode, char *flags)
318  {  {
319          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
320            check_buffer(&obuf, strlen("STORE") + strlen(mesg) +
321                strlen("FLAGS.SILENT") + strlen(flags) + 18);
322    
323          snprintf(cmd, MEDIUM_CMD, "%X STORE %s %sFLAGS.SILENT (%s)\r\n", tag,          snprintf(obuf.data, obuf.size, "%08X STORE %s %sFLAGS.SILENT (%s)\r\n",
324              mesg, (mode == STORE_FLAG_REPLACE ? "" :              tag, mesg, (mode == STORE_FLAG_REPLACE ? "" :
325                  mode == STORE_FLAG_ADD ? "+" : "-"), flags);                  mode == STORE_FLAG_ADD ? "+" : "-"), flags);
326    
327          return send_command(sock, cmd);          return send_command(sock, obuf.data);
328  }  }
329    
330    
# Line 312  imap_store(int *sock, char *mesg, unsign Line 334  imap_store(int *sock, char *mesg, unsign
334  int  int
335  imap_copy(int *sock, char *mesg, char *mbox)  imap_copy(int *sock, char *mesg, char *mbox)
336  {  {
337          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
338            check_buffer(&obuf, strlen("COPY") + strlen(mesg) + strlen(mbox) + 16);
339    
340          snprintf(cmd, MEDIUM_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);          snprintf(obuf.data, obuf.size, "%08X COPY %s \"%s\"\r\n", tag, mesg, mbox);
341    
342          return send_command(sock, cmd);          return send_command(sock, obuf.data);
343  }  }
344    
345    
# Line 326  imap_copy(int *sock, char *mesg, char *m Line 349  imap_copy(int *sock, char *mesg, char *m
349  int  int
350  imap_append(int *sock, char *mbox, unsigned int size)  imap_append(int *sock, char *mbox, unsigned int size)
351  {  {
352          char cmd[MEDIUM_CMD];          reset_buffer(&obuf);
353            check_buffer(&obuf, strlen("APPEND") + strlen(mbox) +
354                strlen(ultostr(size, 10)) + 18);
355    
356          snprintf(cmd, MEDIUM_CMD, "%X APPEND \"%s\" {%d}\r\n", tag, mbox, size);          snprintf(obuf.data, obuf.size, "%08X APPEND \"%s\" {%d}\r\n", tag, mbox,
357                size);
358    
359          return send_command(sock, cmd);          return send_command(sock, obuf.data);
360  }  }
361    
362    
# Line 341  imap_append(int *sock, char *mbox, unsig Line 367  imap_append(int *sock, char *mbox, unsig
367  int  int
368  imap_close(int *sock)  imap_close(int *sock)
369  {  {
370          char cmd[SMALL_CMD];          reset_buffer(&obuf);
371            check_buffer(&obuf, strlen("CLOSE") + 12);
372    
373          snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X CLOSE\r\n", tag);
374    
375          return send_command(sock, cmd);          return send_command(sock, obuf.data);
376  }  }
377    
378    
# Line 355  imap_close(int *sock) Line 382  imap_close(int *sock)
382  int  int
383  imap_expunge(int *sock)  imap_expunge(int *sock)
384  {  {
385          char cmd[SMALL_CMD];          reset_buffer(&obuf);
386            check_buffer(&obuf, strlen("EXPUNGE") + 12);
387    
388          snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X EXPUNGE\r\n", tag);
389    
390          return send_command(sock, cmd);          return send_command(sock, obuf.data);
391  }  }

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26