Skip to content

Commit

Permalink
Pass sender/recip parameters into plugins (unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceg committed Jul 13, 2011
1 parent b48301d commit d665228
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 50 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Changes in version 2.00
- Capabilities reported by the SMTP EHLO response can be added by
plugins.

- Plugins are passed any SMTP parameters given with the sender and
recipient commands.

Plugins compiled for previous versions of mailfront will not work
without recompiling.

Expand Down
6 changes: 4 additions & 2 deletions backend-echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ static const response* reset(void)
return 0;
}

static const response* sender(str* s)
static const response* sender(str* s, str* params)
{
str_copys(&tmp, "Sender='");
str_cat(&tmp, s);
str_cats(&tmp, "'.");
resp.message = tmp.s;
return &resp;
(void)params;
}

static const response* recipient(str* r)
static const response* recipient(str* r, str* params)
{
str_copys(&tmp, "Recipient='");
str_cat(&tmp, r);
str_cats(&tmp, "'.");
resp.message = tmp.s;
return &resp;
(void)params;
}

static const response* data_block(const char* bytes, unsigned long len)
Expand Down
6 changes: 4 additions & 2 deletions backend-qmail.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ static const response* reset(void)
return 0;
}

static const response* do_sender(str* sender)
static const response* do_sender(str* sender, str* params)
{
if (!str_catc(&buffer, 'F') ||
!str_cat(&buffer, sender) ||
!str_catc(&buffer, 0)) return &resp_oom;
return 0;
(void)params;
}

static const response* do_recipient(str* recipient)
static const response* do_recipient(str* recipient, str* params)
{
if (!str_catc(&buffer, 'T') ||
!str_cat(&buffer, recipient) ||
!str_catc(&buffer, 0)) return &resp_oom;
return 0;
(void)params;
}

static const response *start_qq(int msgfd, int envfd)
Expand Down
12 changes: 8 additions & 4 deletions builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ static RESPONSE(ok, 250, 0);
static RESPONSE(mustauth, 530, "5.7.1 You must authenticate first.");
static response resp;

static const response* accept(str* s)
static const response* accept(str* s, str* params)
{
return &resp_accept;
(void)s;
(void)params;
}

static const response* reject(str* s)
static const response* reject(str* s, str* params)
{
const char* sr;
if ((sr = session_getenv("SMTPREJECT")) != 0
Expand All @@ -30,9 +31,10 @@ static const response* reject(str* s)
}
return 0;
(void)s;
(void)params;
}

static const response* relayclient_recip(str* recipient)
static const response* relayclient_recip(str* recipient, str* params)
{
const char* relayclient = session_getenv("RELAYCLIENT");
if (relayclient != 0) {
Expand All @@ -42,15 +44,17 @@ static const response* relayclient_recip(str* recipient)
else if (session_getnum("authenticated", 0))
return &resp_ok;
return 0;
(void)params;
}

static const response* require_auth(str* s)
static const response* require_auth(str* s, str* params)
{
if (!session_getnum("authenticated", 0)
&& session_getenv("RELAYCLIENT") == 0)
return &resp_mustauth;
return 0;
(void)s;
(void)params;
}

struct plugin builtin_plugins[] = {
Expand Down
22 changes: 16 additions & 6 deletions mailfront.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern void report_io_bytes(void);

static str tmp_prefix;

static str no_params;

#define MODULE_CALL(NAME,PARAMS,SHORT,RESET) do{ \
struct plugin* plugin; \
const response* tmp; \
Expand Down Expand Up @@ -80,29 +82,37 @@ const response* handle_reset(void)
return resp;
}

const response* handle_sender(str* sender)
const response* handle_sender(str* sender, str* params)
{
const response* resp = 0;
const response* tmpresp = 0;
MODULE_CALL(sender, (sender), 1, 0);
if (params == 0) {
no_params.len = 0;
params = &no_params;
}
MODULE_CALL(sender, (sender, params), 1, 0);
if (resp == 0)
return &resp_no_sender;
if (session.backend->sender != 0)
if (!response_ok(tmpresp = session.backend->sender(sender)))
if (!response_ok(tmpresp = session.backend->sender(sender, params)))
return tmpresp;
if (resp == 0 || resp->message == 0) resp = tmpresp;
return resp;
}

const response* handle_recipient(str* recip)
const response* handle_recipient(str* recip, str* params)
{
const response* resp = 0;
const response* hresp = 0;
MODULE_CALL(recipient, (recip), 1, 0);
if (params == 0) {
no_params.len = 0;
params = &no_params;
}
MODULE_CALL(recipient, (recip, params), 1, 0);
if (resp == 0)
return &resp_no_rcpt;
if (session.backend->recipient != 0)
if (!response_ok(hresp = session.backend->recipient(recip)))
if (!response_ok(hresp = session.backend->recipient(recip, params)))
return hresp;
if (resp == 0 || resp->message == 0) resp = hresp;
return resp;
Expand Down
8 changes: 4 additions & 4 deletions mailfront.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct plugin
const response* (*init)(void);
const response* (*helo)(str* hostname, str* capabilities);
const response* (*reset)(void);
const response* (*sender)(str*);
const response* (*recipient)(str*);
const response* (*sender)(str* address, str* params);
const response* (*recipient)(str* address, str* params);
const response* (*data_start)(int fd);
const response* (*data_block)(const char* bytes, unsigned long len);
const response* (*message_end)(int fd);
Expand All @@ -45,8 +45,8 @@ extern const char* getprotoenv(const char*);
extern const char UNKNOWN[];
extern const response* handle_helo(str* host, str* capabilities);
extern const response* handle_reset(void);
extern const response* handle_sender(str* sender);
extern const response* handle_recipient(str* recip);
extern const response* handle_sender(str* sender, str* params);
extern const response* handle_recipient(str* recip, str* params);
extern const response* handle_data_start(void);
extern void handle_data_bytes(const char* bytes, unsigned len);
extern const response* handle_message_end(void);
Expand Down
21 changes: 13 additions & 8 deletions plugin-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ <h2>Hook Functions</h2>
str</a> documentation module for functions to use in manipulating these
objects.</p>

<p>Sender and recipient SMTP parameters are passed as a <tt>str*</tt>
containing a NUL delimited list of <tt>KEYWORD=VALUE</tt> pairs. If the
parameter keyword was not followed by a value in the SMTP conversation,
the <tt>=VALUE</tt> portion will not be present in the string.</tt>

<p>Be aware that the <tt>sender</tt> and <tt>recipient</tt> hooks may be
called before the message data is handled (as with the SMTP protocol) or
after (as with the QMQP and QMTP protocol). In either case, the
Expand All @@ -128,15 +133,15 @@ <h2>Hook Functions</h2>
The <tt>capabilities</tt> variable contains a list of SMTP EHLO response
capabilities, each followed by a newline.</dd>

<dt><tt>const response* sender(str* address)</tt></dt> <dd>This hook is
called after a sender email address is transmitted by the client, and is
called exactly once per message. This chain short-circuits on non-error
response.</dd>
<dt><tt>const response* sender(str* address, str* params)</tt></dt>
<dd>This hook is called after a sender email address is transmitted by
the client, and is called exactly once per message. This chain
short-circuits on non-error response.</dd>

<dt><tt>const response* recipient(str* address)</tt></dt> <dd>This hook
is called after a sender email address is transmitted by the client, and
may be called zero or more times per message. This chain short-circuits
on non-error responses.</dd>
<dt><tt>const response* recipient(str* address, str* params)</tt></dt>
<dd>This hook is called after a sender email address is transmitted by
the client, and may be called zero or more times per message. This
chain short-circuits on non-error responses.</dd>

<dt><tt>const response* data_start(int fd)</tt></dt> <dd>This hook is
called when the sender starts transmitting the message data. Note that
Expand Down
6 changes: 4 additions & 2 deletions plugin-check-fqdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static const response* check_domains(const str* s, const char* domains)
}
}

static const response* sender(str* s)
static const response* sender(str* s, str* params)
{
const response* r;
const char* domains;
Expand All @@ -80,13 +80,15 @@ static const response* sender(str* s)
if ((domains = session_getenv("SENDER_DOMAINS")) != 0)
return check_domains(s, domains);
return 0;
(void)params;
}

static const response* recipient(str* s)
static const response* recipient(str* s, str* params)
{
if (s->len == 0)
return &resp_notemptyrcpt;
return check_fqdn(s);
(void)params;
}

struct plugin plugin = {
Expand Down
6 changes: 4 additions & 2 deletions plugin-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ static const response* reset(void)
return 0;
}

static const response* sender(str* r)
static const response* sender(str* r, str* params)
{
/* This MUST be done as a sender match to make sure SMTP "MAIL FROM"
* commands with a SIZE parameter can be rejected properly. */
minenv("maxdatabytes", "DATABYTES");
minenv("maxrcpts", "MAXRCPTS");
(void)r;
return 0;
(void)params;
}

static const response* recipient(str* r)
static const response* recipient(str* r, str* params)
{
unsigned long maxrcpts = minenv("maxrcpts", "MAXRCPTS");
minenv("maxdatabytes", "DATABYTES");
Expand All @@ -70,6 +71,7 @@ static const response* recipient(str* r)
return &resp_manyrcpt;
return 0;
(void)r;
(void)params;
}

static const response* start(int fd)
Expand Down
3 changes: 2 additions & 1 deletion plugin-cvm-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static const response* validate_init(void)
return 0;
}

static const response* validate_recipient(str* recipient)
static const response* validate_recipient(str* recipient, str* params)
{
struct cvm_credential creds[3];
unsigned i;
Expand Down Expand Up @@ -70,6 +70,7 @@ static const response* validate_recipient(str* recipient)
str_free(&creds[1].value);
str_free(&creds[2].value);
return r;
(void)params;
}

struct plugin plugin = {
Expand Down
12 changes: 8 additions & 4 deletions plugin-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,26 @@ static const response* helo(str* hostname, str* capabilities)
return 0;
}

static const response* sender(str* address)
static const response* sender(str* address, str* params)
{
if (setup("sender")) {
lua_pushlstring(L, address->s, address->len);
return callit(1);
lua_pushlstring(L, params->s, params->len);
return callit(2);
}
return 0;
(void)params;
}

static const response* recipient(str* address)
static const response* recipient(str* address, str* params)
{
if (setup("recipient")) {
lua_pushlstring(L, address->s, address->len);
return callit(1);
lua_pushlstring(L, params->s, params->len);
return callit(2);
}
return 0;
(void)params;
}

static const response* data_start(int fd)
Expand Down
6 changes: 4 additions & 2 deletions plugin-mailrules.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static void copy_addr(const str* addr,
static str saved_sender;
static str sender_domain;

static const response* validate_sender(str* sender)
static const response* validate_sender(str* sender, str* params)
{
struct rule* rule;
const response* r;
Expand All @@ -407,12 +407,13 @@ static const response* validate_sender(str* sender)
return r;
}
return 0;
(void)params;
}

static str laddr;
static str rdomain;

static const response* validate_recipient(str* recipient)
static const response* validate_recipient(str* recipient, str* params)
{
struct rule* rule;
const response* r;
Expand All @@ -428,6 +429,7 @@ static const response* validate_recipient(str* recipient)
return r;
}
return 0;
(void)params;
}

struct plugin plugin = {
Expand Down
6 changes: 4 additions & 2 deletions plugin-qmail-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const response* validate_init(void)
return 0;
}

static const response* validate_sender(str* sender)
static const response* validate_sender(str* sender, str* params)
{
int at;
str_copy(&tmp, sender);
Expand All @@ -54,9 +54,10 @@ static const response* validate_sender(str* sender)
if (dict_get(&bmf, &tmp)) return &resp_badmailfrom;
}
return 0;
(void)params;
}

static const response* validate_recipient(str* recipient)
static const response* validate_recipient(str* recipient, str* params)
{
int at;

Expand Down Expand Up @@ -84,6 +85,7 @@ static const response* validate_recipient(str* recipient)
}
}
return 0;
(void)params;
}

struct plugin plugin = {
Expand Down
Loading

0 comments on commit d665228

Please sign in to comment.