/** * icmd_version - Parse 'version' command - Implements ::icommand_t */ static enum CommandResult icmd_version(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { char tempfile[PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); FILE *fp_out = mutt_file_fopen(tempfile, "w"); if (!fp_out) { mutt_buffer_addstr(err, _("Could not create temporary file")); return MUTT_CMD_ERROR; } print_version(fp_out); mutt_file_fclose(&fp_out); struct Pager info = { 0 }; if (mutt_pager("version", tempfile, 0, &info) == -1) { mutt_buffer_addstr(err, _("Could not create temporary file")); return MUTT_CMD_ERROR; } return MUTT_CMD_SUCCESS; }
/** * mutt_do_pager - Display some page-able text to the user * @param banner Message for status bar * @param tempfile File to display * @param do_color Flags, see #PagerFlags * @param info Info about current mailbox (OPTIONAL) * @retval 0 Success * @retval -1 Error */ int mutt_do_pager(const char *banner, const char *tempfile, PagerFlags do_color, struct Pager *info) { int rc; if (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0)) rc = mutt_pager(banner, tempfile, do_color, info); else { char cmd[256]; mutt_endwin(); mutt_file_expand_fmt_quote(cmd, sizeof(cmd), C_Pager, tempfile); if (mutt_system(cmd) == -1) { mutt_error(_("Error running \"%s\""), cmd); rc = -1; } else rc = 0; mutt_file_unlink(tempfile); } return rc; }
int mutt_do_pager (const char *banner, const char *tempfile, int do_color, pager_t *info) { int rc; if (!Pager || mutt_strcmp (Pager, "builtin") == 0) rc = mutt_pager (banner, tempfile, do_color, info); else { char cmd[STRING]; endwin (); mutt_expand_file_fmt (cmd, sizeof(cmd), Pager, tempfile); if (mutt_system (cmd) == -1) { mutt_error (_("Error running \"%s\"!"), cmd); rc = -1; } else rc = 0; mutt_unlink (tempfile); } return rc; }
/** * icmd_set - Parse 'set' command to display config - Implements ::icommand_t */ static enum CommandResult icmd_set(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { char tempfile[PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); FILE *fp_out = mutt_file_fopen(tempfile, "w"); if (!fp_out) { mutt_buffer_addstr(err, _("Could not create temporary file")); return MUTT_CMD_ERROR; } if (mutt_str_strcmp(s->data, "set all") == 0) { dump_config(Config, CS_DUMP_STYLE_NEO, 0, fp_out); } else if (mutt_str_strcmp(s->data, "set") == 0) { dump_config(Config, CS_DUMP_STYLE_NEO, CS_DUMP_ONLY_CHANGED, fp_out); } else { mutt_file_fclose(&fp_out); return MUTT_CMD_ERROR; } mutt_file_fclose(&fp_out); struct Pager info = { 0 }; if (mutt_pager("set", tempfile, 0, &info) == -1) { mutt_buffer_addstr(err, _("Could not create temporary file")); return MUTT_CMD_ERROR; } return MUTT_CMD_SUCCESS; }
/** * icmd_bind - Parse 'bind' and 'macro' commands - Implements ::icommand_t */ static enum CommandResult icmd_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { FILE *fp_out = NULL; char tempfile[PATH_MAX]; bool dump_all = false, bind = (data == 0); if (!MoreArgs(s)) dump_all = true; else mutt_extract_token(buf, s, 0); if (MoreArgs(s)) { /* More arguments potentially means the user is using the * ::command_t :bind command thus we delegate the task. */ return MUTT_CMD_ERROR; } struct Buffer *filebuf = mutt_buffer_alloc(4096); if (dump_all || (mutt_str_strcasecmp(buf->data, "all") == 0)) { dump_all_menus(filebuf, bind); } else { const int menu_index = mutt_map_get_value(buf->data, Menus); if (menu_index == -1) { mutt_buffer_printf(err, _("%s: no such menu"), buf->data); mutt_buffer_free(&filebuf); return MUTT_CMD_ERROR; } struct Mapping menu = { buf->data, menu_index }; dump_menu(filebuf, &menu, bind); } if (mutt_buffer_is_empty(filebuf)) { mutt_buffer_printf(err, _("%s: no %s for this menu"), dump_all ? "all" : buf->data, bind ? "binds" : "macros"); mutt_buffer_free(&filebuf); return MUTT_CMD_ERROR; } mutt_mktemp(tempfile, sizeof(tempfile)); fp_out = mutt_file_fopen(tempfile, "w"); if (!fp_out) { mutt_buffer_printf(err, _("Could not create temporary file %s"), tempfile); mutt_buffer_free(&filebuf); return MUTT_CMD_ERROR; } fputs(filebuf->data, fp_out); mutt_file_fclose(&fp_out); mutt_buffer_free(&filebuf); struct Pager info = { 0 }; if (mutt_pager((bind) ? "bind" : "macro", tempfile, 0, &info) == -1) { mutt_buffer_printf(err, _("Could not create temporary file %s"), tempfile); return MUTT_CMD_ERROR; } return MUTT_CMD_SUCCESS; }
int mutt_display_message (HEADER *cur) { char tempfile[_POSIX_PATH_MAX], buf[LONG_STRING]; int rc = 0, builtin = 0; int cmflags = M_CM_DECODE | M_CM_DISPLAY | M_CM_CHARCONV; FILE *fpout = NULL; FILE *fpfilterout = NULL; pid_t filterpid = -1; int res; snprintf (buf, sizeof (buf), "%s/%s", TYPE (cur->content), cur->content->subtype); mutt_parse_mime_message (Context, cur); mutt_message_hook (Context, cur, M_MESSAGEHOOK); /* see if crypto is needed for this message. if so, we should exit curses */ if (WithCrypto && cur->security) { if (cur->security & ENCRYPT) { if (cur->security & APPLICATION_SMIME) crypt_smime_getkeys (cur->env); if(!crypt_valid_passphrase(cur->security)) return 0; cmflags |= M_CM_VERIFY; } else if (cur->security & SIGN) { /* find out whether or not the verify signature */ if (query_quadoption (OPT_VERIFYSIG, _("Verify PGP signature?")) == M_YES) { cmflags |= M_CM_VERIFY; } } } if (cmflags & M_CM_VERIFY || cur->security & ENCRYPT) { if (cur->security & APPLICATION_PGP) { if (cur->env->from) crypt_pgp_invoke_getkeys (cur->env->from); crypt_invoke_message (APPLICATION_PGP); } if (cur->security & APPLICATION_SMIME) crypt_invoke_message (APPLICATION_SMIME); } mutt_mktemp (tempfile, sizeof (tempfile)); if ((fpout = safe_fopen (tempfile, "w")) == NULL) { mutt_error _("Could not create temporary file!"); return (0); } if (DisplayFilter && *DisplayFilter) { fpfilterout = fpout; fpout = NULL; /* mutt_endwin (NULL); */ filterpid = mutt_create_filter_fd (DisplayFilter, &fpout, NULL, NULL, -1, fileno(fpfilterout), -1); if (filterpid < 0) { mutt_error (_("Cannot create display filter")); safe_fclose (&fpfilterout); unlink (tempfile); return 0; } } if (!Pager || mutt_strcmp (Pager, "builtin") == 0) builtin = 1; else { struct hdr_format_info hfi; hfi.ctx = Context; hfi.pager_progress = ExtPagerProgress; hfi.hdr = cur; mutt_make_string_info (buf, sizeof (buf), NONULL(PagerFmt), &hfi, M_FORMAT_MAKEPRINT); fputs (buf, fpout); fputs ("\n\n", fpout); } res = mutt_copy_message (fpout, Context, cur, cmflags, (option (OPTWEED) ? (CH_WEED | CH_REORDER) : 0) | CH_DECODE | CH_FROM | CH_DISPLAY); if ((safe_fclose (&fpout) != 0 && errno != EPIPE) || res < 0) { mutt_error (_("Could not copy message")); if (fpfilterout != NULL) { mutt_wait_filter (filterpid); safe_fclose (&fpfilterout); } mutt_unlink (tempfile); return 0; } if (fpfilterout != NULL && mutt_wait_filter (filterpid) != 0) mutt_any_key_to_continue (NULL); safe_fclose (&fpfilterout); /* XXX - check result? */ if (WithCrypto) { /* update crypto information for this message */ cur->security &= ~(GOODSIGN|BADSIGN); cur->security |= crypt_query (cur->content); /* Remove color cache for this message, in case there are color patterns for both ~g and ~V */ cur->pair = 0; } if (builtin) { pager_t info; if (WithCrypto && (cur->security & APPLICATION_SMIME) && (cmflags & M_CM_VERIFY)) { if (cur->security & GOODSIGN) { if (!crypt_smime_verify_sender(cur)) mutt_message ( _("S/MIME signature successfully verified.")); else mutt_error ( _("S/MIME certificate owner does not match sender.")); } else if (cur->security & PARTSIGN) mutt_message (_("Warning: Part of this message has not been signed.")); else if (cur->security & SIGN || cur->security & BADSIGN) mutt_error ( _("S/MIME signature could NOT be verified.")); } if (WithCrypto && (cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) { if (cur->security & GOODSIGN) mutt_message (_("PGP signature successfully verified.")); else if (cur->security & PARTSIGN) mutt_message (_("Warning: Part of this message has not been signed.")); else if (cur->security & SIGN) mutt_message (_("PGP signature could NOT be verified.")); } /* Invoke the builtin pager */ memset (&info, 0, sizeof (pager_t)); info.hdr = cur; info.ctx = Context; rc = mutt_pager (NULL, tempfile, M_PAGER_MESSAGE, &info); } else { int r; mutt_endwin (NULL); snprintf (buf, sizeof (buf), "%s %s", NONULL(Pager), tempfile); if ((r = mutt_system (buf)) == -1) mutt_error (_("Error running \"%s\"!"), buf); unlink (tempfile); if (!option (OPTNOCURSES)) keypad (stdscr, TRUE); if (r != -1) mutt_set_flag (Context, cur, M_READ, 1); if (r != -1 && option (OPTPROMPTAFTER)) { mutt_unget_event (mutt_any_key_to_continue _("Command: "), 0); rc = km_dokey (MENU_PAGER); } else rc = 0; } return rc; }