Skip to content

Commit

Permalink
submission: client: Add API for adding extra (non-standard) capabilit…
Browse files Browse the repository at this point in the history
…ies.
  • Loading branch information
stephanbosch authored and villesavolainen committed Feb 12, 2019
1 parent 946a45a commit ee00653
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/submission/submission-client.c
Expand Up @@ -19,6 +19,7 @@
#include "mail-storage-service.h"
#include "raw-storage.h"
#include "imap-urlauth.h"
#include "smtp-syntax.h"
#include "smtp-client-connection.h"

#include "submission-backend-relay.h"
Expand Down Expand Up @@ -502,6 +503,29 @@ uoff_t client_get_max_mail_size(struct client *client)
return max_size;
}

void client_add_extra_capability(struct client *client, const char *capability,
const char *params)
{
struct client_extra_capability cap;

/* Don't add capabilties handled by lib-smtp here */
i_assert(smtp_capability_find_by_name(capability)
== SMTP_CAPABILITY_NONE);

/* Avoid committing protocol errors */
i_assert(smtp_ehlo_keyword_is_valid(capability));
i_assert(params == NULL || smtp_ehlo_params_are_valid(params));

i_zero(&cap);
cap.capability = p_strdup(client->pool, capability);
cap.params = p_strdup(client->pool, params);

if (!array_is_created(&client->extra_capabilities))
p_array_init(&client->extra_capabilities, client->pool, 5);

array_append(&client->extra_capabilities, &cap, 1);
}

void clients_destroy_all(void)
{
while (submission_clients != NULL) {
Expand Down
11 changes: 11 additions & 0 deletions src/submission/submission-client.h
Expand Up @@ -17,6 +17,11 @@ struct client_state {
uoff_t data_size;
};

struct client_extra_capability {
const char *capability;
const char *params;
};

struct submission_client_vfuncs {
void (*destroy)(struct client *client, const char *prefix,
const char *reason);
Expand Down Expand Up @@ -79,6 +84,9 @@ struct client {
struct submission_backend *backends;
unsigned int backends_count;

/* Extra (non-standard) capabilities */
ARRAY(struct client_extra_capability) extra_capabilities;

/* Module-specific contexts. */
ARRAY(union submission_module_context *) module_contexts;

Expand Down Expand Up @@ -124,6 +132,9 @@ const char *client_state_get_name(struct client *client);

uoff_t client_get_max_mail_size(struct client *client);

void client_add_extra_capability(struct client *client, const char *capability,
const char *params) ATTR_NULL(2);

int client_input_read(struct client *client);
int client_handle_input(struct client *client);

Expand Down
21 changes: 21 additions & 0 deletions src/submission/submission-commands.c
Expand Up @@ -20,6 +20,25 @@
* EHLO, HELO commands
*/

static void
submission_helo_reply_add_extra(struct client *client,
struct smtp_server_reply *reply)
{
const struct client_extra_capability *cap;

if (!array_is_created(&client->extra_capabilities))
return;

array_foreach(&client->extra_capabilities, cap) {
if (cap->params == NULL) {
smtp_server_reply_ehlo_add(reply, cap->capability);
} else {
smtp_server_reply_ehlo_add_param(reply, cap->capability,
"%s", cap->params);
}
}
}

void submission_helo_reply_submit(struct smtp_server_cmd_ctx *cmd,
struct smtp_server_cmd_helo *data)
{
Expand Down Expand Up @@ -71,6 +90,8 @@ void submission_helo_reply_submit(struct smtp_server_cmd_ctx *cmd,
smtp_server_reply_ehlo_add(reply, "SIZE");
}
smtp_server_reply_ehlo_add(reply, "VRFY");

submission_helo_reply_add_extra(client, reply);
}
smtp_server_reply_submit(reply);
}
Expand Down

0 comments on commit ee00653

Please sign in to comment.