char key_pressed() { char ch; start_curses(); timeout(0); ch = getch(); stop_curses(); if (ch != ERR) return ch; else return 'p'; }
void final_perror( char *msg, BOOLEAN clean_flag ) { int saved_errno = *(int*)(__errno_location( )); if ( LYCursesON ) { if ( clean_flag ) cleanup( ); else stop_curses( ); } *(int*)(__errno_location( )) = saved_errno; perror( msg ); 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; }
PUBLIC int LYSendMailFile ARGS5( char *, the_address, char *, the_filename, char *, the_subject GCC_UNUSED, char *, the_ccaddr GCC_UNUSED, char *, message) { char *cmd = NULL; #ifdef __DJGPP__ char *shell; #endif /* __DJGPP__ */ int code; if (!LYSystemMail()) return 0; #if USE_BLAT_MAILER if (mail_is_blat) StrAllocCopy(cmd, blat_cmd( system_mail, the_filename, the_address, the_subject, the_ccaddr, personal_mail_address ) ); else #endif #ifdef __DJGPP__ if ((shell = LYGetEnv("SHELL")) != NULL) { if (strstr(shell, "sh") != NULL) { HTSprintf0(&cmd, "%s -c %s -t \"%s\" -F %s", shell, system_mail, the_address, the_filename); } else { HTSprintf0(&cmd, "%s /c %s -t \"%s\" -F %s", shell, system_mail, the_address, the_filename); } } else { HTSprintf0(&cmd, "%s -t \"%s\" -F %s", system_mail, the_address, the_filename); } #else HTSprintf0(&cmd, "%s -t \"%s\" -F %s", system_mail, the_address, the_filename); #endif /* __DJGPP__ */ stop_curses(); SetOutputMode(O_TEXT); printf("%s\n\n$ %s\n\n%s", *message ? message : gettext("Sending"), cmd, PLEASE_WAIT); code = LYSystem(cmd); LYSleepMsg(); start_curses(); SetOutputMode( O_BINARY ); FREE(cmd); return code; }
/* ** 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; }
void LYDownload(char *line) { char *Line = NULL, *method, *file, *sug_file = NULL; int method_number; int count; char *the_command = 0; bstring *buffer = NULL; bstring *command = NULL; char *cp; lynx_list_item_type *download_command = 0; int ch; RecallType recall; int FnameTotal; int FnameNum; BOOLEAN FirstRecall = TRUE; BOOLEAN SecondS = FALSE; #ifdef VMS LYDidRename = FALSE; #endif /* VMS */ /* * Make sure we have a valid download file comparison string loaded via the * download options menu. - FM */ if (LYValidDownloadFile[0] == '\0') { goto failed; } /* * Make a copy of the LYNXDOWNLOAD internal URL for parsing. - FM */ StrAllocCopy(Line, line); /* * Parse out the File, sug_file, and the Method. */ if ((file = strstr(Line, "/File=")) == NULL) goto failed; *file = '\0'; /* * Go past "File=". */ file += 6; if ((sug_file = strstr(file + 1, "/SugFile=")) != NULL) { *sug_file = '\0'; /* * Go past "SugFile=". */ sug_file += 9; HTUnEscape(sug_file); } /* * Make sure that the file string is the one from the last displayed * download options menu. - FM */ if (strcmp(file, LYValidDownloadFile)) { goto failed; } #if defined(DIRED_SUPPORT) /* FIXME: use HTLocalName */ if (!StrNCmp(file, "file://localhost", 16)) { #ifdef __DJGPP__ if (!StrNCmp(file + 16, "/dev/", 5)) file += 16; else { file += 17; file = HTDOS_name(file); } #else file += 16; #endif /* __DJGPP__ */ } else if (isFILE_URL(file)) file += LEN_FILE_URL; HTUnEscape(file); #else #if defined(_WINDOWS) /* 1997/10/15 (Wed) 16:27:38 */ if (!StrNCmp(file, "file://localhost/", 17)) file += 17; else if (!StrNCmp(file, "file:/", 6)) file += 6; HTUnEscape(file); #endif /* _WINDOWS */ #endif /* DIRED_SUPPORT */ if ((method = strstr(Line, "Method=")) == NULL) goto failed; /* * Go past "Method=". */ method += 7; method_number = atoi(method); /* * Set up the sug_filenames recall buffer. */ FnameTotal = (sug_filenames ? HTList_count(sug_filenames) : 0); recall = ((FnameTotal >= 1) ? RECALL_URL : NORECALL); FnameNum = FnameTotal; if (method_number < 0) { /* * Write to local file. */ _statusline(FILENAME_PROMPT); retry: if (sug_file) { BStrCopy0(buffer, sug_file); } else { BStrCopy0(buffer, ""); } check_recall: if ((ch = LYgetBString(&buffer, FALSE, 0, recall)) < 0 || isBEmpty(buffer) || ch == UPARROW_KEY || ch == DNARROW_KEY) { if (recall && ch == UPARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the last Fname in the list. - FM */ FnameNum = 0; } else { /* * Go back to the previous Fname in the list. - FM */ FnameNum++; } if (FnameNum >= FnameTotal) { /* * Reset the FirstRecall flag, and use sug_file or a blank. * - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto retry; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_recall; } } else if (recall && ch == DNARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the first Fname in the list. - FM */ FnameNum = FnameTotal - 1; } else { /* * Advance to the next Fname in the list. - FM */ FnameNum--; } if (FnameNum < 0) { /* * Set the FirstRecall flag, and use sug_file or a blank. * - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto retry; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_recall; } } /* * Save cancelled. */ goto cancelled; } BStrCopy(command, buffer); if (!LYValidateFilename(&buffer, &command)) goto cancelled; #ifdef HAVE_POPEN else if (LYIsPipeCommand(buffer->str)) { /* I don't know how to download to a pipe */ HTAlert(CANNOT_WRITE_TO_FILE); _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; } #endif /* * See if it already exists. */ switch (LYValidateOutput(buffer->str)) { case 'Y': break; case 'N': _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto retry; default: goto cleanup; } /* * See if we can write to it. */ CTRACE((tfp, "LYDownload: filename is %s\n", buffer->str)); SecondS = TRUE; HTInfoMsg(SAVING); #ifdef VMS /* * Try rename() first. - FM */ CTRACE((tfp, "command: rename(%s, %s)\n", file, buffer->str)); if (rename(file, buffer->str)) { /* * Failed. Use spawned COPY_COMMAND. - FM */ CTRACE((tfp, " FAILED!\n")); LYCopyFile(file, buffer->str); } else { /* * We don't have the temporary file (it was renamed to a permanent * file), so set a flag to pop out of the download menu. - FM */ LYDidRename = TRUE; } chmod(buffer->str, HIDE_CHMOD); #else /* Unix: */ LYCopyFile(file, buffer->str); LYRelaxFilePermissions(buffer->str); #endif /* VMS */ } else { /* * Use configured download commands. */ BStrCopy0(buffer, ""); for (count = 0, download_command = downloaders; count < method_number; count++, download_command = download_command->next) ; /* null body */ /* * Commands have the form "command %s [etc]" where %s is the filename. */ if (download_command->command != NULL) { /* * Check for two '%s' and ask for the local filename if there is. */ if (HTCountCommandArgs(download_command->command) >= 2) { _statusline(FILENAME_PROMPT); again: if (sug_file) { BStrCopy0(buffer, sug_file); } else { BStrCopy0(buffer, ""); } check_again: if ((ch = LYgetBString(&buffer, FALSE, 0, recall)) < 0 || isBEmpty(buffer) || ch == UPARROW_KEY || ch == DNARROW_KEY) { if (recall && ch == UPARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the last Fname in the list. - FM */ FnameNum = 0; } else { /* * Go back to the previous Fname in the list. - FM */ FnameNum++; } if (FnameNum >= FnameTotal) { /* * Reset the FirstRecall flag, and use sug_file or * a blank. - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto again; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_again; } } else if (recall && ch == DNARROW_KEY) { if (FirstRecall) { FirstRecall = FALSE; /* * Use the first Fname in the list. - FM */ FnameNum = FnameTotal - 1; } else { /* * Advance to the next Fname in the list. - FM */ FnameNum--; } if (FnameNum < 0) { /* * Set the FirstRecall flag, and use sug_file or a * blank. - FM */ FirstRecall = TRUE; FnameNum = FnameTotal; _statusline(FILENAME_PROMPT); goto again; } else if ((cp = (char *) HTList_objectAt(sug_filenames, FnameNum)) != NULL) { BStrCopy0(buffer, cp); if (FnameTotal == 1) { _statusline(EDIT_THE_PREV_FILENAME); } else { _statusline(EDIT_A_PREV_FILENAME); } goto check_again; } } /* * Download cancelled. */ goto cancelled; } if (no_dotfiles || !show_dotfiles) { if (*LYPathLeaf(buffer->str) == '.') { HTAlert(FILENAME_CANNOT_BE_DOT); _statusline(NEW_FILENAME_PROMPT); goto again; } } /* * Cancel if the user entered "/dev/null" on Unix, or an "nl:" * path on VMS. - FM */ if (LYIsNullDevice(buffer->str)) { goto cancelled; } SecondS = TRUE; } /* * The following is considered a bug by the community. If the * command only takes one argument on the command line, then the * suggested file name is not used. It actually is not a bug at * all and does as it should, putting both names on the command * line. */ count = 1; HTAddParam(&the_command, download_command->command, count, file); if (HTCountCommandArgs(download_command->command) > 1) HTAddParam(&the_command, download_command->command, ++count, buffer->str); HTEndParam(&the_command, download_command->command, count); } else { HTAlert(MISCONF_DOWNLOAD_COMMAND); goto failed; } CTRACE((tfp, "command: %s\n", the_command)); stop_curses(); LYSystem(the_command); FREE(the_command); start_curses(); /* don't remove(file); */ } if (SecondS == TRUE) { #ifdef VMS if (0 == strncasecomp(buffer->str, "sys$disk:", 9)) { if (0 == StrNCmp((buffer->str + 9), "[]", 2)) { HTAddSugFilename(buffer->str + 11); } else { HTAddSugFilename(buffer->str + 9); } } else { HTAddSugFilename(buffer->str); } #else HTAddSugFilename(buffer->str); #endif /* VMS */ } goto cleanup; failed: HTAlert(CANNOT_DOWNLOAD_FILE); goto cleanup; cancelled: HTInfoMsg(CANCELLING); cleanup: FREE(Line); BStrFree(buffer); return; }
int main(void) { int secs = 1; int usecs = 0; CursesHandle handle = start_curses(); int input = '0'; /* Set to something printable */ int num_loops = 0; /* Number of times through main loop */ while ( input != 'q' && input != 'Q' ) { /* Output messages */ mvprintw(3, 3, "Main loop entered %d times", ++num_loops); mvprintw(4, 3, "Last character input was %c", input); mvprintw(5, 3, "Press 'q' to quit"); refresh(); /* select() modifies the fd_sets passed to it, * so zero and set them prior to each call. */ fd_set fds; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); /* Same deal for the struct timeval, select() may * modify it, it may not, so recreate to be portable. */ struct timeval tv; tv.tv_sec = secs; tv.tv_usec = usecs; /* Wait for input or timeout */ if ( select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv) == -1 ) { /* select() returned with an error. */ if ( errno != EINTR ) { /* If interrupted by a signal, no problem, * keep going. Otherwise, let's just quit. */ stop_curses(handle); perror("error calling select()"); return EXIT_FAILURE; } } else if ( FD_ISSET(STDIN_FILENO, &fds) ) { /* Only call getch() if input is ready. * getch() will not block when we do it this way. */ if ( (input = getch()) == ERR ) { stop_curses(handle); fprintf(stderr, "ERR returned from getch()\n"); return EXIT_FAILURE; } } } stop_curses(handle); return 0; }
int LYUpload( char *line ) { int eax; char *method, *directory; int method_number; int count; char *the_upload = 0; char tmpbuf[256]; char *filename = 0; lynx_list_item_type *upload_command = 0; char *the_command = 0; directory = strstr( line, "TO=" ); if ( directory != 0 ) { directory[ -1 ] = 0; directory += 3; method = strstr( line, "UPLOAD=" ); if ( method != 0 ) { method += 7; method_number = atoi( method ); count = 0; upload_command = uploaders; for ( ; count < method_number; upload_command = &upload_command ) { count++; //upload_command = &upload_command; } if ( upload_command->command == 0 ) { HTAlert( gettext( "ERROR! - upload command is misconfigured" ) ); } if ( HTCountCommandArgs( upload_command->command ) != 0 ) { mustshow = 1; statusline( gettext( "Enter a filename: " ) ); do { tmpbuf[0] = 0; if ( LYgetstr( tmpbuf, 0, 256, 0 ) >= 0 && ( tmpbuf[0] & 255 ) != 0 ) { if ( strstr( tmpbuf, "../" ) != 0 ) { HTAlert( gettext( "Illegal redirection \"../\" found! Request ignored." ) ); } if ( strchr( tmpbuf, 47 ) != 0 ) { HTAlert( gettext( "Illegal character \"/\" found! Request ignored." ) ); } if ( tmpbuf[0] == '~' ) { HTAlert( gettext( "Illegal redirection using \"~\" found! Request ignored." ) ); } HTSprintf0( &filename, "%s/%s", directory, tmpbuf[0] ); if ( filename[0] == '|' ) { HTAlert( gettext( "Cannot write to file." ) ); mustshow = 1; statusline( gettext( "Enter a new filename: " ) ); } switch ( LYValidateOutput( filename ) ) { case 89: if ( ( WWW_TraceFlag & 255 ) != 0 ) { fprintf( TraceFP( ), "LYUpload: filename is %s", filename ); } break; default: HTInfoMsg( gettext( "Cancelling!" ) ); if ( ( 0 ^ 0 ) != 0 ) { __stack_chk_fail( ); break; } break; } } } while ( ( LYCanWriteFile( filename ) & 255 ) == 0 ); HTAddParam( &the_upload, upload_command->command, 1, filename ); HTEndParam( &the_upload, upload_command->command, 1 ); } else { HTSACopy( &the_upload, upload_command->command ); HTAddParam( &the_command, "cd %s ; ", 1, directory ); HTEndParam( &the_command, "cd %s ; ", 1 ); HTSACat( &the_command, the_upload ); if ( ( WWW_TraceFlag & 255 ) != 0 ) { fprintf( TraceFP( ), "command: %s\n", the_command ); } stop_curses( ); LYSystem( the_command ); start_curses( ); if ( the_command != 0 ) { free( the_command ); the_command = 0; } if ( the_upload != 0 ) { free( the_upload ); the_upload = 0; } if ( filename != 0 ) chmod( filename, 384 ); if ( filename != 0 ) { free( filename ); filename = 0; } } } } HTAlert( gettext( "Unable to upload file." ) ); }
PUBLIC void edit_temporary_file ARGS3( char *, filename, char *, position, char *, message) { #ifdef UNIX struct stat stat_info; #endif char *format = "%s %s"; char *command = NULL; char *editor_arg = ""; int params = 1; int rv; if (strstr(editor, "pico")) { editor_arg = " -t"; /* No prompt for filename to use */ } if (editor_can_position() && *position) { #ifdef VMS format = "%s %s -%s%s"; HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, filename); HTAddParam(&command, format, params++, position); HTAddParam(&command, format, params++, editor_arg); HTEndParam(&command, format, params); #else format = "%s +%s%s %s"; HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, position); HTAddParam(&command, format, params++, editor_arg); HTAddParam(&command, format, params++, filename); HTEndParam(&command, format, params); #endif } #ifdef DOSPATH else if (strncmp(editor, "VZ", 2)==0) { /* for Vz editor */ format = "%s %s -%s"; HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, HTDOS_short_name(filename)); HTAddParam(&command, format, params++, position); HTEndParam(&command, format, params); } else if (strncmp(editor, "edit", 4)==0) { /* for standard editor */ HTAddXpand(&command, format, params++, editor); HTAddParam(&command, format, params++, HTDOS_short_name(filename)); HTEndParam(&command, format, params); } #endif else { #ifdef _WINDOWS if (strchr(editor, ' ')) HTAddXpand(&command, format, params++, HTDOS_short_name(editor)); else HTAddXpand(&command, format, params++, editor); #else HTAddXpand(&command, format, params++, editor); #endif HTAddParam(&command, format, params++, filename); HTEndParam(&command, format, params); } if (message != NULL) { _statusline(message); } CTRACE((tfp, "LYEdit: %s\n", command)); CTRACE_SLEEP(MessageSecs); stop_curses(); #ifdef UNIX set_errno(0); #endif if ((rv = LYSystem(command)) != 0) { /* Spawn Editor */ start_curses(); /* * If something went wrong, we should probably return soon; * currently we don't, but at least put out a message. - kw */ { #ifdef UNIX CTRACE((tfp, "ExtEditForm: system() returned %d (0x%x), %s\n", rv, rv, errno ? LYStrerror(errno) : "reason unknown")); LYFixCursesOn("show error warning:"); if (rv == -1) { HTUserMsg2(gettext("Error starting editor, %s"), LYStrerror(errno)); } else if (WIFSIGNALED(rv)) { HTAlwaysAlert(NULL, gettext("Editor killed by signal")); } else if (WIFEXITED(rv) && WEXITSTATUS(rv) != 127) { HTUserMsg2(gettext("Editor returned with exit code %d"), WEXITSTATUS(rv)); } else #endif HTAlwaysAlert(NULL, ERROR_SPAWNING_EDITOR); } } else { start_curses(); } #ifdef UNIX /* * Delete backup file, if that's your style. */ HTSprintf0 (&command, "%s~", filename); if (stat (command, &stat_info) == 0) remove (command); #endif FREE(command); }
void cleanup(void) { #ifdef VMS extern BOOLEAN DidCleanup; #endif /* VMS */ /* * Cleanup signals - just in case. Ignore further interrupts. - mhc: * 11/2/91 */ #ifndef NOSIGHUP (void) signal(SIGHUP, SIG_IGN); #endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_IGN); #ifndef VMS /* use ttclose() from cleanup() for VMS */ (void) signal(SIGINT, SIG_IGN); #endif /* !VMS */ if (LYCursesON) { LYmove(LYlines - 1, 0); LYclrtoeol(); lynx_stop_all_colors(); LYrefresh(); stop_curses(); } #ifdef EXP_CHARTRANS_AUTOSWITCH /* * Currently implemented only for LINUX: Restore original font. */ UCChangeTerminalCodepage(-1, (LYUCcharset *) 0); #endif /* EXP_CHARTRANS_AUTOSWITCH */ #ifdef USE_PERSISTENT_COOKIES /* * This can go right here for now. We need to work up a better place * to save cookies for the next release, preferably whenever a new * persistent cookie is received or used. Some sort of protocol to * handle two processes writing to the cookie file needs to be worked * out as well. */ if (persistent_cookies) LYStoreCookies(LYCookieSaveFile); #endif cleanup_files(); #ifdef VMS ttclose(); DidCleanup = TRUE; #endif /* VMS */ /* * If we're looking at memory leaks, hang onto the trace file, since there * is no memory freed in this function, and it is a nuisance to not be able * to trace the cleanup activity -TD */ #ifndef LY_FIND_LEAKS LYCloseTracelog(); #endif }
PUBLIC int LYNewsPost ARGS1(document *,newdoc) { char *newsgroups = strchr(newdoc->address,':')+1; char user_input[1024]; FILE *fd; char *tmptr; char c; /* user input */ char tmpfile[100]; char cmd[130]; DocAddress WWWDoc; term_message=FALSE; /* pop previous document off of stack and load into main memory */ pop(newdoc); WWWDoc.address = newdoc->address; WWWDoc.post_data = newdoc->post_data; WWWDoc.post_content_type = newdoc->post_content_type; if(!HTLoadAbsolute(&WWWDoc)) return(NOT_FOUND); clear(); move(2,0); tempname(tmpfile,NEW_FILE); if((fd = fopen(tmpfile,"w")) == NULL) { statusline("Unable to open temp file"); sleep(2); return(NORMAL); } addstr("You will be posting to:"); addstr("\n "); addstr(newsgroups); addch('\n'); /* Use ^C to cancel mailing of comment */ /* and don't let sigints exit lynx */ signal(SIGINT, terminate_message); term_message=FALSE; addstr("\n\n Please enter your mail address\n"); strcpy(user_input,"From: "); /* add the mail address if there is one */ if(personal_mail_address) strcat(user_input,personal_mail_address); if (LYgetstr(user_input, VISIBLE) < 0 || term_message) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } fprintf(fd,"%s\n",user_input); addstr("\n\n Please enter a subject line\n"); strcpy(user_input,"Subject: "); /* add the default subject */ tmptr = newdoc->title; while(isspace(*tmptr)) tmptr++; if(strncasecomp(tmptr, "Re:",3)) strcat(user_input, "Re: "); strcat(user_input, newdoc->title); if (LYgetstr(user_input, VISIBLE) < 0 || term_message) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } fprintf(fd,"%s\n",user_input); /* add Newsgroups: summary: and Keywords: */ fprintf(fd,"Newsgroups: %s\nSummary: \nKeywords: \n\n",newsgroups); if(!no_editor && editor && *editor != '\0') { /* ask if the user wants to include the original message */ statusline("Do you wish to inlude the original message? (y/n) "); c=0; while((c = toupper(LYgetch())) != 'Y' && c != 'N') ; /* null body */ if(toupper(c) == 'Y') /* the 1 will add the reply ">" in front of every line */ print_wwwfile_to_fd(fd,1); fclose(fd); /* spawn the users editor on the news file */ sprintf(user_input,"%s %s",editor,tmpfile); statusline("Spawning your selected editor to edit mail message"); stop_curses(); if(system(user_input)) { statusline("Error spawning editor, check your editor definition in the options menu"); sleep(1); } start_curses(); } else { addstr("\n\n Please enter your message below."); addstr("\n When you are done, press enter and put a single period (.)"); addstr("\n on a line and press enter again."); addstr("\n\n"); scrollok(stdscr,TRUE); refresh(); *user_input = '\0'; if (LYgetstr(user_input, VISIBLE) < 0 || term_message) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } while(!STREQ(user_input,".") && !term_message) { addch('\n'); fprintf(fd,"%s\n",user_input); *user_input = '\0'; if (LYgetstr(user_input, VISIBLE) < 0) { statusline("News Post Cancelled!!!"); sleep(1); fclose(fd); /* close the temp file */ goto cleanup; } } fprintf(fd,"\n"); fclose(fd); /* close the temp file */ scrollok(stdscr,FALSE); /* stop scrolling */ } statusline("Post this message? (y/n) "); while((c = toupper(LYgetch())) != 'Y' && c != 'N') ; /* null body */ clear(); /* clear the screen */ if(c == 'N') { goto cleanup; } sprintf(cmd,"%s %s",INEWS,tmpfile); stop_curses(); printf("Posting your message:\n\n%s\n\nPlease wait...", cmd); #ifndef VMS signal(SIGINT, SIG_IGN); #endif /* not VMS */ system(cmd); start_curses(); #ifdef VMS goto cleandown; #endif /* VMS */ /* come here to cleanup and exit */ cleanup: signal(SIGINT, cleanup_sig); cleandown: term_message = FALSE; scrollok(stdscr,FALSE); /* stop scrolling */ remove(tmpfile); return(NORMAL); }
void HTFWriter_free( HTStream *me ) { int len; char *path = 0; char *addr = 0; int status; BOOLEAN use_zread = 0; BOOLEAN found = 0; if ( me->fp ) fflush( &me->fp ); if ( me->end_command ) { LYCloseTempFP( &me->fp ); if ( me->input_format == HTAtom_for( "www/compressed" ) ) { if ( me->anchor->FileCache ) { BOOLEAN skip_loadfile = me->viewer_command != 0; HTSACopy( &path, &me->anchor->FileCache ); len = strlen( path ); if ( len > 3 && ( strcasecomp( &path[ len + -2 ], "gz" ) == 0 || strcasecomp( &path[ len + -2 ], "zz" ) == 0 ) ) { if ( skip_loadfile == 0 ) use_zread = 1; else { path[ len + -3 ] = 0; remove( path ); } } else if ( len > 4 && strcasecomp( &path[ len + -3 ], "bz2" ) == 0 ) { path[ len + -4 ] = 0; remove( path ); } else if ( len > 2 && strcasecomp( &path[ len + -1 ], "Z" ) == 0 ) { path[ len + -2 ] = 0; remove( path ); } if ( use_zread == 0 ) { if ( dump_output_immediately == 0 ) { mustshow = 1; HTProgress( &me->end_command ); } if ( me->end_command && me->end_command[0] ) LYSystem( &me->end_command ); found = LYCanReadFile( &me->anchor->FileCache ); } if ( found ) { if ( dump_output_immediately == 0 ) { lynx_force_repaint( ); LYrefresh( ); } HTAlert( gettext( "Error uncompressing temporary file!" ) ); LYRemoveTemp( &me->anchor->FileCache ); if ( me->anchor->FileCache ) { free( &me->anchor->FileCache ); me->anchor->FileCache = 0; } } else { LYLocalFileToURL( &addr, path ); if ( use_zread == 0 ) { LYRenamedTemp( &me->anchor->FileCache, path ); HTSACopy( &me->anchor->FileCache, path ); HTSACopy( &me->anchor->content_encoding, "binary" ); } if ( path ) { free( path ); path = 0; } if ( skip_loadfile == 0 ) { if ( HTAnchor_getUCLYhndl( &me->anchor, 1 ) < 0 ) HTAnchor_copyUCInfoStage( &me->anchor, 1, 0, 2 ); HTAnchor_copyUCInfoStage( &me->anchor, 1, 0, -1 ); } if ( dump_output_immediately == 0 ) { LYstore_message2( gettext( "Using %s" ), addr ); } if ( skip_loadfile ) { if ( me->end_command ) { free( &me->end_command ); *(int*)&me->end_command = 0; } HTAddParam( &me->end_command, &me->viewer_command, 1, &me->anchor->FileCache ); HTEndParam( &me->end_command, &me->viewer_command, 1 ); if ( dump_output_immediately == 0 ) { HTProgress( &me->end_command ); stop_curses( ); } LYSystem( &me->end_command ); if ( me->remove_command && me->remove_command ) { free( &me->remove_command ); *(int*)&me->remove_command = 0; } if ( dump_output_immediately == 0 ) start_curses( ); } else { status = HTLoadFile( addr, &me->anchor, &me->output_format, &me->sink ); } if ( dump_output_immediately && me->output_format == HTAtom_for( "www/present" ) ) { if ( addr ) { free( addr ); addr = 0; } remove( &me->anchor->FileCache ); if ( me->anchor->FileCache ) { free( &me->anchor->FileCache ); me->anchor->FileCache = 0; } if ( me->remove_command ) { free( &me->remove_command ); *(int*)&me->remove_command = 0; } if ( me->end_command ) { free( &me->end_command ); *(int*)&me->end_command = 0; } if ( me->viewer_command ) { free( &me->viewer_command ); *(int*)&me->viewer_command = 0; } if ( me == 0 ) { return; } free( me ); me = 0; return; } } if ( addr ) { free( addr ); addr = 0; } } if ( me->remove_command && me->remove_command ) { free( &me->remove_command ); *(int*)&me->remove_command = 0; } } else { if ( strcmp( &me->end_command, "SaveToFile" ) ) { if ( dump_output_immediately == 0 ) { mustshow = 1; HTProgress( &me->end_command ); stop_curses( ); } LYSystem( &me->end_command ); if ( me->remove_command && me->remove_command ) { free( &me->remove_command ); *(int*)&me->remove_command = 0; } if ( dump_output_immediately == 0 ) start_curses( ); } else { if ( me->remove_command && me->remove_command ) { free( &me->remove_command ); *(int*)&me->remove_command = 0; } if ( dump_output_immediately == 0 ) start_curses( ); } } if ( me->end_command ) { free( &me->end_command ); *(int*)&me->end_command = 0; } } if ( me->viewer_command ) { free( &me->viewer_command ); *(int*)&me->viewer_command = 0; } if ( dump_output_immediately ) { if ( me->anchor->FileCache ) remove( &me->anchor->FileCache ); if ( me ) { free( me ); me = 0; } if ( persistent_cookies ) LYStoreCookies( LYCookieSaveFile ); exit_immediately( 0 ); } if ( me == 0 ) { return; } free( me ); me = 0; return; }
static void send_file_to_screen(DocInfo *newdoc, char *content_base, int Lpansi) { FILE *outfile_fp; bstring *prompt = NULL; if (Lpansi) { _statusline(CHECK_PRINTER); } else { _statusline(PRESS_RETURN_TO_BEGIN); } BStrCopy0(prompt, ""); if (LYgetBString(&prompt, FALSE, 0, NORECALL) < 0) { CancelPrint(PRINT_REQUEST_CANCELLED); } else { outfile_fp = stdout; stop_curses(); SetOutputMode(O_TEXT); #ifndef VMS signal(SIGINT, SIG_IGN); #endif /* !VMS */ if (LYPrependBaseToSource && HTisDocumentSource()) { /* * Added the document's base as a BASE tag to the top of the file. May * create technically invalid HTML, but will help get any partial or * relative URLs resolved properly if no BASE tag is present to replace * it. - FM */ fprintf(outfile_fp, "<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n", newdoc->address, content_base); } if (Lpansi) printf("\033[5i"); print_wwwfile_to_fd(outfile_fp, FALSE, FALSE); /* SCREEN */ if (keypad_mode) printlist(outfile_fp, FALSE); #ifdef VMS if (HadVMSInterrupt) { HadVMSInterrupt = FALSE; start_curses(); CancelPrint(PRINT_REQUEST_CANCELLED); } #endif /* VMS */ if (Lpansi) { printf("\n\014"); /* Form feed */ printf("\033[4i"); fflush(stdout); /* refresh to screen */ } else { fprintf(stdout, "\n\n%s", PRESS_RETURN_TO_FINISH); fflush(stdout); /* refresh to screen */ (void) LYgetch(); /* grab some user input to pause */ #ifdef VMS HadVMSInterrupt = FALSE; #endif /* VMS */ } #ifdef SH_EX fprintf(stdout, "\n"); #endif SetOutputMode(O_BINARY); start_curses(); } done: /* send_file_to_screen() */ BStrFree(prompt); return; }
static void send_file_to_printer(DocInfo *newdoc, char *content_base, char *sug_filename, int printer_number) { BOOLEAN FirstRecall = TRUE; FILE *outfile_fp; char *the_command = 0; bstring *my_file = NULL; char my_temp[LY_MAXPATH]; int FnameTotal, FnameNum = -1; lynx_list_item_type *cur_printer; outfile_fp = LYOpenTemp(my_temp, (HTisDocumentSource()) ? HTML_SUFFIX : TEXT_SUFFIX, "w"); if (outfile_fp == NULL) { CannotPrint(FILE_ALLOC_FAILED); } if (LYPrependBaseToSource && HTisDocumentSource()) { /* * Added the document's base as a BASE tag to the top of the file. May * create technically invalid HTML, but will help get any partial or * relative URLs resolved properly if no BASE tag is present to replace * it. - FM */ fprintf(outfile_fp, "<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n", newdoc->address, content_base); } print_wwwfile_to_fd(outfile_fp, FALSE, FALSE); /* PRINTER */ if (keypad_mode) printlist(outfile_fp, FALSE); LYCloseTempFP(outfile_fp); /* find the right printer number */ { int count = 0; for (cur_printer = printers; count < printer_number; count++, cur_printer = cur_printer->next) ; /* null body */ } /* * Commands have the form "command %s [%s] [etc]" where %s is the filename * and the second optional %s is the suggested filename. */ if (cur_printer->command == NULL) { CannotPrint(PRINTER_MISCONF_ERROR); } /* * Check for two '%s' and ask for the second filename argument if there * is. */ BStrCopy0(my_file, ""); if (HTCountCommandArgs(cur_printer->command) >= 2) { _statusline(FILENAME_PROMPT); again: SetupFilename(&my_file, sug_filename); check_again: switch (RecallFilename(&my_file, &FirstRecall, &FnameNum, &FnameTotal, PRINT_FLAG)) { case FN_INIT: goto again; case FN_READ: goto check_again; case FN_QUIT: goto done; default: break; } if (no_dotfiles || !show_dotfiles) { if (*LYPathLeaf(my_file->str) == '.') { HTAlert(FILENAME_CANNOT_BE_DOT); _statusline(NEW_FILENAME_PROMPT); FirstRecall = TRUE; FnameNum = FnameTotal; goto again; } } /* * Cancel if the user entered "/dev/null" on Unix, or an "nl:" path * on VMS. - FM */ if (LYIsNullDevice(my_file->str)) { CancelPrint(PRINT_REQUEST_CANCELLED); } HTAddSugFilename(my_file->str); } #ifdef SH_EX /* 1999/01/04 (Mon) 09:37:03 */ HTAddParam(&the_command, cur_printer->command, 1, my_temp); if (!isBEmpty(my_file)) { HTAddParam(&the_command, cur_printer->command, 2, my_file->str); HTEndParam(&the_command, cur_printer->command, 3); } else { HTEndParam(&the_command, cur_printer->command, 2); } #else HTAddParam(&the_command, cur_printer->command, 1, my_temp); HTAddParam(&the_command, cur_printer->command, 2, my_file->str); HTEndParam(&the_command, cur_printer->command, 2); #endif /* * Move the cursor to the top of the screen so that output from system'd * commands don't scroll up the screen. */ LYmove(1, 1); stop_curses(); CTRACE((tfp, "command: %s\n", the_command)); SetOutputMode(O_TEXT); printf(PRINTING_FILE); /* * Set various bits of document information as environment variables, for * use by external print scripts/etc. On UNIX, We assume there are values, * and leave NULL value checking up to the external PRINTER: cmd/script - * KED */ SET_ENVIRON(LYNX_PRINT_TITLE, HText_getTitle(), "No Title"); SET_ENVIRON(LYNX_PRINT_URL, newdoc->address, "No URL"); SET_ENVIRON(LYNX_PRINT_DATE, HText_getDate(), "No Date"); SET_ENVIRON(LYNX_PRINT_LASTMOD, HText_getLastModified(), "No LastMod"); LYSystem(the_command); FREE(the_command); (void) LYRemoveTemp(my_temp); /* * Remove the various LYNX_PRINT_xxxx logicals. - KED * [could use unsetenv(), but it's not portable] */ SET_ENVIRON(LYNX_PRINT_TITLE, "", ""); SET_ENVIRON(LYNX_PRINT_URL, "", ""); SET_ENVIRON(LYNX_PRINT_DATE, "", ""); SET_ENVIRON(LYNX_PRINT_LASTMOD, "", ""); fflush(stdout); #ifndef VMS signal(SIGINT, cleanup_sig); #endif /* !VMS */ #ifdef SH_EX fprintf(stdout, gettext(" Print job complete.\n")); fflush(stdout); #endif SetOutputMode(O_BINARY); LYSleepMsg(); start_curses(); done: /* send_file_to_printer() */ BStrFree(my_file); return; }
static void send_file_to_mail(DocInfo *newdoc, char *content_base, char *content_location) { static BOOLEAN first_mail_preparsed = TRUE; #if USE_VMS_MAILER BOOLEAN isPMDF = LYMailPMDF(); FILE *hfd; char hdrfile[LY_MAXPATH]; #endif BOOL use_mime; #if !CAN_PIPE_TO_MAILER char my_temp[LY_MAXPATH]; #endif BOOL use_cte; BOOL use_type; const char *disp_charset; FILE *outfile_fp; char *buffer = NULL; char *subject = NULL; bstring *user_response = NULL; if (!LYSystemMail()) return; if (LYPreparsedSource && first_mail_preparsed && HTisDocumentSource()) { if (HTConfirmDefault(CONFIRM_MAIL_SOURCE_PREPARSED, NO) == YES) { LYaddstr(" Ok..."); first_mail_preparsed = FALSE; } else { CancelPrint(MAIL_REQUEST_CANCELLED); } } _statusline(MAIL_ADDRESS_PROMPT); BStrCopy0(user_response, NonNull(personal_mail_address)); if (LYgetBString(&user_response, FALSE, 0, RECALL_MAIL) < 0 || isBEmpty(user_response)) { CancelPrint(MAIL_REQUEST_CANCELLED); } /* * Determine which mail headers should be sent. Use Content-Type and * MIME-Version headers only if needed. We need them if we are mailing * HTML source, or if we have 8-bit characters and will be sending * Content-Transfer-Encoding to indicate this. We will append a charset * parameter to the Content-Type if we do not have an "x-" charset, and we * will include the Content-Transfer-Encoding only if we are appending the * charset parameter, because indicating an 8-bit transfer without also * indicating the charset can cause problems with many mailers. - FM & KW */ disp_charset = LYCharSet_UC[current_char_set].MIMEname; use_cte = HTLoadedDocumentEightbit(); if (!(use_cte && strncasecomp(disp_charset, "x-", 2))) { disp_charset = NULL; #if USE_VMS_MAILER use_cte = FALSE; #endif } #if USE_VMS_MAILER use_type = (BOOL) (disp_charset || HTisDocumentSource()); #endif /* * Use newdoc->title as a subject instead of sug_filename: MORE readable * and 8-bit letters shouldn't be a problem - LP */ /* change_sug_filename(sug_filename); */ subject = subject_translate8bit(newdoc->title); if (newdoc->isHEAD) { /* * Special case for mailing HEAD responce: this is rather technical * information, show URL. */ FREE(subject); StrAllocCopy(subject, "HEAD "); StrAllocCat(subject, newdoc->address); } #if USE_VMS_MAILER if (StrChr(user_response->str, '@') && !StrChr(user_response->str, ':') && !StrChr(user_response->str, '%') && !StrChr(user_response->str, '"')) { char *temp = 0; HTSprintf0(&temp, mail_adrs, user_response->str); BStrCopy0(user_response, temp); FREE(temp); } outfile_fp = LYOpenTemp(my_temp, (HTisDocumentSource()) ? HTML_SUFFIX : TEXT_SUFFIX, "w"); if (outfile_fp == NULL) { CannotPrint(UNABLE_TO_OPEN_TEMPFILE); } if (isPMDF) { if ((hfd = LYOpenTemp(hdrfile, TEXT_SUFFIX, "w")) == NULL) { CannotPrint(UNABLE_TO_OPEN_TEMPFILE); } if (use_type) { fprintf(hfd, "Mime-Version: 1.0\n"); if (use_cte) { fprintf(hfd, "Content-Transfer-Encoding: 8bit\n"); } } if (HTisDocumentSource()) { /* * Add Content-Type, Content-Location, and Content-Base headers for * HTML source. - FM */ fprintf(hfd, "Content-Type: text/html"); if (disp_charset != NULL) { fprintf(hfd, "; charset=%s\n", disp_charset); } else { fprintf(hfd, "\n"); } fprintf(hfd, "Content-Base: %s\n", content_base); fprintf(hfd, "Content-Location: %s\n", content_location); } else { /* * Add Content-Type: text/plain if we have 8-bit characters and a * valid charset for non-source documents. - FM */ if (disp_charset != NULL) { fprintf(hfd, "Content-Type: text/plain; charset=%s\n", disp_charset); } } /* * X-URL header. - FM */ fprintf(hfd, "X-URL: %s\n", newdoc->address); /* * For PMDF, put the subject in the header file and close it. - FM */ fprintf(hfd, "Subject: %.70s\n\n", subject); LYCloseTempFP(hfd); } /* * Write the contents to a temp file. */ if (LYPrependBaseToSource && HTisDocumentSource()) { /* * Added the document's base as a BASE tag to the top of the message * body. May create technically invalid HTML, but will help get any * partial or relative URLs resolved properly if no BASE tag is present * to replace it. - FM */ fprintf(outfile_fp, "<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n", newdoc->address, content_base); } else if (!isPMDF) { fprintf(outfile_fp, "X-URL: %s\n\n", newdoc->address); } print_wwwfile_to_fd(outfile_fp, TRUE, FALSE); /* MAIL */ if (keypad_mode) printlist(outfile_fp, FALSE); LYCloseTempFP(outfile_fp); buffer = NULL; if (isPMDF) { /* * Now set up the command. - FM */ HTSprintf0(&buffer, "%s %s %s,%s %s", system_mail, system_mail_flags, hdrfile, my_temp, user_response->str); } else { /* * For "generic" VMS MAIL, include the subject in the command. - FM */ remove_quotes(subject); HTSprintf0(&buffer, "%s %s/subject=\"%.70s\" %s %s", system_mail, system_mail_flags, subject, my_temp, user_response->str); } stop_curses(); SetOutputMode(O_TEXT); printf(MAILING_FILE); LYSystem(buffer); LYSleepAlert(); start_curses(); SetOutputMode(O_BINARY); if (isPMDF) (void) LYRemoveTemp(hdrfile); (void) LYRemoveTemp(my_temp); #else /* !VMS (Unix or DOS) */ #if CAN_PIPE_TO_MAILER outfile_fp = LYPipeToMailer(); #else outfile_fp = LYOpenTemp(my_temp, TEXT_SUFFIX, "w"); #endif if (outfile_fp == NULL) { CannotPrint(MAIL_REQUEST_FAILED); } /* * Determine which mail headers should be sent. Use Content-Type and * MIME-Version headers only if needed. We need them if we are mailing * HTML source, or if we have 8-bit characters and will be sending * Content-Transfer-Encoding to indicate this. * * Send Content-Transfer-Encoding only if the document has 8-bit * characters. Send a charset parameter only if the document has 8-bit * characters and we seem to have a valid charset. - kw */ use_cte = HTLoadedDocumentEightbit(); disp_charset = LYCharSet_UC[current_char_set].MIMEname; /* * 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. - kw */ if (!use_cte || LYHaveCJKCharacterSet || strncasecomp(disp_charset, "x-", 2) == 0) { disp_charset = NULL; } #ifdef NOTDEFINED /* Enable this if indicating an 8-bit transfer without also indicating the * charset causes problems. - kw */ if (use_cte && !disp_charset) use_cte = FALSE; #endif /* NOTDEFINED */ use_type = (BOOL) (disp_charset || HTisDocumentSource()); use_mime = (BOOL) (use_cte || use_type); if (use_mime) { fprintf(outfile_fp, "Mime-Version: 1.0\n"); if (use_cte) { fprintf(outfile_fp, "Content-Transfer-Encoding: 8bit\n"); } } if (HTisDocumentSource()) { /* * Add Content-Type, Content-Location, and Content-Base headers for * HTML source. - FM */ fprintf(outfile_fp, "Content-Type: text/html"); if (disp_charset != NULL) { fprintf(outfile_fp, "; charset=%s\n", disp_charset); } else { fprintf(outfile_fp, "\n"); } } else { /* * Add Content-Type: text/plain if we have 8-bit characters and a * valid charset for non-source documents. - KW */ if (disp_charset != NULL) { fprintf(outfile_fp, "Content-Type: text/plain; charset=%s\n", disp_charset); } } /* * If we are using MIME headers, add content-base and content-location if * we have them. This will always be the case if the document is source. * - kw */ if (use_mime) { if (content_base) fprintf(outfile_fp, "Content-Base: %s\n", content_base); if (content_location) fprintf(outfile_fp, "Content-Location: %s\n", content_location); } /* * Add the To, Subject, and X-URL headers. - FM */ fprintf(outfile_fp, "To: %s\nSubject: %s\n", user_response->str, subject); fprintf(outfile_fp, "X-URL: %s\n\n", newdoc->address); if (LYPrependBaseToSource && HTisDocumentSource()) { /* * Added the document's base as a BASE tag to the top of the message * body. May create technically invalid HTML, but will help get any * partial or relative URLs resolved properly if no BASE tag is present * to replace it. - FM */ fprintf(outfile_fp, "<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n", newdoc->address, content_base); } print_wwwfile_to_fd(outfile_fp, TRUE, FALSE); /* MAIL */ if (keypad_mode) printlist(outfile_fp, FALSE); #if CAN_PIPE_TO_MAILER pclose(outfile_fp); #else LYCloseOutput(outfile_fp); LYSendMailFile(user_response->str, my_temp, subject, "", ""); (void) LYRemoveTemp(my_temp); /* Delete the tmpfile. */ #endif /* CAN_PIPE_TO_MAILER */ #endif /* USE_VMS_MAILER */ done: /* send_file_to_mail() */ BStrFree(user_response); FREE(buffer); FREE(subject); return; }