Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/deliver/deliver.c @ 5049:1acb3b558c3f HEAD
If log_timestamp isn't uncommented in dovecot.conf, use the default.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 21 Jan 2007 17:50:13 +0200 |
parents | 1e5b5484c603 |
children | 167c602ef8b4 |
rev | line source |
---|---|
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
|
1 /* Copyright (C) 2005-2006 Timo Sirainen */ |
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" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #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
|
7 #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
|
8 #include "home-expand.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #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
|
10 #include "fd-set-nonblock.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #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
|
12 #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
|
13 #include "module-dir.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "str.h" |
4637
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
15 #include "str-sanitize.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #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
|
17 #include "message-address.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
|
18 #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
|
19 #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
|
20 #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
|
21 #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
|
22 #include "duplicate.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
|
23 #include "deliver.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
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
|
25 #include <stdio.h> |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 #include <stdlib.h> |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 #include <unistd.h> |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 #include <fcntl.h> |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 #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
|
30 #include <syslog.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 #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
|
33 #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
|
34 #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
|
35 #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
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 /* 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
|
38 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
|
39 #define MAIL_MAX_MEMORY_BUFFER (1024*128) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 |
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
|
41 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
|
42 deliver_mail_func_t *deliver_mail = NULL; |
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 static struct module *modules; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 static struct ioloop *ioloop; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
47 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
|
48 { |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
49 /* 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
|
50 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
|
51 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
52 i_warning("Killed with signal %d", signo); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 io_loop_stop(ioloop); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 static int sync_quick(struct mailbox *box) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 struct mailbox_sync_context *ctx; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 struct mailbox_sync_rec sync_rec; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 ctx = mailbox_sync_init(box, 0); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 while (mailbox_sync_next(ctx, &sync_rec) > 0) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 ; |
4848
967de900c73a
Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents:
4843
diff
changeset
|
64 return mailbox_sync_deinit(&ctx, 0, NULL); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
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
|
67 static struct mailbox * |
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
|
68 mailbox_open_or_create_synced(struct mail_storage *storage, const char *name) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 { |
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
|
70 struct mailbox *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
|
71 bool syntax, temp; |
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
|
72 |
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
|
73 box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST | |
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
|
74 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
|
75 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
|
76 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
|
77 |
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
|
78 (void)mail_storage_get_last_error(storage, &syntax, &temp); |
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
|
79 if (syntax || temp) |
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
|
80 return NULL; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 |
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
|
82 /* probably the mailbox just doesn't exist. try creating it. */ |
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 if (mail_storage_mailbox_create(storage, name, FALSE) < 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
|
84 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
|
85 |
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
|
86 /* and try opening again */ |
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
|
87 box = mailbox_open(storage, name, NULL, MAILBOX_OPEN_FAST | |
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 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
|
89 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
|
90 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
|
91 |
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
|
92 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
|
93 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
|
94 return NULL; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
95 } |
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
|
96 return box; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 |
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 int deliver_save(struct mail_storage *storage, const char *mailbox, |
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
|
100 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
|
101 const char *const *keywords) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 struct mailbox *box; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 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
|
105 struct mail_keywords *kw; |
4637
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
106 const char *msgid; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 int ret = 0; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 |
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 box = mailbox_open_or_create_synced(storage, mailbox); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 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
|
111 return -1; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 |
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
|
113 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
|
114 |
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
|
115 kw = strarray_length(keywords) == 0 ? 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 mailbox_keywords_create(t, keywords); |
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 (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
|
118 ret = -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
|
119 mailbox_keywords_free(t, &kw); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 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
|
122 mailbox_transaction_rollback(&t); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 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
|
124 ret = mailbox_transaction_commit(&t, 0); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 |
4637
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
126 msgid = mail_get_first_header(mail, "Message-ID"); |
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
127 i_info(ret < 0 ? "msgid=%s: save failed to %s" : |
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
128 "msgid=%s: saved mail to %s", |
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
129 msgid == NULL ? "" : str_sanitize(msgid, 80), |
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
130 str_sanitize(mailbox_get_name(box), 80)); |
0af548f101f8
Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents:
4636
diff
changeset
|
131 |
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
|
132 mailbox_close(&box); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 return ret; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 |
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
|
136 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
|
137 { |
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
|
138 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
|
139 const char *str; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 |
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
|
141 str = mail_get_first_header(mail, "Return-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
|
142 addr = str == NULL ? 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
|
143 message_address_parse(pool_datastack_create(), |
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
|
144 (const unsigned char *)str, |
4636
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
145 strlen(str), 1, 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
|
146 return addr == NULL || addr->mailbox == NULL || addr->domain == 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
|
147 NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 |
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
|
150 const char *deliver_get_new_message_id(void) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 { |
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
|
152 static int count = 0; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 |
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
|
154 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
|
155 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
|
156 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
|
157 count++, deliver_set->hostname); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 |
4963
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
160 #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
|
161 #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
|
162 #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
|
163 |
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
|
164 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t') |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 |
4963
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
166 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
|
167 { |
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
168 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
|
169 |
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 } |
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
174 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
|
175 } |
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
176 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 static void config_file_init(const char *path) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 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
|
180 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
|
181 char *line, *p, quote; |
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
|
182 int fd, sections = 0, lda_section = 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
|
183 size_t len; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 fd = open(path, O_RDONLY); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 if (fd < 0) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 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
|
188 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 t_push(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 input = i_stream_create_file(fd, default_pool, 1024, TRUE); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 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
|
192 /* @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
|
193 |
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 /* 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
|
195 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
|
196 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
|
197 |
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
|
198 /* 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
|
199 if (*line == '#' || *line == '\0') |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 continue; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
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
|
202 /* 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 } |
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
|
210 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
|
211 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
|
212 } 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
|
213 *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
|
214 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
|
215 } |
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
|
216 } |
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
|
217 |
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
|
218 /* 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 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
|
225 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
|
226 if (strchr(line, '{') != 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
|
227 if (strcmp(line, "protocol lda {") == 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
|
228 strcmp(line, "plugin {") == 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
|
229 lda_section = TRUE; |
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
|
230 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
|
231 } |
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
|
232 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
|
233 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
|
234 lda_section = 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
|
235 } |
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 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
|
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 |
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 if (sections > 0 && !lda_section) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 continue; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 while (p > line && p[-1] == ' ') p--; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 key = t_strdup_until(line, p); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 do { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 value++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 } while (*value == ' '); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 |
4963
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
249 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
|
250 continue; |
b13c7888563c
deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
251 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 env_put(t_strconcat(t_str_ucase(key), "=", value, NULL)); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 } |
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
|
254 i_stream_unref(&input); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 t_pop(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 static const struct var_expand_table * |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 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
|
260 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 static struct var_expand_table static_tab[] = { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 { 'u', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 { 'n', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 { 'd', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 { 's', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 { 'h', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 { 'l', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 { 'r', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 { 'p', NULL }, |
4625 | 270 { 'i', NULL }, |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 { '\0', NULL } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 }; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 struct var_expand_table *tab; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 tab = t_malloc(sizeof(static_tab)); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 memcpy(tab, static_tab, sizeof(static_tab)); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 tab[0].value = user; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 tab[1].value = t_strcut(user, '@'); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 tab[2].value = strchr(user, '@'); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 if (tab[2].value != NULL) tab[2].value++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 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
|
283 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
|
284 "/HOME_DIRECTORY_USED_BUT_NOT_GIVEN_BY_USERDB"; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 tab[5].value = NULL; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 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
|
287 tab[7].value = my_pid; |
4625 | 288 tab[8].value = dec2str(geteuid()); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 return tab; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 static const char * |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 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
|
295 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 string_t *str; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 const char *p; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 str = t_str_new(256); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 /* it's either type:data or just data */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 p = strchr(env, ':'); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 if (p != NULL) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 while (env != p) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 str_append_c(str, *env); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 env++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 str_append_c(str, *env++); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 if (env[0] == '~' && env[1] == '/') { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 /* expand home */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 env = t_strconcat("%h", env+1, NULL); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 /* expand %vars */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 var_expand(str, env, table); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 return str_c(str); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 |
4636
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
322 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
|
323 { |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
324 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
|
325 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
|
326 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
|
327 |
4647
5f467dc79a19
Increase default address sanitizer pool size
Timo Sirainen <tss@iki.fi>
parents:
4637
diff
changeset
|
328 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
|
329 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
|
330 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
|
331 |
af8caaba0f67
Don't crash with -f "". Changed the default from envelope to be
Timo Sirainen <tss@iki.fi>
parents:
4701
diff
changeset
|
332 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
|
333 *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
|
334 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
|
335 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
|
336 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
|
337 else |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
338 ret = t_strdup_printf("%s@%s", addr->mailbox, addr->domain); |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
339 pool_unref(pool); |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
340 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
|
341 } |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
342 |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
343 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
|
344 { |
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
|
345 const char *mbox_hdr; |
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
|
346 struct istream *input_list[4], *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
|
347 |
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
|
348 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
|
349 |
4636
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
350 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
|
351 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
|
352 |
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
|
353 input_list[0] = i_stream_create_from_data(default_pool, mbox_hdr, |
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
|
354 strlen(mbox_hdr)); |
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
|
355 input_list[1] = i_stream_create_file(fd, default_pool, 4096, 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
|
356 input_list[2] = i_stream_create_from_data(default_pool, "\n", 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
|
357 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
|
358 |
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
|
359 input = i_stream_create_seekable(input_list, default_pool, |
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
|
360 MAIL_MAX_MEMORY_BUFFER, |
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
|
361 "/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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 } |
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
|
367 |
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
|
368 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
|
369 { |
5049
1acb3b558c3f
If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents:
5044
diff
changeset
|
370 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
|
371 |
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
|
372 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
|
373 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
|
374 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
|
375 const char *env = getenv("SYSLOG_FACILITY"); |
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
|
376 i_set_failure_syslog(prefix, LOG_NDELAY, |
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
|
377 env == NULL ? LOG_MAIL : atoi(env)); |
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
|
378 } 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
|
379 /* log to file or stderr */ |
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
|
380 i_set_failure_file(log_path, prefix); |
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
|
381 } |
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
|
382 |
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
|
383 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
|
384 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
|
385 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
|
386 |
5049
1acb3b558c3f
If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents:
5044
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 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
|
391 } |
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
|
392 |
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
|
393 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
|
394 { |
4727
4710a0429914
Added -f parameter to usage help.
Timo Sirainen <tss@iki.fi>
parents:
4725
diff
changeset
|
395 printf( |
4710a0429914
Added -f parameter to usage help.
Timo Sirainen <tss@iki.fi>
parents:
4725
diff
changeset
|
396 "Usage: deliver [-c <config file>] [-d <destination user>] [-m <mailbox>]\n" |
4710a0429914
Added -f parameter to usage help.
Timo Sirainen <tss@iki.fi>
parents:
4725
diff
changeset
|
397 " [-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
|
398 } |
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
|
399 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 int main(int argc, char *argv[]) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 { |
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
|
402 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
|
403 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
|
404 const char *mailbox = "INBOX"; |
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
|
405 const char *auth_socket, *env_tz; |
4563
5d725c24d5a0
Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents:
4548
diff
changeset
|
406 const char *home, *destination, *user, *mail_env, *value; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 const struct var_expand_table *table; |
3260
6a179bf1272e
Moved several getenv()s from lib-storage to main code. deliver binary was
Timo Sirainen <tss@iki.fi>
parents:
3255
diff
changeset
|
408 enum mail_storage_flags flags; |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
409 enum file_lock_method lock_method; |
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
|
410 struct mail_storage *storage, *mbox_storage; |
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
|
411 struct mailbox *box; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 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
|
413 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
|
414 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
|
415 uid_t process_euid; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 int i, ret; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 lib_init(); |
3624
d53d0de2ffbb
ioloop needs to be created before setting signals or we crash
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
419 ioloop = io_loop_create(default_pool); |
d53d0de2ffbb
ioloop needs to be created before setting signals or we crash
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
420 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
421 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 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
|
426 #ifdef SIGXFSZ |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4891
diff
changeset
|
427 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
|
428 #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
|
429 |
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
|
430 /* Clean up environment. */ |
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
|
431 env_tz = getenv("TZ"); |
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
|
432 home = getenv("HOME"); |
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
|
433 env_clean(); |
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
|
434 if (env_tz != 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
|
435 env_put(t_strconcat("TZ=", env_tz, 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
|
436 if (home != 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 env_put(t_strconcat("HOME=", home, NULL)); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 destination = NULL; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 for (i = 1; i < argc; i++) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 if (strcmp(argv[i], "-d") == 0) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 /* destination user */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 i++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 if (i == argc) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 i_fatal_status(EX_USAGE, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 "Missing destination argument"); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 destination = argv[i]; |
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
|
449 } 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
|
450 /* config file path */ |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 i++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 if (i == argc) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 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
|
454 "Missing config file path argument"); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 } |
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
|
456 config_path = argv[i]; |
3660
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
457 } 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
|
458 /* destination mailbox */ |
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
459 i++; |
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
460 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
|
461 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
|
462 "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
|
463 } |
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
464 mailbox = argv[i]; |
4636
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
465 } 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
|
466 /* 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
|
467 i++; |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
468 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
|
469 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
|
470 "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
|
471 } |
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
472 envelope_sender = argv[i]; |
5044
1e5b5484c603
Ignore empty parameters. "Unknown argument: xx" printed wrong argument.
Timo Sirainen <tss@iki.fi>
parents:
4963
diff
changeset
|
473 } 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
|
474 print_help(); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 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
|
476 "Unknown argument: %s", argv[i]); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 /* 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
|
485 struct passwd *pw; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 |
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 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 } 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
|
493 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
|
494 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
|
495 } |
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
|
496 } else { |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
497 i_fatal_status(EX_USAGE, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
498 "destination user parameter (-d user) not given"); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 |
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
|
501 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
|
502 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
|
503 |
4728
80afcbfce92a
Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents:
4727
diff
changeset
|
504 if (getenv("MAIL_DEBUG") != NULL) |
80afcbfce92a
Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents:
4727
diff
changeset
|
505 env_put("DEBUG=1"); |
80afcbfce92a
Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents:
4727
diff
changeset
|
506 |
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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 |
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
|
512 ret = auth_client_put_user_env(ioloop, auth_socket, |
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
|
513 destination, 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
|
514 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
|
515 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
|
516 |
4805
3c92ff93e241
If user has a home directory, but we can't chdir() there, log an error (but
Timo Sirainen <tss@iki.fi>
parents:
4763
diff
changeset
|
517 /* If possible chdir to home directory, so that core file |
3c92ff93e241
If user has a home directory, but we can't chdir() there, log an error (but
Timo Sirainen <tss@iki.fi>
parents:
4763
diff
changeset
|
518 could be written in case we crash. */ |
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
|
519 home = getenv("HOME"); |
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
|
520 if (home != NULL) { |
4843
57955b19a35d
chdir() now gives error only if error is something else than ENOENT. Also
Timo Sirainen <tss@iki.fi>
parents:
4805
diff
changeset
|
521 if (chdir(home) < 0) { |
57955b19a35d
chdir() now gives error only if error is something else than ENOENT. Also
Timo Sirainen <tss@iki.fi>
parents:
4805
diff
changeset
|
522 if (errno != ENOENT) |
57955b19a35d
chdir() now gives error only if error is something else than ENOENT. Also
Timo Sirainen <tss@iki.fi>
parents:
4805
diff
changeset
|
523 i_error("chdir(%s) failed: %m", home); |
57955b19a35d
chdir() now gives error only if error is something else than ENOENT. Also
Timo Sirainen <tss@iki.fi>
parents:
4805
diff
changeset
|
524 else if (getenv("DEBUG") != NULL) |
57955b19a35d
chdir() now gives error only if error is something else than ENOENT. Also
Timo Sirainen <tss@iki.fi>
parents:
4805
diff
changeset
|
525 i_info("Home dir not found: %s", home); |
57955b19a35d
chdir() now gives error only if error is something else than ENOENT. Also
Timo Sirainen <tss@iki.fi>
parents:
4805
diff
changeset
|
526 } |
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
|
527 } |
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
|
528 } 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
|
529 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
|
530 } |
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
|
531 |
4563
5d725c24d5a0
Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents:
4548
diff
changeset
|
532 value = getenv("UMASK"); |
5d725c24d5a0
Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents:
4548
diff
changeset
|
533 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
|
534 i = 0077; |
5d725c24d5a0
Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents:
4548
diff
changeset
|
535 (void)umask(i); |
5d725c24d5a0
Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents:
4548
diff
changeset
|
536 |
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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
544 "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
|
545 } |
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
|
546 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
|
547 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
|
548 deliver_set->sendmail_path = DEFAULT_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
|
549 |
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
|
550 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
|
551 duplicate_init(); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
552 mail_storage_init(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
553 mail_storage_register_all(); |
4891
6ab2712f1a93
Only imap binary was actually working.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
554 mailbox_list_register_all(); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
555 |
4701
190a66df2f82
Renamed default_mail_env to mail_location. Keep the default_mail_env working
Timo Sirainen <tss@iki.fi>
parents:
4652
diff
changeset
|
556 /* MAIL comes from userdb, MAIL_LOCATION from dovecot.conf */ |
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
|
557 mail_env = getenv("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
|
558 if (mail_env == NULL) |
4701
190a66df2f82
Renamed default_mail_env to mail_location. Keep the default_mail_env working
Timo Sirainen <tss@iki.fi>
parents:
4652
diff
changeset
|
559 mail_env = getenv("MAIL_LOCATION"); |
190a66df2f82
Renamed default_mail_env to mail_location. Keep the default_mail_env working
Timo Sirainen <tss@iki.fi>
parents:
4652
diff
changeset
|
560 if (mail_env == NULL) { |
190a66df2f82
Renamed default_mail_env to mail_location. Keep the default_mail_env working
Timo Sirainen <tss@iki.fi>
parents:
4652
diff
changeset
|
561 /* Keep this for backwards compatibility */ |
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
|
562 mail_env = getenv("DEFAULT_MAIL_ENV"); |
4701
190a66df2f82
Renamed default_mail_env to mail_location. Keep the default_mail_env working
Timo Sirainen <tss@iki.fi>
parents:
4652
diff
changeset
|
563 } |
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
|
564 if (mail_env != 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
|
565 table = get_var_expand_table(destination, getenv("HOME")); |
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
|
566 mail_env = expand_mail_env(mail_env, table); |
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 } |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
568 |
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
|
569 if (getenv("MAIL_PLUGINS") == 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
|
570 modules = 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
|
571 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
|
572 const char *plugin_dir = getenv("MAIL_PLUGIN_DIR"); |
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
|
573 |
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
|
574 if (plugin_dir == 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
|
575 plugin_dir = MODULEDIR"/lda"; |
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
|
576 modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"), |
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 TRUE); |
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 } |
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 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 /* FIXME: how should we handle namespaces? */ |
4121
f63ff46276a8
Use mail_storage_parse_env(), even though this code doesn't even compile
Timo Sirainen <tss@iki.fi>
parents:
4070
diff
changeset
|
581 mail_storage_parse_env(&flags, &lock_method); |
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
|
582 storage = mail_storage_create_with_data(mail_env, destination, |
3260
6a179bf1272e
Moved several getenv()s from lib-storage to main code. deliver binary was
Timo Sirainen <tss@iki.fi>
parents:
3255
diff
changeset
|
583 flags, lock_method); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 if (storage == NULL) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
585 i_fatal_status(EX_CONFIG, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 "Failed to create storage for '%s' with mail '%s'", |
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
|
587 destination, mail_env == NULL ? "(null)" : mail_env); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
589 |
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
|
590 mbox_storage = mail_storage_create("mbox", "/tmp", destination, 0, |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
591 FILE_LOCK_METHOD_FCNTL); |
4636
630e6121fb8d
Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents:
4625
diff
changeset
|
592 input = create_mbox_stream(0, 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
|
593 box = mailbox_open(mbox_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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 |
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
|
601 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
|
602 mail = mail_alloc(t, 0, 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
|
603 if (mail_set_seq(mail, 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
|
604 i_fatal("mail_set_seq() failed"); |
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
|
605 |
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
|
606 ret = deliver_mail == 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
|
607 deliver_mail(storage, mail, destination, mailbox); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
608 |
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
|
609 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
|
610 /* plugins didn't handle this. save into INBOX. */ |
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 i_stream_seek(input, 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 if (deliver_save(storage, mailbox, mail, 0, 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
|
613 const char *error; |
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
|
614 bool syntax, temporary_error; |
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
|
615 int 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
|
616 |
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
|
617 error = mail_storage_get_last_error(storage, &syntax, |
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 &temporary_error); |
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
|
619 if (temporary_error) |
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
|
620 return EX_TEMPFAIL; |
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
|
621 |
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
|
622 /* we'll have to reply with permanent failure */ |
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
|
623 ret = mail_send_rejection(mail, destination, error); |
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
|
624 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
|
625 return ret < 0 ? EX_TEMPFAIL : 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
|
626 /* ok, rejection sent */ |
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
|
627 } |
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
|
628 } |
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
|
629 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
|
630 |
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
|
631 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
|
632 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
|
633 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
|
634 |
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
|
635 mail_storage_destroy(&mbox_storage); |
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
|
636 mail_storage_destroy(&storage); |
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
|
637 |
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
|
638 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
|
639 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
|
640 |
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
|
641 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
|
642 dict_driver_unregister(&dict_driver_client); |
3625 | 643 lib_signals_deinit(); |
644 | |
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
|
645 io_loop_destroy(&ioloop); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 lib_deinit(); |
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 return EX_OK; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
649 } |