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

📄 utils.cpp

📁 一个国外学生做的基于Web浏览器的email程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		i1++;		i2++;	} 	return 0;}void scansend(char * search, char * data, int length, char * newboundary){	sprintf(search, "");	while (fgets(data, length, stdin) != NULL)	{		if (strncasecmp(newboundary, data, strlen(newboundary)) == 0)		{			break;		}		else if (data[0] == '\n' || data[0] == '\r')		{						}		else			sprintf(search, "%s%s", search, data); 			//end of data can have a \n, not sure this is ok?	}	return;}/*****************************************Not used any more I think.*****************************************/void encodeuuline(char * filename){	char command[400];	passwd *info;	info=getpwnam(globaluser);	//in, name in uue file, > to real file	snprintf(command, 400, "/usr/bin/uuencode %s/.webmail/uutmp %s > %s/.webmail/uutmp.uue", info->pw_dir, filename, info->pw_dir);	system(command);	}void intofile(char * b, char * name){	int key;	FILE * out;	long size = 0;	char enddata[200];	snprintf(enddata, 200, "%c%c%s", 0x0d, 0x0a, b);		char *env;	char data[200];	char filename[200];	int filenamefound = 0;	char fullpath[400];	passwd *user;	user = getpwnam(globaluser);	if (user == NULL)	{		error("intofile(): User not valid.");		return;	}		if ((env = getenv("HTTP_USER_AGENT")) == NULL)	{		error("intofile(): Browser version can't be found.");		return;	}	if (strncmp(env, "Mozilla/4", 9)==0 ||	strncmp(env, "Mozilla/3", 9)==0)	{			}	else	{		error("intofile(): Your browser is not supported for file up loads.");		return;	}	int index = 0;	snprintf(fullpath, 400, "%s/.webmail/uutmp", user->pw_dir);	out = fopen(fullpath, "w+");	if (out == NULL)	{		error("intofile(): can't open uutmp for write.");			return;	}	if (bothlock(out, 'w')!=0)	{		fclose(out);		error("intofile():Error locking out");		return;			}	while (fread(&key, 1, 1, stdin))	{		if (enddata[index] == '\0')		{			break;		}		else if ((key&0xFF) == enddata[index])		{			index++;		}		else		{			for (int i = 0; i < index; i++)			{ 				fwrite(&enddata[i], 1, 1, out);				size++;			}			index = 0;			if ((key&0xFF) == enddata[index])				index++;			else			{				fwrite(&key, 1, 1, out);				size++;			}		}	}	bothunlock(out); 	fclose(out);	return;}void procconf(){	char *env;	char *data;	char *signature;	char *forward;	int length;	char forwardpath[400];	char signaturepath[400];	FILE *forwardfile;	FILE *signaturefile;	char *popuser;	char *poppass;	char *popserver;	char poppath[400];	FILE *popfile;	char *userreturn;	char userreturnpath[400];	FILE *userreturnfile;	passwd *info;	info=getpwnam(globaluser);	if (info == NULL)	{		error("Procconf(): Can't get user info.");		return;	}	if ((env = getenv("CONTENT_LENGTH"))==NULL)	{		error("Procconf(): Can't read environment.");		return;	}	length = atoi(env);	length+=5; // needed for null space	data = new char[length];	forward = new char[length];	signature = new char[length];	if (USERRETURN)	{		userreturn = new char[length];	}	if (USEEXTERNMAIL)	{		popuser = new char[length];		poppass = new char[length];		popserver = new char[length];	}	if (fgets(data, length, stdin) == NULL)	{		error("procconf(): Can't read form stdin.");	}		if (finddata(data, "sign=", signature) == NULL)	{		error("procconf(): Can't find sign tag.");		return;	}	if (finddata(data, "forward=", forward) == NULL)	{		error ("procconf(): Can't find forward tag");		return;	}	if (USERRETURN)	{		if (finddata(data, "userreturn=", userreturn) == NULL)		{			error ("procconf(): Can't find userreturn tag");			return;		}	}	if (USEEXTERNMAIL)	{		if (finddata(data, "popuser=", popuser) == NULL)		{			error("procconf(): Can't find popuser tag.");			return;		}		if (finddata(data, "poppass=", poppass) == NULL)		{			error("procconf(): Can't find poppass tag.");			return;		}		if (finddata(data, "popserver=", popserver) == NULL)		{			error ("procconf(): Can't find popserver tag");			return;		}	}	htmldecode(signature);	snprintf(signaturepath, 400, "%s/.signature", info->pw_dir);	if (signature[0] == '\0')	{		remove(signaturepath);	}	else	{		signaturefile = fopen(signaturepath, "w");		if (signaturefile == NULL)		{			error("procconf(): can't open signature file for write.");			return;		}		fputs(signature, signaturefile);		fclose(signaturefile);	}	htmldecode(forward);	snprintf(forwardpath, 400, "%s/.forward", info->pw_dir);	if (forward[0] == '\0')	{			remove(forwardpath);	}	else	{		forwardfile = fopen(forwardpath, "w");		if (forwardfile == NULL)		{			error("procconf(): can't open forward file for write.");			return;		}		if (bothlock(forwardfile, 'w')!=0)		{			fclose(forwardfile);			error("procconf():Error locking tmpstore");			return;				}		fputs(forward, forwardfile);		bothunlock(forwardfile);		fclose(forwardfile);	}	if (USERRETURN)	{		htmldecode(userreturn);		snprintf(userreturnpath, 400, "%s/.webmail/return",info->pw_dir);		if (userreturn[0] == '\0')		{			remove(userreturnpath);		}		else		{			umask(066);			userreturnfile = fopen(userreturnpath, "w");			if (userreturnfile == NULL)			{				error("procconf(): can't open return file for write.");				return;			}			if (bothlock(userreturnfile, 'w')!=0)			{				fclose(userreturnfile);				error("procconf():Error locking return file");				return;			}			//writes web e-mail's data			fputs(userreturn, userreturnfile);			bothunlock(userreturnfile);			fclose(userreturnfile);		}	}	if (USEEXTERNMAIL)	{		htmldecode(popuser);		htmldecode(poppass);		htmldecode(popserver);		snprintf(poppath, 400, "%s/.fetchmailrc", info->pw_dir);		if (popuser[0] == '\0')		{				remove(poppath);		}		else		{			umask(066);			popfile = fopen(poppath, "w");			if (popfile == NULL)			{				error("procconf(): can't open fetchmail file for write.");				return;			}			if (bothlock(popfile, 'w')!=0)			{				fclose(popfile);				error("procconf():Error locking popfile");				return;			}			//writes web e-mail's data			fputs("# popuser=", popfile);			fputs(popuser, popfile);			fputs("&popserver=", popfile);			fputs(popserver, popfile);			fputs("&poppass=", popfile);			fputs(poppass, popfile);			fputs("\n\n", popfile);			//writes warning			fputs("# Configuration created by Web E-Mail.\n", popfile);			fputs("# Changing this file will brake Web E-Mail's\n", popfile);			fputs("# ablity to configure fetchmail.\n", popfile);			fputs("# If you use Web e-mail's confuration utility\n", popfile);			fputs("# after this file has been edited, you may lose\n", popfile);			fputs("# your current edited fetchmail configuation.\n\n", popfile);						//write fetchmail data			fputs("set postmaster \"", popfile);			fputs(globaluser, popfile);			fputs("\"\n", popfile);			fputs("set bouncemail\n", popfile);			fputs("set properties \"\"\n", popfile);			fputs("poll ", popfile); 			fputs(popserver, popfile);			fputs(" with proto POP3\n", popfile);       			fputs("\tuser \"", popfile); 			fputs(popuser, popfile);			fputs("\" there with password \"", popfile);			fputs(poppass, popfile);			fputs("\" is ", popfile);			fputs(globaluser, popfile);			fputs(" here", popfile);			bothunlock(popfile);			fclose(popfile);		}	}	delete data;	delete forward;	delete signature;	if (USEEXTERNMAIL)	{		delete popuser;		delete poppass;		delete popserver;	}	sync();		disjavascript("", "System configured", "menu");	return;}void markreplied(int number){	passwd *info;	FILE *mailstore;	FILE *tmpstore;	char mailname[400];	char tmpname[400];	char data[500];	int count = 0;	int infonotfound = 1;	info=getpwnam(globaluser);	snprintf(mailname, 400, MAILBOXPATH);	snprintf(tmpname, 400, "%s/.webmail/tmp",info->pw_dir);	mailstore = fopen(mailname, "r");	if (mailstore == NULL)	{		error("Markreplied():Error opening data for read");		return;	}	if (bothlock(mailstore, 'r')!=0)	{		fclose(mailstore);		error("Markreplied():Error locking mailstore");		return;			}	tmpstore = fopen(tmpname, "w");	if (tmpstore == NULL)	{		error("Markreplied():error opening temp for write");		fclose(mailstore);		return;	}	if (bothlock(tmpstore, 'w')!=0)	{		fclose(tmpstore);		fclose(mailstore);		error("Markreplied():Error locking tmpstore");		return;			}	while (fgets(data, 499, mailstore) != NULL)	{		fputs(data, tmpstore);	}	bothunlock(mailstore);	fclose(mailstore);	bothunlock(tmpstore);	fclose(tmpstore);	sync();	mailstore = fopen(mailname, "w");	if (mailstore == NULL)	{		return; //errors will be encountered by calling function	}	if (bothlock(mailstore, 'w')!=0)	{		fclose(mailstore);		error("Markreplied():Error locking tmpstore");		return;			}	tmpstore = fopen(tmpname, "r");	if (tmpstore == NULL)	{		return; //errors will be encountered by calling function	}	if (bothlock(tmpstore, 'r')!=0)	{		fclose(tmpstore);		fclose(mailstore);		error("Markreplied():Error locking tmpstore");		return;			}	while (fgets(data, 499, tmpstore) != NULL)	{		if (strncmp(data, "From ", 5)==0)		{			count++;		}		if (count == number)		{			if (strncmp(data, "\n", 1)==0)			{				count++;				if (infonotfound == 1)				{					fputs("X-Status: A", mailstore);					fputs("\n", mailstore);				}			}			if (strncasecmp(data, "X-Status: ", 10)==0)			{				fputs("X-Status: A", mailstore);				fputs("\n", mailstore);				infonotfound = 0;			}			else				fputs(data, mailstore);					}		else			fputs(data, mailstore);	}	bothunlock(tmpstore);	fclose(tmpstore);	bothunlock(mailstore);	fclose(mailstore);	remove(tmpname);	sync();	return;}

⌨️ 快捷键说明

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