⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgimail1.c.txt

📁 基于80C196KC单片机的智能型开关电源研制??0C196KC单片机的智能型开关电源研制??0C196KC单片机的智能型开关电源研制??0C196KC单片机的智能型开关电源研制基于80C196
💻 TXT
字号:


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; 
} 
} 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -