]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Added lmtp_address_translate setting.
authorTimo Sirainen <tss@iki.fi>
Tue, 3 Jul 2012 01:23:03 +0000 (04:23 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 3 Jul 2012 01:23:03 +0000 (04:23 +0300)
The idea is that if you need userdb lookup to be done with a special kind of
a username like user:domain@extrainfo, you can set
lmtp_address_translate=%n:%d@ which translates the address to user@domain
after the userdb lookup is done.

src/lmtp/commands.c
src/lmtp/lmtp-settings.c
src/lmtp/lmtp-settings.h

index 009a4461b00907feae4474bd743b48af3321afda..35421378b97b6a7da84e293b09981d88ab2a621e 100644 (file)
@@ -380,6 +380,69 @@ static void rcpt_address_parse(struct client *client, const char *address,
        }
 }
 
+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 @@ int cmd_rcpt(struct client *client, const char *args)
                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);
index aa803a2db38cc163c55c8a73ed8e0475719ce282..854fa5b030ebaf0375a4ce273447f9faa8a54156 100644 (file)
@@ -60,6 +60,7 @@ static const struct setting_define lmtp_setting_defines[] = {
        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 setting_define lmtp_setting_defines[] = {
 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[] = {
index d8dc2b19b7f9dc3ddcf8b8e017b3ec74c4920c3f..ba49d17367286ac0d32ffcde45ec7c73d636f102 100644 (file)
@@ -8,6 +8,7 @@ struct lmtp_settings {
        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;