annotate src/deliver/deliver.c @ 7082:ce15433c6212 HEAD

If mail begins with a mbox From_ line, take the message's received date from it. Also if -f parameter hasn't been specified, take the envelope sender from it.
author Timo Sirainen <tss@iki.fi>
date Tue, 01 Jan 2008 20:04:11 +0200
parents 4b51ee73ed51
children 7ed926ed7aa4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6429
65c69a53a7be Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents: 6428
diff changeset
1 /* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
3 /* This is getting pretty horrible. Especially the config file parsing.
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
4 Dovecot v2.0 should have a config file handling process which should help
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
5 with this.. */
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
6
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "lib.h"
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #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
9 #include "file-lock.h"
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
10 #include "array.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #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
12 #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
13 #include "home-expand.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #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
15 #include "fd-set-nonblock.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #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
17 #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
18 #include "module-dir.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 #include "str.h"
4637
0af548f101f8 Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents: 4636
diff changeset
20 #include "str-sanitize.h"
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
21 #include "strescape.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 #include "var-expand.h"
6660
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
23 #include "rfc822-parser.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
24 #include "message-address.h"
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
25 #include "mail-namespace.h"
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
26 #include "raw-storage.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
27 #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
28 #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
29 #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
30 #include "duplicate.h"
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
31 #include "mbox/mbox-from.h"
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
32 #include "../master/syslog-util.h"
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
33 #include "../master/syslog-util.c" /* ugly, ugly.. */
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
34 #include "deliver.h"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35
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
36 #include <stdio.h>
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 #include <stdlib.h>
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 #include <unistd.h>
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 #include <fcntl.h>
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 #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
41 #include <syslog.h>
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
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
43 #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
44 #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
45 #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
46 #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON"
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
48 /* 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
49 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
50 #define MAIL_MAX_MEMORY_BUFFER (1024*128)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
52 static const char *wanted_headers[] = {
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
53 "From", "Message-ID", "Subject", "Return-Path",
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
54 NULL
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
55 };
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
56
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
57 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
58 deliver_mail_func_t *deliver_mail = NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
60 /* FIXME: these two should be in some context struct instead of as globals.. */
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
61 static const char *default_mailbox_name = NULL;
5978
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
62 static bool saved_mail = FALSE;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
63 static bool tried_default_save = FALSE;
5351
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
64 static bool no_mailbox_autocreate = FALSE;
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
65 static char *explicit_envelope_sender = NULL;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
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 module *modules;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 static struct ioloop *ioloop;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
70 static pool_t plugin_pool;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
71 static ARRAY_DEFINE(plugin_envs, const char *);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
72
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 6361
diff changeset
73 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
74 {
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
75 /* 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
76 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
77 if (signo != SIGINT)
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
78 i_warning("Killed with signal %d", signo);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 io_loop_stop(ioloop);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
82 static const char *deliver_get_address(struct mail *mail, const char *header)
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
83 {
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
84 struct message_address *addr;
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
85 const char *str;
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
86
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
87 if (explicit_envelope_sender != NULL)
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
88 return explicit_envelope_sender;
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
89
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
90 if (mail_get_first_header(mail, header, &str) <= 0)
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
91 return NULL;
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
92 addr = message_address_parse(pool_datastack_create(),
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
93 (const unsigned char *)str,
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
94 strlen(str), 1, FALSE);
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
95 return addr == NULL || addr->mailbox == NULL || addr->domain == NULL ||
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
96 *addr->mailbox == '\0' || *addr->domain == '\0' ?
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
97 NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL);
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
98 }
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
99
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
100 static const struct var_expand_table *
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
101 get_log_var_expand_table(struct mail *mail, const char *message)
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
102 {
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
103 static struct var_expand_table static_tab[] = {
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
104 { '$', NULL },
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
105 { 'm', NULL },
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
106 { 's', NULL },
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
107 { 'f', NULL },
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
108 { '\0', NULL }
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
109 };
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
110 struct var_expand_table *tab;
6949
eda51f08e8bf Sanitize the headers before logging.
Timo Sirainen <tss@iki.fi>
parents: 6948
diff changeset
111 unsigned int i;
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
112
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
113 tab = t_malloc(sizeof(static_tab));
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
114 memcpy(tab, static_tab, sizeof(static_tab));
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
115
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
116 tab[0].value = message;
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
117 (void)mail_get_first_header(mail, "Message-ID", &tab[1].value);
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
118 (void)mail_get_first_header(mail, "Subject", &tab[2].value);
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
119 tab[3].value = deliver_get_address(mail, "From");
6949
eda51f08e8bf Sanitize the headers before logging.
Timo Sirainen <tss@iki.fi>
parents: 6948
diff changeset
120 for (i = 1; tab[i].key != '\0'; i++)
eda51f08e8bf Sanitize the headers before logging.
Timo Sirainen <tss@iki.fi>
parents: 6948
diff changeset
121 tab[i].value = str_sanitize(tab[i].value, 80);
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
122 return tab;
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
123 }
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
124
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
125 static void
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
126 deliver_log(struct mail *mail, const char *fmt, ...) ATTR_FORMAT(2, 3);
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
127
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
128 static void deliver_log(struct mail *mail, const char *fmt, ...)
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
129 {
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
130 va_list args;
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
131 string_t *str;
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
132 const char *msg;
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
133
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
134 va_start(args, fmt);
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
135 msg = t_strdup_vprintf(fmt, args);
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
136
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
137 str = t_str_new(256);
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
138 var_expand(str, deliver_set->log_format,
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
139 get_log_var_expand_table(mail, msg));
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
140 i_info("%s", str_c(str));
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
141 va_end(args);
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
142 }
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
143
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
144 static struct mailbox *
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
145 mailbox_open_or_create_synced(struct mail_namespace *namespaces,
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
146 struct mail_storage **storage_r, const char *name)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 {
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
148 struct mail_namespace *ns;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
149 struct mailbox *box;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
150 enum mail_error error;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
151
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
152 ns = mail_namespace_find(namespaces, &name);
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
153 if (ns == NULL) {
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
154 *storage_r = NULL;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
155 return NULL;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
156 }
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
157 *storage_r = ns->storage;
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
158
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
159 box = mailbox_open(ns->storage, name, NULL, MAILBOX_OPEN_FAST |
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
160 MAILBOX_OPEN_KEEP_RECENT);
5351
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
161 if (box != NULL || no_mailbox_autocreate)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
162 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
163
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
164 (void)mail_storage_get_last_error(ns->storage, &error);
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
165 if (error != MAIL_ERROR_NOTFOUND)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
166 return NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
168 /* try creating it. */
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
169 if (mail_storage_mailbox_create(ns->storage, name, FALSE) < 0)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
170 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
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 /* and try opening again */
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
173 box = mailbox_open(ns->storage, name, NULL, MAILBOX_OPEN_FAST |
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
174 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
175 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
176 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
177
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
178 if (mailbox_sync(box, 0, 0, NULL) < 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
179 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
180 return NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 }
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
182 return box;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
185 int deliver_save(struct mail_namespace *namespaces,
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
186 struct mail_storage **storage_r, const char *mailbox,
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
187 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
188 const char *const *keywords)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 struct mailbox *box;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 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
192 struct mail_keywords *kw;
6918
2f7939f262ef If we can't open/create the wanted mailbox, log an error.
Timo Sirainen <tss@iki.fi>
parents: 6786
diff changeset
193 enum mail_error error;
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
194 const char *mailbox_name;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 int ret = 0;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
197 if (strcmp(mailbox, default_mailbox_name) == 0)
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
198 tried_default_save = TRUE;
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
199
6918
2f7939f262ef If we can't open/create the wanted mailbox, log an error.
Timo Sirainen <tss@iki.fi>
parents: 6786
diff changeset
200 mailbox_name = str_sanitize(mailbox, 80);
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
201 box = mailbox_open_or_create_synced(namespaces, storage_r, mailbox);
6918
2f7939f262ef If we can't open/create the wanted mailbox, log an error.
Timo Sirainen <tss@iki.fi>
parents: 6786
diff changeset
202 if (box == NULL) {
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
203 deliver_log(mail, "save failed to %s: %s", mailbox_name,
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
204 mail_storage_get_last_error(*storage_r, &error));
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
205 return -1;
6918
2f7939f262ef If we can't open/create the wanted mailbox, log an error.
Timo Sirainen <tss@iki.fi>
parents: 6786
diff changeset
206 }
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207
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
208 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
209
6424
687efa138e77 Renamed strarray_length/remote() to str_array_length/remove()
Timo Sirainen <tss@iki.fi>
parents: 6411
diff changeset
210 kw = str_array_length(keywords) == 0 ? NULL :
6354
8476d665530f Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents: 6353
diff changeset
211 mailbox_keywords_create_valid(box, keywords);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
212 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
213 ret = -1;
6354
8476d665530f Changed mail_keywords creation APIs to take mailbox/index instead of
Timo Sirainen <tss@iki.fi>
parents: 6353
diff changeset
214 mailbox_keywords_free(box, &kw);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 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
217 mailbox_transaction_rollback(&t);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 else
6512
1a3604c8ee05 mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents: 6508
diff changeset
219 ret = mailbox_transaction_commit(&t);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220
5978
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
221 if (ret == 0) {
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
222 saved_mail = TRUE;
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
223 deliver_log(mail, "saved mail to %s", mailbox_name);
5978
28836909b3b0 If Sieve plugin returns any errors, ignore them. Bounce the message only if
Timo Sirainen <tss@iki.fi>
parents: 5894
diff changeset
224 } else {
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
225 deliver_log(mail, "save failed to %s: %s", mailbox_name,
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
226 mail_storage_get_last_error(*storage_r, &error));
5710
d4b7a25c814c If save failed, log also the reason for it.
Timo Sirainen <tss@iki.fi>
parents: 5665
diff changeset
227 }
4637
0af548f101f8 Log all mail saves and save failures.
Timo Sirainen <tss@iki.fi>
parents: 4636
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 mailbox_close(&box);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 return ret;
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
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
233 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
234 {
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
235 return deliver_get_address(mail, "Return-Path");
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237
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
238 const char *deliver_get_new_message_id(void)
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 {
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
240 static int count = 0;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241
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
242 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
243 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
244 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
245 count++, deliver_set->hostname);
3199
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
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
248 #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
249 #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
250 #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
251
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
252 #define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
254 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
255 {
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
256 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
257
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
258 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
259 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
260 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
261 }
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
262 if (strncmp(name, "NAMESPACE_", 10) == 0) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
263 return strstr(name, "_list") != NULL ||
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
264 strstr(name, "_inbox") != NULL ||
6603
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
265 strstr(name, "_hidden") != NULL ||
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
266 strstr(name, "_subscriptions") != NULL;
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
267 }
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
268 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
269 }
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
270
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 static void config_file_init(const char *path)
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 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
274 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
275 char *line, *p, quote;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
276 int fd, sections = 0;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
277 bool lda_section = FALSE, pop3_section = FALSE, plugin_section = FALSE;
6580
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
278 bool ns_section = FALSE, ns_location = FALSE, ns_list = FALSE;
6603
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
279 bool ns_subscriptions = FALSE;
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
280 unsigned int ns_idx = 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
281 size_t len;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
283 plugin_pool = pool_alloconly_create("Plugin strings", 512);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
284 i_array_init(&plugin_envs, 16);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
285
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 fd = open(path, O_RDONLY);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 if (fd < 0)
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 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
289
6162
896cc473c1f0 Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
290 input = i_stream_create_fd(fd, 1024, TRUE);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 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
292 /* @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
293
a73d2867f6e1 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 /* 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
295 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
296 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
297
a73d2867f6e1 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 /* 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
299 if (*line == '#' || *line == '\0')
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 continue;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301
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
302 /* 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
303 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
304 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
305 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
306 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
307 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
308 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
309 }
a73d2867f6e1 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 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
311 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
312 } 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
313 *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
314 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
315 }
a73d2867f6e1 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 /* 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
319 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
320 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
321 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
322 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
323
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 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
325 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
326 if (strchr(line, '{') != NULL) {
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
327 if (strcmp(line, "protocol lda {") == 0)
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
328 lda_section = TRUE;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
329 else if (strcmp(line, "plugin {") == 0) {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
330 plugin_section = TRUE;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
331 lda_section = TRUE;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
332 } else if (strcmp(line, "protocol pop3 {") == 0)
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
333 pop3_section = TRUE;
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
334 else if (strncmp(line, "namespace ", 10) == 0) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
335 ns_section = TRUE;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
336 ns_idx++;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
337 line += 10;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
338 env_put(t_strdup_printf(
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
339 "NAMESPACE_%u_TYPE=%s", ns_idx,
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
340 t_strcut(line, ' ')));
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
341 }
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
342 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
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 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
345 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
346 lda_section = FALSE;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
347 plugin_section = FALSE;
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
348 pop3_section = FALSE;
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
349 ns_section = FALSE;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
350 if (ns_location)
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
351 ns_location = FALSE;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
352 else {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
353 env_put(t_strdup_printf(
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
354 "NAMESPACE_%u=", ns_idx));
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
355 }
6580
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
356 if (ns_list)
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
357 ns_list = FALSE;
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
358 else {
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
359 env_put(t_strdup_printf(
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
360 "NAMESPACE_%u_LIST=1", ns_idx));
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
361 }
6603
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
362 if (ns_subscriptions)
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
363 ns_subscriptions = FALSE;
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
364 else {
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
365 env_put(t_strdup_printf(
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
366 "NAMESPACE_%u_SUBSCRIPTIONS=1",
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
367 ns_idx));
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
368 }
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
369 }
a73d2867f6e1 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 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
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
6235
8992a20c229f deliver didn't ignore TABs the same way spaces were ignored.
Timo Sirainen <tss@iki.fi>
parents: 6162
diff changeset
373 while (p > line && IS_WHITE(p[-1])) p--;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 key = t_strdup_until(line, p);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
376 if (sections > 0 && !lda_section) {
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
377 if (pop3_section) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
378 if (strcmp(key, "pop3_uidl_format") != 0)
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
379 continue;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
380 } else if (ns_section) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
381 if (strcmp(key, "separator") == 0) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
382 key = t_strdup_printf(
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
383 "NAMESPACE_%u_SEP", ns_idx);
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
384 } else if (strcmp(key, "location") == 0) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
385 ns_location = TRUE;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
386 key = t_strdup_printf("NAMESPACE_%u",
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
387 ns_idx);
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
388 } else {
6580
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
389 if (strcmp(key, "list") == 0)
d172fb7d216f Default to list=yes in namespaces.
Timo Sirainen <tss@iki.fi>
parents: 6553
diff changeset
390 ns_list = TRUE;
6603
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
391 if (strcmp(key, "subscriptions") == 0)
afc28dd2d4c5 Added subscriptions setting to namespaces to specify if it should handle
Timo Sirainen <tss@iki.fi>
parents: 6580
diff changeset
392 ns_subscriptions = TRUE;
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
393 key = t_strdup_printf("NAMESPACE_%u_%s",
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
394 ns_idx, key);
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
395 }
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
396 }
5166
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
397 }
cc8b33172a86 Get pop3_uidl_format even if it's inside protocol pop3 {}
Timo Sirainen <tss@iki.fi>
parents: 5148
diff changeset
398
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 do {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 value++;
6235
8992a20c229f deliver didn't ignore TABs the same way spaces were ignored.
Timo Sirainen <tss@iki.fi>
parents: 6162
diff changeset
401 } while (IS_WHITE(*value));
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
403 len = strlen(value);
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
404 if (len > 0 &&
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
405 ((*value == '"' && value[len-1] == '"') ||
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
406 (*value == '\'' && value[len-1] == '\''))) {
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
407 value = str_unescape(p_strndup(unsafe_data_stack_pool,
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
408 value+1, len - 2));
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
409 }
4963
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
410 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
411 continue;
b13c7888563c deliver was treating boolean settings set to "no" as if they were "yes"
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
412
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
413 if (!plugin_section) {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
414 env_put(t_strconcat(t_str_ucase(key), "=",
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
415 value, NULL));
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
416 } else {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
417 /* %variables need to be expanded.
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
418 store these for later. */
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
419 value = p_strconcat(plugin_pool,
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
420 t_str_ucase(key), "=", value, NULL);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
421 array_append(&plugin_envs, &value, 1);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
422 }
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 }
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
424 i_stream_unref(&input);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
425 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427 static const struct var_expand_table *
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 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
429 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 static struct var_expand_table static_tab[] = {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 { 'u', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 { 'n', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 { 'd', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 { 's', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 { 'h', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 { 'l', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 { 'r', NULL },
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 { 'p', NULL },
4625
97c9db4980fc %i didn't work.
Timo Sirainen <tss@iki.fi>
parents: 4563
diff changeset
439 { 'i', NULL },
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 { '\0', NULL }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441 };
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 struct var_expand_table *tab;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 tab = t_malloc(sizeof(static_tab));
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445 memcpy(tab, static_tab, sizeof(static_tab));
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 tab[0].value = user;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 tab[1].value = t_strcut(user, '@');
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 tab[2].value = strchr(user, '@');
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450 if (tab[2].value != NULL) tab[2].value++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 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
452 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
453 "/HOME_DIRECTORY_USED_BUT_NOT_GIVEN_BY_USERDB";
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 tab[5].value = NULL;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 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
456 tab[7].value = my_pid;
4625
97c9db4980fc %i didn't work.
Timo Sirainen <tss@iki.fi>
parents: 4563
diff changeset
457 tab[8].value = dec2str(geteuid());
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 return tab;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 static const char *
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 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
464 {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 string_t *str;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 const char *p;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 str = t_str_new(256);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 /* it's either type:data or just data */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 p = strchr(env, ':');
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 if (p != NULL) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 while (env != p) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 str_append_c(str, *env);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 env++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 }
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 str_append_c(str, *env++);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 if (env[0] == '~' && env[1] == '/') {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 /* expand home */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483 env = t_strconcat("%h", env+1, NULL);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 /* expand %vars */
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
487 var_expand(str, env, table);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
488 return str_c(str);
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
489 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490
6660
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
491 static const char *escape_local_part(const char *local_part)
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
492 {
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
493 const char *p;
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
494
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
495 /* if there are non-atext chars, we need to return quoted-string */
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
496 for (p = local_part; *p != '\0'; p++) {
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
497 if (!IS_ATEXT(*p)) {
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
498 return t_strdup_printf("\"%s\"",
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
499 str_escape(local_part));
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
500 }
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
501 }
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
502 return local_part;
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
503 }
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
504
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
505 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
506 {
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
507 struct message_address *addr;
6660
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
508 const char *ret, *mailbox;
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
509 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
510
4647
5f467dc79a19 Increase default address sanitizer pool size
Timo Sirainen <tss@iki.fi>
parents: 4637
diff changeset
511 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
512 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
513 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
514
af8caaba0f67 Don't crash with -f "". Changed the default from envelope to be
Timo Sirainen <tss@iki.fi>
parents: 4701
diff changeset
515 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
516 *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
517 ret = DEFAULT_ENVELOPE_SENDER;
6660
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
518 else {
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
519 mailbox = escape_local_part(addr->mailbox);
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
520 if (*addr->domain == '\0')
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
521 ret = t_strdup(mailbox);
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
522 else
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
523 ret = t_strdup_printf("%s@%s", mailbox, addr->domain);
a7d462ed94df Fix handling envelope senders containing spaces.
Timo Sirainen <tss@iki.fi>
parents: 6624
diff changeset
524 }
6428
7cad076906eb pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents: 6424
diff changeset
525 pool_unref(&pool);
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
526 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
527 }
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
528
6471
910aadd76897 If the first line begins with "From ", ignore it.
Timo Sirainen <tss@iki.fi>
parents: 6459
diff changeset
529
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
530 static struct istream *create_raw_stream(int fd, time_t *mtime_r)
6471
910aadd76897 If the first line begins with "From ", ignore it.
Timo Sirainen <tss@iki.fi>
parents: 6459
diff changeset
531 {
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
532 struct istream *input, *input2, *input_list[2];
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
533 const unsigned char *data;
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
534 char *sender = NULL;
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
535 size_t i, size;
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
536 int ret;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
537
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
538 *mtime_r = (time_t)-1;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
539 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
540
6162
896cc473c1f0 Renamed i_stream_create_file() to i_stream_create_fd().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
541 input = i_stream_create_fd(fd, 4096, FALSE);
6730
5f30b309a79e Our input stream is blocking, mark it as such.
Timo Sirainen <tss@iki.fi>
parents: 6660
diff changeset
542 input->blocking = TRUE;
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
543 /* If input begins with a From-line, drop it */
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
544 ret = i_stream_read_data(input, &data, &size, 5);
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
545 if (ret > 0 && size >= 5 && memcmp(data, "From ", 5) == 0) {
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
546 /* skip until the first LF */
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
547 i_stream_skip(input, 5);
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
548 while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
549 for (i = 0; i < size; i++) {
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
550 if (data[i] == '\n')
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
551 break;
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
552 }
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
553 if (i != size) {
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
554 (void)mbox_from_parse(data, i, mtime_r,
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
555 &sender);
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
556 i_stream_skip(input, i + 1);
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
557 break;
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
558 }
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
559 i_stream_skip(input, size);
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
560 }
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
561 }
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
562
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
563 if (sender != NULL && explicit_envelope_sender == NULL) {
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
564 /* use the envelope sender from From_-line, but only if it
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
565 hasn't been specified with -f already. */
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
566 explicit_envelope_sender = i_strdup(sender);
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
567 }
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
568 i_free(sender);
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
569
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
570 if (input->v_offset == 0) {
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
571 input2 = input;
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
572 i_stream_ref(input2);
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
573 } else {
7031
4b51ee73ed51 Removed v_start_offset parameter from i_stream_create_limit(). We'll always
Timo Sirainen <tss@iki.fi>
parents: 6949
diff changeset
574 input2 = i_stream_create_limit(input, (uoff_t)-1);
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
575 }
5210
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
576 i_stream_unref(&input);
b77a67169fc5 While parsing the input stream ignore the mbox hidden headers so that eg.
Timo Sirainen <tss@iki.fi>
parents: 5186
diff changeset
577
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
578 input_list[0] = input2; input_list[1] = NULL;
6142
6c0bfc35af03 Removed memory pool parameter from iostreams. Default pool was almost always
Timo Sirainen <tss@iki.fi>
parents: 6140
diff changeset
579 input = i_stream_create_seekable(input_list, MAIL_MAX_MEMORY_BUFFER,
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
580 "/tmp/dovecot.deliver.");
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
581 i_stream_unref(&input2);
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 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
583 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
584
5141
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
585 static void failure_exit_callback(int *status)
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
586 {
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
587 /* we want all our exit codes to be sysexits.h compatible */
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
588 switch (*status) {
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
589 case FATAL_LOGOPEN:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
590 case FATAL_LOGWRITE:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
591 case FATAL_LOGERROR:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
592 case FATAL_OUTOFMEM:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
593 case FATAL_EXEC:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
594 case FATAL_DEFAULT:
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
595 *status = EX_TEMPFAIL;
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
596 break;
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
597 }
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
598 }
8c0c4b524d84 Hook all exit()s and if the exit code is one of Dovecot's own FATAL_* ones,
Timo Sirainen <tss@iki.fi>
parents: 5050
diff changeset
599
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
600 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
601 {
5049
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
602 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
603
a73d2867f6e1 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 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
605 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
606 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
607 const char *env = getenv("SYSLOG_FACILITY");
5050
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
608 int facility;
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
609
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
610 if (env == NULL || !syslog_facility_find(env, &facility))
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
611 facility = LOG_MAIL;
167c602ef8b4 If config file contained quoted "value", the quotes weren't stripped.
Timo Sirainen <tss@iki.fi>
parents: 5049
diff changeset
612 i_set_failure_syslog(prefix, LOG_NDELAY, facility);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
613 } 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
614 /* log to file or stderr */
5333
55260092b094 Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents: 5291
diff changeset
615 i_set_failure_file(log_path, t_strconcat(prefix, ": ", NULL));
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
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
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
618 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
619 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
620 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
621
5049
1acb3b558c3f If log_timestamp isn't uncommented in dovecot.conf, use the default.
Timo Sirainen <tss@iki.fi>
parents: 5044
diff changeset
622 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
623 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
624 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
625 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
626 }
a73d2867f6e1 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 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
629 {
4727
4710a0429914 Added -f parameter to usage help.
Timo Sirainen <tss@iki.fi>
parents: 4725
diff changeset
630 printf(
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
631 "Usage: deliver [-c <config file>] [-a <address>] [-d <username>]\n"
6517
4e92a6c44b44 Update help string.
Timo Sirainen <tss@iki.fi>
parents: 6516
diff changeset
632 " [-f <envelope sender>] [-m <mailbox>] [-n] [-e] [-k]\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
633 }
a73d2867f6e1 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
5220
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
635 void deliver_env_clean(void)
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
636 {
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
637 const char *tz, *home;
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
638
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
639 tz = getenv("TZ");
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
640 if (tz != NULL)
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
641 tz = t_strconcat("TZ=", tz, NULL);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
642 home = getenv("HOME");
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
643 if (home != NULL)
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
644 home = t_strconcat("HOME=", home, NULL);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
645
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
646 /* Note that if the original environment was set with env_put(), the
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
647 environment strings will be invalid after env_clean(). That's why
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
648 we t_strconcat() them above. */
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
649 env_clean();
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
650
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
651 if (tz != NULL) env_put(tz);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
652 if (home != NULL) env_put(home);
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
653 }
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
654
6515
95eb92b49d9c Added -a parameter to specify authentication username. It can be used to
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
655 static void expand_envs(const char *user)
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
656 {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
657 const struct var_expand_table *table;
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
658 const char *mail_env, *const *envs, *home;
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
659 unsigned int i, count;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
660 string_t *str;
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
661
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
662 home = getenv("HOME");
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
663
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
664 str = t_str_new(256);
6515
95eb92b49d9c Added -a parameter to specify authentication username. It can be used to
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
665 table = get_var_expand_table(user, home);
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
666 envs = array_get(&plugin_envs, &count);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
667 for (i = 0; i < count; i++) {
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
668 str_truncate(str, 0);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
669 var_expand(str, envs[i], table);
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
670 env_put(str_c(str));
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
671 }
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
672
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
673 mail_env = getenv("MAIL_LOCATION");
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
674 if (mail_env != NULL) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
675 /* get the table again in case plugin envs provided the home
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
676 directory (yea, kludgy) */
6358
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
677 if (home == NULL)
6bd13d514294 Fixed home directory handling which got broken by previous changes.
Timo Sirainen <tss@iki.fi>
parents: 6354
diff changeset
678 home = getenv("HOME");
6515
95eb92b49d9c Added -a parameter to specify authentication username. It can be used to
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
679 table = get_var_expand_table(user, home);
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
680 mail_env = expand_mail_env(mail_env, table);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
681 }
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
682 env_put(t_strconcat("MAIL=", mail_env, NULL));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
683 }
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
684
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
685 static void putenv_extra_fields(ARRAY_TYPE(string) *extra_fields)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
686 {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
687 char **fields;
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
688 const char *key, *p;
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
689 unsigned int i, count;
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
690
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
691 fields = array_get_modifiable(extra_fields, &count);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
692 for (i = 0; i < count; i++) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
693 p = strchr(fields[i], '=');
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
694 if (p == NULL)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
695 env_put(t_strconcat(fields[i], "=1", NULL));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
696 else {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
697 key = t_str_ucase(t_strdup_until(fields[i], p));
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
698 env_put(t_strconcat(key, p, NULL));
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
699 }
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
700 i_free(fields[i]);
5894
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
701 }
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
702 }
1b90285069f9 %variables in plugin {} settings need to be expanded.
Timo Sirainen <tss@iki.fi>
parents: 5710
diff changeset
703
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
704 int main(int argc, char *argv[])
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
705 {
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
706 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
707 const char *mailbox = "INBOX";
5220
7fbdcce95982 Keep only TZ and HOME environments when calling sendmail.
Timo Sirainen <tss@iki.fi>
parents: 5210
diff changeset
708 const char *auth_socket;
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
709 const char *home, *destaddr, *user, *value, *error;
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
710 ARRAY_TYPE(string) extra_fields;
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
711 struct mail_namespace *ns, *raw_ns;
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
712 struct mail_storage *storage;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
713 struct mailbox *box;
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
714 struct raw_mailbox *raw_box;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
715 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
716 struct mailbox_transaction_context *t;
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
717 struct mailbox_header_lookup_ctx *headers_ctx;
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
718 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
719 uid_t process_euid;
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
720 pool_t namespace_pool;
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
721 bool stderr_rejection = FALSE;
6361
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
722 bool keep_environment = FALSE;
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
723 bool user_auth = FALSE;
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
724 time_t mtime;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
725 int i, ret;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
726
5416
22e2a1eef74b failure callback was still set too late.
Timo Sirainen <tss@iki.fi>
parents: 5351
diff changeset
727 i_set_failure_exit_callback(failure_exit_callback);
22e2a1eef74b failure callback was still set too late.
Timo Sirainen <tss@iki.fi>
parents: 5351
diff changeset
728
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
729 lib_init();
5249
784dc7224718 Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents: 5220
diff changeset
730 ioloop = io_loop_create();
3624
d53d0de2ffbb ioloop needs to be created before setting signals or we crash
Timo Sirainen <tss@iki.fi>
parents: 3620
diff changeset
731
3620
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
732 lib_signals_init();
3360cc019737 Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents: 3389
diff changeset
733 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
734 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
735 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
736 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
737 #ifdef SIGXFSZ
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
738 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
739 #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
740
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
741 destaddr = user = NULL;
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
742 for (i = 1; i < argc; i++) {
6515
95eb92b49d9c Added -a parameter to specify authentication username. It can be used to
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
743 if (strcmp(argv[i], "-a") == 0) {
95eb92b49d9c Added -a parameter to specify authentication username. It can be used to
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
744 /* destination address */
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
745 i++;
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
746 if (i == argc)
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
747 i_fatal_status(EX_USAGE, "Missing -a argument");
6515
95eb92b49d9c Added -a parameter to specify authentication username. It can be used to
Timo Sirainen <tss@iki.fi>
parents: 6512
diff changeset
748 destaddr = argv[i];
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
749 } else if (strcmp(argv[i], "-d") == 0) {
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
750 /* destination user */
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
751 i++;
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
752 if (i == argc)
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
753 i_fatal_status(EX_USAGE, "Missing -d argument");
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
754 user = argv[i];
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
755 user_auth = TRUE;
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
756 } else if (strcmp(argv[i], "-e") == 0) {
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
757 stderr_rejection = TRUE;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
758 } 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
759 /* config file path */
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
760 i++;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
761 if (i == argc) {
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
762 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
763 "Missing config file path argument");
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
764 }
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
765 config_path = argv[i];
6361
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
766 } else if (strcmp(argv[i], "-k") == 0) {
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
767 keep_environment = TRUE;
3660
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
768 } 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
769 /* destination mailbox */
f2d65601097c Added -m parameter to store mail to non-INBOX mailbox without Sieve
Timo Sirainen <tss@iki.fi>
parents: 3637
diff changeset
770 i++;
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
771 if (i == argc)
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
772 i_fatal_status(EX_USAGE, "Missing -m argument");
5351
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
773 /* Ignore -m "". This allows doing -m ${extension}
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
774 in Postfix to handle user+mailbox */
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
775 if (*argv[i] != '\0')
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
776 mailbox = argv[i];
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
777 } else if (strcmp(argv[i], "-n") == 0) {
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
778 /* destination mailbox */
5220d4e6690d Ignore -m "" parameter. Added -n option to not autocreate the mailbox. If
Timo Sirainen <tss@iki.fi>
parents: 5333
diff changeset
779 no_mailbox_autocreate = TRUE;
4636
630e6121fb8d Added -f parameter to specify the envelope sender which is used in mbox
Timo Sirainen <tss@iki.fi>
parents: 4625
diff changeset
780 } 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
781 /* 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
782 i++;
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
783 if (i == argc)
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
784 i_fatal_status(EX_USAGE, "Missing -f argument");
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
785 explicit_envelope_sender =
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
786 i_strdup(address_sanitize(argv[i]));
5044
1e5b5484c603 Ignore empty parameters. "Unknown argument: xx" printed wrong argument.
Timo Sirainen <tss@iki.fi>
parents: 4963
diff changeset
787 } 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
788 print_help();
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
789 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
790 "Unknown argument: %s", argv[i]);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
791 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
792 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
793
6361
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
794 if (!keep_environment)
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
795 deliver_env_clean();
7f6c99dc1f17 Added -k parameter to preserve environment. Normally everything but TZ and
Timo Sirainen <tss@iki.fi>
parents: 6358
diff changeset
796
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
797 process_euid = geteuid();
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
798 if (user_auth)
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
799 ;
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
800 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
801 /* 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
802 struct passwd *pw;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
803
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
804 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
805 if (pw != NULL) {
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
806 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
807 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
808 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
809 } 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
810 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
811 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
812 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
813 } else {
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
814 i_fatal_status(EX_USAGE,
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
815 "destination user parameter (-d user) not given");
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
816 }
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
817
6940
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6918
diff changeset
818 T_FRAME(
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6918
diff changeset
819 config_file_init(config_path);
414c9d631a81 Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents: 6918
diff changeset
820 );
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
821 open_logfile(user);
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
822
4728
80afcbfce92a Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents: 4727
diff changeset
823 if (getenv("MAIL_DEBUG") != NULL)
80afcbfce92a Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents: 4727
diff changeset
824 env_put("DEBUG=1");
80afcbfce92a Make mail_debug=yes work with deliver too.
Timo Sirainen <tss@iki.fi>
parents: 4727
diff changeset
825
5497
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
826 if (getenv("MAIL_PLUGINS") == NULL)
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
827 modules = NULL;
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
828 else {
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
829 const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
830 const char *version;
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
831
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
832 if (plugin_dir == NULL)
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
833 plugin_dir = MODULEDIR"/lda";
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
834
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
835 version = getenv("VERSION_IGNORE") != NULL ?
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
836 NULL : PACKAGE_VERSION;
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
837 modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
838 TRUE, version);
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
839 }
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
840
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
841 t_array_init(&extra_fields, 64);
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
842 if (user_auth) {
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
843 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
844 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
845 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
846
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
847 ret = auth_client_lookup_and_restrict(ioloop, auth_socket,
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
848 user, process_euid,
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
849 &extra_fields);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
850 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
851 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
852 }
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
853 if (destaddr == NULL)
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
854 destaddr = user;
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
855
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
856 expand_envs(user);
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
857 putenv_extra_fields(&extra_fields);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
858
6553
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
859 /* Fix namespaces with empty locations */
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
860 for (i = 1;; i++) {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
861 value = getenv(t_strdup_printf("NAMESPACE_%u", i));
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
862 if (value == NULL)
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
863 break;
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
864
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
865 if (*value == '\0') {
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
866 env_put(t_strdup_printf("NAMESPACE_%u=%s", i,
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
867 getenv("MAIL")));
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
868 }
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
869 }
e752f60f7e60 Parse namespaces from config file.
Timo Sirainen <tss@iki.fi>
parents: 6540
diff changeset
870
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
871 /* If possible chdir to home directory, so that core file
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
872 could be written in case we crash. */
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
873 home = getenv("HOME");
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
874 if (home != NULL) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
875 if (chdir(home) < 0) {
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
876 if (errno != ENOENT)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
877 i_error("chdir(%s) failed: %m", home);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
878 else if (getenv("DEBUG") != NULL)
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
879 i_info("Home dir not found: %s", home);
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
880 }
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
881 }
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
882
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
883 env_put(t_strconcat("USER=", user, NULL));
6317
3cee177eced6 Extra fields from userdb lookup should override everything. Fixed the code
Timo Sirainen <tss@iki.fi>
parents: 6280
diff changeset
884
4563
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
885 value = getenv("UMASK");
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
886 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
887 i = 0077;
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
888 (void)umask(i);
5d725c24d5a0 Set umask from dovecot.conf, or default to 0077.
Timo Sirainen <tss@iki.fi>
parents: 4548
diff changeset
889
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
890 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
891 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
892 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
893 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
894 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
895 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
896 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
897 "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
898 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
899 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
900 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
901 deliver_set->sendmail_path = DEFAULT_SENDMAIL_PATH;
5661
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
902 deliver_set->rejection_reason = getenv("REJECTION_REASON");
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
903 if (deliver_set->rejection_reason == NULL) {
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
904 deliver_set->rejection_reason =
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
905 DEFAULT_MAIL_REJECTION_HUMAN_REASON;
f18a7fd8ac9a Added rejection_reason setting for deliver.
Timo Sirainen <tss@iki.fi>
parents: 5623
diff changeset
906 }
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
907 deliver_set->log_format = getenv("DELIVER_LOG_FORMAT");
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
908 if (deliver_set->log_format == NULL)
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
909 deliver_set->log_format = DEFAULT_LOG_FORMAT;
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
910
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
911 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
912 duplicate_init();
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
913 mail_storage_init();
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
914 mail_storage_register_all();
4891
6ab2712f1a93 Only imap binary was actually working.
Timo Sirainen <tss@iki.fi>
parents: 4876
diff changeset
915 mailbox_list_register_all();
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
916
5497
e57b685ad093 Load plugins before chrooting.
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
917 module_dir_init(modules);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
918
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
919 namespace_pool = pool_alloconly_create("namespaces", 1024);
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
920 if (mail_namespaces_init(namespace_pool, user, &ns) < 0)
6540
12a779e08a73 If namespace initialization fails, die with a fatal error message instead of
Timo Sirainen <tss@iki.fi>
parents: 6518
diff changeset
921 i_fatal("Namespace initialization failed");
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
922
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
923 raw_ns = mail_namespaces_init_empty(namespace_pool);
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
924 raw_ns->flags |= NAMESPACE_FLAG_INTERNAL;
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
925 if (mail_storage_create(raw_ns, "raw", "/tmp", user,
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5978
diff changeset
926 0, FILE_LOCK_METHOD_FCNTL, &error) < 0)
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
927 i_fatal("Couldn't create internal raw storage: %s", error);
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
928 input = create_raw_stream(0, &mtime);
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
929 box = mailbox_open(raw_ns->storage, "Dovecot Delivery Mail", input,
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
930 MAILBOX_OPEN_NO_INDEX_FILES);
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
931 if (box == NULL)
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
932 i_fatal("Can't open delivery mail as raw");
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
933 if (mailbox_sync(box, 0, 0, NULL) < 0) {
6624
91a003d00b4e If syncing internal dummy mbox fails, show the error message.
Timo Sirainen <tss@iki.fi>
parents: 6603
diff changeset
934 enum mail_error error;
91a003d00b4e If syncing internal dummy mbox fails, show the error message.
Timo Sirainen <tss@iki.fi>
parents: 6603
diff changeset
935
91a003d00b4e If syncing internal dummy mbox fails, show the error message.
Timo Sirainen <tss@iki.fi>
parents: 6603
diff changeset
936 i_fatal("Can't sync delivery mail: %s",
6786
92768090a106 Error handling fix
Timo Sirainen <tss@iki.fi>
parents: 6769
diff changeset
937 mail_storage_get_last_error(raw_ns->storage, &error));
6624
91a003d00b4e If syncing internal dummy mbox fails, show the error message.
Timo Sirainen <tss@iki.fi>
parents: 6603
diff changeset
938 }
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
939 raw_box = (struct raw_mailbox *)box;
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
940 raw_box->envelope_sender = explicit_envelope_sender != NULL ?
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
941 explicit_envelope_sender : DEFAULT_ENVELOPE_SENDER;
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
942 raw_box->mtime = mtime;
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
943
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
944 t = mailbox_transaction_begin(box, 0);
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
945 headers_ctx = mailbox_header_lookup_init(box, wanted_headers);
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
946 mail = mail_alloc(t, 0, headers_ctx);
6277
5f66277bbe40 mail_index_lookup*() can't fail anymore. Changed several APIs not to return
Timo Sirainen <tss@iki.fi>
parents: 6235
diff changeset
947 mail_set_seq(mail, 1);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
948
6140
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
949 storage = NULL;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
950 default_mailbox_name = mailbox;
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
951 if (deliver_mail == NULL)
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
952 ret = -1;
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
953 else {
6516
af3194cbd364 And call deliver_mail() with destaddr instead of user.
Timo Sirainen <tss@iki.fi>
parents: 6515
diff changeset
954 if (deliver_mail(ns, &storage, mail, destaddr, mailbox) <= 0) {
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
955 /* if message was saved, don't bounce it even though
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
956 the script failed later. */
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
957 ret = saved_mail ? 0 : -1;
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
958 } else {
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
959 /* success. message may or may not have been saved. */
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
960 ret = 0;
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
961 }
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
962 }
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
963
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
964 if (ret < 0 && !tried_default_save) {
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
965 /* plugins didn't handle this. save into the default mailbox. */
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
966 i_stream_seek(input, 0);
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
967 ret = deliver_save(ns, &storage, mailbox, mail, 0, NULL);
5424
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
968 }
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
969 if (ret < 0 && strcasecmp(mailbox, "INBOX") != 0) {
5424
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
970 /* still didn't work. try once more to save it
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
971 to INBOX. */
448901e76f93 INBOX fallbacking with -n wasn't working.
Timo Sirainen <tss@iki.fi>
parents: 5416
diff changeset
972 i_stream_seek(input, 0);
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
973 ret = deliver_save(ns, &storage, "INBOX", mail, 0, NULL);
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
974 }
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
975
6139
cd0f9be6f8ad If Sieve script didn't save the message anywhere, we saved it to INBOX.
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
976 if (ret < 0 ) {
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
977 const char *error_string;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
978 enum mail_error error;
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
979 int ret;
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
980
6140
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
981 if (storage == NULL) {
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
982 /* This shouldn't happen */
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
983 i_error("BUG: Saving failed for unknown storage");
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
984 return EX_TEMPFAIL;
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
985 }
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
986
291135c986b3 If save failed for non-first namespace, we got a wrong error message.
Timo Sirainen <tss@iki.fi>
parents: 6139
diff changeset
987 error_string = mail_storage_get_last_error(storage, &error);
5616
0d6cd7281aa7 Added quota_full_tempfail setting.
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
988 if (error != MAIL_ERROR_NOSPACE ||
0d6cd7281aa7 Added quota_full_tempfail setting.
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
989 getenv("QUOTA_FULL_TEMPFAIL") != NULL) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
990 /* Saving to INBOX should always work unless
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
991 we're over quota. If it didn't, it's probably a
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
992 configuration problem. */
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
993 return EX_TEMPFAIL;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
994 }
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
995
6947
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
996 deliver_log(mail, "rejected: %s",
0a7d53a1b8fe Added deliver_log(), which is used to log the mail delivery status instead
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
997 str_sanitize(error_string, 512));
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
998
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
999 /* we'll have to reply with permanent failure */
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
1000 if (stderr_rejection) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5607
diff changeset
1001 fprintf(stderr, "%s\n", error_string);
5603
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
1002 return EX_NOPERM;
86886a8fb0f1 Added -e parameter to write rejection error to stderr and exit with
Timo Sirainen <tss@iki.fi>
parents: 5500
diff changeset
1003 }
6518
9b71007b70c7 Another try, -d is now destination user as originally and -a is now
Timo Sirainen <tss@iki.fi>
parents: 6517
diff changeset
1004 ret = mail_send_rejection(mail, user, error_string);
5143
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
1005 if (ret != 0)
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
1006 return ret < 0 ? EX_TEMPFAIL : ret;
5a0506cb73c5 Don't bother trying to save the mail twice into the default mailbox (eg. if it's
Timo Sirainen <tss@iki.fi>
parents: 5141
diff changeset
1007 /* ok, rejection sent */
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
1008 }
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
1009 i_stream_unref(&input);
7082
ce15433c6212 If mail begins with a mbox From_ line, take the message's received date from
Timo Sirainen <tss@iki.fi>
parents: 7031
diff changeset
1010 i_free(explicit_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
1011
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
1012 mail_free(&mail);
6948
6b5f89c41de5 Added deliver_log_format setting to control what's logged when a mail is
Timo Sirainen <tss@iki.fi>
parents: 6947
diff changeset
1013 mailbox_header_lookup_deinit(&headers_ctx);
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
1014 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
1015 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
1016
6750
b822b7b78d7b Use raw storage instead of mbox storage to access input mail stream.
Timo Sirainen <tss@iki.fi>
parents: 6743
diff changeset
1017 mail_namespaces_deinit(&raw_ns);
5500
4862cb37106c Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents: 5497
diff changeset
1018 mail_namespaces_deinit(&ns);
4347
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
1019
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
1020 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
1021 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
1022
a73d2867f6e1 Moved all the non-Sieve code from dovecot-lda in here and rewrote parts of
Timo Sirainen <tss@iki.fi>
parents: 4253
diff changeset
1023 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
1024 dict_driver_unregister(&dict_driver_client);
3625
04e62fc6230f And don't crash at exit..
Timo Sirainen <tss@iki.fi>
parents: 3624
diff changeset
1025 lib_signals_deinit();
04e62fc6230f And don't crash at exit..
Timo Sirainen <tss@iki.fi>
parents: 3624
diff changeset
1026
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
1027 io_loop_destroy(&ioloop);
3199
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1028 lib_deinit();
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1029
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1030 return EX_OK;
938f948651f1 Added initial version of Dovecot LDA.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1031 }