/* This file is part of Mailfromd.
Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#define MF_SOURCE_NAME MF_SOURCE_ENGINE
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
#include <syslog.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pthread.h>
#include <mailutils/mailutils.h>
#include <mailutils/daemon.h>
#include "mailfromd.h"
static const char *ctx_getsym(void *data, const char *str);
static int ctx_setreply(void *data, char *code, char *xcode, char *message);
static void ctx_msgmod(void *data, struct msgmod_closure *cmd);
/* Per-message data */
struct smtp_io_data; /* Declared later on */
struct message_data {
eval_environ_t env; /* Evaluation environment */
struct smtp_io_data *io; /* I/O data for SMTP transactions */
mu_list_t hdr; /* List of header modifications */
char *helostr; /* Domain name obtained in HELO phase */
char msgid[64]; /* Message ID */
};
static struct message_data *
priv_get(SMFICTX *ctx)
{
static struct message_data *test_data;
struct message_data *md;
if (mode == MAILFROMD_TEST)
md = test_data;
else
md = (struct message_data*) gacopyz_getpriv(ctx);
if (!md) {
md = malloc(sizeof(*md));
if (!md)
mu_error(_("Not enough memory"));
else {
md->env = create_environment(ctx,
ctx_getsym,
ctx_setreply,
ctx_msgmod,
ctx);
clear_rcpt_count(md->env);
md->hdr = NULL;
md->io = NULL;
md->helostr = NULL;
md->msgid[0] = 0;
if (mode == MAILFROMD_TEST)
test_data = md;
else
gacopyz_setpriv(ctx, md);
env_init(md->env);
xeval(md->env, smtp_state_begin);
}
}
if (!md->msgid[0]) {
const char *p = gacopyz_getsymval(ctx, "i");
if (p) {
size_t len = strlen(p);
if (len > sizeof md->msgid - 3)
len = sizeof md->msgid - 3;
memcpy(md->msgid, p, len);
md->msgid[len++] = ':';
md->msgid[len++] = ' ';
md->msgid[len] = 0;
}
}
return md;
}
|