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

Diff of /imapfilter/imap.c

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

revision 1.43 by lefcha, Wed Feb 11 00:03:46 2004 UTC revision 1.44 by lefcha, Fri Feb 13 12:17:16 2004 UTC
# Line 3  Line 3 
3    
4  #include "config.h"  #include "config.h"
5  #include "imapfilter.h"  #include "imapfilter.h"
6    #include "filter.h"
7  #include "buffer.h"  #include "buffer.h"
8    
9    
10  extern opts_t opts;  extern options_t opts;
11  extern conn_t connpri, connaux;  extern connection_t connpri, connaux;
12    
13  buffer_t obuf;                  /* Output buffer. */  buffer_t obuf;                  /* Output buffer. */
14    
# Line 15  static unsigned int tag = 0x1000;      /* Eve Line 16  static unsigned int tag = 0x1000;      /* Eve
16                                           * a unique [:alnum:] string. */                                           * a unique [:alnum:] string. */
17    
18    
19  unsigned int send_command(conn_t * conn, char *cmd, char *alt);  unsigned int send_command(connection_t * conn, char *cmd, char *alt);
20  void send_command_cont(conn_t * conn, char *cmd);  void send_command_cont(connection_t * conn, char *cmd);
21    
22    
23  /*  /*
24   * Send to server data; a command.   * Send to server data; a command.
25   */   */
26  unsigned int  unsigned int
27  send_command(conn_t * conn, char *cmd, char *alt)  send_command(connection_t * conn, char *cmd, char *alt)
28  {  {
29    
30          debug("sending command (%s):\n\n%s\n",          debug("sending command (%s):\n\n%s\n",
# Line 46  send_command(conn_t * conn, char *cmd, c Line 47  send_command(conn_t * conn, char *cmd, c
47   * Send to server data: a continuation command.   * Send to server data: a continuation command.
48   */   */
49  void  void
50  send_command_cont(conn_t * conn, char *cmd)  send_command_cont(connection_t * conn, char *cmd)
51  {  {
52    
53          debug("sending command (%s):\n\n%s\r\n\n",          debug("sending command (%s):\n\n%s\r\n\n",
# Line 62  send_command_cont(conn_t * conn, char *c Line 63  send_command_cont(conn_t * conn, char *c
63   * IMAP NOOP: does nothing always succeeds.   * IMAP NOOP: does nothing always succeeds.
64   */   */
65  int  int
66  imap_noop(conn_t * conn)  imap_noop(connection_t * conn)
67  {  {
68    
69          reset_buffer(&obuf);          buffer_reset(&obuf);
70          check_buffer(&obuf, strlen("NOOP") + 12);          buffer_check(&obuf, strlen("NOOP") + 12);
71    
72          snprintf(obuf.data, obuf.size, "%04X NOOP\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X NOOP\r\n", tag);
73    
# Line 78  imap_noop(conn_t * conn) Line 79  imap_noop(conn_t * conn)
79   * IMAP CAPABILITY: requests listing of capabilities that the server supports.   * IMAP CAPABILITY: requests listing of capabilities that the server supports.
80   */   */
81  int  int
82  imap_capability(conn_t * conn)  imap_capability(connection_t * conn)
83  {  {
84    
85          reset_buffer(&obuf);          buffer_reset(&obuf);
86          check_buffer(&obuf, strlen("CAPABILITY") + 12);          buffer_check(&obuf, strlen("CAPABILITY") + 12);
87    
88          snprintf(obuf.data, obuf.size, "%04X CAPABILITY\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X CAPABILITY\r\n", tag);
89    
# Line 95  imap_capability(conn_t * conn) Line 96  imap_capability(conn_t * conn)
96   * the server for mailboxes (RFC 2342).   * the server for mailboxes (RFC 2342).
97   */   */
98  int  int
99  imap_namespace(conn_t * conn)  imap_namespace(connection_t * conn)
100  {  {
101    
102          reset_buffer(&obuf);          buffer_reset(&obuf);
103          check_buffer(&obuf, strlen("NAMESPACE") + 12);          buffer_check(&obuf, strlen("NAMESPACE") + 12);
104    
105          snprintf(obuf.data, obuf.size, "%04X NAMESPACE\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X NAMESPACE\r\n", tag);
106    
# Line 111  imap_namespace(conn_t * conn) Line 112  imap_namespace(conn_t * conn)
112   * IMAP LOGOUT: informs server that client is done.   * IMAP LOGOUT: informs server that client is done.
113   */   */
114  int  int
115  imap_logout(conn_t * conn)  imap_logout(connection_t * conn)
116  {  {
117    
118          reset_buffer(&obuf);          buffer_reset(&obuf);
119          check_buffer(&obuf, strlen("LOGOUT") + 12);          buffer_check(&obuf, strlen("LOGOUT") + 12);
120    
121          snprintf(obuf.data, obuf.size, "%04X LOGOUT\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X LOGOUT\r\n", tag);
122    
# Line 127  imap_logout(conn_t * conn) Line 128  imap_logout(conn_t * conn)
128   * IMAP STARTTLS: begin TLS negotiation.   * IMAP STARTTLS: begin TLS negotiation.
129   */   */
130  int  int
131  imap_starttls(conn_t * conn)  imap_starttls(connection_t * conn)
132  {  {
133    
134          reset_buffer(&obuf);          buffer_reset(&obuf);
135          check_buffer(&obuf, strlen("STARTTLS") + 12);          buffer_check(&obuf, strlen("STARTTLS") + 12);
136    
137          snprintf(obuf.data, obuf.size, "%04X STARTTLS\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X STARTTLS\r\n", tag);
138    
# Line 145  imap_starttls(conn_t * conn) Line 146  imap_starttls(conn_t * conn)
146   * authentication protocol exchange.   * authentication protocol exchange.
147   */   */
148  int  int
149  imap_authenticate(conn_t * conn, char *auth, int cont)  imap_authenticate(connection_t * conn, char *auth, int cont)
150  {  {
151    
152          reset_buffer(&obuf);          buffer_reset(&obuf);
153          check_buffer(&obuf, strlen("AUTHENTICATE") + 12);          buffer_check(&obuf, strlen("AUTHENTICATE") + 12);
154    
155          if (!cont) {          if (!cont) {
156                  snprintf(obuf.data, obuf.size, "%04X AUTHENTICATE %s\r\n",                  snprintf(obuf.data, obuf.size, "%04X AUTHENTICATE %s\r\n",
# Line 167  imap_authenticate(conn_t * conn, char *a Line 168  imap_authenticate(conn_t * conn, char *a
168   * IMAP LOGIN: identifies client to server.   * IMAP LOGIN: identifies client to server.
169   */   */
170  int  int
171  imap_login(conn_t * conn, char *user, char *pass)  imap_login(connection_t * conn, char *user, char *pass)
172  {  {
173          int r, n;          int r, n;
174          char *sbuf;          char *sbuf;
# Line 178  imap_login(conn_t * conn, char *user, ch Line 179  imap_login(conn_t * conn, char *user, ch
179          snprintf(sbuf, n, "%04X LOGIN \"%s\" \"%s\"\r\n", tag, user, pass);          snprintf(sbuf, n, "%04X LOGIN \"%s\" \"%s\"\r\n", tag, user, pass);
180    
181          /* Alternate command with password shrouded for safe printing. */          /* Alternate command with password shrouded for safe printing. */
182          reset_buffer(&obuf);          buffer_reset(&obuf);
183          check_buffer(&obuf, strlen("LOGIN") + strlen(user) + 18);          buffer_check(&obuf, strlen("LOGIN") + strlen(user) + 18);
184          snprintf(obuf.data, obuf.size, "%04X LOGIN \"%s\" *\r\n", tag, user);          snprintf(obuf.data, obuf.size, "%04X LOGIN \"%s\" *\r\n", tag, user);
185    
186          r = send_command(conn, sbuf, obuf.data);          r = send_command(conn, sbuf, obuf.data);
# Line 194  imap_login(conn_t * conn, char *user, ch Line 195  imap_login(conn_t * conn, char *user, ch
195   * 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
196   * available to the client.   * available to the client.
197   *   *
198  int imap_list(conn_t *conn, char *refer, char *mbox)  int imap_list(connection_t *conn, char *refer, char *mbox)
199  {  {
200    
201          reset_buffer(&obuf);          buffer_reset(&obuf);
202          check_buffer(&obuf, strlen("LIST") + strlen(refer) + strlen(mbox) + 18);          buffer_check(&obuf, strlen("LIST") + strlen(refer) + strlen(mbox) + 18);
203                    
204          snprintf(obuf.data, obuf.size, "%04X LIST \"%s\" \"%s\"\r\n", tag,          snprintf(obuf.data, obuf.size, "%04X LIST \"%s\" \"%s\"\r\n", tag,
205              refer, mbox);              refer, mbox);
# Line 212  int imap_list(conn_t *conn, char *refer, Line 213  int imap_list(conn_t *conn, char *refer,
213   * set of "active" or "subscribed" mailboxes.   * set of "active" or "subscribed" mailboxes.
214   */   */
215  int  int
216  imap_subscribe(conn_t * conn, char *mbox)  imap_subscribe(connection_t * conn, char *mbox)
217  {  {
218    
219          reset_buffer(&obuf);          buffer_reset(&obuf);
220          check_buffer(&obuf, strlen("SUBSCRIBE") + strlen(mbox) + 15);          buffer_check(&obuf, strlen("SUBSCRIBE") + strlen(mbox) + 15);
221    
222          snprintf(obuf.data, obuf.size, "%04X SUBSCRIBE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%04X SUBSCRIBE \"%s\"\r\n", tag, mbox);
223    
# Line 228  imap_subscribe(conn_t * conn, char *mbox Line 229  imap_subscribe(conn_t * conn, char *mbox
229   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
230   *   *
231  int  int
232  imap_examine(conn_t *conn, char *mbox)  imap_examine(connection_t *conn, char *mbox)
233  {  {
234    
235          reset_buffer(&obuf);          buffer_reset(&obuf);
236          check_buffer(&obuf, strlen("EXAMINE") + strlen(mbox) + 15);          buffer_check(&obuf, strlen("EXAMINE") + strlen(mbox) + 15);
237    
238          snprintf(obuf.data, MEDIUM_CMD, "%04X EXAMINE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, MEDIUM_CMD, "%04X EXAMINE \"%s\"\r\n", tag, mbox);
239    
# Line 244  imap_examine(conn_t *conn, char *mbox) Line 245  imap_examine(conn_t *conn, char *mbox)
245   * IMAP SELECT: access a mailbox in READ-WRITE mode.   * IMAP SELECT: access a mailbox in READ-WRITE mode.
246   */   */
247  int  int
248  imap_select(conn_t * conn, char *mbox)  imap_select(connection_t * conn, char *mbox)
249  {  {
250    
251          reset_buffer(&obuf);          buffer_reset(&obuf);
252          check_buffer(&obuf, strlen("SELECT") + strlen(mbox) + 15);          buffer_check(&obuf, strlen("SELECT") + strlen(mbox) + 15);
253    
254          snprintf(obuf.data, obuf.size, "%04X SELECT \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%04X SELECT \"%s\"\r\n", tag, mbox);
255    
# Line 260  imap_select(conn_t * conn, char *mbox) Line 261  imap_select(conn_t * conn, char *mbox)
261   * IMAP STATUS: requests status of the indicated mailbox.   * IMAP STATUS: requests status of the indicated mailbox.
262   */   */
263  int  int
264  imap_status(conn_t * conn, char *mbox, char *items)  imap_status(connection_t * conn, char *mbox, char *items)
265  {  {
266    
267          reset_buffer(&obuf);          buffer_reset(&obuf);
268          check_buffer(&obuf, strlen("STATUS") + strlen(mbox) +          buffer_check(&obuf, strlen("STATUS") + strlen(mbox) +
269              strlen(items) + 18);              strlen(items) + 18);
270    
271          snprintf(obuf.data, obuf.size, "%04X STATUS \"%s\" (%s)\r\n", tag, mbox, items);          snprintf(obuf.data, obuf.size, "%04X STATUS \"%s\" (%s)\r\n", tag, mbox, items);
# Line 277  imap_status(conn_t * conn, char *mbox, c Line 278  imap_status(conn_t * conn, char *mbox, c
278   * IMAP CREATE: create mailbox.   * IMAP CREATE: create mailbox.
279   */   */
280  int  int
281  imap_create(conn_t * conn, char *mbox)  imap_create(connection_t * conn, char *mbox)
282  {  {
283    
284          reset_buffer(&obuf);          buffer_reset(&obuf);
285          check_buffer(&obuf, strlen("CREATE") + strlen(mbox) + 14);          buffer_check(&obuf, strlen("CREATE") + strlen(mbox) + 14);
286    
287          snprintf(obuf.data, obuf.size, "%04X CREATE \"%s\"\r\n", tag, mbox);          snprintf(obuf.data, obuf.size, "%04X CREATE \"%s\"\r\n", tag, mbox);
288    
# Line 293  imap_create(conn_t * conn, char *mbox) Line 294  imap_create(conn_t * conn, char *mbox)
294   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
295   */   */
296  int  int
297  imap_search(conn_t * conn, char *charset, char *search)  imap_search(connection_t * conn, char *charset, char *search)
298  {  {
299    
300          reset_buffer(&obuf);          buffer_reset(&obuf);
301          check_buffer(&obuf, strlen("SEARCH CHARSET") + strlen(charset) +          buffer_check(&obuf, strlen("SEARCH CHARSET") + strlen(charset) +
302              strlen(search) + 15);              strlen(search) + 15);
303    
304          if (*charset)          if (*charset)
# Line 314  imap_search(conn_t * conn, char *charset Line 315  imap_search(conn_t * conn, char *charset
315   * IMAP FETCH: retrieves data associated with a message.   * IMAP FETCH: retrieves data associated with a message.
316   */   */
317  int  int
318  imap_fetch(conn_t * conn, char *mesg, char *items)  imap_fetch(connection_t * conn, char *mesg, char *items)
319  {  {
320    
321          reset_buffer(&obuf);          buffer_reset(&obuf);
322          check_buffer(&obuf, strlen("FETCH") + strlen(mesg) + strlen(items) + 14);          buffer_check(&obuf, strlen("FETCH") + strlen(mesg) + strlen(items) + 14);
323    
324          snprintf(obuf.data, obuf.size, "%04X FETCH %s %s\r\n", tag, mesg, items);          snprintf(obuf.data, obuf.size, "%04X FETCH %s %s\r\n", tag, mesg, items);
325    
# Line 330  imap_fetch(conn_t * conn, char *mesg, ch Line 331  imap_fetch(conn_t * conn, char *mesg, ch
331   * IMAP STORE: alters data associated with a message.   * IMAP STORE: alters data associated with a message.
332   */   */
333  int  int
334  imap_store(conn_t * conn, char *mesg, unsigned int mode, char *flags)  imap_store(connection_t * conn, char *mesg, unsigned int mode, char *flags)
335  {  {
336    
337          reset_buffer(&obuf);          buffer_reset(&obuf);
338          check_buffer(&obuf, strlen("STORE") + strlen(mesg) +          buffer_check(&obuf, strlen("STORE") + strlen(mesg) +
339              strlen("FLAGS.SILENT") + strlen(flags) + 18);              strlen("FLAGS.SILENT") + strlen(flags) + 18);
340    
341          snprintf(obuf.data, obuf.size, "%04X STORE %s %sFLAGS.SILENT (%s)\r\n",          snprintf(obuf.data, obuf.size, "%04X STORE %s %sFLAGS.SILENT (%s)\r\n",
342              tag, mesg, (mode == STORE_FLAG_REPLACE ? "" :              tag, mesg, (mode == ACTION_FLAG_REPLACE ? "" :
343                  mode == STORE_FLAG_ADD ? "+" : "-"), flags);                  mode == ACTION_FLAG_ADD ? "+" : "-"), flags);
344    
345          return send_command(conn, obuf.data, NULL);          return send_command(conn, obuf.data, NULL);
346  }  }
# Line 349  imap_store(conn_t * conn, char *mesg, un Line 350  imap_store(conn_t * conn, char *mesg, un
350   * IMAP COPY: copy messages to mailbox.   * IMAP COPY: copy messages to mailbox.
351   */   */
352  int  int
353  imap_copy(conn_t * conn, char *mesg, char *mbox)  imap_copy(connection_t * conn, char *mesg, char *mbox)
354  {  {
355    
356          reset_buffer(&obuf);          buffer_reset(&obuf);
357          check_buffer(&obuf, strlen("COPY") + strlen(mesg) + strlen(mbox) + 16);          buffer_check(&obuf, strlen("COPY") + strlen(mesg) + strlen(mbox) + 16);
358    
359          snprintf(obuf.data, obuf.size, "%04X COPY %s \"%s\"\r\n", tag, mesg, mbox);          snprintf(obuf.data, obuf.size, "%04X COPY %s \"%s\"\r\n", tag, mesg, mbox);
360    
# Line 365  imap_copy(conn_t * conn, char *mesg, cha Line 366  imap_copy(conn_t * conn, char *mesg, cha
366   * IMAP APPEND: append message to the end of a mailbox.   * IMAP APPEND: append message to the end of a mailbox.
367   */   */
368  int  int
369  imap_append(conn_t * conn, char *mbox, char *flags, char *date, unsigned int size)  imap_append(connection_t * conn, char *mbox, char *flags, char *date, unsigned int size)
370  {  {
371    
372          reset_buffer(&obuf);          buffer_reset(&obuf);
373          check_buffer(&obuf, strlen("APPEND") + strlen(mbox) + strlen(flags) +          buffer_check(&obuf, strlen("APPEND") + strlen(mbox) + strlen(flags) +
374              strlen(date) + strlen(ultostr(size, 10)) + 24);              strlen(date) + strlen(ultostr(size, 10)) + 24);
375    
376          snprintf(obuf.data, obuf.size, "%04X APPEND \"%s\" (%s) \"%s\" {%d}\r\n",          snprintf(obuf.data, obuf.size, "%04X APPEND \"%s\" (%s) \"%s\" {%d}\r\n",
# Line 384  imap_append(conn_t * conn, char *mbox, c Line 385  imap_append(conn_t * conn, char *mbox, c
385   * IMAP CLOSE: delete messages and return to authenticated state.   * IMAP CLOSE: delete messages and return to authenticated state.
386   */   */
387  int  int
388  imap_close(conn_t * conn)  imap_close(connection_t * conn)
389  {  {
390    
391          reset_buffer(&obuf);          buffer_reset(&obuf);
392          check_buffer(&obuf, strlen("CLOSE") + 12);          buffer_check(&obuf, strlen("CLOSE") + 12);
393    
394          snprintf(obuf.data, obuf.size, "%04X CLOSE\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X CLOSE\r\n", tag);
395    
# Line 400  imap_close(conn_t * conn) Line 401  imap_close(conn_t * conn)
401   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
402   */   */
403  int  int
404  imap_expunge(conn_t * conn)  imap_expunge(connection_t * conn)
405  {  {
406    
407          reset_buffer(&obuf);          buffer_reset(&obuf);
408          check_buffer(&obuf, strlen("EXPUNGE") + 12);          buffer_check(&obuf, strlen("EXPUNGE") + 12);
409    
410          snprintf(obuf.data, obuf.size, "%04X EXPUNGE\r\n", tag);          snprintf(obuf.data, obuf.size, "%04X EXPUNGE\r\n", tag);
411    

Legend:
Removed from v.1.43  
changed lines
  Added in v.1.44

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26