/*
* Copyright (c) 2006 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
* $Id: example.c,v 8.5 2013-11-22 20:51:36 ca Exp $
*/
/*
** A trivial example filter that logs all email to a file.
** This milter also has some callbacks which it does not really use,
** but they are defined to serve as an example.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#ifndef true
# define false 0
# define true 1
#endif /* ! true */
struct mlfiPriv
{
char *mlfi_fname;
};
static unsigned long mta_caps = 0;
bool ok;
{
char *p;
return rstat;
/* close the archive file */
{
/* failed; we have to wait until later */
}
else if (ok)
{
/* add a header to the message announcing our presence */
if (p == NULL)
p = priv->mlfi_fname;
else
p++;
}
else
{
/* message was aborted -- delete the archive file */
}
/* release private memory */
/* return status */
return rstat;
}
char **envfrom;
{
/* allocate some private memory */
{
/* can't accept this message right now */
return SMFIS_TEMPFAIL;
}
/* open a file to store this message */
{
return SMFIS_TEMPFAIL;
}
{
if (fd >= 0)
return SMFIS_TEMPFAIL;
}
/* save the private data */
/* continue processing */
return SMFIS_CONTINUE;
}
char *headerf;
char *headerv;
{
/* write the header to the log file */
/* continue processing */
return ((mta_caps & SMFIP_NR_HDR) != 0)
}
{
/* output the blank line between the header and the body */
/* continue processing */
return SMFIS_CONTINUE;
}
{
/* output body block to log file */
{
/* write failed */
(void) mlfi_cleanup(ctx, false);
return SMFIS_TEMPFAIL;
}
/* continue processing */
return SMFIS_CONTINUE;
}
{
return mlfi_cleanup(ctx, true);
}
{
return SMFIS_ACCEPT;
}
{
return mlfi_cleanup(ctx, false);
}
char *cmd;
{
return SMFIS_CONTINUE;
}
{
return SMFIS_CONTINUE;
}
unsigned long f0;
unsigned long f1;
unsigned long f2;
unsigned long f3;
unsigned long *pf0;
unsigned long *pf1;
unsigned long *pf2;
unsigned long *pf3;
{
/* milter actions: add headers */
*pf0 = SMFIF_ADDHDRS;
/* milter protocol steps: all but connect, HELO, RCPT */
if ((mta_caps & SMFIP_NR_HDR) != 0)
*pf1 |= SMFIP_NR_HDR;
*pf2 = 0;
*pf3 = 0;
return SMFIS_CONTINUE;
}
{
"SampleFilter", /* filter name */
SMFI_VERSION, /* version code -- do not change */
SMFIF_ADDHDRS, /* flags */
NULL, /* connection info filter */
NULL, /* SMTP HELO command filter */
mlfi_envfrom, /* envelope sender filter */
NULL, /* envelope recipient filter */
mlfi_header, /* header filter */
mlfi_eoh, /* end of header */
mlfi_body, /* body block filter */
mlfi_eom, /* end of message */
mlfi_abort, /* message aborted */
mlfi_close, /* connection cleanup */
mlfi_unknown, /* unknown/unimplemented SMTP commands */
mlfi_data, /* DATA command filter */
mlfi_negotiate /* option negotiation at connection startup */
};
int
int argc;
char *argv[];
{
bool setconn;
int c;
setconn = false;
/* Process command line options */
{
switch (c)
{
case 'p':
{
optarg);
}
(void) smfi_setconn(optarg);
setconn = true;
break;
}
}
if (!setconn)
{
}
{
}
return smfi_main();
}