/* * Seek and handle a subject=foo. - FM */ PRIVATE void extract_subject ARGS2( char *, dst, char *, src) { CONST char *keyword = "subject="; int len = strlen(keyword); char *cp, *cp1; cp = (src + 1); while (*cp != '\0') { if ((*(cp - 1) == '?' || *(cp - 1) == '&') && !strncasecomp(cp, keyword, len)) break; cp++; } if (*cp) { cp += len; if ((cp1 = strchr(cp, '&')) != NULL) { *cp1 = '\0'; } if (*cp) { strncpy(dst, cp, MAX_SUBJECT); dst[MAX_SUBJECT] = '\0'; SafeHTUnEscape(dst); } if (cp1) { *cp1 = '&'; cp1 = NULL; } } CTRACE((tfp, "extract_subject(%s) = '%s'\n", keyword, NONNULL(dst))); }
PRIVATE void extract_field ARGS3( char **, dst, char *, src, char *, keyword) { int len = strlen(keyword); char *cp, *cp1; cp = (src + 1); while (*cp != '\0') { if ((*(cp - 1) == '?' || *(cp - 1) == '&') && !strncasecomp(cp, keyword, len)) { cp += len; if ((cp1 = strchr(cp, '&')) != NULL) { *cp1 = '\0'; } comma_append(dst, cp); if (cp1) { *cp1 = '&'; cp = cp1; cp1 = NULL; } else { break; } } cp++; } CTRACE((tfp, "extract_field(%s) = '%s'\n", keyword, NONNULL(*dst))); }
static BOOL rule_cond_ok(rule * r) { BOOL result; if (!r->condition_op) return YES; if (strcmp(r->condition_op, "if") && strcmp(r->condition_op, "unless")) { CTRACE((tfp, "....... rule ignored, unrecognized `%s'!\n", r->condition_op)); return NO; } if (!strcmp(r->condition, "redirected")) result = (BOOL) (redirection_attempts > 0); else if (!strcmp(r->condition, "userspec")) result = LYUserSpecifiedURL; else { CTRACE((tfp, "....... rule ignored, unrecognized `%s %s'!\n", r->condition_op, NONNULL(r->condition))); return NO; } if (!strcmp(r->condition_op, "if")) return result; else return (BOOL) (!result); }
int HTAddRule(HTRuleOp op, const char *pattern, const char *equiv, const char *cond_op, const char *cond) { /* BYTE_ADDRESSING removed and memory check - AS - 1 Sep 93 */ rule *temp; char *pPattern = NULL; temp = typecalloc(rule); if (temp == NULL) outofmem(__FILE__, "HTAddRule"); if (equiv) { /* Two operands */ char *pEquiv = NULL; StrAllocCopy(pEquiv, equiv); temp->equiv = pEquiv; } else { temp->equiv = 0; } if (cond_op) { StrAllocCopy(temp->condition_op, cond_op); StrAllocCopy(temp->condition, cond); } StrAllocCopy(pPattern, pattern); temp->pattern = pPattern; temp->op = op; if (equiv) { CTRACE((tfp, "Rule: For `%s' op %d `%s'", pattern, op, equiv)); } else { CTRACE((tfp, "Rule: For `%s' op %d", pattern, op)); } if (cond_op) { CTRACE((tfp, "\t%s %s\n", cond_op, NONNULL(cond))); } else { CTRACE((tfp, "\n")); } if (!rules) { #ifdef LY_FIND_LEAKS atexit(HTClearRules); #endif } #ifdef PUT_ON_HEAD temp->next = rules; rules = temp; #else temp->next = 0; if (rule_tail) rule_tail->next = temp; else rules = temp; rule_tail = temp; #endif return 0; }
const char * safe_getenv(const char *s) { const char *result; #if OPT_EVAL && OPT_SHELL char *v = getenv(s); #if defined(_WIN32) if (v == 0) v = vile_getenv(s); #endif result = NONNULL(v); #else result = ""; #endif return result; }
static BOOLEAN message_has_content(const char *filename, BOOLEAN *nonspaces) { FILE *fp; char *buffer = NULL; BOOLEAN in_headers = TRUE; *nonspaces = FALSE; if (!filename || (fp = fopen(filename, "r")) == NULL) { CTRACE((tfp, "Failed to open file %s for reading!\n", NONNULL(filename))); return FALSE; } while (LYSafeGets(&buffer, fp) != NULL) { char *cp = buffer; char firstnonblank = '\0'; LYTrimNewline(cp); for (; *cp; cp++) { if (!firstnonblank && isgraph(UCH(*cp))) { firstnonblank = *cp; } else if (!isspace(UCH(*cp))) { *nonspaces = TRUE; } } if (firstnonblank && firstnonblank != '>') { if (!in_headers) { LYCloseInput(fp); FREE(buffer); return TRUE; } } if (!firstnonblank) { in_headers = FALSE; } } FREE(buffer); LYCloseInput(fp); return FALSE; }
int system_SHELL(char *cmd) { int cpid; TRACE(("system_SHELL(%s)\n", NONNULL(cmd))); cpid = softfork(); if (cpid < 0) { IGNORE_RC(write(2, "cannot fork\n", (size_t) 13)); return cpid; } if (cpid) { /* parent */ int child; int status; beginDisplay(); while ((child = wait(&status)) != cpid) { if (child < 0 && errno == EINTR) { (void) kill(SIGKILL, cpid); } } endofDisplay(); #if VILE_SOMEDAY shellstatus = process_exit_status(status); #endif return 0; } else { beginDisplay(); exec_sh_c(cmd); IGNORE_RC(write(2, "cannot exec\n", (size_t) 13)); endofDisplay(); return -1; } }
/* ** mailmsg() sends a message to the owner of the file, if one is defined, ** telling of errors (i.e., link not available). */ PUBLIC void mailmsg ARGS4( int, cur, char *, owner_address, char *, filename, char *, linkname) { FILE *fd, *fp; char *address = NULL; char *searchpart = NULL; char *cmd = NULL, *cp; #ifdef ALERTMAIL BOOLEAN skip_parsing = FALSE; #endif #if !CAN_PIPE_TO_MAILER char *ccaddr; char subject[128]; char my_tmpfile[LY_MAXPATH]; #endif #if USE_VMS_MAILER BOOLEAN isPMDF = LYMailPMDF(); char hdrfile[LY_MAXPATH]; char *command = NULL; CTRACE((tfp, "mailmsg(%d, \"%s\", \"%s\", \"%s\")\n", cur, NONNULL(owner_address), NONNULL(filename), NONNULL(linkname))); #endif /* VMS */ if (!LYSystemMail()) return; #ifdef ALERTMAIL if (owner_address == NULL) { owner_address = ALERTMAIL; skip_parsing = TRUE; } #endif if (isEmpty(owner_address)) return; if ((cp = (char *)strchr(owner_address,'\n')) != NULL) { #ifdef ALERTMAIL if (skip_parsing) return; /* invalidly defined - ignore - kw */ #else *cp = '\0'; #endif } if (!strncasecomp(owner_address, "lynx-dev@", 9)) { /* * Silently refuse sending bad link messages to lynx-dev. */ return; } StrAllocCopy(address, owner_address); #ifdef ALERTMAIL /* * If we are using a fixed address given by ALERTMAIL, it is * supposed to already be in usable form, without URL-isms like * ?-searchpart and URL-escaping. So skip some code. - kw */ if (!skip_parsing) #endif { /* * Check for a ?searchpart. - FM */ if ((cp = strchr(address, '?')) != NULL) { StrAllocCopy(searchpart, cp); *cp = '\0'; cp = (searchpart + 1); if (*cp != '\0') { /* * Seek and handle to=address(es) fields. * Appends to address. We ignore any other * headers in the ?searchpart. - FM */ extract_field(&address, searchpart, "to="); } } convert_explorer(address); /* * Unescape the address field. - FM */ SafeHTUnEscape(address); } if (trim_comma(address)) { FREE(address); CTRACE((tfp, "mailmsg: No address in '%s'.\n", owner_address)); return; } #if CAN_PIPE_TO_MAILER if ((fd = LYPipeToMailer()) == 0) { FREE(address); CTRACE((tfp, "mailmsg: '%s' failed.\n", cmd)); return; } fprintf(fd, "To: %s\n", address); fprintf(fd, "Subject: Lynx Error in %s\n", filename); if (!isEmpty(personal_mail_address)) { fprintf(fd, "Cc: %s\n", personal_mail_address); } fprintf(fd, "X-URL: %s\n", filename); fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION); #else if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", my_tmpfile)); FREE(address); return; } sprintf(subject, "Lynx Error in %.56s", filename); ccaddr = personal_mail_address; #if USE_VMS_MAILER if (isPMDF) { FILE *hfd; if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", hdrfile)); FREE(address); return; } if (!isEmpty(personal_mail_address)) { fprintf(fd, "Cc: %s\n", personal_mail_address); } fprintf(fd, "X-URL: %s\n", filename); fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION); /* * For PMDF, put the subject in the * header file and close it. - FM */ fprintf(hfd, "Subject: Lynx Error in %.56s\n\n", filename); LYCloseTempFP(hfd); } #endif /* USE_VMS_MAILER */ #endif /* CAN_PIPE_TO_MAILER */ fprintf(fd, gettext("The link %s :?: %s \n"), links[cur].lname, links[cur].target); fprintf(fd, gettext("called \"%s\"\n"), LYGetHiliteStr(cur, 0)); fprintf(fd, gettext("in the file \"%s\" called \"%s\"\n"), filename, linkname); fprintf(fd, "%s\n\n", gettext("was requested but was not available.")); fprintf(fd, "%s\n\n", gettext("Thought you might want to know.")); fprintf(fd, "%s\n", gettext("This message was automatically generated by")); fprintf(fd, "%s %s", LYNX_NAME, LYNX_VERSION); if ((LynxSigFile != NULL) && (fp = fopen(LynxSigFile, TXT_R)) != NULL) { fputs("-- \n", fd); while (LYSafeGets(&cmd, fp) != NULL) fputs(cmd, fd); LYCloseInput(fp); } #if CAN_PIPE_TO_MAILER pclose(fd); #else LYCloseTempFP(fd); #if USE_VMS_MAILER if (isPMDF) { /* * Now set up the command. - FM */ HTSprintf0(&command, "%s %s %s,%s ", system_mail, system_mail_flags, hdrfile, my_tmpfile); } else { /* * For "generic" VMS MAIL, include the * subject in the command. - FM */ HTSprintf0(&command, "%s %s/self/subject=\"Lynx Error in %.56s\" %s ", system_mail, system_mail_flags, filename, my_tmpfile); } vms_append_addrs(&command, address, ""); LYSystem(command); /* VMS */ FREE(command); FREE(cmd); LYRemoveTemp(my_tmpfile); if (isPMDF) { LYRemoveTemp(hdrfile); } #else /* DOS */ LYSendMailFile ( address, my_tmpfile, subject, ccaddr, ""); LYRemoveTemp(my_tmpfile); #endif /* USE_VMS_MAILER */ #endif /* CAN_PIPE_TO_MAILER */ if (traversal) { FILE *ofp; if ((ofp = LYAppendToTxtFile(TRAVERSE_ERRORS)) == NULL) { if ((ofp = LYNewTxtFile(TRAVERSE_ERRORS)) == NULL) { perror(NOOPEN_TRAV_ERR_FILE); exit_immediately(EXIT_FAILURE); } } fprintf(ofp, "%s\t%s \tin %s\n", links[cur].lname, links[cur].target, filename); LYCloseOutput(ofp); } FREE(address); return; }
/* ** mailform() sends form content to the mailto address(es). - FM */ PUBLIC void mailform ARGS4( CONST char *, mailto_address, CONST char *, mailto_subject, CONST char *, mailto_content, CONST char *, mailto_type) { FILE *fd; char *address = NULL; char *ccaddr = NULL; char *keywords = NULL; char *cp = NULL; char self[MAX_SUBJECT + 10]; char subject[MAX_SUBJECT + 10]; char *searchpart = NULL; char buf[512]; int ch, len, i; #if USE_VMS_MAILER static char *cmd; char *command = NULL; BOOLEAN isPMDF = LYMailPMDF(); char hdrfile[LY_MAXPATH]; #endif #if !CAN_PIPE_TO_MAILER char my_tmpfile[LY_MAXPATH]; #endif CTRACE((tfp, "mailto_address: \"%s\"\n", NONNULL(mailto_address))); CTRACE((tfp, "mailto_subject: \"%s\"\n", NONNULL(mailto_subject))); CTRACE((tfp, "mailto_content: \"%s\"\n", NONNULL(mailto_content))); CTRACE((tfp, "mailto_type: \"%s\"\n", NONNULL(mailto_type))); if (!LYSystemMail()) return; if (!mailto_address || !mailto_content) { HTAlert(BAD_FORM_MAILTO); return; } subject[0] = '\0'; self[0] = '\0'; if ((cp = (char *)strchr(mailto_address,'\n')) != NULL) *cp = '\0'; StrAllocCopy(address, mailto_address); /* * Check for a ?searchpart. - FM */ if ((cp = strchr(address, '?')) != NULL) { StrAllocCopy(searchpart, cp); *cp = '\0'; cp = (searchpart + 1); if (*cp != '\0') { /* * Seek and handle a subject=foo. - FM */ extract_subject(subject, searchpart); /* * Seek and handle to=address(es) fields. * Appends to address. - FM */ extract_field(&address, searchpart, "to="); /* * Seek and handle cc=address(es) fields. Excludes * Bcc=address(es) as unsafe. We may append our own * cc (below) as a list for the actual mailing. - FM */ extract_field(&ccaddr, searchpart, "cc="); /* * Seek and handle keywords=term(s) fields. - FM */ extract_field(&keywords, searchpart, "keywords="); if (keywords != NULL) { if (*keywords != '\0') { SafeHTUnEscape(keywords); } else { FREE(keywords); } } FREE(searchpart); } } if (convert_explorer(address)) { HTAlert(BAD_FORM_MAILTO); goto cleanup; } if (ccaddr != NULL) { if (convert_explorer(ccaddr)) { FREE(ccaddr); } } /* * Unescape the address and ccaddr fields. - FM */ SafeHTUnEscape(address); if (ccaddr != NULL) { SafeHTUnEscape(ccaddr); } /* * Allow user to edit the default Subject - FM */ if (isEmpty(subject)) { if (!isEmpty(mailto_subject)) { LYstrncpy(subject, mailto_subject, MAX_SUBJECT); } else { sprintf(subject, "mailto:%.63s", address); } } _statusline(SUBJECT_PROMPT); if ((ch = LYgetstr(subject, VISIBLE, MAX_SUBJECT, NORECALL)) < 0) { /* * User cancelled via ^G. - FM */ HTInfoMsg(FORM_MAILTO_CANCELLED); goto cleanup; } /* * Allow user to specify a self copy via a CC: * entry, if permitted. - FM */ if (!LYNoCc) { sprintf(self, "%.*s", MAX_SUBJECT, isEmpty(personal_mail_address) ? "" : personal_mail_address); _statusline("Cc: "); if ((ch = LYgetstr(self, VISIBLE, MAX_SUBJECT, NORECALL)) < 0) { /* * User cancelled via ^G. - FM */ HTInfoMsg(FORM_MAILTO_CANCELLED); goto cleanup; } remove_tildes(self); if (ccaddr == NULL) { StrAllocCopy(ccaddr, self); } else { StrAllocCat(ccaddr, ","); StrAllocCat(ccaddr, self); } } #if CAN_PIPE_TO_MAILER if ((fd = LYPipeToMailer()) == 0) { HTAlert(FORM_MAILTO_FAILED); goto cleanup; } if (!isEmpty(mailto_type)) { fprintf(fd, "Mime-Version: 1.0\n"); fprintf(fd, "Content-Type: %s\n", mailto_type); } fprintf(fd, "To: %s\n", address); if (!isEmpty(personal_mail_address)) fprintf(fd, "From: %s\n", personal_mail_address); if (!isEmpty(ccaddr)) fprintf(fd, "Cc: %s\n", ccaddr); fprintf(fd, "Subject: %s\n\n", subject); if (!isEmpty(keywords)) fprintf(fd, "Keywords: %s\n", keywords); _statusline(SENDING_FORM_CONTENT); #else /* e.g., VMS, DOS */ if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { HTAlert(FORM_MAILTO_FAILED); goto cleanup; } #if USE_VMS_MAILER if (isPMDF) { FILE *hfd; if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { HTAlert(FORM_MAILTO_FAILED); LYCloseTempFP(fd); goto cleanup; } if (!isEmpty(mailto_type)) { fprintf(hfd, "Mime-Version: 1.0\n"); fprintf(hfd, "Content-Type: %s\n", mailto_type); if (!isEmpty(personal_mail_address)) fprintf(hfd, "From: %s\n", personal_mail_address); } /* * For PMDF, put any keywords and the subject * in the header file and close it. - FM */ if (!isEmpty(keywords)) { fprintf(hfd, "Keywords: %s\n", keywords); } fprintf(hfd, "Subject: %s\n\n", subject); LYCloseTempFP(hfd); } else if (mailto_type && !strncasecomp(mailto_type, "multipart/form-data", 19)) { /* * Ugh! There's no good way to include headers while * we're still using "generic" VMS MAIL, so we'll put * this in the body of the message. - FM */ fprintf(fd, "X-Content-Type: %s\n\n", mailto_type); } #else /* !VMS (DOS) */ #if USE_BLAT_MAILER if (mail_is_blat) { if (strlen(subject) > MAX_SUBJECT) subject[MAX_SUBJECT] = '\0'; } else #endif { if (!isEmpty(mailto_type)) { fprintf(fd, "Mime-Version: 1.0\n"); fprintf(fd, "Content-Type: %s\n", mailto_type); } fprintf(fd,"To: %s\n", address); if (!isEmpty(personal_mail_address)) fprintf(fd,"From: %s\n", personal_mail_address); fprintf(fd,"Subject: %.70s\n\n", subject); } #endif /* VMS */ #endif /* CAN_PIPE_TO_MAILER */ /* * Break up the content into lines with a maximum length of 78. * If the ENCTYPE was text/plain, we have physical newlines and * should take them into account. Otherwise, the actual newline * characters in the content are hex escaped. - FM */ while((cp = strchr(mailto_content, '\n')) != NULL) { *cp = '\0'; i = 0; len = strlen(mailto_content); while (len > 78) { strncpy(buf, &mailto_content[i], 78); buf[78] = '\0'; fprintf(fd, "%s\n", buf); i += 78; len = strlen(&mailto_content[i]); } fprintf(fd, "%s\n", &mailto_content[i]); mailto_content = (cp+1); } i = 0; len = strlen(mailto_content); while (len > 78) { strncpy(buf, &mailto_content[i], 78); buf[78] = '\0'; fprintf(fd, "%s\n", buf); i += 78; len = strlen(&mailto_content[i]); } if (len) fprintf(fd, "%s\n", &mailto_content[i]); #if CAN_PIPE_TO_MAILER pclose(fd); LYSleepMsg(); #else LYCloseTempFP(fd); #if USE_VMS_MAILER /* * Set the mail command. - FM */ if (isPMDF) { /* * Now set up the command. - FM */ HTSprintf0(&cmd, "%s %s %s,%s ", system_mail, system_mail_flags, hdrfile, my_tmpfile); } else { /* * For "generic" VMS MAIL, include the subject in the * command, and ignore any keywords to minimize risk * of them making the line too long or having problem * characters. - FM */ HTSprintf0(&cmd, "%s %s%s/subject=\"%s\" %s ", system_mail, system_mail_flags, (strncasecomp(system_mail, "MAIL", 4) ? "" : "/noself"), subject, my_tmpfile); } StrAllocCopy(command, cmd); vms_append_addrs(&command, address, ""); if (!isEmpty(ccaddr)) { vms_append_addrs(&command, ccaddr, "/CC"); } stop_curses(); printf("%s\n\n$ %s\n\n%s", SENDING_FORM_CONTENT, command, PLEASE_WAIT); LYSystem(command); /* Mail (VMS) */ FREE(command); LYSleepAlert(); start_curses(); LYRemoveTemp(my_tmpfile); if (isPMDF) LYRemoveTemp(hdrfile); #else /* DOS */ LYSendMailFile ( address, my_tmpfile, subject, ccaddr, SENDING_FORM_CONTENT); LYRemoveTemp(my_tmpfile); #endif /* USE_VMS_MAILER */ #endif /* CAN_PIPE_TO_MAILER */ cleanup: FREE(address); FREE(ccaddr); FREE(keywords); return; }
/* * Seek and handle body=foo fields. - FM */ PRIVATE void extract_body ARGS2( char **, dst, char *, src) { CONST char *keyword = "body="; int len = strlen(keyword); int i; char *cp, *cp0, *cp1, *temp = 0; cp = (src + 1); while (*cp != '\0') { if ((*(cp - 1) == '?' || *(cp - 1) == '&') && !strncasecomp(cp, keyword, len)) { cp += len; if ((cp1 = strchr(cp, '&')) != NULL) { *cp1 = '\0'; } if (*cp) { /* * Break up the value into lines with * a maximum length of 78. - FM */ StrAllocCopy(temp, cp); HTUnEscape(temp); cp0 = temp; while((cp = strchr(cp0, '\n')) != NULL) { *cp = '\0'; if (cp > cp0) { if (*(cp - 1) == '\r') { *(cp - 1) = '\0'; } } i = 0; len = strlen(cp0); while (len > 78) { HTSprintf(dst, "%.78s\n", &cp0[i]); i += 78; len = strlen(&cp0[i]); } HTSprintf(dst, "%s\n", &cp0[i]); cp0 = (cp + 1); } i = 0; len = strlen(cp0); while (len > 78) { HTSprintf(dst, "%.78s\n", &cp0[i]); i += 78; len = strlen(&cp0[i]); } if (len) { HTSprintf(dst, "%s\n", &cp0[i]); } FREE(temp); } if (cp1) { *cp1 = '&'; cp = cp1; cp1 = NULL; } else { break; } } cp++; } CTRACE((tfp, "extract_body(%s) = '%s'\n", keyword, NONNULL(*dst))); }
/* ** reply_by_mail() invokes sendmail on Unix or mail on VMS to send ** a comment from the users to the owner */ PUBLIC void reply_by_mail ARGS4( char *, mail_address, char *, filename, CONST char *, title, CONST char *, refid) { #ifndef NO_ANONYMOUS_EMAIL static char *personal_name = NULL; #endif char user_input[LINESIZE]; FILE *fd, *fp; char *label = NULL; char *from_address = NULL; char *cc_address = NULL; char *to_address = NULL; char *the_subject = NULL; char *ccaddr = NULL; char *keywords = NULL; char *searchpart = NULL; char *body = NULL; char *cp = NULL, *cp1 = NULL; int i; int c = 0; /* user input */ char my_tmpfile[LY_MAXPATH]; char default_subject[MAX_SUBJECT + 10]; #if USE_VMS_MAILER char *command = NULL; BOOLEAN isPMDF = LYMailPMDF(); char hdrfile[LY_MAXPATH]; FILE *hfd = 0; #else #if !CAN_PIPE_TO_MAILER char tmpfile2[LY_MAXPATH]; #endif char buf[4096]; /* 512 */ char *header = NULL; int n; #endif /* USE_VMS_MAILER */ CTRACE((tfp, "reply_by_mail(\"%s\", \"%s\", \"%s\", \"%s\")\n", NONNULL(mail_address), NONNULL(filename), NONNULL(title), NONNULL(refid))); term_letter = FALSE; if (!LYSystemMail()) return; if (isEmpty(mail_address)) { HTAlert(NO_ADDRESS_IN_MAILTO_URL); return; } StrAllocCopy(to_address, mail_address); if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { HTAlert(MAILTO_URL_TEMPOPEN_FAILED); return; } #if USE_VMS_MAILER if (isPMDF) { if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { HTAlert(MAILTO_URL_TEMPOPEN_FAILED); return; } } #endif /* VMS */ default_subject[0] = '\0'; /* * Check for a ?searchpart. - FM */ if ((cp = strchr(to_address, '?')) != NULL) { StrAllocCopy(searchpart, cp); *cp = '\0'; cp = (searchpart + 1); if (*cp != '\0') { /* * Seek and handle a subject=foo. - FM */ extract_subject(default_subject, searchpart); /* * Seek and handle to=address(es) fields. * Appends to address. - FM */ extract_field(&to_address, searchpart, "to="); /* * Seek and handle cc=address(es) fields. Excludes * Bcc=address(es) as unsafe. We may append our own * cc (below) as a list for the actual mailing. - FM */ extract_field(&ccaddr, searchpart, "cc="); /* * Seek and handle keywords=term(s) fields. - FM */ extract_field(&keywords, searchpart, "keywords="); if (keywords != NULL) { if (*keywords != '\0') { SafeHTUnEscape(keywords); } else { FREE(keywords); } } /* * Seek and handle body=foo fields. - FM */ extract_body(&body, searchpart); FREE(searchpart); } } if (convert_explorer(to_address)) { HTAlert(NO_ADDRESS_IN_MAILTO_URL); goto cancelled; } if (ccaddr != NULL) { if (convert_explorer(ccaddr)) { FREE(ccaddr); } } /* * Unescape the address and ccaddr fields. - FM */ SafeHTUnEscape(to_address); if (ccaddr != NULL) { SafeHTUnEscape(ccaddr); } /* * Set the default subject. - FM */ if (isEmpty(default_subject) && !isEmpty(title)) { strncpy(default_subject, title, MAX_SUBJECT); default_subject[MAX_SUBJECT] = '\0'; } /* * Use ^G to cancel mailing of comment * and don't let SIGINTs exit lynx. */ signal(SIGINT, terminate_letter); #if USE_VMS_MAILER if (isPMDF || !body) { /* * Put the X-URL and X-Mailer lines in the hdrfile * for PMDF or my_tmpfile for VMS MAIL. - FM */ fprintf((isPMDF ? hfd : fd), "X-URL: %s%s\n", isEmpty(filename) ? STR_MAILTO_URL : filename, isEmpty(filename) ? to_address : ""); fprintf((isPMDF ? hfd : fd), "X-Mailer: %s, Version %s\n", LYNX_NAME, LYNX_VERSION); #ifdef NO_ANONYMOUS_EMAIL if (!isPMDF) { fprintf(fd, "\n"); } #endif /* NO_ANONYMOUS_EMAIL */ } #else /* Unix/DOS/Windows */ /* * Put the To: line in the header. */ #ifndef DOSPATH asprintf(&header, "To: %s\n", to_address); if (!header) { fprintf(stderr, "Out of memory, you lose!\n"); exit(1); } #endif /* * Put the Mime-Version, Content-Type and * Content-Transfer-Encoding in the header. * This assumes that the same character set is used * for composing the mail which is currently selected * as display character set... * Don't send a charset if we have a CJK character set * selected, since it may not be appropriate for mail... * Also don't use an unofficial "x-" charset. * Also if the charset would be "us-ascii" (7-bit replacements * selected, don't send any MIME headers. - kw */ if (strncasecomp(LYCharSet_UC[current_char_set].MIMEname, "us-ascii", 8) != 0) { StrAllocCat(header, "Mime-Version: 1.0\n"); if (!LYHaveCJKCharacterSet && strncasecomp(LYCharSet_UC[current_char_set].MIMEname, "x-", 2) != 0) { HTSprintf(&header, "Content-Type: text/plain; charset=%s\n", LYCharSet_UC[current_char_set].MIMEname); } StrAllocCat(header, "Content-Transfer-Encoding: 8bit\n"); } /* * Put the X-URL and X-Mailer lines in the header. */ if (!isEmpty(filename)) { HTSprintf(&header, "X-URL: %s\n", filename); } else { HTSprintf(&header, "X-URL: mailto:%s\n", to_address); } HTSprintf(&header, "X-Mailer: %s, Version %s\n", LYNX_NAME, LYNX_VERSION); if (!isEmpty(refid)) { HTSprintf(&header, "In-Reply-To: <%s>\n", refid); } #endif /* VMS */ /* * Clear the screen and inform the user. */ LYclear(); LYmove(2,0); scrollok(LYwin, TRUE); /* Enable scrolling. */ if (body) LYaddstr(SENDING_MESSAGE_WITH_BODY_TO); else LYaddstr(SENDING_COMMENT_TO); show_addresses(to_address); if ( #if USE_VMS_MAILER (isPMDF == TRUE) && #endif /* VMS */ (cp = ccaddr) != NULL) { if (strchr(cp, ',') != NULL) { LYaddstr(WITH_COPIES_TO); } else { LYaddstr(WITH_COPY_TO); } show_addresses(ccaddr); } LYaddstr(CTRL_G_TO_CANCEL_SEND); #if USE_VMS_MAILER if (isPMDF || !body) { #endif /* USE_VMS_MAILER */ #ifndef NO_ANONYMOUS_EMAIL /* * Get the user's personal name. */ LYaddstr(ENTER_NAME_OR_BLANK); #if USE_VMS_MAILER if (isPMDF) { label = "Personal_name: "; } else { label = "X-Personal_name: "; } #else label = "X-Personal_Name: "; #endif /* USE_VMS_MAILER */ if (!header_prompt(label, &personal_name, LINESIZE)) { goto cancelled; } if (*personal_name) { #if USE_VMS_MAILER fprintf((isPMDF ? hfd : fd), "%s: %s\n", label, personal_name); #else HTSprintf(&header, "%s: %s\n", label, personal_name); #endif /* VMS */ } /* * Get the user's return address. */ LYaddstr(ENTER_MAIL_ADDRESS_OR_OTHER); LYaddstr(MEANS_TO_CONTACT_FOR_RESPONSE); #if USE_VMS_MAILER if (isPMDF) { label = "From"; } else { label = "X-From"; } #else label = "From"; #endif /* VMS */ /* Add the personal mail address if there is one. */ if (personal_mail_address) StrAllocCopy(from_address, personal_mail_address); if (!header_prompt(label, &from_address, LINESIZE)) { goto cancelled; } #if USE_VMS_MAILER if (*from_address) { fprintf(isPMDF ? hfd : fd, "%s: %s\n", label, from_address); } if (!isPMDF) { fprintf(fd, "\n"); } #else HTSprintf(&header, "%s: %s\n", label, from_address); #endif /* USE_VMS_MAILER */ #endif /* !NO_ANONYMOUS_EMAIL */ #if USE_VMS_MAILER } #endif /* USE_VMS_MAILER */ /* * Get the subject line. */ LYaddstr(ENTER_SUBJECT_LINE); label = "Subject"; if (*default_subject) { StrAllocCopy(the_subject, default_subject); } else if (!isEmpty(filename)) { HTSprintf(&the_subject, "%s", filename); } else { HTSprintf(&the_subject, "mailto:%s", to_address); } if (!header_prompt(label, &the_subject, MAX_SUBJECT)) { goto cancelled; } /* * Offer a CC line, if permitted. - FM */ if (!LYNoCc) { LYaddstr(ENTER_ADDRESS_FOR_CC); LYaddstr(BLANK_FOR_NO_COPY); if (personal_mail_address) StrAllocCopy(cc_address, personal_mail_address); if (!header_prompt("Cc", &cc_address, LINESIZE)) { goto cancelled; } comma_append(&ccaddr, cc_address); } #if !USE_VMS_MAILER HTSprintf(&header, "%s: %s\n", label, the_subject); #if !CAN_PIPE_TO_MAILER if (*to_address) { HTSprintf(&header, "To: %s\n", to_address); } #endif /* ** Add the Cc: header. - FM */ if (!isEmpty(ccaddr)) { HTSprintf(&header, "Cc: %s\n", ccaddr); } /* ** Add the Keywords: header. - FM */ if (!isEmpty(keywords)) { HTSprintf(&header, "Keywords: %s\n", keywords); } /* * Terminate the header. */ StrAllocCat(header, "\n"); CTRACE((tfp,"**header==\n%s",header)); #endif /* !VMS */ if (!no_editor && !isEmpty(editor)) { if (body) { cp1 = body; while((cp = strchr(cp1, '\n')) != NULL) { *cp++ = '\0'; fprintf(fd, "%s\n", cp1); cp1 = cp; } } else if (strcmp(HTLoadedDocumentURL(), "")) { /* * Ask if the user wants to include the original message. */ BOOLEAN is_preparsed = (BOOL) (LYPreparsedSource && HTisDocumentSource()); if (HTConfirm(is_preparsed ? INC_PREPARSED_MSG_PROMPT : INC_ORIG_MSG_PROMPT) == YES) { print_wwwfile_to_fd(fd, (BOOL) !is_preparsed); } } LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(LYwin,FALSE); /* Stop scrolling. */ if (term_letter || LYCharIsINTERRUPT(c)) goto cleanup; /* * Spawn the users editor on the mail file */ edit_temporary_file(my_tmpfile, "", SPAWNING_EDITOR_FOR_MAIL); } else if (body) { /* * Let user review the body. - FM */ LYclear(); LYmove(0,0); LYaddstr(REVIEW_MESSAGE_BODY); LYrefresh(); cp1 = body; i = (LYlines - 5); while((cp = strchr(cp1, '\n')) != NULL) { if (i <= 0) { LYaddstr(RETURN_TO_CONTINUE); LYrefresh(); c = LYgetch(); LYaddstr("\n"); if (term_letter || LYCharIsINTERRUPT(c)) { goto cancelled; } i = (LYlines - 2); } *cp++ = '\0'; fprintf(fd, "%s\n", cp1); LYaddstr(cp1); LYaddstr("\n"); cp1 = cp; i--; } while (i >= 0) { LYaddstr("\n"); i--; } LYrefresh(); LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(LYwin,FALSE); /* Stop scrolling. */ } else { /* * Use the internal line editor for the message. */ LYaddstr(ENTER_MESSAGE_BELOW); LYaddstr(ENTER_PERIOD_WHEN_DONE_A); LYaddstr(ENTER_PERIOD_WHEN_DONE_B); LYaddstr("\n\n"); LYrefresh(); *user_input = '\0'; if (LYgetstr(user_input, VISIBLE, sizeof(user_input), NORECALL) < 0 || term_letter || STREQ(user_input, ".")) { goto cancelled; } while (!STREQ(user_input, ".") && !term_letter) { LYaddstr("\n"); remove_tildes(user_input); fprintf(fd, "%s\n", user_input); *user_input = '\0'; if (LYgetstr(user_input, VISIBLE, sizeof(user_input), NORECALL) < 0) { goto cancelled; } } fprintf(fd, "\n"); /* Terminate the message. */ LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(LYwin,FALSE); /* Stop scrolling. */ } #if !USE_VMS_MAILER /* * Ignore CTRL-C on this last question. */ signal(SIGINT, SIG_IGN); #endif /* !VMS */ LYStatusLine = (LYlines - 1); c = HTConfirm (body ? SEND_MESSAGE_PROMPT : SEND_COMMENT_PROMPT); LYStatusLine = -1; if (c != YES) { LYclear(); /* clear the screen */ goto cleanup; } if ((body == NULL && LynxSigFile != NULL) && (fp = fopen(LynxSigFile, TXT_R)) != NULL) { LYStatusLine = (LYlines - 1); if (term_letter) { _user_message(APPEND_SIG_FILE, LynxSigFile); c = 0; } else { char *msg = NULL; HTSprintf0(&msg, APPEND_SIG_FILE, LynxSigFile); c = HTConfirm(msg); FREE(msg); } LYStatusLine = -1; if (c == YES) { if ((fd = fopen(my_tmpfile, TXT_A)) != NULL) { char *buffer = NULL; fputs("-- \n", fd); while (LYSafeGets(&buffer, fp) != NULL) { fputs(buffer, fd); } LYCloseOutput(fd); FREE(buffer); } } LYCloseInput(fp); } LYclear(); /* Clear the screen. */ /* * Send the message. */ #if USE_VMS_MAILER /* * Set the mail command. - FM */ if (isPMDF) { /* * For PMDF, put any keywords and the subject * in the header file and close it. - FM */ if (!isEmpty(keywords)) { fprintf(hfd, "Keywords: %s\n", keywords); } fprintf(hfd, "Subject: %s\n\n", the_subject); LYCloseTempFP(hfd); /* * Now set up the command. - FM */ HTSprintf0(&command, "%s %s %s,%s ", system_mail, system_mail_flags, hdrfile, my_tmpfile); } else { /* * For "generic" VMS MAIL, include the subject in the * command, and ignore any keywords to minimize risk * of them making the line too long or having problem * characters. - FM */ HTSprintf0(&command, "%s %s%s/subject=\"%s\" %s ", system_mail, system_mail_flags, (strncasecomp(system_mail, "MAIL", 4) ? "" : "/noself"), the_subject, my_tmpfile); } vms_append_addrs(&command, to_address, ""); if (!isEmpty(ccaddr)) { vms_append_addrs(&command, ccaddr, "/CC"); } stop_curses(); printf("%s\n\n$ %s\n\n%s", SENDING_COMMENT, command, PLEASE_WAIT); LYSystem(command); /* SENDING COMMENT (VMS) */ FREE(command); LYSleepAlert(); start_curses(); #else /* Unix/DOS/Windows */ /* * Send the tmpfile into sendmail. */ _statusline(SENDING_YOUR_MSG); #if CAN_PIPE_TO_MAILER signal(SIGINT, SIG_IGN); if ((fp = LYPipeToMailer()) == 0) { HTInfoMsg(CANCELLED); } #else if ((fp = LYOpenTemp(tmpfile2, ".txt", "w")) == NULL) { HTAlert(MAILTO_URL_TEMPOPEN_FAILED); } #endif /* CAN_PIPE_TO_MAILER */ if (fp != 0) { fd = fopen(my_tmpfile, TXT_R); if (fd == NULL) { HTInfoMsg(CANCELLED); #if CAN_PIPE_TO_MAILER pclose(fp); #else LYCloseTempFP(fp); #endif /* CAN_PIPE_TO_MAILER */ } else { #if USE_BLAT_MAILER if (!mail_is_blat) fputs(header, fp); #else fputs(header, fp); #endif while ((n = fread(buf, 1, sizeof(buf), fd)) != 0) { fwrite(buf, 1, n, fp); } #if CAN_PIPE_TO_MAILER pclose(fp); #else LYCloseTempFP(fp); /* Close the tmpfile. */ LYSendMailFile ( to_address, tmpfile2, the_subject, ccaddr, SENDING_COMMENT); LYRemoveTemp(tmpfile2); /* Delete the tmpfile. */ #endif /* CAN_PIPE_TO_MAILER */ LYCloseInput(fd); /* Close the tmpfile. */ } } #endif /* USE_VMS_MAILER */ goto cleanup; /* * Come here to cleanup and exit. */ cancelled: HTInfoMsg(CANCELLED); LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(LYwin,FALSE); /* Stop scrolling. */ cleanup: signal(SIGINT, cleanup_sig); term_letter = FALSE; #if USE_VMS_MAILER while (LYRemoveTemp(my_tmpfile) == 0) ; /* Delete the tmpfile(s). */ if (isPMDF) { LYRemoveTemp(hdrfile); /* Delete the hdrfile. */ } #else FREE(header); LYRemoveTemp(my_tmpfile); /* Delete the tmpfile. */ #endif /* VMS */ FREE(from_address); FREE(the_subject); FREE(cc_address); FREE(to_address); FREE(ccaddr); FREE(keywords); FREE(body); return; }
/* Translate by rules HTTranslate() * ------------------ * * The most recently defined rules are applied first. * * On entry, * required points to a string whose equivalent value is needed * On exit, * returns the address of the equivalent string allocated from * the heap which the CALLER MUST FREE. If no translation * occurred, then it is a copy of the original. * NEW FEATURES: * When a "protect" or "defprot" rule is matched, * a call to HTAA_setCurrentProtection() or * HTAA_setDefaultProtection() is made to notify * the Access Authorization module that the file is * protected, and so it knows how to handle it. * -- AL */ char *HTTranslate(const char *required) { rule *r; char *current = NULL; char *msgtmp = NULL; const char *pMsg; int proxy_none_flag = 0; int permitredir_flag = 0; StrAllocCopy(current, required); HTAA_clearProtections(); /* Reset from previous call -- AL */ for (r = rules; r; r = r->next) { char *p = r->pattern; int m = 0; /* Number of characters matched against wildcard */ const char *q = current; for (; *p && *q; p++, q++) { /* Find first mismatch */ if (*p != *q) break; } if (*p == '*') { /* Match up to wildcard */ m = strlen(q) - strlen(p + 1); /* Amount to match to wildcard */ if (m < 0) continue; /* tail is too short to match */ if (0 != strcmp(q + m, p + 1)) continue; /* Tail mismatch */ } else /* Not wildcard */ if (*p != *q) continue; /* plain mismatch: go to next rule */ if (!rule_cond_ok(r)) /* check condition, next rule if false - kw */ continue; switch (r->op) { /* Perform operation */ #ifdef ACCESS_AUTH case HT_DefProt: case HT_Protect: { char *local_copy = NULL; char *p2; char *eff_ids = NULL; char *prot_file = NULL; CTRACE((tfp, "HTRule: `%s' matched %s %s: `%s'\n", current, (r->op == HT_Protect ? "Protect" : "DefProt"), "rule, setup", (r->equiv ? r->equiv : (r->op == HT_Protect ? "DEFAULT" : "NULL!!")))); if (r->equiv) { StrAllocCopy(local_copy, r->equiv); p2 = local_copy; prot_file = HTNextField(&p2); eff_ids = HTNextField(&p2); } if (r->op == HT_Protect) HTAA_setCurrentProtection(current, prot_file, eff_ids); else HTAA_setDefaultProtection(current, prot_file, eff_ids); FREE(local_copy); /* continue translating rules */ } break; #endif /* ACCESS_AUTH */ case HT_UserMsg: /* Produce message immediately */ LYFixCursesOn("show rule message:"); HTUserMsg2((r->equiv ? r->equiv : "Rule: %s"), current); break; case HT_InfoMsg: /* Produce messages immediately */ case HT_Progress: case HT_Alert: LYFixCursesOn("show rule message:"); /* and fall through */ case HT_AlwaysAlert: pMsg = r->equiv ? r->equiv : (r->op == HT_AlwaysAlert) ? "%s" : "Rule: %s"; if (strchr(pMsg, '%')) { HTSprintf0(&msgtmp, pMsg, current); pMsg = msgtmp; } switch (r->op) { /* Actually produce message */ case HT_InfoMsg: HTInfoMsg(pMsg); break; case HT_Progress: HTProgress(pMsg); break; case HT_Alert: HTAlert(pMsg); break; case HT_AlwaysAlert: HTAlwaysAlert("Rule alert:", pMsg); break; default: break; } FREE(msgtmp); break; case HT_PermitRedir: /* Set special flag */ permitredir_flag = 1; CTRACE((tfp, "HTRule: Mark for redirection permitted\n")); break; case HT_Pass: /* Authorised */ if (!r->equiv) { if (proxy_none_flag) { char *temp = NULL; StrAllocCopy(temp, "NoProxy="); StrAllocCat(temp, current); FREE(current); current = temp; } CTRACE((tfp, "HTRule: Pass `%s'\n", current)); return current; } /* Else fall through ...to map and pass */ case HT_Map: case HT_Redirect: case HT_RedirectPerm: if (*p == *q) { /* End of both strings, no wildcard */ CTRACE((tfp, "For `%s' using `%s'\n", current, r->equiv)); StrAllocCopy(current, r->equiv); /* use entire translation */ } else { char *ins = strchr(r->equiv, '*'); /* Insertion point */ if (ins) { /* Consistent rule!!! */ char *temp = NULL; HTSprintf0(&temp, "%.*s%.*s%s", (int) (ins - r->equiv), r->equiv, m, q, ins + 1); CTRACE((tfp, "For `%s' using `%s'\n", current, temp)); FREE(current); current = temp; /* Use this */ } else { /* No insertion point */ char *temp = NULL; StrAllocCopy(temp, r->equiv); CTRACE((tfp, "For `%s' using `%s'\n", current, temp)); FREE(current); current = temp; /* Use this */ } /* If no insertion point exists */ } if (r->op == HT_Pass) { if (proxy_none_flag) { char *temp = NULL; StrAllocCopy(temp, "NoProxy="); StrAllocCat(temp, current); FREE(current); current = temp; } CTRACE((tfp, "HTRule: ...and pass `%s'\n", current)); return current; } else if (r->op == HT_Redirect) { CTRACE((tfp, "HTRule: ...and redirect to `%s'\n", current)); redirecting_url = current; HTPermitRedir = (BOOL) (permitredir_flag == 1); return (char *) 0; } else if (r->op == HT_RedirectPerm) { CTRACE((tfp, "HTRule: ...and redirect like 301 to `%s'\n", current)); redirecting_url = current; permanent_redirection = TRUE; HTPermitRedir = (BOOL) (permitredir_flag == 1); return (char *) 0; } break; case HT_UseProxy: if (r->equiv && 0 == strcasecomp(r->equiv, "none")) { CTRACE((tfp, "For `%s' will not use proxy\n", current)); proxy_none_flag = 1; } else if (proxy_none_flag) { CTRACE((tfp, "For `%s' proxy server ignored: %s\n", current, NONNULL(r->equiv))); } else { char *temp = NULL; StrAllocCopy(temp, "Proxied="); StrAllocCat(temp, r->equiv); StrAllocCat(temp, current); CTRACE((tfp, "HTRule: proxy server found: %s\n", NONNULL(r->equiv))); FREE(current); return temp; } break; case HT_Invalid: case HT_Fail: /* Unauthorised */ CTRACE((tfp, "HTRule: *** FAIL `%s'\n", current)); FREE(current); return (char *) 0; } /* if tail matches ... switch operation */ } /* loop over rules */ if (proxy_none_flag) { char *temp = NULL; StrAllocCopy(temp, "NoProxy="); StrAllocCat(temp, current); FREE(current); return temp; } return current; }
static const char * AttrsOnce(KEYWORD * entry) { entry->kw_used = 999; return NONNULL(entry->kw_attr); }