I'd like to see more of you on IRC:-)

OK, I'm regularly logging onto #apache-modules now

SMTP is two tasks: accept incoming connections (a protocol module -
c.f. the ftp modules), and make outgoing connections to another
server.  The latter would be a proxy_smtp module in the mod_proxy
framework - c.f. proxy_http and proxy_ftp.  These are clearly

That makes more sense than the route I was going

Have you done any research on available code for handling the protocol?

I will do more along those lines. The only SMTP package I am familiar with is Postfix, but I think we encountered a licensing issue in earlier discussion. If the protocol handling has to be redone from scratch, I am willing to work on that.

That's basically a similar task to CGI, and a first pass at that
would be to try running procmail under CGI (with incoming HTTP POST
or PUT requests will do fine).  I imagine that would be a pretty
trivial job with perl or python.

Attached is a quick demo that allows mail delivery via CGI (HTTP POST).
cat raw-email-message | curl -s --data-binary @- http://.../cgi-procmail

It works on my Linux and FreeBSD system. It's hard coded to deliver to the current user only (web server user) but procmail runs suid root so you could deliver to other users too.

Now look at what you needed to do.  That's a first-pass spec for
this task.  It should be a fairly straightforward mod to mod_cgi(d).
I'm not sure whether that's the best approach, but hacking it up
will surely throw some light on the matter.

I don't quite understand this... are you saying that instead of an external CGI program (as attached), the pipe to procmail functionality should be a server module?
/*
        cgi-procmail 0.90
        Copyright (C) 2005 Jem E. Berkes
        
        Accept an email from an HTTP POST request, for local delivery.
        The cgi program runs with web server user's privileges so mail can
        only be delivered to the web server user. Warning, uses popen()
        
        To send the web server an email, use:
                cat raw-email-message | curl -s --data-binary @- http://address
        
*/


#define PROCMAIL_CMD    "/usr/bin/procmail -f -"
#define MAXIMUM_LINE    1000    /* As per RFC, max line including \n and \0 */
#define EXIT_SUCCESS    0
#define EXIT_FAILURE    1


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


int main()
{
        FILE* dest = popen(PROCMAIL_CMD, "w");
        printf("Content-Type: text/plain\n\n");
        if (dest)
        {
                char dataline[MAXIMUM_LINE];
                /* pipe HTTP POST data to procmail */
                while (fgets(dataline, sizeof(dataline), stdin))
                        fputs(dataline, dest);
                if (fclose(dest) == 0)
                {
                        puts("Mail sent to procmail");
                        return EXIT_SUCCESS;
                }
                else
                {
                        puts("Error closing pipe");
                        fprintf(stderr, "Error closing pipe to " PROCMAIL_CMD 
"\n");
                        return EXIT_FAILURE;
                }
        }
        else
        {
                puts("Pipe failure");
                fprintf(stderr, "Unable to open pipe to " PROCMAIL_CMD "\n");
                return EXIT_FAILURE;
        }
}

Reply via email to