[dovecot-cvs] dovecot/src/imap cmd-idle.c,NONE,1.1 Makefile.am,1.12,1.13 client.c,1.25,1.26 client.h,1.12,1.13 cmd-select.c,1.15,1.16 commands.c,1.8,1.9 commands.h,1.9,1.10 common.h,1.4,1.5 main.c,1.26,1.27
cras at procontrol.fi
cras at procontrol.fi
Fri Feb 14 12:46:46 EET 2003
Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv6296/src/imap
Modified Files:
Makefile.am client.c client.h cmd-select.c commands.c
commands.h common.h main.c
Added Files:
cmd-idle.c
Log Message:
Support for IDLE extension.
--- NEW FILE: cmd-idle.c ---
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "istream.h"
#include "commands.h"
#include <stdlib.h>
#define DEFAULT_IDLE_CHECK_INTERVAL 30
static void idle_finish(struct client *client)
{
io_remove(client->io);
client->io = io_add(i_stream_get_fd(client->input),
IO_READ, _client_input, client);
_client_reset_command(client);
client->bad_counter = 0;
client->mailbox->auto_sync(client->mailbox,
mailbox_check_interval != 0 ?
MAILBOX_SYNC_NO_EXPUNGES : MAILBOX_SYNC_NONE,
mailbox_check_interval);
client_sync_full(client);
client_send_tagline(client, "OK Idle completed.");
}
static void idle_client_input(void *context)
{
struct client *client = context;
char *line;
client->last_input = ioloop_time;
switch (i_stream_read(client->input)) {
case -1:
/* disconnected */
client_destroy(client);
return;
case -2:
client->input_skip_line = TRUE;
client_send_line(client, "* BAD Expected DONE.");
idle_finish(client);
break;
}
while ((line = i_stream_next_line(client->input)) != NULL) {
if (client->input_skip_line)
client->input_skip_line = FALSE;
else {
if (strcmp(line, "DONE") != 0) {
client_send_line(client,
"* BAD Expected DONE.");
}
idle_finish(client);
break;
}
}
}
int cmd_idle(struct client *client)
{
const char *str;
unsigned int interval;
if (!client_verify_open_mailbox(client))
return TRUE;
str = getenv("MAILBOX_IDLE_CHECK_INTERVAL");
interval = str == NULL ? 0 : (unsigned int)strtoul(str, NULL, 10);
if (interval == 0)
interval = DEFAULT_IDLE_CHECK_INTERVAL;
client->mailbox->auto_sync(client->mailbox, MAILBOX_SYNC_ALL, interval);
client_send_line(client, "+ idling");
io_remove(client->io);
client->io = io_add(i_stream_get_fd(client->input),
IO_READ, idle_client_input, client);
return FALSE;
}
Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/imap/Makefile.am,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- Makefile.am 22 Jan 2003 20:46:36 -0000 1.12
+++ Makefile.am 14 Feb 2003 10:46:44 -0000 1.13
@@ -35,6 +35,7 @@
cmd-examine.c \
cmd-expunge.c \
cmd-fetch.c \
+ cmd-idle.c \
cmd-list.c \
cmd-login.c \
cmd-logout.c \
Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/client.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- client.c 14 Feb 2003 08:00:52 -0000 1.25
+++ client.c 14 Feb 2003 10:46:44 -0000 1.26
@@ -30,8 +30,6 @@
static struct client *my_client; /* we don't need more than one currently */
static struct timeout *to_idle;
-static void client_input(void *context);
-
static void client_output_timeout(void *context)
{
struct client *client = context;
@@ -67,7 +65,7 @@
o_stream_set_blocking(client->output, CLIENT_OUTPUT_TIMEOUT,
client_output_timeout, client);
- client->io = io_add(hin, IO_READ, client_input, client);
+ client->io = io_add(hin, IO_READ, _client_input, client);
client->parser = imap_parser_create(client->input, client->output,
MAX_INBUF_SIZE,
MAX_IMAP_ARG_ELEMENTS);
@@ -222,7 +220,7 @@
return i == count;
}
-static void client_reset_command(struct client *client)
+void _client_reset_command(struct client *client)
{
client->cmd_tag = NULL;
client->cmd_name = NULL;
@@ -260,7 +258,7 @@
client->input_skip_line = TRUE;
if (client->cmd_func(client) || client->cmd_error) {
/* command execution was finished */
- client_reset_command(client);
+ _client_reset_command(client);
client->bad_counter = 0;
return TRUE;
}
@@ -273,7 +271,7 @@
return FALSE;
/* got the newline */
- client_reset_command(client);
+ _client_reset_command(client);
/* pass through to parse next command */
}
@@ -302,20 +300,23 @@
client_send_command_error(client, t_strconcat(
"Unknown command '", client->cmd_name, "'", NULL));
client->input_skip_line = TRUE;
- client_reset_command(client);
+ _client_reset_command(client);
} else {
client->input_skip_line = TRUE;
if (client->cmd_func(client) || client->cmd_error) {
/* command execution was finished */
- client_reset_command(client);
+ _client_reset_command(client);
client->bad_counter = 0;
+ } else {
+ /* unfinished */
+ return FALSE;
}
}
return TRUE;
}
-static void client_input(void *context)
+void _client_input(void *context)
{
struct client *client = context;
@@ -333,7 +334,7 @@
client->input_skip_line = TRUE;
client_send_command_error(client, "Too long argument.");
- client_reset_command(client);
+ _client_reset_command(client);
break;
}
Index: client.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/client.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- client.h 14 Feb 2003 08:00:52 -0000 1.12
+++ client.h 14 Feb 2003 10:46:44 -0000 1.13
@@ -70,4 +70,7 @@
void clients_init(void);
void clients_deinit(void);
+void _client_input(void *context);
+void _client_reset_command(struct client *client);
+
#endif
Index: cmd-select.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/cmd-select.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- cmd-select.c 14 Feb 2003 08:00:52 -0000 1.15
+++ cmd-select.c 14 Feb 2003 10:46:44 -0000 1.16
@@ -73,6 +73,11 @@
"OK [READ-ONLY] Select completed." :
"OK [READ-WRITE] Select completed.");
+ if (mailbox_check_interval != 0) {
+ box->auto_sync(box, MAILBOX_SYNC_NO_EXPUNGES,
+ mailbox_check_interval);
+ }
+
return TRUE;
}
Index: commands.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/commands.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- commands.c 27 Jan 2003 01:59:59 -0000 1.8
+++ commands.c 14 Feb 2003 10:46:44 -0000 1.9
@@ -41,6 +41,10 @@
if (strcmp(name, "FETCH") == 0)
return cmd_fetch;
break;
+ case 'I':
+ if (strcmp(name, "IDLE") == 0)
+ return cmd_idle;
+ break;
case 'L':
if (strcmp(name, "LIST") == 0)
return cmd_list;
Index: commands.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/commands.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- commands.h 27 Jan 2003 04:23:45 -0000 1.9
+++ commands.h 14 Feb 2003 10:46:44 -0000 1.10
@@ -44,6 +44,7 @@
int cmd_copy(struct client *client);
int cmd_uid(struct client *client);
int cmd_unselect(struct client *client);
+int cmd_idle(struct client *client);
/* private: */
int _cmd_list_full(struct client *client, int subscribed);
Index: common.h
===================================================================
RCS file: /home/cvs/dovecot/src/imap/common.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- common.h 14 Feb 2003 08:00:52 -0000 1.4
+++ common.h 14 Feb 2003 10:46:44 -0000 1.5
@@ -11,6 +11,6 @@
#define DEFAULT_MAX_CUSTOM_FLAG_LENGTH 50
extern struct ioloop *ioloop;
-extern unsigned int max_custom_flag_length;
+extern unsigned int max_custom_flag_length, mailbox_check_interval;
#endif
Index: main.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/main.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- main.c 14 Feb 2003 08:00:52 -0000 1.26
+++ main.c 14 Feb 2003 10:46:44 -0000 1.27
@@ -16,7 +16,7 @@
(getenv("LOGGED_IN") == NULL)
struct ioloop *ioloop;
-unsigned int max_custom_flag_length;
+unsigned int max_custom_flag_length, mailbox_check_interval;
static char log_prefix[128]; /* syslog() needs this to be permanent */
@@ -106,6 +106,10 @@
max_custom_flag_length = str != NULL ?
(unsigned int)strtoul(str, NULL, 10) :
DEFAULT_MAX_CUSTOM_FLAG_LENGTH;
+
+ str = getenv("MAILBOX_CHECK_INTERVAL");
+ mailbox_check_interval = str == NULL ? 0 :
+ (unsigned int)strtoul(str, NULL, 10);
client = client_create(hin, hout, storage);
More information about the dovecot-cvs
mailing list