#include "iostream-temp.h"
#include "master-service.h"
#include "settings-parser.h"
-#include "lda-settings.h"
#include "mail-user.h"
#include "smtp-address.h"
#include "mail-deliver.h"
struct smtp_server_transaction *trans;
struct lmtp_recipient *lrcpt;
+ i_assert(!smtp_address_isnull(rcpt->path));
+ if (*rcpt->path->localpart == '\0' && rcpt->path->domain == NULL) {
+ smtp_server_recipient_reply(
+ rcpt, 550, "5.1.1",
+ "Unacceptable TO: Empty path not allowed");
+ return -1;
+ }
+
trans = smtp_server_connection_get_transaction(rcpt->conn);
i_assert(trans != NULL); /* MAIL command is synchronous */
struct smtp_server_cmd_ctx *cmd,
struct lmtp_recipient *lrcpt)
{
- struct smtp_server_recipient *rcpt = lrcpt->rcpt;
- const char *username, *detail;
- char delim = '\0';
int ret;
- i_assert(!smtp_address_isnull(rcpt->path));
- if (*rcpt->path->localpart == '\0' && rcpt->path->domain == NULL) {
- smtp_server_recipient_reply(
- rcpt, 550, "5.1.1",
- "Unacceptable TO: Empty path not allowed");
- return -1;
- }
-
- smtp_address_detail_parse_temp(
- client->unexpanded_lda_set->recipient_delimiter,
- rcpt->path, &username, &delim, &detail);
- i_assert(*username != '\0');
-
- /* Make user name and detail available in the recipient event. The
- mail_user event (for local delivery) also adds the user field, but
- adding it here makes it available to the recipient event in general.
- Additionally, the auth lookups performed for local and proxy delivery
- can further override the "user" recipient event when the auth service
- returns a different user name. In any case, we provide the initial
- value here.
- */
- event_add_str(rcpt->event, "user", username);
- if (detail[0] != '\0')
- event_add_str(rcpt->event, "detail", detail);
-
if (client->lmtp_set->lmtp_proxy) {
/* proxied? */
- if ((ret=lmtp_proxy_rcpt(client, cmd, lrcpt,
- username, detail, delim)) != 0)
+ if ((ret = lmtp_proxy_rcpt(client, cmd, lrcpt)) != 0)
return (ret < 0 ? -1 : 0);
/* no */
}
/* local delivery */
- return lmtp_local_rcpt(client, cmd, lrcpt, username, detail);
+ return lmtp_local_rcpt(client, cmd, lrcpt);
}
/*
struct lmtp_local_recipient {
struct lmtp_recipient *rcpt;
- char *detail;
-
struct mail_storage_service_user *service_user;
struct anvil_query *anvil_query;
int lmtp_local_rcpt(struct client *client,
struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
- struct lmtp_recipient *lrcpt, const char *username,
- const char *detail)
+ struct lmtp_recipient *lrcpt)
{
struct smtp_server_recipient *rcpt = lrcpt->rcpt;
struct lmtp_local_recipient *llrcpt;
struct mail_storage_service_input input;
struct mail_storage_service_user *service_user;
- const char *error = NULL;
+ const char *error = NULL, *username = lrcpt->username;
int ret = 0;
i_zero(&input);
llrcpt = p_new(rcpt->pool, struct lmtp_local_recipient, 1);
llrcpt->rcpt = lrcpt;
- llrcpt->detail = p_strdup(rcpt->pool, detail);
llrcpt->service_user = service_user;
lrcpt->type = LMTP_RECIPIENT_TYPE_LOCAL;
lldctx.smtp_set = smtp_set;
lldctx.lda_set = lda_set;
- if (*llrcpt->detail == '\0' ||
+ if (*lrcpt->detail == '\0' ||
!client->lmtp_set->lmtp_save_to_detail_mailbox)
lldctx.rcpt_default_mailbox = "INBOX";
else {
ns = mail_namespace_find_inbox(rcpt_user->namespaces);
lldctx.rcpt_default_mailbox =
- t_strconcat(ns->prefix, llrcpt->detail, NULL);
+ t_strconcat(ns->prefix, lrcpt->detail, NULL);
}
ret = client->v.local_deliver(client, lrcpt, cmd, trans, &lldctx);
int lmtp_local_rcpt(struct client *client,
struct smtp_server_cmd_ctx *cmd,
- struct lmtp_recipient *lrcpt, const char *username,
- const char *detail);
+ struct lmtp_recipient *lrcpt);
void lmtp_local_add_headers(struct lmtp_local *local,
struct smtp_server_transaction *trans,
int lmtp_proxy_rcpt(struct client *client,
struct smtp_server_cmd_ctx *cmd,
- struct lmtp_recipient *lrcpt,
- const char *username, const char *detail,
- char delim)
+ struct lmtp_recipient *lrcpt)
{
struct auth_master_connection *auth_conn;
struct lmtp_proxy_rcpt_settings set;
struct smtp_address *address = rcpt->path;
struct auth_user_info info;
struct mail_storage_service_input input;
- const char *const *fields, *errstr, *orig_username = username;
+ const char *const *fields, *errstr, *username, *orig_username;
struct smtp_proxy_data proxy_data;
struct smtp_address *user;
string_t *fwfields;
info.forward_fields = lrcpt->forward_fields;
// FIXME: make this async
+ username = orig_username = lrcpt->username;
auth_pool = pool_alloconly_create("auth lookup", 1024);
auth_conn = mail_storage_service_get_auth_conn(storage_service);
ret = auth_master_pass_lookup(auth_conn, username, &info,
return -1;
}
/* Username changed. change the address as well */
- if (*detail == '\0') {
+ if (*lrcpt->detail == '\0') {
address = user;
} else {
address = smtp_address_add_detail_temp(
- user, detail, delim);
+ user, lrcpt->detail, lrcpt->delim);
}
} else if (lmtp_proxy_is_ourself(client, &set)) {
e_error(rcpt->event, "Proxying to <%s> loops to itself",
int lmtp_proxy_rcpt(struct client *client,
struct smtp_server_cmd_ctx *cmd,
- struct lmtp_recipient *rcpt, const char *username,
- const char *detail, char delim);
+ struct lmtp_recipient *rcpt);
void lmtp_proxy_data(struct client *client,
struct smtp_server_cmd_ctx *cmd,
#include "lmtp-common.h"
#include "array.h"
+#include "smtp-address.h"
#include "smtp-server.h"
+#include "lda-settings.h"
#include "lmtp-recipient.h"
+#include "lmtp-client.h"
struct lmtp_recipient_module_register
lmtp_recipient_module_register = { 0 };
struct smtp_server_recipient *rcpt)
{
struct lmtp_recipient *lrcpt;
+ const char *username, *detail;
+ char delim = '\0';
lrcpt = p_new(rcpt->pool, struct lmtp_recipient, 1);
lrcpt->rcpt = rcpt;
lrcpt->client = client;
+ smtp_address_detail_parse_temp(
+ client->unexpanded_lda_set->recipient_delimiter,
+ rcpt->path, &username, &delim, &detail);
+ i_assert(*username != '\0');
+
+ lrcpt->username = p_strdup(rcpt->pool, username);
+ lrcpt->detail = p_strdup(rcpt->pool, detail);
+ lrcpt->delim = delim;
+
+ /* Make user name and detail available in the recipient event. The
+ mail_user event (for local delivery) also adds the user field, but
+ adding it here makes it available to the recipient event in general.
+ Additionally, the auth lookups performed for local and proxy delivery
+ can further override the "user" recipient event when the auth service
+ returns a different user name. In any case, we provide the initial
+ value here.
+ */
+ event_add_str(rcpt->event, "user", lrcpt->username);
+ if (detail[0] != '\0')
+ event_add_str(rcpt->event, "detail", lrcpt->detail);
+
rcpt->context = lrcpt;
p_array_init(&lrcpt->module_contexts, rcpt->pool, 5);
struct client *client;
struct smtp_server_recipient *rcpt;
+ char *username, *detail;
+ char delim;
+
enum lmtp_recipient_type type;
void *backend_context;