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

Diff of /imapfilter/imap.c

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

revision 1.36 by lefcha, Sun Jul 27 15:54:49 2003 UTC revision 1.37 by lefcha, Sun Jul 27 17:39:45 2003 UTC
# Line 9  Line 9 
9  #include "data.h"  #include "data.h"
10    
11    
12  extern int sockpri;  extern conn_t connpri, connaux;
13    
14  buffer_t obuf;                  /* Output buffer. */  buffer_t obuf;                  /* Output buffer. */
15    
# Line 20  static unsigned int tag = 0;   /* Every IM Line 20  static unsigned int tag = 0;   /* Every IM
20   * Send to server data; a command.   * Send to server data; a command.
21   */   */
22  unsigned int  unsigned int
23  send_command(int *sock, char *cmd)  send_command(conn_t * conn, char *cmd)
24  {  {
25  #ifdef DEBUG  #ifdef DEBUG
26          fprintf(stderr, "debug: sending command (%s):\n\n%s\n",          fprintf(stderr, "debug: sending command (%s):\n\n%s\n",
27              (sock == &sockpri ? "primary" : "auxiliary"), cmd);              (conn == &connpri ? "primary" : "auxiliary"), cmd);
28  #endif  #endif
29          verbose("%s: %s", (sock == &sockpri ? "C" : "c"), cmd);          verbose("%s: %s", (conn == &connpri ? "C" : "c"), cmd);
30    
31          socket_write(sock, cmd);          socket_write(conn, cmd);
32    
33          return tag++;          return tag++;
34  }  }
# Line 39  send_command(int *sock, char *cmd) Line 39  send_command(int *sock, char *cmd)
39   * Send to server data: a continuation command.   * Send to server data: a continuation command.
40   */   */
41  void  void
42  send_command_cont(int *sock, char *cmd)  send_command_cont(conn_t * conn, char *cmd)
43  {  {
44  #ifdef DEBUG  #ifdef DEBUG
45          fprintf(stderr, "debug: sending command (%s):\n\n%s\r\n\n",          fprintf(stderr, "debug: sending command (%s):\n\n%s\r\n\n",
46              (sock == &sockpri ? "primary" : "auxiliary"), cmd);              (conn == &connpri ? "primary" : "auxiliary"), cmd);
47  #endif  #endif
48    
49          socket_write(sock, cmd);          socket_write(conn, cmd);
50          socket_write(sock, "\r\n");          socket_write(conn, "\r\n");
51  }  }
52    
53  #endif  #endif
# Line 58  send_command_cont(int *sock, char *cmd) Line 58  send_command_cont(int *sock, char *cmd)
58   * IMAP NOOP: does nothing always succeeds.   * IMAP NOOP: does nothing always succeeds.
59   */   */
60  int  int
61  imap_noop(int *sock)  imap_noop(conn_t * conn)
62  {  {
63          reset_buffer(&obuf);          reset_buffer(&obuf);
64          check_buffer(&obuf, strlen("NOOP") + 12);          check_buffer(&obuf, strlen("NOOP") + 12);
65    
66          snprintf(obuf.data, obuf.size, "%08X NOOP\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X NOOP\r\n", tag);
67    
68          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
69  }  }
70    
71  #endif  #endif
# Line 75  imap_noop(int *sock) Line 75  imap_noop(int *sock)
75   * IMAP CAPABILITY: requests listing of capabilities that the server supports.   * IMAP CAPABILITY: requests listing of capabilities that the server supports.
76   */   */
77  int  int
78  imap_capability(int *sock)  imap_capability(conn_t * conn)
79  {  {
80          reset_buffer(&obuf);          reset_buffer(&obuf);
81          check_buffer(&obuf, strlen("CAPABILITY") + 12);          check_buffer(&obuf, strlen("CAPABILITY") + 12);
82    
83          snprintf(obuf.data, obuf.size, "%08X CAPABILITY\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X CAPABILITY\r\n", tag);
84    
85          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
86  }  }
87    
88    
# Line 91  imap_capability(int *sock) Line 91  imap_capability(int *sock)
91   * the server for mailboxes (RFC 2342).   * the server for mailboxes (RFC 2342).
92   */   */
93  int  int
94  imap_namespace(int *sock)  imap_namespace(conn_t * conn)
95  {  {
96          reset_buffer(&obuf);          reset_buffer(&obuf);
97          check_buffer(&obuf, strlen("NAMESPACE") + 12);          check_buffer(&obuf, strlen("NAMESPACE") + 12);
98    
99          snprintf(obuf.data, obuf.size, "%08X NAMESPACE\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X NAMESPACE\r\n", tag);
100    
101          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
102  }  }
103    
104    
# Line 106  imap_namespace(int *sock) Line 106  imap_namespace(int *sock)
106   * IMAP LOGOUT: informs server that client is done.   * IMAP LOGOUT: informs server that client is done.
107   */   */
108  int  int
109  imap_logout(int *sock)  imap_logout(conn_t * conn)
110  {  {
111          reset_buffer(&obuf);          reset_buffer(&obuf);
112          check_buffer(&obuf, strlen("LOGOUT") + 12);          check_buffer(&obuf, strlen("LOGOUT") + 12);
113    
114          snprintf(obuf.data, obuf.size, "%08X LOGOUT\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X LOGOUT\r\n", tag);
115    
116          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
117  }  }
118    
119    
# Line 121  imap_logout(int *sock) Line 121  imap_logout(int *sock)
121   * IMAP STARTTLS: begin TLS negotiation.   * IMAP STARTTLS: begin TLS negotiation.
122   */   */
123  int  int
124  imap_starttls(int *sock)  imap_starttls(conn_t * conn)
125  {  {
126          reset_buffer(&obuf);          reset_buffer(&obuf);
127          check_buffer(&obuf, strlen("STARTTLS") + 12);          check_buffer(&obuf, strlen("STARTTLS") + 12);
128    
129          snprintf(obuf.data, obuf.size, "%08X STARTTLS\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X STARTTLS\r\n", tag);
130    
131          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
132  }  }
133    
134    
# Line 138  imap_starttls(int *sock) Line 138  imap_starttls(int *sock)
138   * authentication protocol exchange.   * authentication protocol exchange.
139   */   */
140  int  int
141  imap_authenticate(int *sock, char *auth, int cont)  imap_authenticate(conn_t * conn, char *auth, int cont)
142  {  {
143          reset_buffer(&obuf);          reset_buffer(&obuf);
144          check_buffer(&obuf, strlen("AUTHENTICATE") + 12);          check_buffer(&obuf, strlen("AUTHENTICATE") + 12);
# Line 146  imap_authenticate(int *sock, char *auth, Line 146  imap_authenticate(int *sock, char *auth,
146          if (!cont) {          if (!cont) {
147                  snprintf(obuf.data, obuf.size, "%08X AUTHENTICATE %s\r\n",                  snprintf(obuf.data, obuf.size, "%08X AUTHENTICATE %s\r\n",
148                      tag, auth);                      tag, auth);
149                  return send_command(sock, obuf.data);                  return send_command(conn, obuf.data);
150          } else {          } else {
151                  send_command_cont(sock, auth);                  send_command_cont(conn, auth);
152                  return 0;                  return 0;
153          }          }
154  }  }
# Line 160  imap_authenticate(int *sock, char *auth, Line 160  imap_authenticate(int *sock, char *auth,
160   * IMAP LOGIN: identifies client to server.   * IMAP LOGIN: identifies client to server.
161   */   */
162  int  int
163  imap_login(int *sock, char *user, char *pass)  imap_login(conn_t * conn, char *user, char *pass)
164  {  {
165          int r, n;          int r, n;
166          char *sbuf;          char *sbuf;
# Line 170  imap_login(int *sock, char *user, char * Line 170  imap_login(int *sock, char *user, char *
170    
171          snprintf(sbuf, n, "%08X LOGIN \"%s\" \"%s\"\r\n", tag, user, pass);          snprintf(sbuf, n, "%08X LOGIN \"%s\" \"%s\"\r\n", tag, user, pass);
172    
173          r = send_command(sock, sbuf);          r = send_command(conn, sbuf);
174    
175          sfree(sbuf);          sfree(sbuf);
176    
# Line 182  imap_login(int *sock, char *user, char * Line 182  imap_login(int *sock, char *user, char *
182   * IMAP LIST: returns a subset of names from the complete set of names   * IMAP LIST: returns a subset of names from the complete set of names
183   * available to the client.   * available to the client.
184   *   *
185  int imap_list(int *sock, char *refer, char *mbox)  int imap_list(conn_t *conn, char *refer, char *mbox)
186  {  {
187          int r;          int r;
188                    
# Line 192  int imap_list(int *sock, char *refer, ch Line 192  int imap_list(int *sock, char *refer, ch
192          snprintf(obuf.data, obuf.size, "%08X LIST \"%s\" \"%s\"\r\n", tag,          snprintf(obuf.data, obuf.size, "%08X LIST \"%s\" \"%s\"\r\n", tag,
193              refer, mbox);              refer, mbox);
194    
195          r = send_command(sock, obuf.data);          r = send_command(conn, obuf.data);
196    
197          return r;          return r;
198  }*/  }*/
# Line 203  int imap_list(int *sock, char *refer, ch Line 203  int imap_list(int *sock, char *refer, ch
203   * set of "active" or "subscribed" mailboxes.   * set of "active" or "subscribed" mailboxes.
204   */   */
205  int  int
206  imap_subscribe(int *sock, char *mbox)  imap_subscribe(conn_t * conn, char *mbox)
207  {  {
208          reset_buffer(&obuf);          reset_buffer(&obuf);
209          check_buffer(&obuf, strlen("SUBSCRIBE") + strlen(mbox) + 15);          check_buffer(&obuf, strlen("SUBSCRIBE") + strlen(mbox) + 15);
210    
211          snprintf(obuf.data, obuf.size, "%08X SUBSCRIBE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%08X SUBSCRIBE \"%s\"\r\n", tag, mbox);
212    
213          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
214  }  }
215    
216    
# Line 218  imap_subscribe(int *sock, char *mbox) Line 218  imap_subscribe(int *sock, char *mbox)
218   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
219   *   *
220  int  int
221  imap_examine(int *sock, char *mbox)  imap_examine(conn_t *conn, char *mbox)
222  {  {
223          reset_buffer(&obuf);          reset_buffer(&obuf);
224          check_buffer(&obuf, strlen("EXAMINE") + strlen(mbox) + 15);          check_buffer(&obuf, strlen("EXAMINE") + strlen(mbox) + 15);
225    
226          snprintf(obuf.data, MEDIUM_CMD, "%08X EXAMINE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, MEDIUM_CMD, "%08X EXAMINE \"%s\"\r\n", tag, mbox);
227    
228          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
229  }*/  }*/
230    
231    
# Line 233  imap_examine(int *sock, char *mbox) Line 233  imap_examine(int *sock, char *mbox)
233   * IMAP SELECT: access a mailbox in READ-WRITE mode.   * IMAP SELECT: access a mailbox in READ-WRITE mode.
234   */   */
235  int  int
236  imap_select(int *sock, char *mbox)  imap_select(conn_t * conn, char *mbox)
237  {  {
238          reset_buffer(&obuf);          reset_buffer(&obuf);
239          check_buffer(&obuf, strlen("SELECT") + strlen(mbox) + 15);          check_buffer(&obuf, strlen("SELECT") + strlen(mbox) + 15);
240    
241          snprintf(obuf.data, obuf.size, "%08X SELECT \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%08X SELECT \"%s\"\r\n", tag, mbox);
242    
243          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
244  }  }
245    
246    
# Line 248  imap_select(int *sock, char *mbox) Line 248  imap_select(int *sock, char *mbox)
248   * IMAP STATUS: requests status of the indicated mailbox.   * IMAP STATUS: requests status of the indicated mailbox.
249   */   */
250  int  int
251  imap_status(int *sock, char *mbox, char *items)  imap_status(conn_t * conn, char *mbox, char *items)
252  {  {
253          reset_buffer(&obuf);          reset_buffer(&obuf);
254          check_buffer(&obuf, strlen("STATUS") + strlen(mbox) +          check_buffer(&obuf, strlen("STATUS") + strlen(mbox) +
# Line 256  imap_status(int *sock, char *mbox, char Line 256  imap_status(int *sock, char *mbox, char
256    
257          snprintf(obuf.data, obuf.size, "%08X 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, obuf.data);          return send_command(conn, obuf.data);
260  }  }
261    
262    
# Line 264  imap_status(int *sock, char *mbox, char Line 264  imap_status(int *sock, char *mbox, char
264   * IMAP CREATE: create mailbox.   * IMAP CREATE: create mailbox.
265   */   */
266  int  int
267  imap_create(int *sock, char *mbox)  imap_create(conn_t * conn, char *mbox)
268  {  {
269          reset_buffer(&obuf);          reset_buffer(&obuf);
270          check_buffer(&obuf, strlen("CREATE") + strlen(mbox) + 14);          check_buffer(&obuf, strlen("CREATE") + strlen(mbox) + 14);
271    
272          snprintf(obuf.data, obuf.size, "%08X CREATE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%08X CREATE \"%s\"\r\n", tag, mbox);
273    
274          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
275  }  }
276    
277    
# Line 279  imap_create(int *sock, char *mbox) Line 279  imap_create(int *sock, char *mbox)
279   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
280   */   */
281  int  int
282  imap_search(int *sock, char *charset, char *search)  imap_search(conn_t * conn, char *charset, char *search)
283  {  {
284          reset_buffer(&obuf);          reset_buffer(&obuf);
285          check_buffer(&obuf, strlen("SEARCH CHARSET") + strlen(charset) +          check_buffer(&obuf, strlen("SEARCH CHARSET") + strlen(charset) +
# Line 291  imap_search(int *sock, char *charset, ch Line 291  imap_search(int *sock, char *charset, ch
291          else          else
292                  snprintf(obuf.data, obuf.size, "%08X SEARCH %s\r\n", tag, search);                  snprintf(obuf.data, obuf.size, "%08X SEARCH %s\r\n", tag, search);
293    
294          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
295  }  }
296    
297    
# Line 299  imap_search(int *sock, char *charset, ch Line 299  imap_search(int *sock, char *charset, ch
299   * IMAP FETCH: retrieves data associated with a message.   * IMAP FETCH: retrieves data associated with a message.
300   */   */
301  int  int
302  imap_fetch(int *sock, char *mesg, char *items)  imap_fetch(conn_t * conn, char *mesg, char *items)
303  {  {
304          reset_buffer(&obuf);          reset_buffer(&obuf);
305          check_buffer(&obuf, strlen("FETCH") + strlen(mesg) + strlen(items) + 14);          check_buffer(&obuf, strlen("FETCH") + strlen(mesg) + strlen(items) + 14);
306    
307          snprintf(obuf.data, obuf.size, "%08X 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, obuf.data);          return send_command(conn, obuf.data);
310  }  }
311    
312    
# Line 314  imap_fetch(int *sock, char *mesg, char * Line 314  imap_fetch(int *sock, char *mesg, char *
314   * IMAP STORE: alters data associated with a message.   * IMAP STORE: alters data associated with a message.
315   */   */
316  int  int
317  imap_store(int *sock, char *mesg, unsigned int mode, char *flags)  imap_store(conn_t * conn, char *mesg, unsigned int mode, char *flags)
318  {  {
319          reset_buffer(&obuf);          reset_buffer(&obuf);
320          check_buffer(&obuf, strlen("STORE") + strlen(mesg) +          check_buffer(&obuf, strlen("STORE") + strlen(mesg) +
# Line 324  imap_store(int *sock, char *mesg, unsign Line 324  imap_store(int *sock, char *mesg, unsign
324              tag, 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, obuf.data);          return send_command(conn, obuf.data);
328  }  }
329    
330    
# Line 332  imap_store(int *sock, char *mesg, unsign Line 332  imap_store(int *sock, char *mesg, unsign
332   * IMAP COPY: copy messages to mailbox.   * IMAP COPY: copy messages to mailbox.
333   */   */
334  int  int
335  imap_copy(int *sock, char *mesg, char *mbox)  imap_copy(conn_t * conn, char *mesg, char *mbox)
336  {  {
337          reset_buffer(&obuf);          reset_buffer(&obuf);
338          check_buffer(&obuf, strlen("COPY") + strlen(mesg) + strlen(mbox) + 16);          check_buffer(&obuf, strlen("COPY") + strlen(mesg) + strlen(mbox) + 16);
339    
340          snprintf(obuf.data, obuf.size, "%08X 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, obuf.data);          return send_command(conn, obuf.data);
343  }  }
344    
345    
# Line 347  imap_copy(int *sock, char *mesg, char *m Line 347  imap_copy(int *sock, char *mesg, char *m
347   * IMAP APPEND: append message to the end of a mailbox.   * IMAP APPEND: append message to the end of a mailbox.
348   */   */
349  int  int
350  imap_append(int *sock, char *mbox, unsigned int size)  imap_append(conn_t * conn, char *mbox, unsigned int size)
351  {  {
352          reset_buffer(&obuf);          reset_buffer(&obuf);
353          check_buffer(&obuf, strlen("APPEND") + strlen(mbox) +          check_buffer(&obuf, strlen("APPEND") + strlen(mbox) +
# Line 356  imap_append(int *sock, char *mbox, unsig Line 356  imap_append(int *sock, char *mbox, unsig
356          snprintf(obuf.data, obuf.size, "%08X APPEND \"%s\" {%d}\r\n", tag, mbox,          snprintf(obuf.data, obuf.size, "%08X APPEND \"%s\" {%d}\r\n", tag, mbox,
357              size);              size);
358    
359          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
360  }  }
361    
362    
# Line 365  imap_append(int *sock, char *mbox, unsig Line 365  imap_append(int *sock, char *mbox, unsig
365   * IMAP CLOSE: delete messages and return to authenticated state.   * IMAP CLOSE: delete messages and return to authenticated state.
366   */   */
367  int  int
368  imap_close(int *sock)  imap_close(conn_t * conn)
369  {  {
370          reset_buffer(&obuf);          reset_buffer(&obuf);
371          check_buffer(&obuf, strlen("CLOSE") + 12);          check_buffer(&obuf, strlen("CLOSE") + 12);
372    
373          snprintf(obuf.data, obuf.size, "%08X CLOSE\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X CLOSE\r\n", tag);
374    
375          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
376  }  }
377    
378    
# Line 380  imap_close(int *sock) Line 380  imap_close(int *sock)
380   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
381   */   */
382  int  int
383  imap_expunge(int *sock)  imap_expunge(conn_t * conn)
384  {  {
385          reset_buffer(&obuf);          reset_buffer(&obuf);
386          check_buffer(&obuf, strlen("EXPUNGE") + 12);          check_buffer(&obuf, strlen("EXPUNGE") + 12);
387    
388          snprintf(obuf.data, obuf.size, "%08X EXPUNGE\r\n", tag);          snprintf(obuf.data, obuf.size, "%08X EXPUNGE\r\n", tag);
389    
390          return send_command(sock, obuf.data);          return send_command(conn, obuf.data);
391  }  }

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26