/* See the section just after the license for important configuration
#defines!
Email handler. This is based on the post_query.c code provided with
the NCSA httpd 1.1 package, released to the public domain
(see their policy, which follows).
Original portions Copyright 1994 Cold Spring Harbor Labs.
Permission granted to copy, modify and otherwise use
this code in whatever manner you see fit, with no warranty
expressed or implied. Plesae retain this notice; this is
the only restriction. We also ask that you credit
yourself for any changes so we are not asked to maintain
versions of the code that are no longer recognizable to us.
Original portions by Thomas Boutell.
Portions developed at the National Center for Supercomputing
Applications at the University of Illinois at Urbana-Champaign.
THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED,
FOR THE SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT
LIMITATION, WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A
PARTICULAR PURPOSE. */
/* where the email configuration file is found. */
#define EMAIL_CONF_PATH "/home/boutell/email/email.conf"
/* where the email program lives on your system. You may want to
change this; try the command 'which mail' to
find out where your mailer lives. */
#define EMAIL_BINARY "/bin/mail"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_ENTRIES 10000
extern char *getenv(char *e);
typedef struct {
char *name;
char *val;
} entry;
/* Removes trailing white space, etc */
void wsremove(char *s);
char *makeword(char *line, char stop);
char *fmakeword(FILE *f, char stop, int *len);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);
main(int argc, char *argv[]) {
entry entries[MAX_ENTRIES];
register int x,m=0;
int i;
char *content;
int len;
int filterState;
int ok = 0;
int cl;
int nameid = -1;
int emailid = -1;
int contentid = -1;
int subjectid = -1;
int recipientid = -1;
FILE *out;
FILE *in;
char buf[81];
char recipientc[81];
char returnpage[81];
printf("Content-type: text/html%c%c",10,10);
if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
printf("This script should be referenced with a METHOD of POST.\n");
printf("If you don't understand this, see this ");
printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
exit(1);
}
if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
printf("This script can only be used to decode form results. \n");
exit(1);
}
cl = atoi(getenv("CONTENT_LENGTH"));
for(x=0;cl && (!feof(stdin));x++) {
m=x;
entries[x].val = fmakeword(stdin,'&',&cl);
plustospace(entries[x].val);
unescape_url(entries[x].val);
entries[x].name = makeword(entries[x].val,'=');
if ((!strcmp(entries[x].name, "name")) &&
(strcmp(entries[x].val, ""))) {
nameid = x;
} else if ((!strcmp(entries[x].name, "email")) &&
(strcmp(entries[x].val, ""))) {
emailid = x;
} else if ((!strcmp(entries[x].name, "recipient")) &&
(strcmp(entries[x].val, ""))) {
recipientid = x;
} else if ((!strcmp(entries[x].name, "content")) &&
(strcmp(entries[x].val, ""))) {
contentid = x;
} else if ((!strcmp(entries[x].name, "subject")) &&
(strcmp(entries[x].val, ""))) {
subjectid = x;
}
}
if ((nameid == -1) || (emailid == -1) ||
(contentid == -1) || (recipientid == -1)) {
printf("<TITLE>Email Rejected</TITLE>");
printf("<H1>Email Rejected</H1>");
printf("<P>Please fill out all fields provided.\n");
printf("Back up to the previous page to try again.\n");
return 0;
}
in = fopen(EMAIL_CONF_PATH, "r");
ok = 0;
while(1) {
if (!fgets(recipientc, 80, in)) {
break;
}
wsremove(recipientc);
if (!fgets(returnpage, 80, in)) {
break;
}
wsremove(returnpage);
if (!strcmp(entries[recipientid].val, recipientc)) {
ok = 1;
break;
}
}
fclose(in);
if (!ok) {
printf("<TITLE>Email Rejected</TITLE>");
printf("<H1>Email Rejected</H1>");
printf("<P>%s is not one of the permitted email recipients.\n",
entries[recipientid].val);
printf("Back up to the previous page to try again.\n");
return 0;
}
sprintf(buf, "%s %s", EMAIL_BINARY, entries[recipientid].val);
out = popen(buf, "w");
fprintf(out, "Subject: %s\n", entries[subjectid].val);
fprintf(out, "Reply-To: %s\n\n", entries[emailid].val);
fprintf(out, "Supposedly-From: %s\n", entries[nameid].val);
fprintf(out, "[This message was sent through a www-email gateway.]\n");
fprintf(out, "--\n");
/* Security fix 8/5/95: we need to filter out ~ escapes. So we
watch for a line break (or series of line-breaking characters)
followed by a ~. If we see one, we replace the ~ with a space. */
content = entries[contentid].val;
len = strlen(content);
/* make sure we're watching for a ~ on the first line */
filterState = 1;
for (i=0; (i < len); i++) {
switch(filterState) {
case 0:
if ((content[i] == '\n') || (content[i] == '\r')) {
filterState = 1;
}
break;
case 1:
if ((content[i] == '\n') || (content[i] == '\r')) {
break;
}
if (content[i] == '~') {
/* Quash the dangerous character */
content[i] = ' ';
}
filterState = 0;
break;
}
}
fprintf(out, "%s\n", content);
pclose(out);
printf("<TITLE>Message Accepted</TITLE>\n");
printf("<H1>Message Accepted</H1>\n");
printf("<A HREF=\"%s\">Follow this link to continue.</A>\n", returnpage);
}
/* Removes trailing white space, etc */
void wsremove(char *s) {
while(1) {
int l = strlen(s);
if (!l) {
break;
}
if (isspace(s[l-1])) {
s[l-1] = '\0';
} else {
break;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
CGI邮件程序源码
共2个文件
txt:2个
需积分: 0 13 下载量 84 浏览量
2008-07-26
21:15:49
上传
评论
收藏 3KB ZIP 举报
温馨提示
CGI邮件程序源码.
资源详情
资源评论
资源推荐
收起资源包目录
CGI邮件程序源码.zip (2个子文件)
cgimail1.c.txt 6KB
网城学校.txt 136B
共 2 条
- 1
lili289235990
- 粉丝: 2
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0