Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/deliver/deliver.c @ 4548:2eb8af6f1285 HEAD
Added MAILBOX_OPEN_MBOX_ONE_MSG_ONLY flag for mailbox_open() which makes it
ignore all but the first From-line in a mbox. This kludge is required for
deliver which builds a temporary mbox stream from the input. Later it
should be fixed to use some plain-mailbox format instead of mbox.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 07 Aug 2006 15:42:37 +0300 |
parents | e661182eab75 |
children | 5d725c24d5a0 |
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" |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #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
|
6 #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
|
7 #include "home-expand.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #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
|
9 #include "fd-set-nonblock.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #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
|
11 #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
|
12 #include "module-dir.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "str.h" |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #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
|
15 #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
|
16 #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
|
17 #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
|
18 #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
|
19 #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
|
20 #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
|
21 #include "deliver.h" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
23 #include <stdio.h> |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 #include <stdlib.h> |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 #include <unistd.h> |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 #include <fcntl.h> |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 #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
|
28 #include <syslog.h> |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
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 #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
|
31 #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
|
32 #define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail" |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
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
|
34 /* 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
|
35 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
|
36 #define MAIL_MAX_MEMORY_BUFFER (1024*128) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 |
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
|
38 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
|
39 deliver_mail_func_t *deliver_mail = NULL; |
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 void (*hook_mail_storage_created)(struct mail_storage *storage) = 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
|
42 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
43 static struct module *modules; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 static struct ioloop *ioloop; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
46 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
|
47 { |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
48 /* 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
|
49 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
|
50 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
51 i_warning("Killed with signal %d", signo); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 io_loop_stop(ioloop); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
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 static int sync_quick(struct mailbox *box) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 struct mailbox_sync_context *ctx; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 struct mailbox_sync_rec sync_rec; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 struct mailbox_status status; |
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 ; |
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
|
64 return mailbox_sync_deinit(&ctx, &status); |
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; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 int ret = 0; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 |
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
|
108 box = mailbox_open_or_create_synced(storage, mailbox); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 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
|
110 return -1; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 |
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
|
112 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
|
113 |
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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 mailbox_keywords_free(t, &kw); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 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
|
121 mailbox_transaction_rollback(&t); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 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
|
123 ret = mailbox_transaction_commit(&t, 0); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 |
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
|
125 mailbox_close(&box); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 return ret; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 |
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
|
129 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
|
130 { |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
131 struct 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
|
132 const char *str; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 |
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
|
134 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
|
135 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
|
136 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
|
137 (const unsigned char *)str, |
a73d2867f6e1
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 strlen(str), 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
|
139 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
|
140 NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
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
|
143 const char *deliver_get_new_message_id(void) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 { |
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
|
145 static int count = 0; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 |
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
|
147 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
|
148 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
|
149 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
|
150 count++, deliver_set->hostname); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
153 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t') |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 static void config_file_init(const char *path) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 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
|
161 size_t len; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 fd = open(path, O_RDONLY); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 if (fd < 0) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 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
|
166 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 t_push(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 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
|
169 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
|
170 /* @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
|
171 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
172 /* 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
|
173 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
|
174 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
|
175 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
176 /* 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
|
177 if (*line == '#' || *line == '\0') |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 continue; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 |
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 /* 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
188 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
|
189 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
|
190 } 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
|
191 *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
|
192 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
|
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 } |
a73d2867f6e1
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 |
a73d2867f6e1
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 /* 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
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 (*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
|
211 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
|
212 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
|
213 } |
a73d2867f6e1
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 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
|
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 if (sections > 0 && !lda_section) |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 continue; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 while (p > line && p[-1] == ' ') p--; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 key = t_strdup_until(line, p); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 do { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 value++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 } while (*value == ' '); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 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
|
228 } |
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
|
229 i_stream_unref(&input); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 t_pop(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 static const struct var_expand_table * |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 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
|
235 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 static struct var_expand_table static_tab[] = { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 { 'u', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 { 'n', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 { 'd', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 { 's', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 { 'h', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 { 'l', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 { 'r', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 { 'p', NULL }, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 { '\0', NULL } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 }; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 struct var_expand_table *tab; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 tab = t_malloc(sizeof(static_tab)); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 memcpy(tab, static_tab, sizeof(static_tab)); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 tab[0].value = user; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 tab[1].value = t_strcut(user, '@'); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 tab[2].value = strchr(user, '@'); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 if (tab[2].value != NULL) tab[2].value++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 tab[3].value = "DELIVER"; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 tab[4].value = home; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 tab[5].value = NULL; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 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
|
260 tab[7].value = my_pid; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 return tab; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 static const char * |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 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
|
267 { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 string_t *str; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 const char *p; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 str = t_str_new(256); |
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 /* it's either type:data or just data */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 p = strchr(env, ':'); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 if (p != NULL) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 while (env != p) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 str_append_c(str, *env); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 env++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 str_append_c(str, *env++); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 if (env[0] == '~' && env[1] == '/') { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 /* expand home */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 env = t_strconcat("%h", env+1, NULL); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 /* expand %vars */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 var_expand(str, env, table); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 return str_c(str); |
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 |
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
|
294 static struct istream *create_mbox_stream(int fd) |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
295 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
296 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
|
297 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
|
298 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
299 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
|
300 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
301 mbox_hdr = mbox_from_create("dovecot.deliver", ioloop_time); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
302 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
309 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
|
310 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
|
311 "/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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
317 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
318 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
|
319 { |
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
|
320 const char *prefix, *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
|
321 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 } 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
|
329 /* 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
|
330 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
|
331 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
332 |
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
|
333 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
|
334 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
|
335 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
|
336 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
337 i_set_failure_timestamp_format(getenv("LOG_TIMESTAMP")); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
338 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
339 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
340 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
|
341 { |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
342 printf("Usage: deliver [-c <config file>] [-d <destination user>] [-m <mailbox>]\n"); |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
343 } |
a73d2867f6e1
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 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 int main(int argc, char *argv[]) |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 { |
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
|
347 const char *config_path = DEFAULT_CONFIG_FILE; |
3660
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
348 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
|
349 const char *auth_socket, *env_tz; |
4445
13350093fa1b
MAIL_STORAGE_FLAG_KEEP_HEADER_MD5 flag was supposed to be set if
Timo Sirainen <tss@iki.fi>
parents:
4347
diff
changeset
|
350 const char *home, *destination, *user, *mail_env; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 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
|
352 enum mail_storage_flags flags; |
6a179bf1272e
Moved several getenv()s from lib-storage to main code. deliver binary was
Timo Sirainen <tss@iki.fi>
parents:
3255
diff
changeset
|
353 enum mail_storage_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
|
354 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
|
355 struct mailbox *box; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 uid_t process_euid; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 int i, ret; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 lib_init(); |
3624
d53d0de2ffbb
ioloop needs to be created before setting signals or we crash
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
363 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
|
364 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
365 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3389
diff
changeset
|
366 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
|
367 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL); |
4253
545a747d0347
Use lib_signals_ignore() for signals we really want ignored.
Timo Sirainen <tss@iki.fi>
parents:
4121
diff
changeset
|
368 lib_signals_ignore(SIGPIPE); |
3689
8b68997d6e34
Ignore SIGALRM signal. We don't want to crash when it happens.
Timo Sirainen <tss@iki.fi>
parents:
3660
diff
changeset
|
369 lib_signals_set_handler(SIGALRM, FALSE, NULL, 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
|
370 #ifdef SIGXFSZ |
a73d2867f6e1
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 lib_signals_set_handler(SIGXFSZ, FALSE, 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
|
372 #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
|
373 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
374 /* 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 env_put(t_strconcat("HOME=", home, NULL)); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 destination = NULL; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 for (i = 1; i < argc; i++) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 if (strcmp(argv[i], "-d") == 0) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 /* destination user */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 i++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 if (i == argc) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 i_fatal_status(EX_USAGE, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 "Missing destination argument"); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 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
|
393 } 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
|
394 /* config file path */ |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 i++; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 if (i == argc) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 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
|
398 "Missing config file path argument"); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 } |
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
|
400 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
|
401 } 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
|
402 /* destination mailbox */ |
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
403 i++; |
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
404 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
|
405 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
|
406 "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
|
407 } |
f2d65601097c
Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents:
3637
diff
changeset
|
408 mailbox = argv[i]; |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 } 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
|
410 print_help(); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 i_fatal_status(EX_USAGE, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 "Unknown argument: %s", argv[1]); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
414 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 |
4347
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
416 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
|
417 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
|
418 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
|
419 else if (process_euid != 0) { |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 /* we're non-root. get our username. */ |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 struct passwd *pw; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 |
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
|
423 pw = getpwuid(process_euid); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 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
|
425 user = t_strdup(pw->pw_name); |
a73d2867f6e1
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 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
|
427 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
|
428 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
|
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 } else { |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 i_fatal_status(EX_USAGE, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 "destination user parameter (-d user) not given"); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 |
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
|
435 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
|
436 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
|
437 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 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
|
442 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
448 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
|
449 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
|
450 /* If possible chdir to home directory so core file |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
451 could be written. If it fails, don't worry. */ |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
452 (void)chdir(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
|
453 } |
a73d2867f6e1
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 } 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
|
455 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
|
456 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
457 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 "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
|
466 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 |
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
|
471 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
|
472 duplicate_init(); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 mail_storage_init(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 mail_storage_register_all(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 |
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
|
476 /* MAIL comes from userdb, DEFAULT_MAIL_ENV from 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
|
477 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
|
478 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
|
479 mail_env = getenv("DEFAULT_MAIL_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
|
480 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
|
481 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
|
482 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
|
483 } |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 |
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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
490 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
|
491 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
|
492 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
|
493 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
|
494 } |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
495 |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 /* 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
|
497 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
|
498 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
|
499 flags, lock_method); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 if (storage == NULL) { |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 i_fatal_status(EX_CONFIG, |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 "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
|
503 destination, mail_env == NULL ? "(null)" : mail_env); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 } |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 |
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
|
506 if (hook_mail_storage_created != 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
|
507 hook_mail_storage_created(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
|
508 |
a73d2867f6e1
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 mbox_storage = mail_storage_create("mbox", "/tmp", destination, 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
|
510 MAIL_STORAGE_LOCK_FCNTL); |
a73d2867f6e1
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 input = create_mbox_stream(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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 |
a73d2867f6e1
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 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
|
521 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
|
522 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
|
523 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
|
524 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
525 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
|
526 deliver_mail(storage, mail, destination, mailbox); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 |
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
|
528 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
|
529 /* 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 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
|
535 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
536 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
|
537 &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
|
538 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
|
539 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
|
540 |
a73d2867f6e1
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 /* 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
|
542 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
|
543 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
|
544 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
|
545 /* 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
|
546 } |
a73d2867f6e1
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 } |
a73d2867f6e1
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 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
|
549 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
550 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
|
551 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
|
552 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
|
553 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
554 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
|
555 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
|
556 |
a73d2867f6e1
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 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
|
558 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
|
559 |
a73d2867f6e1
Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
560 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
|
561 dict_driver_unregister(&dict_driver_client); |
3625 | 562 lib_signals_deinit(); |
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 io_loop_destroy(&ioloop); |
3199
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
565 lib_deinit(); |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
567 return EX_OK; |
938f948651f1
Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
568 } |