1
Author: Stephan Bosch <stephan@rename-it.nl>
2
Description: Adds support for ManageSieve
3
Origin: http://www.rename-it.nl/dovecot/1.2/dovecot-1.2.8-managesieve-0.11.9.diff.gz
4
Last-Update: 2009-11-23
6
diff -r ee1782019a60 README.managesieve
7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
8
+++ b/README.managesieve Mon Nov 23 12:21:06 2009 +0100
11
+MANAGESIEVE service support patch for Dovecot 1.2
13
+NOTICE: As per dovecot-1.1, this patch only contains the changes to the
14
+Dovecot tree that are necessary to use the now external
15
+dovecot-1.x-managesieve package. So, applying this patch is no longer
16
+the only thing you need to do to give Dovecot managesieve support.
17
+Eventually the need for this patch will disappear completely.
22
+After applying this patch you can just use the usual build process
23
+(http://wiki.dovecot.org/CompilingSource):
29
+Don't forget to execute ./autogen.sh if you downloaded dovecot from the
30
+Mercurial repository.
32
+Installation and Configuration
33
+------------------------------
35
+Read the README of the dovecot-managesieve package for the next steps.
36
+Note that this patch adds configuration examples to the dovecot-example.conf
37
+configuration file example.
39
diff -r ee1782019a60 dovecot-example.conf
40
--- a/dovecot-example.conf Thu Nov 19 19:32:13 2009 -0500
41
+++ b/dovecot-example.conf Mon Nov 23 12:21:06 2009 +0100
43
# Base directory where to store runtime data.
44
#base_dir = /var/run/dovecot/
46
-# Protocols we want to be serving: imap imaps pop3 pop3s
47
+# Protocols we want to be serving: imap imaps pop3 pop3s managesieve
48
# If you only want to use dovecot-auth, you can set this to "none".
49
#protocols = imap imaps
52
# interfaces. Use "*, [::]" for listening both IPv4 and IPv6.
54
# If you want to specify ports for each service, you will need to configure
55
-# these settings inside the protocol imap/pop3 { ... } section, so you can
56
-# specify different ports for IMAP/POP3. For example:
57
+# these settings inside the protocol imap/pop3/managesieve { ... } section,
58
+# so you can specify different ports for IMAP/POP3/MANAGESIEVE. For example:
61
# ssl_listen = *:10943
66
+# protocol managesieve {
72
# Disable LOGIN command and all other plaintext authentications unless
77
+## ManageSieve specific settings
80
+protocol managesieve {
81
+ # Login executable location.
82
+ #login_executable = /usr/libexec/dovecot/managesieve-login
84
+ # ManageSieve executable location. See IMAP's mail_executable above for
85
+ # examples how this could be changed.
86
+ #mail_executable = /usr/libexec/dovecot/managesieve
88
+ # Maximum ManageSieve command line length in bytes. This setting is
89
+ # directly borrowed from IMAP. But, since long command lines are very
90
+ # unlikely with ManageSieve, changing this will not be very useful.
91
+ #managesieve_max_line_length = 65536
93
+ # ManageSieve logout format string:
94
+ # %i - total number of bytes read from client
95
+ # %o - total number of bytes sent to client
96
+ #managesieve_logout_format = bytes=%i/%o
98
+ # To fool ManageSieve clients that are focused on timesieved you can
99
+ # specify the IMPLEMENTATION capability that the dovecot reports to clients
100
+ # (default: "dovecot").
101
+ #managesieve_implementation_string = Cyrus timsieved v2.2.13
103
+ # The ManageSieve service also uses the sieve and sieve_dir settings
104
+ # of the Sieve plugin. These are configured in the plugin {} section of
105
+ # this config file.
109
## LDA specific settings
112
@@ -1211,6 +1247,16 @@
113
# Available fields: uid, box, msgid, from, subject, size, vsize, flags
114
# size and vsize are available only for expunge and copy events.
115
#mail_log_fields = uid box msgid size
117
+ # Sieve plugin (http://wiki.dovecot.org/LDA/Sieve) and ManageSieve service
119
+ # Location of the active script. When ManageSieve is used this is actually
120
+ # a symlink pointing to the active script in the sieve storage directory.
121
+ #sieve=~/.dovecot.sieve
123
+ # The path to the directory where the personal Sieve scripts are stored. For
124
+ # ManageSieve this is where the uploaded scripts are stored.
128
# Config files can also be included. deliver doesn't support them currently.
129
diff -r ee1782019a60 src/master/child-process.c
130
--- a/src/master/child-process.c Thu Nov 19 19:32:13 2009 -0500
131
+++ b/src/master/child-process.c Mon Nov 23 12:21:06 2009 +0100
141
struct hash_table *processes;
143
return "Out of memory - see login_process_size setting";
144
case PROCESS_TYPE_IMAP:
145
case PROCESS_TYPE_POP3:
146
+ case PROCESS_TYPE_MANAGESIEVE:
147
return "Out of memory - see mail_process_size setting";
148
case PROCESS_TYPE_UNKNOWN:
149
case PROCESS_TYPE_SSL_PARAM:
152
case PROCESS_TYPE_IMAP:
153
case PROCESS_TYPE_POP3:
154
+ case PROCESS_TYPE_MANAGESIEVE:
155
#ifndef HAVE_PR_SET_DUMPABLE
156
if (!settings_root->defaults->mail_drop_priv_before_exec) {
157
str_append(str, " (core not dumped - set mail_drop_priv_before_exec=yes)");
158
diff -r ee1782019a60 src/master/child-process.h
159
--- a/src/master/child-process.h Thu Nov 19 19:32:13 2009 -0500
160
+++ b/src/master/child-process.h Mon Nov 23 12:21:06 2009 +0100
163
PROCESS_TYPE_SSL_PARAM,
165
+ PROCESS_TYPE_MANAGESIEVE,
169
diff -r ee1782019a60 src/master/listener.c
170
--- a/src/master/listener.c Thu Nov 19 19:32:13 2009 -0500
171
+++ b/src/master/listener.c Mon Nov 23 12:21:06 2009 +0100
173
check_conflicts_set(server->pop3, ip, port,
176
+ if (server->managesieve != NULL) {
177
+ check_conflicts_set(server->managesieve, ip, port,
178
+ "managesieve", proto);
183
@@ -230,13 +234,29 @@
184
if (set->protocol == MAIL_PROTOCOL_POP3 &&
185
strcmp(set->ssl, "no") != 0)
187
+ } else if (strcasecmp(*proto, "managesieve") == 0) {
188
+ if (set->protocol == MAIL_PROTOCOL_MANAGESIEVE)
189
+ nonssl_listen = TRUE;
194
listener_close_fds(&set->listens);
196
- default_port = set->protocol == MAIL_PROTOCOL_IMAP ? 143 : 110;
197
+ switch (set->protocol) {
198
+ case MAIL_PROTOCOL_IMAP:
199
+ default_port = 143;
201
+ case MAIL_PROTOCOL_POP3:
202
+ default_port = 110;
204
+ case MAIL_PROTOCOL_MANAGESIEVE:
205
+ default_port = 2000;
211
listener_init("listen", set->listen, default_port,
215
if (old_set != NULL) {
216
listen_copy_old(old_set->imap, server->imap);
217
listen_copy_old(old_set->pop3, server->pop3);
218
+ listen_copy_old(old_set->managesieve, server->managesieve);
220
listen_parse_and_close_unneeded(server->imap);
221
listen_parse_and_close_unneeded(server->pop3);
222
+ listen_parse_and_close_unneeded(server->managesieve);
225
old_set = old_set->next;
227
listener_listen_missing(server->imap, "imap", retry);
228
if (server->pop3 != NULL)
229
listener_listen_missing(server->pop3, "pop3", retry);
230
+ if (server->managesieve != NULL)
231
+ listener_listen_missing(server->managesieve, "managesieve", retry);
236
listener_close_fds(&server->pop3->listens);
237
listener_close_fds(&server->pop3->ssl_listens);
239
+ if (server->managesieve != NULL) {
240
+ listener_close_fds(&server->managesieve->listens);
244
diff -r ee1782019a60 src/master/login-process.c
245
--- a/src/master/login-process.c Thu Nov 19 19:32:13 2009 -0500
246
+++ b/src/master/login-process.c Mon Nov 23 12:21:06 2009 +0100
248
group = i_new(struct login_group, 1);
251
- group->mail_process_type = set->protocol == MAIL_PROTOCOL_IMAP ?
252
- PROCESS_TYPE_IMAP : PROCESS_TYPE_POP3;
254
+ switch ( set->protocol ) {
255
+ case MAIL_PROTOCOL_IMAP:
256
+ group->mail_process_type = PROCESS_TYPE_IMAP;
258
+ case MAIL_PROTOCOL_POP3:
259
+ group->mail_process_type = PROCESS_TYPE_POP3;
261
+ case MAIL_PROTOCOL_MANAGESIEVE:
262
+ group->mail_process_type = PROCESS_TYPE_MANAGESIEVE;
268
group->next = login_groups;
269
login_groups = group;
271
login_group_create(server->imap);
272
if (server->pop3 != NULL)
273
login_group_create(server->pop3);
274
+ if (server->managesieve != NULL)
275
+ login_group_create(server->managesieve);
280
protocol = MAIL_PROTOCOL_IMAP;
281
else if (strcmp(proto, "pop3") == 0)
282
protocol = MAIL_PROTOCOL_POP3;
283
+ else if (strcmp(proto, "managesieve") == 0)
284
+ protocol = MAIL_PROTOCOL_MANAGESIEVE;
286
i_error("login: Unknown protocol '%s'", proto);
289
set->imap_generated_capability, NULL));
290
if (*set->imap_capability != '\0')
291
env_put("CAPABILITY_STRING_OVERRIDDEN=1");
292
+ } else if (group->mail_process_type == PROCESS_TYPE_MANAGESIEVE) {
293
+ env_put(t_strconcat("CAPABILITY_STRING=",
294
+ set->managesieve_generated_capability, NULL));
295
+ env_put(t_strconcat("MANAGESIEVE_IMPLEMENTATION_STRING=",
296
+ set->managesieve_implementation_string, NULL));
299
if (*set->login_trusted_networks != '\0') {
300
env_put(t_strconcat("TRUSTED_NETWORKS=",
301
set->login_trusted_networks, NULL));
302
diff -r ee1782019a60 src/master/mail-process.c
303
--- a/src/master/mail-process.c Thu Nov 19 19:32:13 2009 -0500
304
+++ b/src/master/mail-process.c Mon Nov 23 12:21:06 2009 +0100
306
/* We care about POP3 UIDL format in all process types */
307
env_put(t_strconcat("POP3_UIDL_FORMAT=", set->pop3_uidl_format, NULL));
309
+ if (set->protocol == MAIL_PROTOCOL_MANAGESIEVE) {
310
+ env_put(t_strdup_printf("MANAGESIEVE_MAX_LINE_LENGTH=%u",
311
+ set->managesieve_max_line_length));
312
+ env_put(t_strconcat("MANAGESIEVE_LOGOUT_FORMAT=",
313
+ set->managesieve_logout_format, NULL));
314
+ env_put(t_strconcat("MANAGESIEVE_IMPLEMENTATION_STRING=",
315
+ set->managesieve_implementation_string, NULL));
318
if (set->mail_save_crlf)
319
env_put("MAIL_SAVE_CRLF=1");
320
if (set->mmap_disable)
323
else if (strcmp(protocol, "pop3") == 0)
325
+ else if (strcmp(protocol, "managesieve") == 0)
326
+ set = server->managesieve;
328
i_fatal("Unknown protocol: '%s'", protocol);
329
executable = set->mail_executable;
331
bool home_given, nfs_check;
333
i_assert(process_type == PROCESS_TYPE_IMAP ||
334
- process_type == PROCESS_TYPE_POP3);
335
+ process_type == PROCESS_TYPE_POP3 ||
336
+ process_type == PROCESS_TYPE_MANAGESIEVE );
338
if (mail_process_count == set->max_mail_processes) {
339
i_error("Maximum number of mail processes exceeded "
341
mail_process_destroyed);
342
child_process_set_destroy_callback(PROCESS_TYPE_POP3,
343
mail_process_destroyed);
344
+ child_process_set_destroy_callback(PROCESS_TYPE_MANAGESIEVE,
345
+ mail_process_destroyed);
348
void mail_processes_deinit(void)
349
diff -r ee1782019a60 src/master/main.c
350
--- a/src/master/main.c Thu Nov 19 19:32:13 2009 -0500
351
+++ b/src/master/main.c Mon Nov 23 12:21:06 2009 +0100
354
if (server->pop3 != NULL && have_stderr_set(server->pop3))
356
+ if (server->managesieve != NULL && have_stderr_set(server->managesieve))
359
server = server->next;
361
diff -r ee1782019a60 src/master/master-settings-defs.c
362
--- a/src/master/master-settings-defs.c Thu Nov 19 19:32:13 2009 -0500
363
+++ b/src/master/master-settings-defs.c Mon Nov 23 12:21:06 2009 +0100
365
DEF_STR(dict_db_config),
366
DEF_INT(dict_process_count),
369
+ DEF_INT(managesieve_max_line_length),
370
+ DEF_STR(managesieve_logout_format),
371
+ DEF_STR(managesieve_implementation_string),
375
diff -r ee1782019a60 src/master/master-settings.c
376
--- a/src/master/master-settings.c Thu Nov 19 19:32:13 2009 -0500
377
+++ b/src/master/master-settings.c Mon Nov 23 12:21:06 2009 +0100
379
MEMBER(dict_db_config) NULL,
380
MEMBER(dict_process_count) 1,
383
+ MEMBER(managesieve_max_line_length) 65536,
384
+ MEMBER(managesieve_logout_format) "bytes=%i/%o",
385
+ MEMBER(managesieve_implementation_string) PACKAGE,
391
auth->parent->pop3->ssl_verify_client_cert = TRUE;
392
if (auth->parent->imap != NULL)
393
auth->parent->imap->ssl_verify_client_cert = TRUE;
394
+ if (auth->parent->managesieve != NULL)
395
+ auth->parent->managesieve->ssl_verify_client_cert = TRUE;
398
for (s = auth->sockets; s != NULL; s = s->next) {
399
@@ -556,12 +563,21 @@
403
- if (set->protocol == MAIL_PROTOCOL_IMAP) {
404
+ switch ( set->protocol ) {
405
+ case MAIL_PROTOCOL_IMAP:
406
if (strstr(set->protocols, "imap") == NULL)
410
+ case MAIL_PROTOCOL_POP3:
411
if (strstr(set->protocols, "pop3") == NULL)
414
+ case MAIL_PROTOCOL_MANAGESIEVE:
415
+ if (strstr(set->protocols, "managesieve") == NULL)
424
(void)closedir(dirp);
429
get_process_capability(enum process_type ptype, struct settings *set)
432
return i_strdup(buf);
436
static bool get_imap_capability(struct settings *set)
438
static const char *generated_capability = NULL;
443
+static bool get_managesieve_capability(struct settings *set)
445
+ static const char *generated_capability = NULL;
447
+ if (generated_capability != NULL) {
448
+ /* See get_imap_capability above.. */
449
+ set->managesieve_generated_capability =
450
+ p_strdup(settings_pool, generated_capability);
454
+ generated_capability = get_process_capability(PROCESS_TYPE_MANAGESIEVE, set);
455
+ if (generated_capability == NULL)
458
+ set->managesieve_generated_capability =
459
+ p_strdup(settings_pool, generated_capability);
463
static bool settings_verify(struct settings *set)
466
@@ -966,6 +1002,11 @@
467
strstr(set->server->imap->login_executable, " -D");
468
if (p != NULL && p[3] == '\0')
470
+ p = set->server->managesieve == NULL ? NULL :
471
+ strstr(set->server->managesieve->login_executable, " -D");
472
+ if (p != NULL && p[3] == '\0')
478
@@ -1025,6 +1066,10 @@
482
+ if ( set->protocol == MAIL_PROTOCOL_MANAGESIEVE ) {
483
+ if (!get_managesieve_capability(set))
489
@@ -1260,6 +1305,15 @@
490
array_append(&ctx->server->lda_settings, &value, 1);
493
+ if (error == NULL &&
494
+ (ctx->protocol == MAIL_PROTOCOL_ANY ||
495
+ ctx->protocol == MAIL_PROTOCOL_MANAGESIEVE)) {
496
+ error = parse_setting_from_defs(settings_pool,
498
+ ctx->server->managesieve,
505
@@ -1318,6 +1372,13 @@
506
array_append(&ctx->server->pop3->plugin_envs,
509
+ if (ctx->protocol == MAIL_PROTOCOL_ANY ||
510
+ ctx->protocol == MAIL_PROTOCOL_MANAGESIEVE) {
511
+ array_append(&ctx->server->managesieve->plugin_envs, &key, 1);
512
+ array_append(&ctx->server->managesieve->plugin_envs,
519
@@ -1327,7 +1388,8 @@
520
static struct server_settings *
521
create_new_server(const char *name,
522
struct settings *imap_defaults,
523
- struct settings *pop3_defaults)
524
+ struct settings *pop3_defaults,
525
+ struct settings *managesieve_defaults)
527
struct server_settings *server;
529
@@ -1335,15 +1397,18 @@
530
server->name = p_strdup(settings_pool, name);
531
server->imap = p_new(settings_pool, struct settings, 1);
532
server->pop3 = p_new(settings_pool, struct settings, 1);
533
+ server->managesieve = p_new(settings_pool, struct settings, 1);
534
server->auth_defaults = default_auth_settings;
536
*server->imap = *imap_defaults;
537
*server->pop3 = *pop3_defaults;
538
+ *server->managesieve = *managesieve_defaults;
540
p_array_init(&server->dicts, settings_pool, 4);
541
p_array_init(&server->lda_settings, settings_pool, 12);
542
p_array_init(&server->imap->plugin_envs, settings_pool, 8);
543
p_array_init(&server->pop3->plugin_envs, settings_pool, 8);
544
+ p_array_init(&server->managesieve->plugin_envs, settings_pool, 8);
546
server->imap->server = server;
547
server->imap->protocol = MAIL_PROTOCOL_IMAP;
548
@@ -1357,6 +1422,12 @@
549
server->pop3->mail_executable = PKG_LIBEXECDIR"/pop3";
550
server->pop3->mail_plugin_dir = MODULEDIR"/pop3";
552
+ server->managesieve->server = server;
553
+ server->managesieve->protocol = MAIL_PROTOCOL_MANAGESIEVE;
554
+ server->managesieve->login_executable = PKG_LIBEXECDIR"/managesieve-login";
555
+ server->managesieve->mail_executable = PKG_LIBEXECDIR"/managesieve";
556
+ server->managesieve->mail_plugin_dir = MODULEDIR"/managesieve";
561
@@ -1399,8 +1470,8 @@
563
ctx->type = SETTINGS_TYPE_SERVER;
564
ctx->server = create_new_server(name, ctx->server->imap,
565
- ctx->server->pop3);
566
- server = ctx->root;
567
+ ctx->server->pop3, ctx->server->managesieve);
568
+ server = ctx->root;
569
while (server->next != NULL)
570
server = server->next;
571
server->next = ctx->server;
572
@@ -1421,6 +1492,8 @@
573
ctx->protocol = MAIL_PROTOCOL_POP3;
574
else if (strcmp(name, "lda") == 0)
575
ctx->protocol = MAIL_PROTOCOL_LDA;
576
+ else if (strcmp(name, "managesieve") == 0)
577
+ ctx->protocol = MAIL_PROTOCOL_MANAGESIEVE;
579
*errormsg = "Unknown protocol name";
581
@@ -1532,6 +1605,8 @@
582
fd_count += server->imap->login_max_processes_count;
583
if (server->pop3 != NULL)
584
fd_count += server->pop3->login_max_processes_count;
585
+ if (server->managesieve != NULL)
586
+ fd_count += server->managesieve->login_max_processes_count;
587
fd_count += server->defaults->max_mail_processes;
590
@@ -1562,7 +1637,7 @@
591
ctx.protocol = MAIL_PROTOCOL_ANY;
592
ctx.server = ctx.root =
593
create_new_server("default",
594
- &default_settings, &default_settings);
595
+ &default_settings, &default_settings, &default_settings);
596
ctx.auth = &ctx.server->auth_defaults;
598
if (!settings_read(path, NULL, parse_setting, parse_section, &ctx))
599
@@ -1579,7 +1654,8 @@
601
if (!nochecks && !nofixes) {
602
def = settings_is_active(ctx.root->imap) ?
603
- ctx.root->imap : ctx.root->pop3;
604
+ ctx.root->imap : ( settings_is_active(ctx.root->pop3) ?
605
+ ctx.root->pop3 : ctx.root->managesieve );
607
path = t_strconcat(def->base_dir, "/master.pid", NULL);
608
pid_file_check_running(path);
609
@@ -1588,7 +1664,8 @@
611
for (server = ctx.root; server != NULL; server = server->next) {
612
if ((*server->imap->protocols == '\0' ||
613
- *server->pop3->protocols == '\0') && !nochecks) {
614
+ *server->pop3->protocols == '\0' ||
615
+ *server->managesieve->protocols == '\0') && !nochecks) {
616
i_error("protocols: No protocols given "
617
"in configuration file");
619
@@ -1619,6 +1696,15 @@
620
server->defaults = server->pop3;
623
+ if (!settings_is_active(server->managesieve) && !nochecks)
624
+ server->managesieve = NULL;
626
+ if (!settings_fix(server->managesieve, nochecks, nofixes))
628
+ if (server->defaults == NULL)
629
+ server->defaults = server->managesieve;
632
if (server->defaults == NULL) {
634
ctx.root = server->next;
635
@@ -1852,8 +1938,8 @@
637
void master_settings_dump(struct server_settings *set, bool nondefaults)
639
- const void *sets[4];
640
- const char *set_names[4];
641
+ const void *sets[5];
642
+ const char *set_names[5];
645
sets[0] = &default_settings;
646
@@ -1872,6 +1958,11 @@
647
sets[count] = set->pop3;
648
set_names[count] = "pop3";
651
+ if (set->managesieve != NULL) {
652
+ sets[count] = set->managesieve;
653
+ set_names[count] = "managesieve";
656
settings_dump(setting_defs, sets, set_names, count, nondefaults, 0);
657
namespace_settings_dump(set->namespaces, nondefaults);
658
diff -r ee1782019a60 src/master/master-settings.h
659
--- a/src/master/master-settings.h Thu Nov 19 19:32:13 2009 -0500
660
+++ b/src/master/master-settings.h Mon Nov 23 12:21:06 2009 +0100
666
- MAIL_PROTOCOL_IMAP,
668
+ MAIL_PROTOCOL_IMAP,
672
+ MAIL_PROTOCOL_MANAGESIEVE
677
const char *dict_db_config;
678
unsigned int dict_process_count;
681
+ unsigned int managesieve_max_line_length;
682
+ const char *managesieve_logout_format;
683
+ const char *managesieve_implementation_string;
686
ARRAY_TYPE(listener) listens;
687
ARRAY_TYPE(listener) ssl_listens;
689
gid_t mail_gid_t, mail_priv_gid_t;
691
const char *imap_generated_capability;
692
+ const char *managesieve_generated_capability;
694
ARRAY_DEFINE(plugin_envs, const char *);
697
struct settings *defaults;
698
struct settings *imap;
699
struct settings *pop3;
700
+ struct settings *managesieve;
701
struct auth_settings *auths;
702
struct auth_settings auth_defaults;
703
- struct namespace_settings *namespaces;
704
+ struct namespace_settings *namespaces;
706
ARRAY_DEFINE(lda_settings, const char *);
707
ARRAY_DEFINE(dicts, const char *);