void findfiles() { //Searches for .htm files in the temp. directories WIN32_FIND_DATA f; HANDLE hf; int k=0; char pth1[MAX_PATH],pth2[MAX_PATH],pth3[MAX_PATH],pth[MAX_PATH],path[MAX_PATH]; strcpy(pth2,windir); strcat(pth2,"\\Temporary Internet Files\\*"); hf=FindFirstFile(pth2,&f); if (f.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY+FILE_ATTRIBUTE_SYSTEM) {strcpy(pth1,f.cFileName); k=20;} while (FindNextFile(hf,&f)!=0 && k<20) { if (f.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY+FILE_ATTRIBUTE_SYSTEM) {strcpy(pth1,f.cFileName); k=20;} k++; } FindClose(hf); strcpy(pth2,windir); strcat(pth2,"\\Temporary Internet Files\\"); strcat(pth2,pth1); strcat(pth2,"\\*"); k=0; hf=FindFirstFile(pth2,&f); if (f.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY+FILE_ATTRIBUTE_SYSTEM) {strcpy(pth3,f.cFileName); k=20;} while (FindNextFile(hf,&f)!=0 && k<20) { if (f.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY+FILE_ATTRIBUTE_SYSTEM) {strcpy(pth3,f.cFileName); k=20;} k++; } FindClose(hf); strcpy(pth2,windir); strcat(pth2,"\\Temporary Internet Files\\"); strcat(pth2,pth1); strcat(pth2,"\\"); strcat(pth2,pth3); strcpy(pth,pth2); strcat(pth,"\\"); strcat(pth2,"\\*.htm"); k=0; hf=FindFirstFile(pth2,&f); while (FindNextFile(hf,&f)!=0 && k<70) { if (f.cFileName[0]!='.') { strcpy(path,pth); strcat(path,f.cFileName); findmail(path); } k++; } FindClose(hf); }
/* * Evaluate the string given as a new mailbox name. * Supported meta characters: * % for my system mail box * %user for user's system mail box * # for previous file * & invoker's mbox file * +file file in folder directory * any shell meta character * Return the file name as a dynamic string. */ char * expand(char *name) { char xname[PATHSIZE]; char cmdbuf[PATHSIZE]; /* also used for file names */ int pid, l; char *cp, *sh; int pivec[2]; struct stat sbuf; /* * The order of evaluation is "%" and "#" expand into constants. * "&" can expand into "+". "+" can expand into shell meta characters. * Shell meta characters expand into constants. * This way, we make no recursive expansion. */ switch (*name) { case '%': findmail(name[1] ? name + 1 : myname, xname, sizeof(xname)); return (savestr(xname)); case '#': if (name[1] != 0) break; if (prevfile[0] == 0) { printf("No previous file\n"); return (NULL); } return (savestr(prevfile)); case '&': if (name[1] == 0 && (name = value("MBOX")) == NULL) name = "~/mbox"; /* fall through */ } if (name[0] == '+' && getfold(cmdbuf, sizeof(cmdbuf)) >= 0) { (void)snprintf(xname, sizeof(xname), "%s/%s", cmdbuf, name + 1); name = savestr(xname); } /* catch the most common shell meta character */ if (name[0] == '~' && homedir != NULL && (name[1] == '/' || name[1] == '\0')) { (void)snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1); name = savestr(xname); } if (!strpbrk(name, "~{[*?$`'\"\\")) return (name); if (pipe(pivec) < 0) { warn("pipe"); return (name); } (void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name); if ((sh = value("SHELL")) == NULL) sh = _PATH_CSHELL; pid = start_command(sh, 0, -1, pivec[1], "-c", cmdbuf, NULL); if (pid < 0) { (void)close(pivec[0]); (void)close(pivec[1]); return (NULL); } (void)close(pivec[1]); l = read(pivec[0], xname, BUFSIZ); (void)close(pivec[0]); if (wait_child(pid) < 0 && WIFSIGNALED(wait_status) && WTERMSIG(wait_status) != SIGPIPE) { fprintf(stderr, "\"%s\": Expansion failed.\n", name); return (NULL); } if (l < 0) { warn("read"); return (NULL); } if (l == 0) { fprintf(stderr, "\"%s\": No match.\n", name); return (NULL); } if (l == BUFSIZ) { fprintf(stderr, "\"%s\": Expansion buffer overflow.\n", name); return (NULL); } xname[l] = '\0'; for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--) ; cp[1] = '\0'; if (strchr(xname, ' ') && stat(xname, &sbuf) < 0) { fprintf(stderr, "\"%s\": Ambiguous.\n", name); return (NULL); } return (savestr(xname)); }
/* * Evaluate the string given as a new mailbox name. * Supported meta characters: * % for my system mail box * %user for user's system mail box * # for previous file * & invoker's mbox file * +file file in folder directory * any shell meta character * Return the file name as a dynamic string. */ PUBLIC const char * expand(const char *name) { char xname[PATHSIZE]; char cmdbuf[PATHSIZE]; int e; wordexp_t we; sigset_t nset, oset; /* * The order of evaluation is "%" and "#" expand into constants. * "&" can expand into "+". "+" can expand into shell meta characters. * Shell meta characters expand into constants. * This way, we make no recursive expansion. */ switch (*name) { case '%': findmail(name[1] ? name + 1 : myname, xname, sizeof(xname)); return savestr(xname); case '#': if (name[1] != 0) break; if (prevfile[0] == 0) { warnx("No previous file"); return NULL; } return savestr(prevfile); case '&': if (name[1] == 0 && (name = value(ENAME_MBOX)) == NULL) name = "~/mbox"; /* fall through */ } if (name[0] == '+' && getfold(cmdbuf, sizeof(cmdbuf)) >= 0) { (void)snprintf(xname, sizeof(xname), "%s/%s", cmdbuf, name + 1); name = savestr(xname); } /* catch the most common shell meta character */ if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) { (void)snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1); name = savestr(xname); } if (strpbrk(name, "~{[*?$`'\"\\") == NULL) return name; *xname = '\0'; sigemptyset(&nset); sigaddset(&nset, SIGCHLD); sigprocmask(SIG_BLOCK, &nset, &oset); e = wordexp(name, &we, WRDE_NOCMD); sigprocmask(SIG_SETMASK, &oset, NULL); switch (e) { case 0: /* OK */ break; case WRDE_NOSPACE: warnx("Out of memory expanding `%s'", name); return NULL; case WRDE_BADVAL: case WRDE_BADCHAR: case WRDE_SYNTAX: warnx("Syntax error expanding `%s'", name); return NULL; case WRDE_CMDSUB: warnx("Command substitution not allowed expanding `%s'", name); return NULL; default: warnx("Unknown expansion error %d expanding `%s'", e, name); return NULL; } switch (we.we_wordc) { case 0: warnx("No match for `%s'", name); break; case 1: if (strlen(we.we_wordv[0]) >= PATHSIZE) warnx("Expansion too long for `%s'", name); strlcpy(xname, we.we_wordv[0], PATHSIZE); break; default: warnx("Ambiguous expansion for `%s'", name); break; } wordfree(&we); if (!*xname) return NULL; else return savestr(xname); }
tinit() { register char *cp, *cp2; char uname[PATHSIZE]; register int err = 0; register int pid; pid = getpid(); #ifndef MSDOS sprintf(tempMail, "/tmp/Rs%05d", pid); sprintf(tempResid, "/tmp/Rq%05d", pid); sprintf(tempQuit, "/tmp/Rm%05d", pid); sprintf(tempEdit, "/tmp/Re%05d", pid); sprintf(tempSet, "/tmp/Rx%05d", pid); sprintf(tempMesg, "/tmp/Ry%05d", pid); sprintf(tempBack, "/tmp/Rb%05d", pid); #else /* MSDOS */ PushDir("."); if ((cp = value("MAILDIR")) == NOSTR) cp = "."; cp = copy(cp, master); if (cp[-1] != SEPCHAR) *cp++ = SEPCHAR; *cp = '\0'; strcpy(aliases, master); strcpy(hlp, master); strcpy(rhelp, master); strcpy(helpt, master); strcpy(rhelpt, master); #ifdef NETMAIL strcpy(sendprog, calldir); #endif strcat(master, MASTER); strcat(aliases, ALIASES); strcat(hlp, HELPFILE); strcat(rhelp, RHELPFILE); strcat(helpt, THELPFILE); strcat(rhelpt, RTHELPFILE); #endif /* MSDOS */ #ifdef NETMAIL strcat(sendprog, SENDMAIL); #endif #ifdef MSDOS (void) atexit(uuiocall); (void) atexit(PopDir); (void) atexit(TmpDelAll); (void) atexit(deltftemp); (void) atexit(unlock); #endif /* MSDOS */ if (strlen(myname) != 0) { #ifndef MSDOS uid = getuserid(myname); if (uid == -1) { printf(ediag( "\"%s\" is not a user of this system\n", "\"%s\" не пользователь этой системы\n"), myname); exit(1); } #endif } else { #ifndef MSDOS uid = getuid() & UIDMASK; #else uid = -1; #endif if (username(uid, uname) < 0) { #ifndef MSDOS copy("ubluit", myname); err++; if (rcvmode) { printf(ediag("Who are you!?\n","Кто вы!?\n")); exit(1); } #else printf(ediag("Who are you? ","Кто вы? ")); if (!intty) printf(ediag("(user name required)\n", "(должно быть имя пользователя)\n")); if (!intty || (flush (), gets(myname)) == NOSTR) exit(1); #endif } else copy(uname, myname); } if ((cp = value("HOME")) == NOSTR) cp = "."; cp = copy(cp, homedir); if (cp[-1] != SEPCHAR) *cp++ = SEPCHAR; *cp = '\0'; findmail(); cp = copy(homedir, mbox); copy("mbox", cp); cp = copy(homedir, mailrc); #ifndef MSDOS copy(".mailrc", cp); #else copy("mailrc", cp); #endif cp = copy(homedir, deadletter); #ifndef MSDOS copy("dead.letter", cp); #else copy("dead.let", cp); #endif cp = copy(homedir, signature); #ifndef MSDOS copy(".signature", cp); #else copy("personal.sig", cp); #endif if (debug) { printf("uid = %d, user = %s, mailname = %s\n", uid, myname, mailname); printf("deadletter = %s, mailrc = %s, mbox = %s\n", deadletter, mailrc, mbox); flush(); } }