📄 address.cpp
字号:
{ fclose(book); error("addaddressproc():Error locking book for read"); return; } tmp = fopen(filenametmp, "w"); if (tmp == NULL) { error("addaddressproc(): Error opening addressbook tmp"); return; } if (bothlock(tmp, 'w')!=0) { fclose(book); fclose(tmp); error("addaddressproc():Error locking tmp for write"); return; } while (1) { if (fgets(data, 199, book)==NULL) break; if (toupper(data[0]) > toupper(name[0]) && inserted == 0) { fputs(name, tmp); fputs("\n", tmp); fputs(email, tmp); fputs("\n", tmp); fputs(phone, tmp); fputs("\n", tmp); fputs(fax, tmp); fputs("\n", tmp); fputs(address1, tmp); fputs("\n", tmp); fputs(address2, tmp); fputs("\n", tmp); fputs(notes, tmp); fputs("\n", tmp); inserted = 1; } fputs(data, tmp);//puts name //fputs("\n", tmp); for (int i = 0; i < 6; i++) { if (fgets(data, 199, book)==NULL) break; fputs(data, tmp); //puts the rest of the data //fputs("\n", tmp); } } if (inserted == 0) { fputs(name, tmp); fputs("\n", tmp); fputs(email, tmp); fputs("\n", tmp); fputs(phone, tmp); fputs("\n", tmp); fputs(fax, tmp); fputs("\n", tmp); fputs(address1, tmp); fputs("\n", tmp); fputs(address2, tmp); fputs("\n", tmp); fputs(notes, tmp); fputs("\n", tmp); } fflush(tmp); fdatasync(fileno(tmp)); bothunlock(tmp); fclose(tmp); bothunlock(book); fclose(book); rename(filenametmp, filename); sync(); cout << "content-type: text/html" << endl; cout << "Pragma: No-Cache" << endl << endl; disjavascript("?book", "Entree entered", "address book"); return;}void addredit(){ char *env; int number = 0; if ((env = getenv("QUERY_STRING")) == NULL) { error("addredit():environment error"); return; } number = atoi(env+9); addaddress("", number); return;}void readd(){ char *env; int number = 0; if ((env = getenv("QUERY_STRING")) == NULL) { error("readd():environment error"); return; } number = atoi(env+10); removeaddr(number); addaddressproc(); return;}void addname(){ FILE *mailstore; char mailname[400]; passwd *info; char data[500]; char *env; int number = 0; int count = 0; int foundit = 0; if ((env = getenv("QUERY_STRING"))==NULL) { error("addname():environment error"); return; } number = atoi(env+8); info=getpwnam(globaluser); snprintf(mailname, 400, MAILBOXPATH); mailstore = fopen(mailname, "r"); if (mailstore == NULL) { error("addname():can't open data for read"); return; } if (bothlock(mailstore, 'r')!=0) { fclose(mailstore); error("addname():Error locking mailstore for read"); return; } while (fgets(data, 499, mailstore) != NULL) { if (strncmp(data, "From ", 5)==0) { count++; } if (count == number) { if (strncasecmp(data, "From: ", 6) == 0) { foundit = 1; break; } } } if (foundit == 1) { addaddress(data+6, -2); } else { error("addname():return address not found"); } bothunlock(mailstore); fclose(mailstore); return;}void gaddaddress(int email){ FILE *gbook; char gbookname[400]; passwd *info; char name[400]; char data[4000]; int count = 0; if (email > 0) { info=getpwnam(globaluser); snprintf(gbookname, 400, "%s/.webmail/gbook", info->pw_dir); gbook = fopen(gbookname, "r"); if (gbook == NULL) { error("gaddaddress():can't open book for read"); return; } if (bothlock(gbook, 'r')!=0) { fclose(gbook); error("gaddaddress():Error locking gbook for read"); return; } while (1) { if(fgets(name, 399, gbook)==NULL) { error("gaddaddress():can't read from book"); return; } if (name[0] == '-') count++; if (count == email) break; } } cout << "Content-type: text/HTML" << endl; cout << "Pragma: No-Cache" << endl << endl; cout << "<html>" << endl; cout << "<head>" << endl; cout << "<title>Web E-Mail</title>" << endl; cout << "<META HTTP-EQUIV=\"expires\" content=\"0\">" << endl; cout << "</head>" << endl; cout << "<body text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000EF\" "; cout << "vlink=\"#0000EF\" alink=\"#FF0000\" background=/email/bg1.gif>"; if (email > 0) header(WEM_Edit_Group_List); else header(WEM_Add_Group_List); if (email > 0) { cout << "<form Method=\"post\" action=\"" << EMAILPATH << "?gaddreproc=" << email << "\">" << WEM_Group_Name << ": "; } else { cout << "<form Method=\"post\" action=\"" << EMAILPATH << "?gaddproc\">" << WEM_Group_Name << ": "; } if (email > 0) { removereturn(name+1); cout << " <input type=text name=group size=25 value=\"" << name+1 << "\">"; } else cout << " <input type=text name=group size=25>"; cout << "<br>" << WEM_E_Mail_Address__One_e_mail_address_per_line << endl; cout << "<br><textarea wrap=virtual cols=80 rows=20 name=addresses>" << endl; if (email > 0) { while (fgets(data, 3999, gbook)!=NULL) { if (data[0] == '-') break; cout << data; } } cout << "</textarea>" << endl; cout << "<br><input type=Submit value=\"" << WEM_Add_Entree << "\"><input type=reset value=" << WEM_Reset << ">"; cout << "<br></form>" << endl; tail(); cout << "</body>" << endl; cout << "</html>" << endl; if (email > 0) { fflush(gbook); fdatasync(fileno(gbook)); bothunlock(gbook); fclose(gbook); } return;}void gaddaddressproc(){ char data[6000]; char name[400]; char *pname; char email[6000]; char *pemail; //char data[400]; passwd *info; FILE *book; FILE *tmp; char filenametmp[200]; char filename[200]; int inserted = 0; if (fgets(data, 5999, stdin)==NULL) { error("gaddaddressproc():Post Error"); return; } pname = finddata(data, "group=", name); htmldecode(name); pemail = finddata(data, "addresses=", email); htmldecode(email); if (isalpha(name[1])==0) { address(); return; } info=getpwnam(globaluser); snprintf(filename, 200, "%s/.webmail/gbook", info->pw_dir); snprintf(filenametmp, 200, "%s/.webmail/tmp", info->pw_dir); book = fopen(filename, "r"); if (book == NULL) { error("gaddaddressproc(): error opening gaddressbook"); return; } if (bothlock(book, 'r')!=0) { fclose(book); error("gaddaddressproc():Error locking gbook for read"); return; } tmp = fopen(filenametmp, "w"); if (tmp == NULL) { error("gaddaddressproc(): Error opening gaddressbook tmp"); return; } if (bothlock(tmp, 'w')!=0) { fclose(book); fclose(tmp); error("gaddaddressproc():Error locking gbook for write"); return; } while (1) { if (fgets(data, 399, book)==NULL) break; if (((data[0] == '-') && toupper(data[1]) > toupper(name[0])) && inserted == 0) { fputs("-", tmp); fputs(name, tmp); fputs("\n", tmp); fputs(email, tmp); fputs("\n", tmp); inserted = 1; } fputs(data, tmp);//puts name } if (inserted == 0) { fputs("-", tmp); fputs(name, tmp); fputs("\n", tmp); checkgroup(email); fputs(email, tmp); fputs("\n", tmp); } fflush(tmp); fdatasync(fileno(tmp)); bothunlock(tmp); fclose(tmp); bothunlock(book); fclose(book); rename(filenametmp, filename); sync(); disjavascript("?book", "Entree added", "address book"); return;}void gaddrremove(int email){ passwd *info; FILE *gbook; FILE *tmp; char gbookname[1000]; char tmpname[1000]; char buf[1000]; int number = 0; int emailcount = 0; char *env; if (email > 0) number = email; else { if ((env = getenv("QUERY_STRING"))==NULL) { error("gaddrremove(): error reading environment"); return; } number = atoi(env+12); } info=getpwnam(globaluser); snprintf(gbookname, 1000, "%s/.webmail/gbook", info->pw_dir); snprintf(tmpname, 1000, "%s/.webmail/tmp", info->pw_dir); rename(gbookname, tmpname); sync(); gbook = fopen(gbookname, "w"); if (gbook == NULL) { error("gaddrremove():Error opening gbook for write"); exit(1); } if (bothlock(gbook, 'w')!=0) { fclose(gbook); error("gaddrremove():Error locking gbook for write"); return; } tmp = fopen(tmpname, "r"); if (tmp == NULL) { error("gaddrremove():error opening temp for read"); fclose(gbook); exit(1); } if (bothlock(tmp, 'r')!=0) { fclose(gbook); fclose(tmp); error("gaddrremove():Error locking gbook for read"); return; } while (fgets(buf, 999, tmp) != NULL) { if (buf[0] == '-') { emailcount++; } if (emailcount != number) { fputs(buf, gbook); } } bothunlock(tmp); fclose(tmp); fflush(gbook); fdatasync(fileno(gbook)); bothunlock(gbook); fclose(gbook); if (email <= 0) { disjavascript("?book", "Address deleted", "address book"); } return;}void gaddrsend(){ char *env; int number = 0; int count = 0; FILE *gbook; char gbookname[400]; passwd *info; char buf[5000]; char email[400]; int first = 0; if ((env = getenv("QUERY_STRING")) == NULL) { error("gaddrsend():environment error"); return; } number = atoi(env+10); info = getpwnam(globaluser); snprintf(gbookname, 400, "%s/.webmail/gbook", info->pw_dir); gbook = fopen(gbookname, "r"); if (gbook == NULL) { error("gaddrsend():can't open book for read"); return; } if (bothlock(gbook, 'r')!=0) { fclose(gbook); error("gaddrsend():Error locking book for read"); return; } while (count <= number) { if (fgets(email, 399, gbook) == NULL) count++; if (email[0] == '-') count++; if (count == number && email[0] != '-') { if (first == 0) { snprintf(buf, 5000, "%s", email); first = 1; } else sprintf(buf, "%s, %s", buf, email); } } bothunlock(gbook); fclose(gbook); wewrite(2, buf, 0); return;}void gaddredit(){ char *env; int number = 0; if ((env = getenv("QUERY_STRING")) == NULL) { error("gaddredit():environment error"); return; } number = atoi(env+10); gaddaddress(number); return;}void greadd(){ char *env; int number = 0; if ((env = getenv("QUERY_STRING")) == NULL) { error("greadd():environment error"); return; } number = atoi(env+11); gaddrremove(number); gaddaddressproc(); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -