예제 #1
0
static int menu_dialog_dokey (MUTTMENU * menu, int *ip)
{
  event_t ch;
  char *p;

  ch = mutt_getch ();

  if (ch.ch == -1) {
    *ip = -1;
    return 0;
  }

  if (ch.ch && (p = strchr (menu->keys, ch.ch))) {
    *ip = OP_MAX + (p - menu->keys + 1);
    return 0;
  }
  else {
    mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
    return -1;
  }
}
예제 #2
0
void menu_jump (MUTTMENU * menu)
{
  int n;
  char buf[SHORT_STRING];

  if (menu->max) {
    mutt_ungetch (LastKey, 0);
    buf[0] = 0;
    if (mutt_get_field (_("Jump to: "), buf, sizeof (buf), 0) == 0 && buf[0]) {
      n = atoi (buf) - 1;
      if (n >= 0 && n < menu->max) {
        menu->current = n;
        menu->redraw = REDRAW_MOTION;
      }
      else
        mutt_error _("Invalid index number.");
    }
  }
  else
    mutt_error _("No entries.");
}
int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy, int multiple, char ***files, int *numfiles)
{
  event_t ch;

  mvaddstr (LINES-1, 0, (char *) prompt);
  addstr (_(" ('?' for list): "));
  if (buf[0])
    addstr (buf);
  clrtoeol ();
  mutt_refresh ();

  ch = mutt_getch();
  if (ch.ch == -1)
  {
    CLEARLINE (LINES-1);
    return (-1);
  }
  else if (ch.ch == '?')
  {
    mutt_refresh ();
    buf[0] = 0;
    _mutt_select_file (buf, blen, 0, multiple, files, numfiles);
    *redraw = REDRAW_FULL;
  }
  else
  {
    char *pc = safe_malloc (mutt_strlen (prompt) + 3);

    sprintf (pc, "%s: ", prompt);
    mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
    if (_mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files, numfiles)
	!= 0)
      buf[0] = 0;
    MAYBE_REDRAW (*redraw);
    FREE (&pc);
  }

  return 0;
}
event_t mutt_getch (void)
{
  int ch;
  event_t err = {-1, OP_NULL }, ret;

  if (UngetCount)
    return (KeyEvent[--UngetCount]);

  SigInt = 0;

#ifdef KEY_RESIZE
  /* ncurses 4.2 sends this when the screen is resized */
  ch = KEY_RESIZE;
  while (ch == KEY_RESIZE)
#endif /* KEY_RESIZE */
    ch = getch ();

  if (SigInt)
    mutt_query_exit ();

  if(ch == ERR)
    return err;
  
  if ((ch & 0x80) && option (OPTMETAKEY))
  {
    /* send ALT-x as ESC-x */
    ch &= ~0x80;
    mutt_ungetch (ch, 0);
    ret.ch = '\033';
    ret.op = 0;
    return ret;
  }

  ret.ch = ch;
  ret.op = 0;
  return (ch == ctrl ('G') ? err : ret);
}
예제 #5
0
파일: commands.c 프로젝트: tejux/mutt-hacks
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_ungetch (mutt_any_key_to_continue _("Command: "), 0);
                        rc = km_dokey (MENU_PAGER);
                }
                else
                        rc = 0;
        }

        return rc;
}