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

📄 delete.cpp

📁 一个国外学生做的基于Web浏览器的email程序
💻 CPP
字号:
#include "webemail.h"#include "delete.h"void deletemail(char path[], int mailnumber){	passwd *info;	FILE *data;	FILE *tmp;	char tmpname[400];	char buf[500];	int emailcount = 0;	char *env;		info=getpwnam(globaluser);	snprintf(tmpname, 400, "%s/.webmail/tmp", info->pw_dir);	data = fopen(path, "r");	if (data == NULL)	{		error("deletemail():Error opening data for read");		return;	}	if (bothlock(data, 'r')!=0)	{		fclose(data);		error("deletemail():Error locking data for read");		return;	}	tmp = fopen(tmpname, "w");	if (tmp == NULL)	{		error("deletemail():error opening temp for write");		fclose(data);		return;	}	if (bothlock(tmp, 'w')!=0)	{		fclose(tmp);		fclose(data);		error("deletemail():error locking temp for write");		return;	}	while (fgets(buf, 499, data) != NULL)	{		fputs(buf, tmp);	}	fclose(data);	fclose(tmp);	data = fopen(path, "w");	if (data == NULL)	{		error("deletemail():Error opening data for write");		return;	}	tmp = fopen(tmpname, "r");	if (tmp == NULL)	{		fclose(data);		error("deletemail():error opening temp for read");		return;	}		while (fgets(buf, 499, tmp) != NULL)	{		if (strncmp(buf, "From ", 5)==0)		{			emailcount++;		}		if (emailcount != mailnumber)		{			fputs(buf, data);		}	}	bothunlock(tmp);	fclose(tmp);	bothunlock(data);	fclose(data);	remove(tmpname);	return;}void removeaddr(int emailnumber) //remove address{	passwd *info;	FILE *book;	FILE *tmp;	char bookname[400];	char tmpname[400];	int number = 0; //one to delete	int count = 0;	char *env;	char data[500];	if (emailnumber < 0)	{		if ((env = getenv("QUERY_STRING"))==NULL)		{			address();			return;		}		number = atoi(env+11);	}	else	{		number = emailnumber;	}	info=getpwnam(globaluser);	snprintf(bookname, 400, "%s/.webmail/book", info->pw_dir);	snprintf(tmpname, 400, "%s/.webmail/tmp", info->pw_dir);	book = fopen(bookname, "r");	if (book == NULL)	{		error("removeaddr():Error opening book for read");		return;	}	if (bothlock(book, 'r')!=0)	{		fclose(book);		error("removeaddr():Error locking book for read");		return;	}	tmp = fopen(tmpname, "w");	if (tmp == NULL)	{		error("removeaddr():Error opening tmp for write");		return;	}	if (bothlock(tmp, 'w')!=0)	{		fclose(book);		fclose(tmp);		error("removeaddr():Error locking tmp for write");		return;	}	while(fgets(data, 499, book)!=NULL)	{		count++;		if (count < (number-1)*7+1 || count > number*7)			fputs(data, tmp);	}	bothunlock(book);	fclose(book);	fflush(tmp);	fdatasync(fileno(tmp));	bothunlock(tmp);	fclose(tmp);	rename(tmpname, bookname);	if (emailnumber < 0)	{		cout << "content-type: text/html" << endl;		cout << "Pragma: No-Cache" << endl << endl;		disjavascript("?book", "Address deleted", "address book");	}	sync();	return;}

⌨️ 快捷键说明

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