annotate src/deliver/deliver.c @ 6429:65c69a53a7be HEAD

Replaced my Copyright notices. The year range always ends with 2007 now. My name was replaced with "Dovecot authors". In many cases I didn't really even own the copyright, so this is more correct.
author Timo Sirainen <tss@iki.fi>
date Sun, 16 Sep 2007 14:34:22 +0300
parents 7cad076906eb
children c6849b4a3812
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6429
65c69a53a7be Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
1 /* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "lib-signals.h"
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
5 #include "file-lock.h"
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
6 #include "array.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "ioloop.h"
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
8 #include "hostpid.h"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
9 #include "home-expand.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "env-util.h"
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
11 #include "fd-set-nonblock.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "istream.h"
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
13 #include "istream-seekable.h"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
14 #include "module-dir.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include "str.h"
4637
0af548f101f8 Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents: 4636
diff changeset
16 #include "str-sanitize.h"
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
17 #include "strescape.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include "var-expand.h"
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
19 #include "message-address.h"
5210
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
20 #include "istream-header-filter.h"
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
21 #include "mbox-storage.h"
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
22 #include "mail-namespace.h"
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
23 #include "dict-client.h"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
24 #include "mbox-from.h"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
25 #include "auth-client.h"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
26 #include "mail-send.h"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
27 #include "duplicate.h"
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
28 #include "../master/syslog-util.h"
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
29 #include "../master/syslog-util.c" /* ugly, ugly.. */
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
30 #include "deliver.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
32 #include <stdio.h>
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 #include <stdlib.h>
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 #include <unistd.h>
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 #include <fcntl.h>
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 #include <pwd.h>
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
37 #include <syslog.h>
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
39 #define DEFAULT_CONFIG_FILE SYSCONFDIR"/dovecot.conf"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
40 #define DEFAULT_AUTH_SOCKET_PATH PKG_RUNDIR"/auth-master"
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
41 #define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail"
4725
af8caaba0f67 Don't crash with -f "". Changed the default from envelope to be
Timo Sirainen <tss@iki.fi>
parents: 4701
diff changeset
42 #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
44 /* After buffer grows larger than this, create a temporary file to /tmp
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
45 where to read the mail. */
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
46 #define MAIL_MAX_MEMORY_BUFFER (1024*128)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
48 struct deliver_settings *deliver_set;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
49 deliver_mail_func_t *deliver_mail = NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
51 /* FIXME: these two should be in some context struct instead of as globals.. */
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
52 static const char *default_mailbox_name = NULL;
5978
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
53 static bool saved_mail = FALSE;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
54 static bool tried_default_save = FALSE;
5351
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
55 static bool no_mailbox_autocreate = FALSE;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
56
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
57 static struct module *modules;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 static struct ioloop *ioloop;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
60 static pool_t plugin_pool;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
61 static ARRAY_DEFINE(plugin_envs, const char *);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
62
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6361
diff changeset
63 static void sig_die(int signo, void *context ATTR_UNUSED)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 {
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
65 /* warn about being killed because of some signal, except SIGINT (^C)
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
66 which is too common at least while testing :) */
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
67 if (signo != SIGINT)
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
68 i_warning("Killed with signal %d", signo);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 io_loop_stop(ioloop);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 static int sync_quick(struct mailbox *box)
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 struct mailbox_sync_context *ctx;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 struct mailbox_sync_rec sync_rec;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 ctx = mailbox_sync_init(box, 0);
6279
f52e7d1402b5 mail_index_view_sync_next() and mailbox_sync_next() returns now bool.
Timo Sirainen <tss@iki.fi>
parents: 6277
diff changeset
78 while (mailbox_sync_next(ctx, &sync_rec))
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 ;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4843
diff changeset
80 return mailbox_sync_deinit(&ctx, 0, NULL);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
83 static struct mailbox *
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
84 mailbox_open_or_create_synced(struct mail_namespace *namespaces,
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
85 struct mail_storage **storage_r, const char *name)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 {
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
87 struct mail_namespace *ns;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
88 struct mailbox *box;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
89 enum mail_error error;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
90
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
91 ns = mail_namespace_find(namespaces, &name);
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
92 if (ns == NULL) {
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
93 *storage_r = NULL;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
94 return NULL;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
95 }
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
96 *storage_r = ns->storage;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
97
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
98 box = mailbox_open(ns->storage, name, NULL, MAILBOX_OPEN_FAST |
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
99 MAILBOX_OPEN_KEEP_RECENT);
5351
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
100 if (box != NULL || no_mailbox_autocreate)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
101 return box;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
102
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
103 (void)mail_storage_get_last_error(ns->storage, &error);
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
104 if (error != MAIL_ERROR_NOTFOUND)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
105 return NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
107 /* try creating it. */
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
108 if (mail_storage_mailbox_create(ns->storage, name, FALSE) < 0)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
109 return NULL;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
110
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
111 /* and try opening again */
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
112 box = mailbox_open(ns->storage, name, NULL, MAILBOX_OPEN_FAST |
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
113 MAILBOX_OPEN_KEEP_RECENT);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
114 if (box == NULL)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
115 return NULL;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
116
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
117 if (sync_quick(box) < 0) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
118 mailbox_close(&box);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
119 return NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 }
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
121 return box;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
124 int deliver_save(struct mail_namespace *namespaces,
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
125 struct mail_storage **storage_r, const char *mailbox,
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
126 struct mail *mail, enum mail_flags flags,
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
127 const char *const *keywords)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 struct mailbox *box;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 struct mailbox_transaction_context *t;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
131 struct mail_keywords *kw;
5710
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
132 const char *msgid, *mailbox_name;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 int ret = 0;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
135 if (strcmp(mailbox, default_mailbox_name) == 0)
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
136 tried_default_save = TRUE;
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
137
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
138 box = mailbox_open_or_create_synced(namespaces, storage_r, mailbox);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 if (box == NULL)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
140 return -1;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141
3209
923ff19873d4 Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents: 3199
diff changeset
142 t = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143
6424
687efa138e77 Renamed strarray_length/remote() to str_array_length/remove()
Timo Sirainen <tss@iki.fi>
parents: 6411
diff changeset
144 kw = str_array_length(keywords) == 0 ? NULL :
6354
8476d665530f Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents: 6353
diff changeset
145 mailbox_keywords_create_valid(box, keywords);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
146 if (mailbox_copy(t, mail, flags, kw, NULL) < 0)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
147 ret = -1;
6354
8476d665530f Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents: 6353
diff changeset
148 mailbox_keywords_free(box, &kw);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 if (ret < 0)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
151 mailbox_transaction_rollback(&t);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 else
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
153 ret = mailbox_transaction_commit(&t, 0);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
155 if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0)
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
156 msgid = "";
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
157 else
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
158 msgid = str_sanitize(msgid, 80);
5710
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
159 mailbox_name = str_sanitize(mailbox_get_name(box), 80);
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
160
5978
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
161 if (ret == 0) {
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
162 saved_mail = TRUE;
5710
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
163 i_info("msgid=%s: saved mail to %s", msgid, mailbox_name);
5978
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
164 } else {
5710
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
165 enum mail_error error;
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
166
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
167 i_info("msgid=%s: save failed to %s: %s", msgid, mailbox_name,
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
168 mail_storage_get_last_error(*storage_r, &error));
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
169 }
4637
0af548f101f8 Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents: 4636
diff changeset
170
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
171 mailbox_close(&box);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 return ret;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
175 const char *deliver_get_return_address(struct mail *mail)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
177 struct message_address *addr;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
178 const char *str;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
180 if (mail_get_first_header(mail, "Return-Path", &str) <= 0)
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
181 return NULL;
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
182 addr = message_address_parse(pool_datastack_create(),
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
183 (const unsigned char *)str,
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
184 strlen(str), 1, FALSE);
5623
e41accd3d6f1 If Return-Path doesn't contain user and domain, treat it as missing
Timo Sirainen <tss@iki.fi>
parents: 5616
diff changeset
185 return addr == NULL || addr->mailbox == NULL || addr->domain == NULL ||
e41accd3d6f1 If Return-Path doesn't contain user and domain, treat it as missing
Timo Sirainen <tss@iki.fi>
parents: 5616
diff changeset
186 *addr->mailbox == '\0' || *addr->domain == '\0' ?
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
187 NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
190 const char *deliver_get_new_message_id(void)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
192 static int count = 0;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
194 return t_strdup_printf("<dovecot-%s-%s-%d@%s>",
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
195 dec2str(ioloop_timeval.tv_sec),
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
196 dec2str(ioloop_timeval.tv_usec),
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
197 count++, deliver_set->hostname);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
200 #include "settings.h"
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
201 #include "../master/master-settings.h"
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
202 #include "../master/master-settings-defs.c"
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
203
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
204 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
206 static bool setting_is_bool(const char *name)
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
207 {
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
208 const struct setting_def *def;
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
209
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
210 for (def = setting_defs; def->name != NULL; def++) {
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
211 if (strcmp(def->name, name) == 0)
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
212 return def->type == SET_BOOL;
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
213 }
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
214 return FALSE;
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
215 }
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
216
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
217 static void config_file_init(const char *path)
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
219 struct istream *input;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
220 const char *key, *value;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
221 char *line, *p, quote;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
222 int fd, sections = 0;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
223 bool lda_section = FALSE, pop3_section = FALSE, plugin_section = FALSE;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
224 size_t len;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
226 plugin_pool = pool_alloconly_create("Plugin strings", 512);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
227 i_array_init(&plugin_envs, 16);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
228
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 fd = open(path, O_RDONLY);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 if (fd < 0)
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 i_fatal_status(EX_CONFIG, "open(%s) failed: %m", path);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 t_push();
6162
896cc473c1f0 Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
234 input = i_stream_create_fd(fd, 1024, TRUE);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 while ((line = i_stream_read_next_line(input)) != NULL) {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
236 /* @UNSAFE: line is modified */
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
237
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
238 /* skip whitespace */
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
239 while (IS_WHITE(*line))
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
240 line++;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
241
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
242 /* ignore comments or empty lines */
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
243 if (*line == '#' || *line == '\0')
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 continue;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
246 /* strip away comments. pretty kludgy way really.. */
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
247 for (p = line; *p != '\0'; p++) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
248 if (*p == '\'' || *p == '"') {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
249 quote = *p;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
250 for (p++; *p != quote && *p != '\0'; p++) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
251 if (*p == '\\' && p[1] != '\0')
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
252 p++;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
253 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
254 if (*p == '\0')
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
255 break;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
256 } else if (*p == '#') {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
257 *p = '\0';
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
258 break;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
259 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
260 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
261
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
262 /* remove whitespace from end of line */
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
263 len = strlen(line);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
264 while (IS_WHITE(line[len-1]))
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
265 len--;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
266 line[len] = '\0';
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
267
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 value = p = strchr(line, '=');
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
269 if (value == NULL) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
270 if (strchr(line, '{') != NULL) {
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
271 if (strcmp(line, "protocol lda {") == 0)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
272 lda_section = TRUE;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
273 else if (strcmp(line, "plugin {") == 0) {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
274 plugin_section = TRUE;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
275 lda_section = TRUE;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
276 } else if (strcmp(line, "protocol pop3 {") == 0)
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
277 pop3_section = TRUE;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
278 sections++;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
279 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
280 if (*line == '}') {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
281 sections--;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
282 lda_section = FALSE;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
283 plugin_section = FALSE;
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
284 pop3_section = FALSE;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
285 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
286 continue;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
287 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
288
6235
8992a20c229f deliver didn't ignore TABs the same way spaces were ignored.
Timo Sirainen <tss@iki.fi>
parents: 6162
diff changeset
289 while (p > line && IS_WHITE(p[-1])) p--;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 key = t_strdup_until(line, p);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
292 if (sections > 0 && !lda_section) {
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
293 if (!pop3_section ||
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
294 strcmp(key, "pop3_uidl_format") != 0)
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
295 continue;
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
296 }
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
297
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 do {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299 value++;
6235
8992a20c229f deliver didn't ignore TABs the same way spaces were ignored.
Timo Sirainen <tss@iki.fi>
parents: 6162
diff changeset
300 } while (IS_WHITE(*value));
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
302 len = strlen(value);
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
303 if (len > 0 &&
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
304 ((*value == '"' && value[len-1] == '"') ||
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
305 (*value == '\'' && value[len-1] == '\''))) {
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
306 value = str_unescape(p_strndup(unsafe_data_stack_pool,
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
307 value+1, len - 2));
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
308 }
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
309 if (setting_is_bool(key) && strcasecmp(value, "yes") != 0)
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
310 continue;
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
311
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
312 if (!plugin_section) {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
313 env_put(t_strconcat(t_str_ucase(key), "=",
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
314 value, NULL));
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
315 } else {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
316 /* %variables need to be expanded.
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
317 store these for later. */
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
318 value = p_strconcat(plugin_pool,
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
319 t_str_ucase(key), "=", value, NULL);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
320 array_append(&plugin_envs, &value, 1);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
321 }
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 }
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
323 i_stream_unref(&input);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 t_pop();
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
325 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
327 static const struct var_expand_table *
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
328 get_var_expand_table(const char *user, const char *home)
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330 static struct var_expand_table static_tab[] = {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
331 { 'u', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
332 { 'n', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
333 { 'd', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
334 { 's', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
335 { 'h', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
336 { 'l', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 { 'r', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 { 'p', NULL },
4625
97c9db4980fc %i didn't work.
Timo Sirainen <tss@iki.fi>
parents: 4563
diff changeset
339 { 'i', NULL },
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
340 { '\0', NULL }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 };
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 struct var_expand_table *tab;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 tab = t_malloc(sizeof(static_tab));
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 memcpy(tab, static_tab, sizeof(static_tab));
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 tab[0].value = user;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348 tab[1].value = t_strcut(user, '@');
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 tab[2].value = strchr(user, '@');
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 if (tab[2].value != NULL) tab[2].value++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 tab[3].value = "DELIVER";
4652
3da6580bb0ed Don't require home directory to be given. If debug is enabled, log what we
Timo Sirainen <tss@iki.fi>
parents: 4647
diff changeset
352 tab[4].value = home != NULL ? home :
3da6580bb0ed Don't require home directory to be given. If debug is enabled, log what we
Timo Sirainen <tss@iki.fi>
parents: 4647
diff changeset
353 "/HOME_DIRECTORY_USED_BUT_NOT_GIVEN_BY_USERDB";
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 tab[5].value = NULL;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355 tab[6].value = NULL;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
356 tab[7].value = my_pid;
4625
97c9db4980fc %i didn't work.
Timo Sirainen <tss@iki.fi>
parents: 4563
diff changeset
357 tab[8].value = dec2str(geteuid());
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
358
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
359 return tab;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
360 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
361
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
362 static const char *
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
363 expand_mail_env(const char *env, const struct var_expand_table *table)
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
364 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365 string_t *str;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366 const char *p;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 str = t_str_new(256);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 /* it's either type:data or just data */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 p = strchr(env, ':');
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 if (p != NULL) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 while (env != p) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 str_append_c(str, *env);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 env++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378 str_append_c(str, *env++);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 if (env[0] == '~' && env[1] == '/') {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 /* expand home */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 env = t_strconcat("%h", env+1, NULL);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386 /* expand %vars */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 var_expand(str, env, table);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 return str_c(str);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
391 static const char *address_sanitize(const char *address)
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
392 {
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
393 struct message_address *addr;
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
394 const char *ret;
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
395 pool_t pool;
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
396
4647
5f467dc79a19 Increase default address sanitizer pool size
Timo Sirainen <tss@iki.fi>
parents: 4637
diff changeset
397 pool = pool_alloconly_create("address sanitizer", 256);
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
398 addr = message_address_parse(pool, (const unsigned char *)address,
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
399 strlen(address), 1, FALSE);
4725
af8caaba0f67 Don't crash with -f "". Changed the default from envelope to be
Timo Sirainen <tss@iki.fi>
parents: 4701
diff changeset
400
af8caaba0f67 Don't crash with -f "". Changed the default from envelope to be
Timo Sirainen <tss@iki.fi>
parents: 4701
diff changeset
401 if (addr == NULL || addr->mailbox == NULL || addr->domain == NULL ||
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
402 *addr->mailbox == '\0')
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
403 ret = DEFAULT_ENVELOPE_SENDER;
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
404 else if (*addr->domain == '\0')
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
405 ret = t_strdup(addr->mailbox);
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
406 else
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
407 ret = t_strdup_printf("%s@%s", addr->mailbox, addr->domain);
6428
7cad076906eb pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents: 6424
diff changeset
408 pool_unref(&pool);
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
409 return ret;
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
410 }
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
411
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
412 static struct istream *create_mbox_stream(int fd, const char *envelope_sender)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
413 {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
414 const char *mbox_hdr;
5210
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
415 struct istream *input_list[4], *input, *input_filter;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
416
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
417 fd_set_nonblock(fd, FALSE);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
418
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
419 envelope_sender = address_sanitize(envelope_sender);
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
420 mbox_hdr = mbox_from_create(envelope_sender, ioloop_time);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
421
6162
896cc473c1f0 Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
422 input = i_stream_create_fd(fd, 4096, FALSE);
5210
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
423 input_filter =
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
424 i_stream_create_header_filter(input,
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
425 HEADER_FILTER_EXCLUDE |
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
426 HEADER_FILTER_NO_CR,
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
427 mbox_hide_headers,
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
428 mbox_hide_headers_count,
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
429 null_header_filter_callback,
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
430 NULL);
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
431 i_stream_unref(&input);
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
432
6142
6c0bfc35af03 Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents: 6140
diff changeset
433 input_list[0] = i_stream_create_from_data(mbox_hdr, strlen(mbox_hdr));
5210
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
434 input_list[1] = input_filter;
6142
6c0bfc35af03 Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents: 6140
diff changeset
435 input_list[2] = i_stream_create_from_data("\n", 1);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
436 input_list[3] = NULL;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
437
6142
6c0bfc35af03 Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents: 6140
diff changeset
438 input = i_stream_create_seekable(input_list, MAIL_MAX_MEMORY_BUFFER,
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
439 "/tmp/dovecot.deliver.");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
440 i_stream_unref(&input_list[0]);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
441 i_stream_unref(&input_list[1]);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
442 i_stream_unref(&input_list[2]);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
443 return input;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
444 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
445
5141
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
446 static void failure_exit_callback(int *status)
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
447 {
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
448 /* we want all our exit codes to be sysexits.h compatible */
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
449 switch (*status) {
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
450 case FATAL_LOGOPEN:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
451 case FATAL_LOGWRITE:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
452 case FATAL_LOGERROR:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
453 case FATAL_OUTOFMEM:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
454 case FATAL_EXEC:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
455 case FATAL_DEFAULT:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
456 *status = EX_TEMPFAIL;
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
457 break;
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
458 }
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
459 }
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
460
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
461 static void open_logfile(const char *username)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
462 {
5049
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
463 const char *prefix, *log_path, *stamp;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
464
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
465 prefix = t_strdup_printf("deliver(%s)", username);
4454
a75da1185a18 Allow log_path settings in config file to be empty without trying to use
Timo Sirainen <tss@iki.fi>
parents: 4445
diff changeset
466 log_path = getenv("LOG_PATH");
a75da1185a18 Allow log_path settings in config file to be empty without trying to use
Timo Sirainen <tss@iki.fi>
parents: 4445
diff changeset
467 if (log_path == NULL || *log_path == '\0') {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
468 const char *env = getenv("SYSLOG_FACILITY");
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
469 int facility;
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
470
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
471 if (env == NULL || !syslog_facility_find(env, &facility))
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
472 facility = LOG_MAIL;
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
473 i_set_failure_syslog(prefix, LOG_NDELAY, facility);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
474 } else {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
475 /* log to file or stderr */
5333
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5291
diff changeset
476 i_set_failure_file(log_path, t_strconcat(prefix, ": ", NULL));
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
477 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
478
4454
a75da1185a18 Allow log_path settings in config file to be empty without trying to use
Timo Sirainen <tss@iki.fi>
parents: 4445
diff changeset
479 log_path = getenv("INFO_LOG_PATH");
a75da1185a18 Allow log_path settings in config file to be empty without trying to use
Timo Sirainen <tss@iki.fi>
parents: 4445
diff changeset
480 if (log_path != NULL && *log_path != '\0')
a75da1185a18 Allow log_path settings in config file to be empty without trying to use
Timo Sirainen <tss@iki.fi>
parents: 4445
diff changeset
481 i_set_info_file(log_path);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
482
5049
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
483 stamp = getenv("LOG_TIMESTAMP");
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
484 if (stamp == NULL)
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
485 stamp = DEFAULT_FAILURE_STAMP_FORMAT;
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
486 i_set_failure_timestamp_format(stamp);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
487 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
488
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
489 static void print_help(void)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
490 {
4727
4710a0429914 Added -f parameter to usage help.
Timo Sirainen <tss@iki.fi>
parents: 4725
diff changeset
491 printf(
4710a0429914 Added -f parameter to usage help.
Timo Sirainen <tss@iki.fi>
parents: 4725
diff changeset
492 "Usage: deliver [-c <config file>] [-d <destination user>] [-m <mailbox>]\n"
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
493 " [-n] [-e] [-f <envelope sender>]\n");
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
494 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
495
5220
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
496 void deliver_env_clean(void)
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
497 {
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
498 const char *tz, *home;
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
499
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
500 tz = getenv("TZ");
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
501 if (tz != NULL)
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
502 tz = t_strconcat("TZ=", tz, NULL);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
503 home = getenv("HOME");
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
504 if (home != NULL)
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
505 home = t_strconcat("HOME=", home, NULL);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
506
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
507 /* Note that if the original environment was set with env_put(), the
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
508 environment strings will be invalid after env_clean(). That's why
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
509 we t_strconcat() them above. */
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
510 env_clean();
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
511
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
512 if (tz != NULL) env_put(tz);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
513 if (home != NULL) env_put(home);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
514 }
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
515
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
516 static void expand_envs(const char *destination)
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
517 {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
518 const struct var_expand_table *table;
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
519 const char *mail_env, *const *envs, *home;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
520 unsigned int i, count;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
521 string_t *str;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
522
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
523 home = getenv("HOME");
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
524
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
525 str = t_str_new(256);
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
526 table = get_var_expand_table(destination, home);
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
527 envs = array_get(&plugin_envs, &count);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
528 for (i = 0; i < count; i++) {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
529 str_truncate(str, 0);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
530 var_expand(str, envs[i], table);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
531 env_put(str_c(str));
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
532 }
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
533
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
534 mail_env = getenv("MAIL_LOCATION");
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
535 if (mail_env != NULL) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
536 /* get the table again in case plugin envs provided the home
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
537 directory (yea, kludgy) */
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
538 if (home == NULL)
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
539 home = getenv("HOME");
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
540 table = get_var_expand_table(destination, home);
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
541 mail_env = expand_mail_env(mail_env, table);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
542 }
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
543 env_put(t_strconcat("MAIL=", mail_env, NULL));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
544 }
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
545
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
546 static void putenv_extra_fields(ARRAY_TYPE(string) *extra_fields)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
547 {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
548 char **fields;
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
549 const char *key, *p;
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
550 unsigned int i, count;
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
551
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
552 fields = array_get_modifiable(extra_fields, &count);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
553 for (i = 0; i < count; i++) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
554 p = strchr(fields[i], '=');
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
555 if (p == NULL)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
556 env_put(t_strconcat(fields[i], "=1", NULL));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
557 else {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
558 key = t_str_ucase(t_strdup_until(fields[i], p));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
559 env_put(t_strconcat(key, p, NULL));
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
560 }
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
561 i_free(fields[i]);
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
562 }
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
563 }
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
564
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
565 int main(int argc, char *argv[])
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
566 {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
567 const char *config_path = DEFAULT_CONFIG_FILE;
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
568 const char *envelope_sender = DEFAULT_ENVELOPE_SENDER;
3660
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
569 const char *mailbox = "INBOX";
5220
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
570 const char *auth_socket;
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5978
diff changeset
571 const char *home, *destination, *user, *value, *error;
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
572 ARRAY_TYPE(string) extra_fields;
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
573 struct mail_namespace *ns, *mbox_ns;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
574 struct mail_storage *storage;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
575 struct mailbox *box;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
576 struct istream *input;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
577 struct mailbox_transaction_context *t;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
578 struct mail *mail;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
579 uid_t process_euid;
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
580 pool_t namespace_pool;
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
581 bool stderr_rejection = FALSE;
6361
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
582 bool keep_environment = FALSE;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583 int i, ret;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
584
5416
22e2a1eef74b failure callback was still set too late.
Timo Sirainen <tss@iki.fi>
parents: 5351
diff changeset
585 i_set_failure_exit_callback(failure_exit_callback);
22e2a1eef74b failure callback was still set too late.
Timo Sirainen <tss@iki.fi>
parents: 5351
diff changeset
586
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
587 lib_init();
5249
784dc7224718 Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents: 5220
diff changeset
588 ioloop = io_loop_create();
3624
d53d0de2ffbb ioloop needs to be created before setting signals or we crash
Timo Sirainen <tss@iki.fi>
parents: 3620
diff changeset
589
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
590 lib_signals_init();
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
591 lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
592 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
593 lib_signals_ignore(SIGPIPE, TRUE);
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
594 lib_signals_ignore(SIGALRM, FALSE);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
595 #ifdef SIGXFSZ
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
596 lib_signals_ignore(SIGXFSZ, TRUE);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
597 #endif
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
598
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
599 destination = NULL;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 for (i = 1; i < argc; i++) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
601 if (strcmp(argv[i], "-d") == 0) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
602 /* destination user */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
603 i++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
604 if (i == argc) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
605 i_fatal_status(EX_USAGE,
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
606 "Missing destination argument");
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
607 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
608 destination = argv[i];
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
609 } else if (strcmp(argv[i], "-e") == 0) {
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
610 stderr_rejection = TRUE;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
611 } else if (strcmp(argv[i], "-c") == 0) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
612 /* config file path */
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
613 i++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
614 if (i == argc) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
615 i_fatal_status(EX_USAGE,
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
616 "Missing config file path argument");
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
617 }
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
618 config_path = argv[i];
6361
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
619 } else if (strcmp(argv[i], "-k") == 0) {
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
620 keep_environment = TRUE;
3660
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
621 } else if (strcmp(argv[i], "-m") == 0) {
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
622 /* destination mailbox */
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
623 i++;
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
624 if (i == argc) {
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
625 i_fatal_status(EX_USAGE,
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
626 "Missing mailbox argument");
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
627 }
5351
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
628 /* Ignore -m "". This allows doing -m ${extension}
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
629 in Postfix to handle user+mailbox */
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
630 if (*argv[i] != '\0')
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
631 mailbox = argv[i];
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
632 } else if (strcmp(argv[i], "-n") == 0) {
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
633 /* destination mailbox */
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
634 no_mailbox_autocreate = TRUE;
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
635 } else if (strcmp(argv[i], "-f") == 0) {
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
636 /* envelope sender address */
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
637 i++;
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
638 if (i == argc) {
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
639 i_fatal_status(EX_USAGE,
4725
af8caaba0f67 Don't crash with -f "". Changed the default from envelope to be
Timo Sirainen <tss@iki.fi>
parents: 4701
diff changeset
640 "Missing envelope argument");
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
641 }
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
642 envelope_sender = argv[i];
5044
1e5b5484c603 Ignore empty parameters. "Unknown argument: xx" printed wrong argument.
Timo Sirainen <tss@iki.fi>
parents: 4963
diff changeset
643 } else if (argv[i][0] != '\0') {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
644 print_help();
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
645 i_fatal_status(EX_USAGE,
5044
1e5b5484c603 Ignore empty parameters. "Unknown argument: xx" printed wrong argument.
Timo Sirainen <tss@iki.fi>
parents: 4963
diff changeset
646 "Unknown argument: %s", argv[i]);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
647 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
648 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
649
6361
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
650 if (!keep_environment)
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
651 deliver_env_clean();
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
652
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
653 process_euid = geteuid();
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
654 if (destination != NULL)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
655 user = destination;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
656 else if (process_euid != 0) {
4763
8bbed82738ec If we're executing as a normal system user, get the HOME environment from
Timo Sirainen <tss@iki.fi>
parents: 4728
diff changeset
657 /* we're non-root. get our username and possibly our home. */
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
658 struct passwd *pw;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
659
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
660 pw = getpwuid(process_euid);
4763
8bbed82738ec If we're executing as a normal system user, get the HOME environment from
Timo Sirainen <tss@iki.fi>
parents: 4728
diff changeset
661 if (pw != NULL) {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
662 user = t_strdup(pw->pw_name);
4763
8bbed82738ec If we're executing as a normal system user, get the HOME environment from
Timo Sirainen <tss@iki.fi>
parents: 4728
diff changeset
663 if (getenv("HOME") == NULL)
8bbed82738ec If we're executing as a normal system user, get the HOME environment from
Timo Sirainen <tss@iki.fi>
parents: 4728
diff changeset
664 env_put(t_strconcat("HOME=", pw->pw_dir, NULL));
8bbed82738ec If we're executing as a normal system user, get the HOME environment from
Timo Sirainen <tss@iki.fi>
parents: 4728
diff changeset
665 } else {
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
666 i_fatal("Couldn't lookup our username (uid=%s)",
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
667 dec2str(process_euid));
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
668 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
669 } else {
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
670 i_fatal_status(EX_USAGE,
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671 "destination user parameter (-d user) not given");
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
672 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
674 config_file_init(config_path);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
675 open_logfile(user);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
676
4728
80afcbfce92a Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents: 4727
diff changeset
677 if (getenv("MAIL_DEBUG") != NULL)
80afcbfce92a Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents: 4727
diff changeset
678 env_put("DEBUG=1");
80afcbfce92a Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents: 4727
diff changeset
679
5497
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
680 if (getenv("MAIL_PLUGINS") == NULL)
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
681 modules = NULL;
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
682 else {
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
683 const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
684 const char *version;
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
685
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
686 if (plugin_dir == NULL)
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
687 plugin_dir = MODULEDIR"/lda";
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
688
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
689 version = getenv("VERSION_IGNORE") != NULL ?
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
690 NULL : PACKAGE_VERSION;
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
691 modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
692 TRUE, version);
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
693 }
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
694
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
695 t_array_init(&extra_fields, 64);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
696 if (destination != NULL) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
697 auth_socket = getenv("AUTH_SOCKET_PATH");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
698 if (auth_socket == NULL)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
699 auth_socket = DEFAULT_AUTH_SOCKET_PATH;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
700
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
701 ret = auth_client_lookup_and_restrict(ioloop, auth_socket,
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
702 destination, process_euid,
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
703 &extra_fields);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
704 if (ret != 0)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
705 return ret;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
706 } else {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
707 destination = user;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
708 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
709
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
710 expand_envs(destination);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
711 putenv_extra_fields(&extra_fields);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
712
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
713 /* If possible chdir to home directory, so that core file
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
714 could be written in case we crash. */
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
715 home = getenv("HOME");
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
716 if (home != NULL) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
717 if (chdir(home) < 0) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
718 if (errno != ENOENT)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
719 i_error("chdir(%s) failed: %m", home);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
720 else if (getenv("DEBUG") != NULL)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
721 i_info("Home dir not found: %s", home);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
722 }
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
723 }
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
724
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
725 env_put(t_strconcat("USER=", destination, NULL));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
726
4563
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
727 value = getenv("UMASK");
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
728 if (value == NULL || sscanf(value, "%i", &i) != 1 || i < 0)
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
729 i = 0077;
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
730 (void)umask(i);
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
731
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
732 deliver_set = i_new(struct deliver_settings, 1);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
733 deliver_set->hostname = getenv("HOSTNAME");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
734 if (deliver_set->hostname == NULL)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
735 deliver_set->hostname = my_hostname;
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
736 deliver_set->postmaster_address = getenv("POSTMASTER_ADDRESS");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
737 if (deliver_set->postmaster_address == NULL) {
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
738 i_fatal_status(EX_CONFIG,
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
739 "postmaster_address setting not given");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
740 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
741 deliver_set->sendmail_path = getenv("SENDMAIL_PATH");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
742 if (deliver_set->sendmail_path == NULL)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
743 deliver_set->sendmail_path = DEFAULT_SENDMAIL_PATH;
5661
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
744 deliver_set->rejection_reason = getenv("REJECTION_REASON");
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
745 if (deliver_set->rejection_reason == NULL) {
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
746 deliver_set->rejection_reason =
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
747 DEFAULT_MAIL_REJECTION_HUMAN_REASON;
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
748 }
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
749
4517
e661182eab75 Berkeley DB dict support is now enabled only when using --with-db configure option.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4454
diff changeset
750 dict_driver_register(&dict_driver_client);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
751 duplicate_init();
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
752 mail_storage_init();
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
753 mail_storage_register_all();
4891
6ab2712f1a93 Only imap binary was actually working.
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
754 mailbox_list_register_all();
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
755
5497
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
756 module_dir_init(modules);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
757
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
758 namespace_pool = pool_alloconly_create("namespaces", 1024);
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
759 if (mail_namespaces_init(namespace_pool, destination, &ns) < 0)
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
760 exit(EX_TEMPFAIL);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
761
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
762 mbox_ns = mail_namespaces_init_empty(namespace_pool);
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
763 if (mail_storage_create(mbox_ns, "mbox", "/tmp", destination,
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5978
diff changeset
764 0, FILE_LOCK_METHOD_FCNTL, &error) < 0)
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5978
diff changeset
765 i_fatal("Couldn't create internal mbox storage: %s", error);
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
766 input = create_mbox_stream(0, envelope_sender);
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
767 box = mailbox_open(mbox_ns->storage, "Dovecot Delivery Mail", input,
4548
2eb8af6f1285 Added MAILBOX_OPEN_MBOX_ONE_MSG_ONLY flag for mailbox_open() which makes it
Timo Sirainen <tss@iki.fi>
parents: 4517
diff changeset
768 MAILBOX_OPEN_NO_INDEX_FILES |
2eb8af6f1285 Added MAILBOX_OPEN_MBOX_ONE_MSG_ONLY flag for mailbox_open() which makes it
Timo Sirainen <tss@iki.fi>
parents: 4517
diff changeset
769 MAILBOX_OPEN_MBOX_ONE_MSG_ONLY);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
770 if (box == NULL)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
771 i_fatal("Can't open delivery mail as mbox");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
772 if (sync_quick(box) < 0)
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
773 i_fatal("Can't sync delivery mail");
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
774
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
775 t = mailbox_transaction_begin(box, 0);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
776 mail = mail_alloc(t, 0, NULL);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6235
diff changeset
777 mail_set_seq(mail, 1);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
778
6140
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
779 storage = NULL;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
780 default_mailbox_name = mailbox;
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
781 if (deliver_mail == NULL)
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
782 ret = -1;
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
783 else {
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
784 if (deliver_mail(ns, &storage, mail,
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
785 destination, mailbox) <= 0) {
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
786 /* if message was saved, don't bounce it even though
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
787 the script failed later. */
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
788 ret = saved_mail ? 0 : -1;
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
789 } else {
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
790 /* success. message may or may not have been saved. */
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
791 ret = 0;
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
792 }
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
793 }
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
794
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
795 if (ret < 0 && !tried_default_save) {
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
796 /* plugins didn't handle this. save into the default mailbox. */
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
797 i_stream_seek(input, 0);
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
798 ret = deliver_save(ns, &storage, mailbox, mail, 0, NULL);
5424
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
799 }
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
800 if (ret < 0 && strcasecmp(mailbox, "INBOX") != 0) {
5424
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
801 /* still didn't work. try once more to save it
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
802 to INBOX. */
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
803 i_stream_seek(input, 0);
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
804 ret = deliver_save(ns, &storage, "INBOX", mail, 0, NULL);
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
805 }
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
806
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
807 if (ret < 0 ) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
808 const char *error_string, *msgid;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
809 enum mail_error error;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
810 int ret;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
811
6140
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
812 if (storage == NULL) {
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
813 /* This shouldn't happen */
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
814 i_error("BUG: Saving failed for unknown storage");
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
815 return EX_TEMPFAIL;
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
816 }
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
817
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
818 error_string = mail_storage_get_last_error(storage, &error);
5616
0d6cd7281aa7 Added quota_full_tempfail setting.
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
819 if (error != MAIL_ERROR_NOSPACE ||
0d6cd7281aa7 Added quota_full_tempfail setting.
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
820 getenv("QUOTA_FULL_TEMPFAIL") != NULL) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
821 /* Saving to INBOX should always work unless
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
822 we're over quota. If it didn't, it's probably a
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
823 configuration problem. */
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
824 return EX_TEMPFAIL;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
825 }
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
826
6280
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
827 if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0)
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
828 msgid = "";
eb7c9d8ece54 mail_*() APIs changed to return int and return the actual data as pointer.
Timo Sirainen <tss@iki.fi>
parents: 6279
diff changeset
829 i_info("msgid=%s: Rejected: %s", str_sanitize(msgid, 80),
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
830 str_sanitize(error_string, 512));
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
831
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
832 /* we'll have to reply with permanent failure */
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
833 if (stderr_rejection) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
834 fprintf(stderr, "%s\n", error_string);
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
835 return EX_NOPERM;
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
836 }
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
837 ret = mail_send_rejection(mail, destination, error_string);
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
838 if (ret != 0)
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
839 return ret < 0 ? EX_TEMPFAIL : ret;
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
840 /* ok, rejection sent */
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
841 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
842 i_stream_unref(&input);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
843
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
844 mail_free(&mail);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
845 mailbox_transaction_rollback(&t);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
846 mailbox_close(&box);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
847
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
848 mail_namespaces_deinit(&mbox_ns);
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
849 mail_namespaces_deinit(&ns);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
850
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
851 module_dir_unload(&modules);
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
852 mail_storage_deinit();
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
853
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
854 duplicate_deinit();
4517
e661182eab75 Berkeley DB dict support is now enabled only when using --with-db configure option.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4454
diff changeset
855 dict_driver_unregister(&dict_driver_client);
3625
04e62fc6230f And don't crash at exit..
Timo Sirainen <tss@iki.fi>
parents: 3624
diff changeset
856 lib_signals_deinit();
04e62fc6230f And don't crash at exit..
Timo Sirainen <tss@iki.fi>
parents: 3624
diff changeset
857
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
858 io_loop_destroy(&ioloop);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
859 lib_deinit();
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
860
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
861 return EX_OK;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
862 }