dovecot-2.1: lmtp: Added lmtp_address_translate setting.
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jul 3 04:23:39 EEST 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/f1509d8eb2c1
changeset: 14595:f1509d8eb2c1
user: Timo Sirainen <tss at iki.fi>
date: Tue Jul 03 04:23:03 2012 +0300
description:
lmtp: Added lmtp_address_translate setting.
The idea is that if you need userdb lookup to be done with a special kind of
a username like user:domain at extrainfo, you can set
lmtp_address_translate=%n:%d@ which translates the address to user at domain
after the userdb lookup is done.
diffstat:
src/lmtp/commands.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
src/lmtp/lmtp-settings.c | 4 ++-
src/lmtp/lmtp-settings.h | 1 +
3 files changed, 69 insertions(+), 1 deletions(-)
diffs (114 lines):
diff -r 955e741ef46a -r f1509d8eb2c1 src/lmtp/commands.c
--- a/src/lmtp/commands.c Tue Jul 03 03:27:52 2012 +0300
+++ b/src/lmtp/commands.c Tue Jul 03 04:23:03 2012 +0300
@@ -380,6 +380,69 @@
}
}
+static void lmtp_address_translate(struct client *client, const char **address)
+{
+ const char *transpos = client->lmtp_set->lmtp_address_translate;
+ const char *p, *nextstr, *addrpos = *address;
+ unsigned int len;
+ string_t *username, *domain, *dest = NULL;
+
+ if (*transpos == '\0')
+ return;
+
+ username = t_str_new(64);
+ domain = t_str_new(64);
+
+ /* check that string matches up to the first '%' */
+ p = strchr(transpos, '%');
+ if (p == NULL)
+ len = strlen(transpos);
+ else
+ len = p-transpos;
+ if (strncmp(transpos, addrpos, len) != 0)
+ return;
+ transpos += len;
+ addrpos += len;
+
+ while (*transpos != '\0') {
+ switch (transpos[1]) {
+ case 'n':
+ case 'u':
+ dest = username;
+ break;
+ case 'd':
+ dest = domain;
+ break;
+ default:
+ return;
+ }
+ transpos += 2;
+
+ /* find where the next string starts */
+ if (*transpos == '\0') {
+ str_append(dest, addrpos);
+ break;
+ }
+ p = strchr(transpos, '%');
+ if (p == NULL)
+ nextstr = transpos;
+ else
+ nextstr = t_strdup_until(transpos, p);
+ p = strstr(addrpos, nextstr);
+ if (p == NULL)
+ return;
+ str_append_n(dest, addrpos, p-addrpos);
+
+ len = strlen(nextstr);
+ transpos += len;
+ addrpos = p + len;
+ }
+ str_append_c(username, '@');
+ if (domain != NULL)
+ str_append_str(username, domain);
+ *address = str_c(username);
+}
+
int cmd_rcpt(struct client *client, const char *args)
{
struct mail_recipient rcpt;
@@ -449,6 +512,8 @@
return 0;
}
+ lmtp_address_translate(client, &address);
+
rcpt.address = p_strdup(client->state_pool, address);
rcpt.detail = p_strdup(client->state_pool, detail);
array_append(&client->state.rcpt_to, &rcpt, 1);
diff -r 955e741ef46a -r f1509d8eb2c1 src/lmtp/lmtp-settings.c
--- a/src/lmtp/lmtp-settings.c Tue Jul 03 03:27:52 2012 +0300
+++ b/src/lmtp/lmtp-settings.c Tue Jul 03 04:23:03 2012 +0300
@@ -60,6 +60,7 @@
DEF(SET_BOOL, lmtp_proxy),
DEF(SET_BOOL, lmtp_save_to_detail_mailbox),
DEF(SET_STR_VARS, login_greeting),
+ DEF(SET_STR, lmtp_address_translate),
SETTING_DEFINE_LIST_END
};
@@ -67,7 +68,8 @@
static const struct lmtp_settings lmtp_default_settings = {
.lmtp_proxy = FALSE,
.lmtp_save_to_detail_mailbox = FALSE,
- .login_greeting = PACKAGE_NAME" ready."
+ .login_greeting = PACKAGE_NAME" ready.",
+ .lmtp_address_translate = ""
};
static const struct setting_parser_info *lmtp_setting_dependencies[] = {
diff -r 955e741ef46a -r f1509d8eb2c1 src/lmtp/lmtp-settings.h
--- a/src/lmtp/lmtp-settings.h Tue Jul 03 03:27:52 2012 +0300
+++ b/src/lmtp/lmtp-settings.h Tue Jul 03 04:23:03 2012 +0300
@@ -8,6 +8,7 @@
bool lmtp_proxy;
bool lmtp_save_to_detail_mailbox;
const char *login_greeting;
+ const char *lmtp_address_translate;
};
extern const struct setting_parser_info lmtp_setting_parser_info;
More information about the dovecot-cvs
mailing list