Commit 8b0317ff 8b0317ffca0594d8769f277062a0b7eb55687add by Wojciech Polak

Add Python scripting to maidag.

* maidag/python.c: New file.
* maidag/script.c (script_tab): Add Python.
* maidag/maidag.h (python_check_msg): New prototype.
* configure.ac: Conditionally define python-related variables.
1 parent 43088a1c
......@@ -50,7 +50,7 @@ AC_SUBST(MU_LIB_SIEVE,'${top_builddir}/libmu_sieve/libmu_sieve.la')
AC_SUBST(MU_LIB_SCM,'${top_builddir}/libmu_scm/libmu_scm.la')
AC_SUBST(MU_LIB_CPP,'${top_builddir}/libmu_cpp/libmu_cpp.la')
AC_SUBST(MU_LIB_ARGP,'${top_builddir}/libmu_argp/libmu_argp.la')
AC_SUBST(MU_LIB_PY, '${top_builddir}/python/libmu_py/libmu_py.la')
AC_SUBST(MU_LIB_PY)
dnl Other variables
AC_SUBST(mu_aux_dir,'$(top_srcdir)/mu-aux')
......@@ -1103,23 +1103,30 @@ case "${withval}" in
*) AC_MSG_ERROR(bad value ${withval} for --without-python) ;;
esac],[status_python=yes])
AC_SUBST(PYTHON_LIBS)
AC_SUBST(PYTHON_INCLUDES)
AC_SUBST(MU_PY_LIB_LTLIBRARIES_BUILD)
AC_SUBST(MU_PY_PKGPYEXEC_LTLIBRARIES_BUILD)
AC_SUBST(MU_PY_PKGPYTHON_BUILD)
if test "$status_python" = yes; then
AM_PATH_PYTHON(2.5.0,, [status_python=no])
if test "$status_python" = yes; then
AC_ARG_VAR([PYTHON_CONFIG], [The name of python-config binary])
AC_PATH_PROG([PYTHON_CONFIG], python-config)
if test -n "$PYTHON_CONFIG"; then
AC_SUBST(PYTHON_LIBS,`python-config --libs`)
AC_SUBST(PYTHON_INCLUDES,`python-config --includes`)
PYTHON_LIBS=`python-config --libs`
PYTHON_INCLUDES=`python-config --includes`
else
status_python=no
fi
if test "$status_python" = yes; then
AC_DEFINE(WITH_PYTHON,1,[Enable Python support])
AC_SUBST(MU_PY_LIB_LTLIBRARIES_BUILD, '$(MU_PY_LIB_LTLIBRARIES_LIST)')
AC_SUBST(MU_PY_PKGPYEXEC_LTLIBRARIES_BUILD,'$(MU_PY_PKGPYEXEC_LTLIBRARIES_LIST)')
AC_SUBST(MU_PY_PKGPYTHON_BUILD,'$(MU_PY_PKGPYTHON_LIST)')
MU_PY_LIB_LTLIBRARIES_BUILD='$(MU_PY_LIB_LTLIBRARIES_LIST)'
MU_PY_PKGPYEXEC_LTLIBRARIES_BUILD='$(MU_PY_PKGPYEXEC_LTLIBRARIES_LIST)'
MU_PY_PKGPYTHON_BUILD='$(MU_PY_PKGPYTHON_LIST)'
MU_LIB_PY='${top_builddir}/python/libmu_py/libmu_py.la'
fi
fi
fi
......
# Copyright (C) 2007 Free Software Foundation, Inc.
# Copyright (C) 2007, 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
......@@ -15,7 +15,8 @@
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
INCLUDES = -I${top_srcdir} @MU_COMMON_INCLUDES@ @GUILE_INCLUDES@
INCLUDES = -I${top_srcdir} @MU_COMMON_INCLUDES@ @GUILE_INCLUDES@ \
@PYTHON_INCLUDES@
sbin_PROGRAMS=maidag
maidag_SOURCES=\
......@@ -27,6 +28,7 @@ maidag_SOURCES=\
maidag.h\
mailtmp.c\
mailquota.c\
python.c\
sieve.c\
script.c\
util.c
......@@ -34,6 +36,7 @@ maidag_SOURCES=\
maidag_LDADD = \
@LIBMU_SCM@ @GUILE_LIBS@\
@LIBMU_SCM_DEPS@\
@MU_LIB_PY@ @PYTHON_LIBS@\
${MU_APP_LIBRARIES}\
${MU_LIB_SIEVE}\
${MU_LIB_MBOX}\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -200,6 +200,10 @@ extern int debug_guile;
int scheme_check_msg (mu_message_t msg, struct mu_auth_data *auth,
const char *prog);
/* python.c */
int python_check_msg (mu_message_t msg, struct mu_auth_data *auth,
const char *prog);
/* sieve.c */
int sieve_check_msg (mu_message_t msg, struct mu_auth_data *auth,
const char *prog);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
GNU Mailutils 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.
GNU Mailutils 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 GNU Mailutils; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA */
#include "maidag.h"
#ifdef WITH_PYTHON
#include <mailutils/python.h>
int
python_check_msg (mu_message_t msg, struct mu_auth_data *auth,
const char *prog)
{
int status;
PyMessage *py_msg;
mu_py_dict dict[2];
mu_py_script_data data[1];
char *argv[] = { "maidag", NULL };
mu_py_script_init (1, argv);
py_msg = PyMessage_NEW ();
py_msg->msg = msg;
Py_INCREF (py_msg);
dict[0].name = "message";
dict[0].obj = (PyObject *)py_msg;
dict[1].name = NULL;
data[0].module_name = "maidag";
data[0].attrs = dict;
mu_py_script_run (prog, data);
mu_py_script_finish ();
return 0;
}
#endif /* WITH_PYTHON */
......@@ -27,6 +27,9 @@ struct script_tab
};
struct script_tab script_tab[] = {
#ifdef WITH_PYTHON
{ "python", "py\0pyc\0", python_check_msg },
#endif
{ "sieve", "sv\0siv\0sieve\0", sieve_check_msg },
#ifdef WITH_GUILE
{ "scheme", "scm\0", scheme_check_msg },
......