Implements IDLE command (rfc 2177)
Showing
1 changed file
with
56 additions
and
0 deletions
imap4d/idle.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2003 Free Software Foundation, Inc. | ||
3 | |||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Mailutils is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Mailutils; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #include "imap4d.h" | ||
19 | |||
20 | int | ||
21 | imap4d_idle (struct imap4d_command *command, char *arg) | ||
22 | { | ||
23 | char *sp; | ||
24 | |||
25 | if (util_getword (arg, &sp)) | ||
26 | return util_finish (command, RESP_BAD, "Too many args"); | ||
27 | |||
28 | if (util_wait_input (0) == -1) | ||
29 | return util_finish (command, RESP_NO, "Cannot idle"); | ||
30 | |||
31 | util_send ("+ idling\r\n"); | ||
32 | util_flush_output (); | ||
33 | |||
34 | while (1) | ||
35 | { | ||
36 | if (util_wait_input (5)) | ||
37 | { | ||
38 | int rc; | ||
39 | char *p; | ||
40 | char *cmd = imap4d_readline (); | ||
41 | |||
42 | p = util_getword (cmd, &sp); | ||
43 | rc = strcasecmp (p, "done") == 0; | ||
44 | |||
45 | free (cmd); | ||
46 | if (rc) | ||
47 | break; | ||
48 | } | ||
49 | |||
50 | imap4d_sync (); | ||
51 | util_flush_output (); | ||
52 | } | ||
53 | |||
54 | return util_finish (command, RESP_OK, "IDLE terminated"); | ||
55 | } | ||
56 |
-
Please register or sign in to post a comment