Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/imap/cmd-idle.c @ 2322:aae574ed7f4c HEAD
Broke mailbox_sync() into iterator.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 12 Jul 2004 14:35:50 +0300 |
parents | 79790750c349 |
children | d141e1bfdd63 |
rev | line source |
---|---|
1172 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "common.h" | |
4 #include "ioloop.h" | |
5 #include "istream.h" | |
1225
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
6 #include "ostream.h" |
1172 | 7 #include "commands.h" |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
8 #include "imap-sync.h" |
1172 | 9 |
10 #include <stdlib.h> | |
11 | |
12 #define DEFAULT_IDLE_CHECK_INTERVAL 30 | |
13 | |
1220 | 14 static void idle_finish(struct client *client, int done_ok) |
1172 | 15 { |
1212 | 16 if (client->idle_to != NULL) { |
17 timeout_remove(client->idle_to); | |
18 client->idle_to = NULL; | |
19 } | |
20 | |
1225
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
21 o_stream_cork(client->output); |
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
22 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
23 if (client->idle_expunge != 0) { |
1212 | 24 client_send_line(client, |
25 t_strdup_printf("* %u EXPUNGE", client->idle_expunge)); | |
26 } | |
27 | |
1172 | 28 io_remove(client->io); |
29 client->io = io_add(i_stream_get_fd(client->input), | |
30 IO_READ, _client_input, client); | |
31 | |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
32 if (client->mailbox != NULL) |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
33 mailbox_notify_changes(client->mailbox, 0, NULL, NULL); |
1172 | 34 |
35 client_sync_full(client); | |
1220 | 36 if (done_ok) |
37 client_send_tagline(client, "OK Idle completed."); | |
38 else | |
39 client_send_tagline(client, "BAD Expected DONE."); | |
40 | |
1225
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
41 o_stream_flush(client->output); |
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
42 |
1220 | 43 _client_reset_command(client); |
44 client->bad_counter = 0; | |
1172 | 45 } |
46 | |
47 static void idle_client_input(void *context) | |
48 { | |
49 struct client *client = context; | |
50 char *line; | |
51 | |
52 client->last_input = ioloop_time; | |
53 | |
54 switch (i_stream_read(client->input)) { | |
55 case -1: | |
56 /* disconnected */ | |
57 client_destroy(client); | |
58 return; | |
59 case -2: | |
60 client->input_skip_line = TRUE; | |
1220 | 61 idle_finish(client, FALSE); |
1221 | 62 return; |
1172 | 63 } |
64 | |
65 while ((line = i_stream_next_line(client->input)) != NULL) { | |
66 if (client->input_skip_line) | |
67 client->input_skip_line = FALSE; | |
68 else { | |
1220 | 69 idle_finish(client, strcmp(line, "DONE") == 0); |
1172 | 70 break; |
71 } | |
72 } | |
73 } | |
74 | |
1212 | 75 static void idle_timeout(void *context) |
76 { | |
77 struct client *client = context; | |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
78 |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
79 /* outlook workaround - it hasn't sent anything for a long time and |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
80 we're about to disconnect unless it does something. send a fake |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
81 EXISTS to see if it responds. it's expunged later. */ |
1212 | 82 |
83 timeout_remove(client->idle_to); | |
84 client->idle_to = NULL; | |
85 | |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
86 client->idle_expunge = client->messages_count+1; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
87 client_send_line(client, |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
88 t_strdup_printf("* %u EXISTS", client->idle_expunge)); |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
89 mailbox_notify_changes(client->mailbox, 0, NULL, NULL); |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
90 } |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
91 |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
92 static void idle_callback(struct mailbox *box, void *context) |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
93 { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
94 struct client *client = context; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
95 |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
96 if (imap_sync(client, box, 0) < 0) { |
1654
31c4bb26a1e9
Getting ready for namespaces. LIST is still broken with them.
Timo Sirainen <tss@iki.fi>
parents:
1225
diff
changeset
|
97 client_send_untagged_storage_error(client, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1732
diff
changeset
|
98 mailbox_get_storage(client->mailbox)); |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
99 mailbox_notify_changes(client->mailbox, 0, NULL, NULL); |
1212 | 100 } |
101 } | |
102 | |
1172 | 103 int cmd_idle(struct client *client) |
104 { | |
105 const char *str; | |
106 unsigned int interval; | |
107 | |
1212 | 108 client->idle_expunge = 0; |
1225
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
109 if ((client_workarounds & WORKAROUND_OUTLOOK_IDLE) != 0 && |
8c85c03e0485
cork the output before sending the ending IDLE replies.
Timo Sirainen <tss@iki.fi>
parents:
1221
diff
changeset
|
110 client->mailbox != NULL) { |
1212 | 111 client->idle_to = timeout_add((CLIENT_IDLE_TIMEOUT - 60) * 1000, |
112 idle_timeout, client); | |
113 } | |
114 | |
1172 | 115 str = getenv("MAILBOX_IDLE_CHECK_INTERVAL"); |
116 interval = str == NULL ? 0 : (unsigned int)strtoul(str, NULL, 10); | |
117 if (interval == 0) | |
118 interval = DEFAULT_IDLE_CHECK_INTERVAL; | |
119 | |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
120 if (client->mailbox != NULL) { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
121 mailbox_notify_changes(client->mailbox, interval, |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
122 idle_callback, client); |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
123 } |
1172 | 124 client_send_line(client, "+ idling"); |
125 | |
126 io_remove(client->io); | |
127 client->io = io_add(i_stream_get_fd(client->input), | |
128 IO_READ, idle_client_input, client); | |
129 return FALSE; | |
130 } |