📄 utils.cpp
字号:
#include "webemail.h"#include "attachments.h"/************************************finds data search in env and stores it in answer.Stops at null, &, :, ;Does not stop at carrage return. hopefull \n is at the endCopies into answer.Returns answer on found or null on falure*************************************/char * finddata(char *env, char *search, char answer[]) //finds data{ int i = 0; //starts search at begining of env int notit = 0; while (env[i] != '\0') { int k = 0; //Restart search for search notit = 0; while (env[i] != '\0' && search[k] != '\0') { //compares env and search if (env[i] == search[k]) { k++; i++; } else //error, not it, loop around { notit = 1; i++; break; } } if (notit == 0) //found it, search to the end and copy data only { //search key in not included? k = 0; while (env[i] != '\0' && env[i] != '&' && env[i] != ':' && env[i] != ';') { answer[k] = env[i]; k++; i++; } answer[k] = '\0'; return answer; } } return NULL;}void htmldecode(char *data) //decode html{ int i = 0; int offset = 0; char value1; char value2; int intvalue = 0; while (data[offset] != '\0') { if (data[offset] == '+') { data[i] = ' '; } else if (data[offset] == '%') { value1 = data[offset+1]; value2 = data[offset+2]; if (value1 == '\0' || value2 == '\0') return; if (value1 <= '9' && value1 >= '0') intvalue = (value1-'0')*(int)pow(16, 1); else if (value1 <= 'f' && value1 >= 'a') intvalue =((value1-'a')+10)*(int)pow(16,1); else if (value1 <= 'F' && value1 >= 'A') intvalue = ((value1-'A')+10)*(int)pow(16,1); else intvalue = 0; if (value2 <= '9' && value2 >= '0') intvalue += (value2-'0'); else if (value2 <= 'f' && value2 >= 'a') intvalue += ((value2-'a')+10); else if (value2 <= 'F' && value2 >= 'A') intvalue += ((value2-'A')+10); else intvalue = 0; data[i] = (char)intvalue; offset+=2; } else { data[i] = data[offset]; } i++; offset++; } data[i] = '\0'; return;}void markold(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("Markold():Error opening data for read"); return; } if (bothlock(mailstore, 'r')!=0) { fclose(mailstore); error("Markold():Error locking mailstore"); return; } tmpstore = fopen(tmpname, "w"); if (tmpstore == NULL) { error("Markold():Error opening temp for write"); fclose(mailstore); return; } if (bothlock(tmpstore, 'w')!=0) { fclose(tmpstore); fclose(mailstore); error("Markold():Error locking tmpstore"); return; } while (fgets(data, 499, mailstore) != NULL) { fputs(data, tmpstore); } bothunlock(mailstore); fclose(mailstore); bothunlock(tmpstore); fclose(tmpstore); sync(); //rename(mailname, tmpname); mailstore = fopen(mailname, "w"); if (mailstore == NULL) { return; //errors will be encountered by calling function } if (bothlock(mailstore, 'w')!=0) { fclose(mailstore); error("Markold():Error locking mailstore"); 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("Markold():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("Status: RO", mailstore); fputs("\n", mailstore); } } if (strncasecmp(data, "Status: ", 8)==0) { fputs("Status: RO", 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;}void reply() //sets up reply then calls write{ char *env; int number = 0; if ((env = getenv("QUERY_STRING")) == NULL) { error("Reply(): ERROR! no environment"); return; } number = atoi(env+6); wewrite(1, "", number);}void setup(){ system("wesetup"); //lauch setup program menu(); return;}void checkgroup(char * data){ int i = 0; if (data[0] == '-') { data[0] = '!'; } while (data[i] != '\0') { if (data[i] == '\n') { if (data[i+1] == '-') { data[i+1] = '!'; } } i++; } return;}void removereturn(char * data){ int org = 0; int not = 0; while(data[org] != '\0') { if (data[org] == '\n') org++; data[not] = data[org]; if (data[org] == '\0') break; org++; not++; } return;}void decodeuuline(char data[70]) //max data is 64 I think{ int count; int four[4]; int three[3]; int fouri = 0; int threei = 0; count = (int)(data[0]) - 0x20; if (count == 64) count = 0; while (threei < count) { for (int i = 0; i < 4; i++, fouri++) { four[i] = data[fouri+1] - 32; if (four[i] == 0x60) four[i] = 0; } three[0] = (four[0] & 0x3F) << 2; three[0] |= ((four[1] & 0x30) >> 4); three[1] = (four[1] & 0xF) << 4; three[1] |= (four[2] & 0x3C) >> 2; three[2] = (four[2] & 0x3) << 6; three[2] |= (four[3] & 0x3F); if (threei < count) printf("%c", three[0]); threei++; if (threei < count) printf("%c", three[1]); threei++; if (threei < count) printf("%c", three[2]); threei++; } return;}void disattch(){ char *env; char *env2; int loop = 9; int attachnum; int mailnum; char mailbox[400]; passwd *info; if ((env = getenv("QUERY_STRING"))==NULL) { disjavascript("", "Attach display error", "menu"); return; } while (env[loop] != '\0') { if (env[loop] == 'x') { env[loop] = '\0'; env2=env+loop+1; } loop++; } attachnum = atoi(env2); mailnum = atoi(env+9); info=getpwnam(globaluser); snprintf(mailbox, 400, MAILBOXPATH); showattachment(mailbox, mailnum, attachnum); }char * guessmime(char filename[]){ int i = 0; int ext = 0; while (filename[i] != '\0' && filename[i] != '\n') { if (filename[i] == '.') { ext = i; } i++; } if (strncasecmp(".jpeg", filename+ext, 5) == 0 || strncasecmp(".jpg", filename+ext, 4) == 0 || strncasecmp(".jpe", filename+ext, 4) == 0) return "image/jpeg"; //defined at the bottom. //if (strncasecmp(".html", filename+ext, 5) == 0 || //strncasecmp(".htm", filename+ext, 4) == 0) // return "text/HTML"; if (strncasecmp(".mp2", filename+ext, 4) == 0 || strncasecmp(".mpa", filename+ext, 4) == 0 || strncasecmp(".mpega", filename+ext, 6) == 0 || strncasecmp(".mp3", filename+ext, 4) == 0) return "audio/x-mpeg"; if (strncasecmp(".ra", filename+ext, 3) == 0 || strncasecmp(".ram", filename+ext, 4)==0) return "audio/x-pn-realaudio-plugin"; if (strncasecmp(".wpd", filename+ext, 4) == 0) return "application/wordperfect5.1"; if (strncasecmp(".doc", filename+ext, 4) == 0) return "application/msword"; if (strncasecmp(".js", filename+ext, 3) == 0) return "application/x-javascript"; if (strncasecmp(".exe", filename+ext, 4) == 0) return "application/octet-stream"; if (strncasecmp(".jar", filename+ext, 4) == 0) return "application/java-archive"; if (strncasecmp(".avi", filename+ext, 4) == 0) return "video/x-msvideo"; if (strncasecmp(".qt", filename+ext, 3) == 0 || strncasecmp(".mov", filename+ext, 4)==0) return "video/quicktime"; if (strncasecmp(".mpeg", filename+ext, 5) == 0 || strncasecmp(".mpg", filename+ext, 4) == 0 || strncasecmp(".mpe", filename+ext, 4) == 0 ) return "video/mpeg"; if (strncasecmp(".wav", filename+ext, 4) == 0) return "audio/x-wav"; if (strncasecmp(".bmp", filename+ext, 4) == 0) return "image/x-ms-bmp"; if (strncasecmp(".xbm", filename+ext, 4) == 0) return "image/x-xbitmap"; if (strncasecmp(".tiff", filename+ext, 5) == 0 || strncasecmp(".tif", filename+ext, 4) == 0) return "image/tiff"; if (strncasecmp(".gif", filename+ext, 4) == 0) return "image/gif"; if (strncasecmp(".rtf", filename+ext, 4) == 0) return "application/rtf"; if (strncasecmp(".txt", filename+ext, 4) == 0 || strncasecmp(".text", filename+ext, 5) == 0) return "text/plain"; if (strncasecmp(".html", filename+ext, 5) == 0 || strncasecmp(".htm", filename+ext, 4) == 0 || strncasecmp(".shtml", filename+ext, 6) == 0) return "text/html"; return "unknown/x-unknown";}void quotestospace(char * data){ int i = 0; while (data[i] != '\0') { if (data[i] == '\"') { data[i] = ' '; } i++; } return;}void commatospace(char * data){ int i = 0; while (data[i] != '\0') { if (data[i] == ',') { data[i] = ' '; } i++; } return;}/****************************************************Checks if one string is contained in another.String to checkSmaller string to compareLengthI think****************************************************/int inthere(char * test1, char * test2, int num){ int i1 = 0; int i2 = 0; int ok = 0; while (test1[i1] != '\0' && test2[i2] !='\0' && ok <= num) { if (test1[i1] == test2[i2]) ok++; else { ok = 0; i2 = 0; i1++; continue; } if (ok == num) return 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -