Esempio n. 1
0
int mutt_select_sort (int reverse)
{
  int method = Sort; /* save the current method in case of abort */

  switch (mutt_multi_choice (reverse ?
			     _("Rev-Sort (d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: ") :
			     _("Sort (d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/(u)nsort/si(z)e/s(c)ore/s(p)am?: "),
			     _("dfrsotuzcp")))
  {
  case -1: /* abort - don't resort */
    return -1;

  case 1: /* (d)ate */
    Sort = SORT_DATE;
    break;

  case 2: /* (f)rm */
    Sort = SORT_FROM;
    break;
  
  case 3: /* (r)ecv */
    Sort = SORT_RECEIVED;
    break;
  
  case 4: /* (s)ubj */
    Sort = SORT_SUBJECT;
    break;
  
  case 5: /* t(o) */
    Sort = SORT_TO;
    break;
  
  case 6: /* (t)hread */
    Sort = SORT_THREADS;
    break;
  
  case 7: /* (u)nsort */
    Sort = SORT_ORDER;
    break;
  
  case 8: /* si(z)e */
    Sort = SORT_SIZE;
    break;
  
  case 9: /* s(c)ore */ 
    Sort = SORT_SCORE;
    break;

  case 10: /* s(p)am */
    Sort = SORT_SPAM;
    break;
  }
  if (reverse)
    Sort |= SORT_REVERSE;

  return (Sort != method ? 0 : -1); /* no need to resort if it's the same */
}
/* return 0 on success, -1 on error */
int mutt_check_overwrite (const char *attname, const char *path,
				char *fname, size_t flen, int *append) 
{
  char tmp[_POSIX_PATH_MAX];
  struct stat st;

  strfcpy (fname, path, flen);
  if (access (fname, F_OK) != 0)
    return 0;
  if (stat (fname, &st) != 0)
    return -1;
  if (S_ISDIR (st.st_mode))
  {
    if (mutt_yesorno (_("File is a directory, save under it?"), 1) != M_YES) 
      return (-1);
    if (!attname || !attname[0])
    {
      tmp[0] = 0;
      if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
				      M_FILE | M_CLEAR) != 0 || !tmp[0])
	return (-1);
      snprintf (fname, flen, "%s/%s", path, tmp);
    }
    else
      snprintf (fname, flen, "%s/%s", path, attname);
  }
  
  if (*append == 0 && access (fname, F_OK) == 0)
  {
    switch (mutt_multi_choice
	    (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
    {
      case -1: /* abort */
      case 3:  /* cancel */
	return -1;

      case 2: /* append */
        *append = M_SAVE_APPEND;
        break;
      case 1: /* overwrite */
        *append = M_SAVE_OVERWRITE;
        break;
    }
  }
  return 0;
}
static int pgp_send_menu (int bits, int *redraw)
{
  pgp_key_t *p;
  char input_signas[SHORT_STRING];
  char input_micalg[SHORT_STRING];

  switch (mutt_multi_choice (_("(e)ncrypt, (s)ign, sign (a)s, (b)oth, select (m)ic algorithm, or (f)orget it? "),
			     _("esabmf")))
  {
  case 1: /* (e)ncrypt */
    bits |= PGPENCRYPT;
    break;

  case 2: /* (s)ign */
    bits |= PGPSIGN;
    break;

  case 3: /* sign (a)s */

    unset_option(OPTPGPCHECKTRUST);

    if ((p = pgp_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, PGP_PUBRING)))
    {
      snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p));
      mutt_str_replace (&PgpSignAs, input_signas);
      mutt_str_replace (&PgpSignMicalg, pgp_pkalg_to_mic (p->algorithm));
      pgp_free_key (&p);
      
      bits |= PGPSIGN;
	
      pgp_void_passphrase ();	/* probably need a different passphrase */
    }
    else
    {
      bits &= ~PGPSIGN;
    }

    *redraw = REDRAW_FULL;
    break;

  case 4: /* (b)oth */
    bits = PGPENCRYPT | PGPSIGN;
    break;

  case 5: /* select (m)ic algorithm */
    if (!(bits & PGPSIGN))
      mutt_error _("This doesn't make sense if you don't want to sign the message.");
    else
    {
      /* Copy the existing MIC algorithm into place */
      strfcpy(input_micalg, NONULL (PgpSignMicalg), sizeof (input_micalg));

      if (mutt_get_field (_("MIC algorithm: "), input_micalg, sizeof (input_micalg), 0) == 0)
      {
	if (mutt_strcasecmp (input_micalg, "pgp-md5") && mutt_strcasecmp (input_micalg, "pgp-sha1")
	   && mutt_strcasecmp (input_micalg, "pgp-rmd160"))
	{
	  mutt_error _("Unknown MIC algorithm, valid ones are: pgp-md5, pgp-sha1, pgp-rmd160");
	}
	else 
	  mutt_str_replace (&PgpSignMicalg, input_micalg);
      }
    }
    break;

  case 6: /* (f)orget it */
    bits = 0;
    break;
  }
  if (!*redraw)
    redraw_pgp_lines (bits);
  return (bits);
}
Esempio n. 4
0
/* return 0 on success, -1 on abort, 1 on error */
int mutt_check_overwrite (const char *attname, const char *path,
                          char *fname, size_t flen, int *append,
                          char **directory)
{
  int rc = 0;
  char tmp[_POSIX_PATH_MAX];
  struct stat st;

  strfcpy (fname, path, flen);
  if (access (fname, F_OK) != 0)
    return 0;
  if (stat (fname, &st) != 0)
    return -1;
  if (S_ISDIR (st.st_mode)) {
    if (directory) {
      switch (mutt_multi_choice
              (_("File is a directory, save under it? [(y)es, (n)o, (a)ll]"),
               _("yna"))) {
      case 3:                  /* all */
        str_replace (directory, fname);
        break;
      case 1:                  /* yes */
        mem_free (directory);
        break;
      case -1:                 /* abort */
        mem_free (directory);
        return -1;
      case 2:                  /* no */
        mem_free (directory);
        return 1;
      }
    }
    else
      if ((rc =
           mutt_yesorno (_("File is a directory, save under it?"),
                         M_YES)) != M_YES)
      return (rc == M_NO) ? 1 : -1;

    if (!attname || !attname[0]) {
      tmp[0] = 0;
      if (mutt_get_field (_("File under directory: "), tmp, sizeof (tmp),
                          M_FILE | M_CLEAR) != 0 || !tmp[0])
        return (-1);
      mutt_concat_path (fname, path, tmp, flen);
    }
    else
      mutt_concat_path (fname, path, mutt_basename (attname), flen);
  }

  if (*append == 0 && access (fname, F_OK) == 0) {
    switch (mutt_multi_choice
            (_("File exists, (o)verwrite, (a)ppend, or (c)ancel?"), _("oac")))
    {
    case -1:                   /* abort */
      return -1;
    case 3:                    /* cancel */
      return 1;

    case 2:                    /* append */
      *append = M_SAVE_APPEND;
      break;
    case 1:                    /* overwrite */
      *append = M_SAVE_OVERWRITE;
      break;
    }
  }
  return 0;
}