Skip to content

Commit

Permalink
lib-smtp: smtp-server-recipient - Emit named events.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch committed Mar 2, 2019
1 parent d62d003 commit c82227c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/lib-smtp/smtp-server-cmd-rcpt.c
Expand Up @@ -64,7 +64,8 @@ cmd_rcpt_completed(struct smtp_server_cmd_ctx *cmd,
if (smtp_server_command_reply_is_forwarded(command))
(void)cmd_rcpt_check_state(cmd);

smtp_server_recipient_denied(rcpt);
smtp_server_recipient_denied(
rcpt, smtp_server_command_get_reply(cmd->cmd, 0));
return;
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib-smtp/smtp-server-private.h
Expand Up @@ -374,13 +374,15 @@ bool smtp_server_recipient_unref(struct smtp_server_recipient **_rcpt);
void smtp_server_recipient_destroy(struct smtp_server_recipient **_rcpt);

bool smtp_server_recipient_approved(struct smtp_server_recipient **_rcpt);
void smtp_server_recipient_denied(struct smtp_server_recipient *rcpt);
void smtp_server_recipient_denied(struct smtp_server_recipient *rcpt,
const struct smtp_server_reply *reply);

void smtp_server_recipient_last_data(struct smtp_server_recipient *rcpt,
struct smtp_server_cmd_ctx *cmd);

void smtp_server_recipient_reset(struct smtp_server_recipient *rcpt);
void smtp_server_recipient_finished(struct smtp_server_recipient *rcpt);
void smtp_server_recipient_finished(struct smtp_server_recipient *rcpt,
const struct smtp_server_reply *reply);

/*
* Transaction
Expand Down
42 changes: 40 additions & 2 deletions src/lib-smtp/smtp-server-recipient.c
Expand Up @@ -80,6 +80,17 @@ bool smtp_server_recipient_unref(struct smtp_server_recipient **_rcpt)
&rcpt, SMTP_SERVER_RECIPIENT_HOOK_DESTROY))
i_unreached();

if (!rcpt->finished) {
struct event_passthrough *e =
e = event_create_passthrough(rcpt->event)->
set_name("smtp_server_transaction_rcpt_finished");
e->add_int("status_code", 9000);
e->add_str("enhanced_code", "9.0.0");
e->add_str("error", "Aborted");

e_debug(e->event(), "Aborted");
}

event_unref(&rcpt->event);
pool_unref(&rcpt->pool);
return FALSE;
Expand All @@ -97,17 +108,27 @@ bool smtp_server_recipient_approved(struct smtp_server_recipient **_rcpt)

i_assert(trans != NULL);

e_debug(rcpt->event, "Approved");

rcpt->cmd = NULL;
smtp_server_transaction_add_rcpt(trans, rcpt);

return smtp_server_recipient_call_hooks(
_rcpt, SMTP_SERVER_RECIPIENT_HOOK_APPROVED);
}

void smtp_server_recipient_denied(struct smtp_server_recipient *rcpt)
void smtp_server_recipient_denied(struct smtp_server_recipient *rcpt,
const struct smtp_server_reply *reply)
{
i_assert(!rcpt->finished);
rcpt->finished = TRUE;

struct event_passthrough *e =
event_create_passthrough(rcpt->event)->
set_name("smtp_server_transaction_rcpt_finished");
smtp_server_reply_add_to_event(reply, e);

e_debug(e->event(), "Denied");
}

void smtp_server_recipient_last_data(struct smtp_server_recipient *rcpt,
Expand All @@ -121,12 +142,29 @@ void smtp_server_recipient_reset(struct smtp_server_recipient *rcpt)
{
i_assert(!rcpt->finished);
rcpt->finished = TRUE;

struct event_passthrough *e =
event_create_passthrough(rcpt->event)->
set_name("smtp_server_transaction_rcpt_finished");
e->add_int("status_code", 9000);
e->add_str("enhanced_code", "9.0.0");
e->add_str("error", "Reset");

e_debug(e->event(), "Reset");
}

void smtp_server_recipient_finished(struct smtp_server_recipient *rcpt)
void smtp_server_recipient_finished(struct smtp_server_recipient *rcpt,
const struct smtp_server_reply *reply)
{
i_assert(!rcpt->finished);
rcpt->finished = TRUE;

struct event_passthrough *e =
event_create_passthrough(rcpt->event)->
set_name("smtp_server_transaction_rcpt_finished");
smtp_server_reply_add_to_event(reply, e);

e_debug(e->event(), "Finished");
}

#undef smtp_server_recipient_add_hook
Expand Down
2 changes: 1 addition & 1 deletion src/lib-smtp/smtp-server-transaction.c
Expand Up @@ -239,7 +239,7 @@ void smtp_server_transaction_finished(struct smtp_server_transaction *trans,
reply = smtp_server_command_get_reply(cmd->cmd, i);
else
reply = smtp_server_command_get_reply(cmd->cmd, 0);
smtp_server_recipient_finished(rcpts[i]);
smtp_server_recipient_finished(rcpts[i], reply);

if (smtp_server_reply_is_success(reply))
rcpts_succeeded++;
Expand Down

0 comments on commit c82227c

Please sign in to comment.