Re: E-Mail form binary

Jay C. Weber (weber@eit.COM)
Fri, 12 Aug 94 16:01:21 PDT


> From: jallaire@skypoint.net (Jeremy D. Allaire)
>
> Does anyone have an e-mail app that works easily with a basic subject,
> name, text filed form?

Here's one I wrote; it uses the libCGI library, available in
ftp://ftp.eit.com/pub/wsk/sunos/libcgi

Kevin Hughes made an enhanced version of this, in the hypermail
distribution (also on our ftp server).

Jay

--- cut here ---

/*
* This CGI program constructs an email form (GET) and sends the contents (POST)
*/

#include<stdio.h>
#include "libcgi/cgi.h"

cgi_main(cgi_info *ci) {
form_entry *parms, *p;
form_entry *get_form_entries(cgi_info *);
char *from, *to, *subject, *body;
FILE *f;

print_mimeheader("text/html");

from = to = subject = body = "";
parms = get_form_entries(ci);
if (parms) {
/* extract specific form parameters */
for(p=parms; p; p = p->next) {
if (!strcasecmp(p->name, "from")) from = p->val;
else if (!strcasecmp(p->name, "to")) to = p->val;
else if (!strcasecmp(p->name, "subject")) subject = p->val;
else if (!strcasecmp(p->name, "body")) body = p->val;
}
}

switch(mcode(ci)) {

case MCODE_HEAD:
return;

case MCODE_GET:
if (!(from && *from) && (ci->remote_user && *(ci->remote_user)))
from = ci->remote_user;
puts("<title>Email Gateway</title><h1>Send an email message</h1>");
puts("<form method=POST action=\"mail\">");
printf("<pre>To: <input size=50 name=to value=\"%s\">\n", to);
printf("From: <input size=50 name=from value=\"%s\">\n", from);
printf("Subject: <input size=50 name=subject value=\"%s\">\n", subject);
printf("<textarea name=body rows=20 cols=60>%s\n</textarea>\n", body);
puts("<input type=submit value=Send></pre></form>");
break;

case MCODE_POST:
puts("<title>Email Gateway response</title>");

if (f = popen("/usr/lib/sendmail -t", "w")) {
fprintf(f, "From: %s\nTo: %s\nSubject: %s\n\n%s",
from, to, subject, body);
pclose(f);
puts("<h1>Ok</h1>message sent");
printf("<pre>From: %s\nTo: %s\nSubject: %s\n\n%s\n</pre>",
from, to, subject, body);
}
else {
puts("<h1>Error</h1>Message not sent, error invoking sendmail.");
}
break;

default:
printf("Unrecognized method '%s'.\n", ci->request_method);
}

free_form_entries(parms);
}