コード例 #1
0
ファイル: rfc3676.c プロジェクト: aschrab/mutt
static size_t print_indent (int ql, STATE *s, int add_suffix)
{
  int i;
  size_t wid = 0;

  if (s->prefix)
  {
    /* use given prefix only for format=fixed replies to format=flowed,
     * for format=flowed replies to format=flowed, use '>' indentation
     */
    if (option (OPTTEXTFLOWED))
      ql++;
    else
    {
      state_puts (s->prefix, s);
      wid = mutt_strwidth (s->prefix);
    }
  }
  for (i = 0; i < ql; i++)
  {
    state_putc ('>', s);
    if (space_quotes (s) )
      state_putc (' ', s);
  }
  if (add_suffix)
    state_putc (' ', s);

  if (space_quotes (s))
    ql *= 2;

  return ql + add_suffix + wid;
}
コード例 #2
0
ファイル: progress.c プロジェクト: darnir/neomutt
/**
 * message_bar - Draw a colourful progress bar
 * @param percent %age complete
 * @param fmt     printf(1)-like formatting string
 * @param ...     Arguments to formatting string
 */
static void message_bar(int percent, const char *fmt, ...)
{
  va_list ap;
  char buf[256], buf2[256];
  int w = percent * COLS / 100;
  size_t l;

  va_start(ap, fmt);
  vsnprintf(buf, sizeof(buf), fmt, ap);
  l = mutt_strwidth(buf);
  va_end(ap);

  mutt_simple_format(buf2, sizeof(buf2), 0, COLS - 2, FMT_LEFT, 0, buf, sizeof(buf), 0);

  move(LINES - 1, 0);

  if (ColorDefs[MT_COLOR_PROGRESS] == 0)
  {
    addstr(buf2);
  }
  else
  {
    if (l < w)
    {
      /* The string fits within the colour bar */
      SETCOLOR(MT_COLOR_PROGRESS);
      addstr(buf2);
      w -= l;
      while (w-- > 0)
      {
        addch(' ');
      }
      NORMAL_COLOR;
    }
    else
    {
      /* The string is too long for the colour bar */
      char ch;
      int off = mutt_wstr_trunc(buf2, sizeof(buf2), w, NULL);

      ch = buf2[off];
      buf2[off] = '\0';
      SETCOLOR(MT_COLOR_PROGRESS);
      addstr(buf2);
      buf2[off] = ch;
      NORMAL_COLOR;
      addstr(&buf2[off]);
    }
  }

  clrtoeol();
  mutt_refresh();
}
コード例 #3
0
ファイル: curs_lib.c プロジェクト: darnir/neomutt
/**
 * mutt_multi_choice - Offer the user a multiple choice question
 * @param prompt  Message prompt
 * @param letters Allowable selection keys
 * @retval >=0 0-based user selection
 * @retval  -1 Selection aborted
 */
int mutt_multi_choice(const char *prompt, const char *letters)
{
  struct Event ch;
  int choice;
  bool redraw = true;
  int prompt_lines = 1;
  char *p = NULL;

  while (true)
  {
    if (redraw || SigWinch)
    {
      redraw = false;
      if (SigWinch)
      {
        SigWinch = 0;
        mutt_resize_screen();
        clearok(stdscr, TRUE);
        mutt_menu_current_redraw();
      }
      if (MuttMessageWindow->cols)
      {
        prompt_lines = (mutt_strwidth(prompt) + MuttMessageWindow->cols - 1) /
                       MuttMessageWindow->cols;
        prompt_lines = MAX(1, MIN(3, prompt_lines));
      }
      if (prompt_lines != MuttMessageWindow->rows)
      {
        mutt_window_reflow_message_rows(prompt_lines);
        mutt_menu_current_redraw();
      }

      SETCOLOR(MT_COLOR_PROMPT);
      mutt_window_mvaddstr(MuttMessageWindow, 0, 0, prompt);
      NORMAL_COLOR;
      mutt_window_clrtoeol(MuttMessageWindow);
    }

    mutt_refresh();
    /* SigWinch is not processed unless timeout is set */
    mutt_getch_timeout(30 * 1000);
    ch = mutt_getch();
    mutt_getch_timeout(-1);
    if (ch.ch == -2)
      continue;
    /* (ch.ch == 0) is technically possible.  Treat the same as < 0 (abort) */
    if ((ch.ch <= 0) || CI_is_return(ch.ch))
    {
      choice = -1;
      break;
    }
    else
    {
      p = strchr(letters, ch.ch);
      if (p)
      {
        choice = p - letters + 1;
        break;
      }
      else if ((ch.ch <= '9') && (ch.ch > '0'))
      {
        choice = ch.ch - '0';
        if (choice <= mutt_str_strlen(letters))
          break;
      }
    }
    BEEP();
  }
  if (MuttMessageWindow->rows != 1)
  {
    mutt_window_reflow_message_rows(1);
    mutt_menu_current_redraw();
  }
  else
    mutt_window_clearline(MuttMessageWindow, 0);
  mutt_refresh();
  return choice;
}
コード例 #4
0
ファイル: curs_lib.c プロジェクト: darnir/neomutt
/**
 * mutt_yesorno - Ask the user a Yes/No question
 * @param msg Prompt
 * @param def Default answer, see #QuadOption
 * @retval num Selection made, see #QuadOption
 */
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
{
  struct Event ch;
  char *yes = _("yes");
  char *no = _("no");
  char *answer_string = NULL;
  int answer_string_wid, msg_wid;
  size_t trunc_msg_len;
  bool redraw = true;
  int prompt_lines = 1;

  char *expr = NULL;
  regex_t reyes;
  regex_t reno;
  char answer[2];

  answer[1] = '\0';

  bool reyes_ok = (expr = nl_langinfo(YESEXPR)) && (expr[0] == '^') &&
                  (REGCOMP(&reyes, expr, REG_NOSUB) == 0);
  bool reno_ok = (expr = nl_langinfo(NOEXPR)) && (expr[0] == '^') &&
                 (REGCOMP(&reno, expr, REG_NOSUB) == 0);

  /* In order to prevent the default answer to the question to wrapped
   * around the screen in the even the question is wider than the screen,
   * ensure there is enough room for the answer and truncate the question
   * to fit.  */
  safe_asprintf(&answer_string, " ([%s]/%s): ", (def == MUTT_YES) ? yes : no,
                (def == MUTT_YES) ? no : yes);
  answer_string_wid = mutt_strwidth(answer_string);
  msg_wid = mutt_strwidth(msg);

  while (true)
  {
    if (redraw || SigWinch)
    {
      redraw = false;
      if (SigWinch)
      {
        SigWinch = 0;
        mutt_resize_screen();
        clearok(stdscr, TRUE);
        mutt_menu_current_redraw();
      }
      if (MuttMessageWindow->cols)
      {
        prompt_lines = (msg_wid + answer_string_wid + MuttMessageWindow->cols - 1) /
                       MuttMessageWindow->cols;
        prompt_lines = MAX(1, MIN(3, prompt_lines));
      }
      if (prompt_lines != MuttMessageWindow->rows)
      {
        mutt_window_reflow_message_rows(prompt_lines);
        mutt_menu_current_redraw();
      }

      /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */
      trunc_msg_len = mutt_wstr_trunc(
          msg, 4 * prompt_lines * MuttMessageWindow->cols,
          prompt_lines * MuttMessageWindow->cols - answer_string_wid, NULL);

      mutt_window_move(MuttMessageWindow, 0, 0);
      SETCOLOR(MT_COLOR_PROMPT);
      addnstr(msg, trunc_msg_len);
      addstr(answer_string);
      NORMAL_COLOR;
      mutt_window_clrtoeol(MuttMessageWindow);
    }

    mutt_refresh();
    /* SigWinch is not processed unless timeout is set */
    mutt_getch_timeout(30 * 1000);
    ch = mutt_getch();
    mutt_getch_timeout(-1);
    if (ch.ch == -2)
      continue;
    if (CI_is_return(ch.ch))
      break;
    if (ch.ch < 0)
    {
      def = MUTT_ABORT;
      break;
    }

    answer[0] = ch.ch;
    if (reyes_ok ? (regexec(&reyes, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'y'))
    {
      def = MUTT_YES;
      break;
    }
    else if (reno_ok ? (regexec(&reno, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'n'))
    {
      def = MUTT_NO;
      break;
    }
    else
    {
      BEEP();
    }
  }

  FREE(&answer_string);

  if (reyes_ok)
    regfree(&reyes);
  if (reno_ok)
    regfree(&reno);

  if (MuttMessageWindow->rows != 1)
  {
    mutt_window_reflow_message_rows(1);
    mutt_menu_current_redraw();
  }
  else
    mutt_window_clearline(MuttMessageWindow, 0);

  if (def != MUTT_ABORT)
  {
    addstr((char *) ((def == MUTT_YES) ? yes : no));
    mutt_refresh();
  }
  else
  {
    /* when the users cancels with ^G, clear the message stored with
     * mutt_message() so it isn't displayed when the screen is refreshed. */
    mutt_clear_error();
  }
  return def;
}
コード例 #5
0
ファイル: rfc3676.c プロジェクト: aschrab/mutt
static void print_flowed_line (char *line, STATE *s, int ql,
			       flowed_state_t *fst, int term)
{
  size_t width, w, words = 0;
  char *p;
  char last;

  if (!line || !*line)
  {
    /* flush current paragraph (if any) first */
    flush_par (s, fst);
    print_indent (ql, s, 0);
    state_putc ('\n', s);
    return;
  }

  width = quote_width (s, ql);
  last = line[mutt_strlen (line) - 1];

  dprint (4, (debugfile, "f=f: line [%s], width = %ld, spaces = %d\n",
	      NONULL(line), (long)width, fst->spaces));

  for (p = (char *)line, words = 0; (p = strsep (&line, " ")) != NULL ; )
  {
    dprint(4,(debugfile,"f=f: word [%s], width: %d, remaining = [%s]\n",
	      p, fst->width, line));

    /* remember number of spaces */
    if (!*p)
    {
      dprint(4,(debugfile,"f=f: additional space\n"));
      fst->spaces++;
      continue;
    }
    /* there's exactly one space prior to every but the first word */
    if (words)
      fst->spaces++;

    w = mutt_strwidth (p);
    /* see if we need to break the line but make sure the first
       word is put on the line regardless;
       if for DelSp=yes only one trailing space is used, we probably
       have a long word that we should break within (we leave that
       up to the pager or user) */
    if (!(!fst->spaces && fst->delsp && last != ' ') &&
	w < width && w + fst->width + fst->spaces > width)
    {
      dprint(4,(debugfile,"f=f: break line at %d, %d spaces left\n",
		fst->width, fst->spaces));
      /* only honor trailing spaces for format=flowed replies */
      if (option(OPTTEXTFLOWED))
	for ( ; fst->spaces; fst->spaces--)
	  state_putc (' ', s);
      state_putc ('\n', s);
      fst->width = 0;
      fst->spaces = 0;
      words = 0;
    }

    if (!words && !fst->width)
      fst->width = print_indent (ql, s, add_quote_suffix (s, ql));
    fst->width += w + fst->spaces;
    for ( ; fst->spaces; fst->spaces--)
      state_putc (' ', s);
    state_puts (p, s);
    words++;
  }

  if (term)
    flush_par (s, fst);
}
コード例 #6
0
ファイル: commands.c プロジェクト: SteveClement/mutt
void ci_bounce_message (HEADER *h, int *redraw)
{
  char prompt[SHORT_STRING];
  char scratch[SHORT_STRING];
  char buf[HUGE_STRING] = { 0 };
  ADDRESS *adr = NULL;
  char *err = NULL;
  int rc;

 /* RfC 5322 mandates a From: header, so warn before bouncing
  * messages without one */
  if (h)
  {
    if (!h->env->from)
    {
      mutt_error _("Warning: message contains no From: header");
      mutt_sleep (2);
    }
  }
  else if (Context)
  {
    for (rc = 0; rc < Context->msgcount; rc++)
    {
      if (Context->hdrs[rc]->tagged && !Context->hdrs[rc]->env->from)
      {
	mutt_error _("Warning: message contains no From: header");
	mutt_sleep (2);
	break;
      }
    }
  }

  if(h)
    strfcpy(prompt, _("Bounce message to: "), sizeof(prompt));
  else
    strfcpy(prompt, _("Bounce tagged messages to: "), sizeof(prompt));
  
  rc = mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS);

  if (option (OPTNEEDREDRAW))
  {
    unset_option (OPTNEEDREDRAW);
    *redraw = REDRAW_FULL;
  }

  if (rc || !buf[0])
    return;

  if (!(adr = mutt_parse_adrlist (adr, buf)))
  {
    mutt_error _("Error parsing address!");
    return;
  }

  adr = mutt_expand_aliases (adr);

  if (mutt_addrlist_to_intl (adr, &err) < 0)
  {
    mutt_error (_("Bad IDN: '%s'"), err);
    FREE (&err);
    rfc822_free_address (&adr);
    return;
  }

  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), adr, 1);

#define extra_space (15 + 7 + 2)
  snprintf (scratch, sizeof (scratch),
           (h ? _("Bounce message to %s") : _("Bounce messages to %s")), buf);

  if (mutt_strwidth (prompt) > COLS - extra_space)
  {
    mutt_format_string (prompt, sizeof (prompt),
			0, COLS-extra_space, FMT_LEFT, 0,
			scratch, sizeof (scratch), 0);
    safe_strcat (prompt, sizeof (prompt), "...?");
  }
  else
    snprintf (prompt, sizeof (prompt), "%s?", scratch);

  if (query_quadoption (OPT_BOUNCE, prompt) != M_YES)
  {
    rfc822_free_address (&adr);
    CLEARLINE (LINES - 1);
    mutt_message (h ? _("Message not bounced.") : _("Messages not bounced."));
    return;
  }

  CLEARLINE (LINES - 1);
  
  rc = mutt_bounce_message (NULL, h, adr);
  rfc822_free_address (&adr);
  /* If no error, or background, display message. */
  if ((rc == 0) || (rc == S_BKG))
    mutt_message (h ? _("Message bounced.") : _("Messages bounced."));
}
コード例 #7
0
void mutt_FormatString (char *dest,     /* output buffer */
                        size_t destlen, /* output buffer len */
                        const char *src,        /* template string */
                        format_t * callback,    /* callback for processing */
                        unsigned long data,     /* callback data */
                        format_flag flags)
{                               /* callback flags */
  char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
  char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
  size_t wlen, count, len, col, wid;

  prefix[0] = '\0';
  destlen--;                    /* save room for the terminal \0 */
  wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
  col = wlen;

  while (*src && wlen < destlen) {
    if (*src == '%') {
      if (*++src == '%') {
        *wptr++ = '%';
        wlen++;
        col++;
        src++;
        continue;
      }

      if (*src == '?') {
        flags |= M_FORMAT_OPTIONAL;
        src++;
      }
      else {
        flags &= ~M_FORMAT_OPTIONAL;

        /* eat the format string */
        cp = prefix;
        count = 0;
        while (count < sizeof (prefix) &&
               (isdigit ((unsigned char) *src) || *src == '.' || *src == '-'))
        {
          *cp++ = *src++;
          count++;
        }
        *cp = 0;
      }

      if (!*src)
        break;                  /* bad format */

      ch = *src++;              /* save the character to switch on */

      if (flags & M_FORMAT_OPTIONAL) {
        if (*src != '?')
          break;                /* bad format */
        src++;

        /* eat the `if' part of the string */
        cp = ifstring;
        count = 0;
        while (count < sizeof (ifstring) && *src && *src != '?'
               && *src != '&') {
          *cp++ = *src++;
          count++;
        }
        *cp = 0;

        /* eat the `else' part of the string (optional) */
        if (*src == '&')
          src++;                /* skip the & */
        cp = elsestring;
        count = 0;
        while (count < sizeof (elsestring) && *src && *src != '?') {
          *cp++ = *src++;
          count++;
        }
        *cp = 0;

        if (!*src)
          break;                /* bad format */

        src++;                  /* move past the trailing `?' */
      }

      /* handle generic cases first */
      if (ch == '>') {
        /* right justify to EOL */
        ch = *src++;            /* pad char */
        /* calculate space left on line.  if we've already written more data
           than will fit on the line, ignore the rest of the line */
        if (DrawFullLine || option (OPTSTATUSONTOP))
          count = (COLS < destlen ? COLS : destlen);
        else
          count = ((COLS - SW) < destlen ? (COLS - SW) : destlen);
        if (count > col) {
          count -= col;         /* how many columns left on this line */
          mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
          wid = str_len (buf);
          if (count > wid) {
            count -= wid;       /* how many chars to pad */
            memset (wptr, ch, count);
            wptr += count;
            col += count;
          }
          if (wid + wlen > destlen)
            len = destlen - wlen;
          else
            len = wid;
          memcpy (wptr, buf, len);
          wptr += len;
          wlen += len;
          col += mutt_strwidth (buf);
        }
        break;                  /* skip rest of input */
      }
      else if (ch == '|') {
        /* pad to EOL */
        ch = *src++;
        if (destlen > COLS)
          destlen = COLS;
        if (destlen > wlen) {
          count = destlen - wlen;
          memset (wptr, ch, count);
          wptr += count;
        }
        break;                  /* skip rest of input */
      }
      else {
        short tolower = 0;
        short nodots = 0;

        while (ch == '_' || ch == ':') {
          if (ch == '_')
            tolower = 1;
          else if (ch == ':')
            nodots = 1;

          ch = *src++;
        }

        /* use callback function to handle this case */
        src =
          callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
                    data, flags);

        if (tolower)
          str_tolower (buf);
        if (nodots) {
          char *p = buf;

          for (; *p; p++)
            if (*p == '.')
              *p = '_';
        }

        if ((len = str_len (buf)) + wlen > destlen)
          len = (destlen - wlen > 0) ? (destlen - wlen) : 0;

        memcpy (wptr, buf, len);
        wptr += len;
        wlen += len;
        col += mutt_strwidth (buf);
      }
    }
    else if (*src == '\\') {
      if (!*++src)
        break;
      switch (*src) {
      case 'n':
        *wptr = '\n';
        break;
      case 't':
        *wptr = '\t';
        break;
      case 'r':
        *wptr = '\r';
        break;
      case 'f':
        *wptr = '\f';
        break;
      case 'v':
        *wptr = '\v';
        break;
      default:
        *wptr = *src;
        break;
      }
      src++;
      wptr++;
      wlen++;
      col++;
    }
    else {
      unsigned int bar = mutt_skipchars (src, "%\\");
      char *bar2 = mem_malloc (bar + 1);

      strfcpy (bar2, src, bar + 1);
      while (bar--) {
        *wptr++ = *src++;
        wlen++;
      }
      col += mutt_strwidth (bar2);
      mem_free (&bar2);
    }
  }
  *wptr = 0;

#if 0
  if (flags & M_FORMAT_MAKEPRINT) {
    /* Make sure that the string is printable by changing all non-printable
       chars to dots, or spaces for non-printable whitespace */
    for (cp = dest; *cp; cp++)
      if (!IsPrint (*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX)))
        *cp = isspace ((unsigned char) *cp) ? ' ' : '.';
  }
#endif
}
コード例 #8
0
ファイル: recvcmd.c プロジェクト: 0xAX/muttx
void mutt_attach_bounce (FILE * fp, struct header * hdr,
			 ATTACHPTR ** idx, short idxlen, struct body * cur)
{
	short i;
	char prompt[STRING];
	char buf[HUGE_STRING];
	struct address *adr = NULL;
	int ret = 0;
	int p   = 0;

	if (check_all_msg (idx, idxlen, cur, 1) == -1)
		return;

	/* one or more messages? */
	p = (cur || count_tagged (idx, idxlen) == 1);

	/* RfC 5322 mandates a From: header, so warn before bouncing
	 * messages without one */
	if (cur)
	{
		if (!cur->hdr->env->from)
		{
			mutt_error("Warning: message contains no From: header");
			mutt_sleep(2);
			mutt_clear_error();
		}
	}
	else
	{
		for (i = 0; i < idxlen; i++)
		{
			if (idx[i]->content->tagged)
			{
				if (!idx[i]->content->hdr->env->from)
				{
					mutt_error("Warning: message contains no From: header");
					mutt_sleep (2);
					mutt_clear_error ();
					break;
				}
			}
		}
	}

	if (p)
		strfcpy (prompt, ("Bounce message to: "), sizeof (prompt));
	else
		strfcpy (prompt, ("Bounce tagged messages to: "), sizeof (prompt));

	buf[0] = '\0';
	if (mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS)
	    || buf[0] == '\0')
		return;

	if (!(adr = rfc822_parse_adrlist (adr, buf)))
	{
		mutt_error("Error parsing address!");
		return;
	}

	adr = mutt_expand_aliases (adr);

	buf[0] = 0;
	rfc822_write_address (buf, sizeof (buf), adr, 1);

#define extra_space (15+7+2)
	/*
	 * See commands.c.
	 */
	snprintf (prompt, sizeof (prompt) - 4,
		  (p ? ("Bounce message to %s") : ("Bounce messages to %s")), buf);

	if (mutt_strwidth (prompt) > COLS - extra_space)
	{
		mutt_format_string (prompt, sizeof (prompt) - 4,
				    0, COLS-extra_space, FMT_LEFT, 0,
				    prompt, sizeof (prompt), 0);
		safe_strcat (prompt, sizeof (prompt), "...?");
	}
	else
		safe_strcat (prompt, sizeof (prompt), "?");

	if (query_quadoption (OPT_BOUNCE, prompt) != M_YES)
	{
		rfc822_free_address (&adr);
		CLEARLINE (LINES - 1);
		mutt_message (p ? ("Message not bounced.") : ("Messages not bounced."));
		return;
	}

	CLEARLINE (LINES - 1);

	if (cur)
		ret = mutt_bounce_message (fp, cur->hdr, adr);
	else
	{
		for (i = 0; i < idxlen; i++)
		{
			if (idx[i]->content->tagged)
				if (mutt_bounce_message (fp, idx[i]->content->hdr, adr))
					ret = 1;
		}
	}

	if (!ret)
		mutt_message (p ? ("Message bounced.") : ("Messages bounced."));
	else
		mutt_error (p ? ("Error bouncing message!") : ("Error bouncing messages!"));
}
コード例 #9
0
void mutt_attach_bounce (FILE * fp, HEADER * hdr,
                         ATTACHPTR ** idx, short idxlen, BODY * cur)
{
  short i;
  char prompt[STRING];
  char buf[HUGE_STRING];
  char *err = NULL;
  ADDRESS *adr = NULL;
  int ret = 0;
  int p = 0;

  if (check_all_msg (idx, idxlen, cur, 1) == -1)
    return;

  /* one or more messages? */
  p = (cur || count_tagged (idx, idxlen) == 1);

  if (p)
    strfcpy (prompt, _("Bounce message to: "), sizeof (prompt));
  else
    strfcpy (prompt, _("Bounce tagged messages to: "), sizeof (prompt));

  buf[0] = '\0';
  if (mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS)
      || buf[0] == '\0')
    return;

  if (!(adr = rfc822_parse_adrlist (adr, buf))) {
    mutt_error _("Error parsing address!");

    return;
  }

  adr = mutt_expand_aliases (adr);

  if (mutt_addrlist_to_idna (adr, &err) < 0) {
    mutt_error (_("Bad IDN: '%s'"), err);
    mem_free (&err);
    rfc822_free_address (&adr);
    return;
  }

  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), adr, 1);

#define extra_space (15+7+2)
  /*
   * See commands.c.
   */
  snprintf (prompt, sizeof (prompt) - 4,
            (p ? _("Bounce message to %s") : _("Bounce messages to %s")),
            buf);

  if (mutt_strwidth (prompt) > COLS - extra_space) {
    mutt_format_string (prompt, sizeof (prompt) - 4,
                        0, COLS - extra_space, 0, 0,
                        prompt, sizeof (prompt), 0);
    str_cat (prompt, sizeof (prompt), "...?");
  }
  else
    str_cat (prompt, sizeof (prompt), "?");

  if (query_quadoption (OPT_BOUNCE, prompt) != M_YES) {
    rfc822_free_address (&adr);
    CLEARLINE (LINES - 1);
    mutt_message (p ? _("Message not bounced.") : _("Messages not bounced."));
    return;
  }

  CLEARLINE (LINES - 1);

  if (cur)
    ret = mutt_bounce_message (fp, cur->hdr, adr);
  else {
    for (i = 0; i < idxlen; i++) {
      if (idx[i]->content->tagged)
        if (mutt_bounce_message (fp, idx[i]->content->hdr, adr))
          ret = 1;
    }
  }

  if (!ret)
    mutt_message (p ? _("Message bounced.") : _("Messages bounced."));
  else
    mutt_error (p ? _("Error bouncing message!") :
                _("Error bouncing messages!"));
}
コード例 #10
0
ファイル: commands.c プロジェクト: tonnerre/mutt
void ci_bounce_message (HEADER *h, int *redraw)
{
  char prompt[SHORT_STRING];
  char scratch[SHORT_STRING];
  char buf[HUGE_STRING] = { 0 };
  ADDRESS *adr = NULL;
  char *err = NULL;
  int rc;

  if(h)
    strfcpy(prompt, _("Bounce message to: "), sizeof(prompt));
  else
    strfcpy(prompt, _("Bounce tagged messages to: "), sizeof(prompt));
  
  rc = mutt_get_field (prompt, buf, sizeof (buf), M_ALIAS);

  if (option (OPTNEEDREDRAW))
  {
    unset_option (OPTNEEDREDRAW);
    *redraw = REDRAW_FULL;
  }

  if (rc || !buf[0])
    return;

  if (!(adr = rfc822_parse_adrlist (adr, buf)))
  {
    mutt_error _("Error parsing address!");
    return;
  }

  adr = mutt_expand_aliases (adr);

  if (mutt_addrlist_to_idna (adr, &err) < 0)
  {
    mutt_error (_("Bad IDN: '%s'"), err);
    FREE (&err);
    rfc822_free_address (&adr);
    return;
  }

  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), adr, 1);

#define extra_space (15 + 7 + 2)
  snprintf (scratch, sizeof (scratch),
           (h ? _("Bounce message to %s") : _("Bounce messages to %s")), buf);

  if (mutt_strwidth (prompt) > COLS - extra_space)
  {
    mutt_format_string (prompt, sizeof (prompt),
			0, COLS-extra_space, FMT_LEFT, 0,
			scratch, sizeof (scratch), 0);
    safe_strcat (prompt, sizeof (prompt), "...?");
  }
  else
    snprintf (prompt, sizeof (prompt), "%s?", scratch);

  if (query_quadoption (OPT_BOUNCE, prompt) != M_YES)
  {
    rfc822_free_address (&adr);
    CLEARLINE (LINES - 1);
    mutt_message (h ? _("Message not bounced.") : _("Messages not bounced."));
    return;
  }

  CLEARLINE (LINES - 1);
  
  rc = mutt_bounce_message (NULL, h, adr);
  rfc822_free_address (&adr);
  /* If no error, or background, display message. */
  if ((rc == 0) || (rc == S_BKG))
    mutt_message (h ? _("Message bounced.") : _("Messages bounced."));
}
コード例 #11
0
ファイル: help.c プロジェクト: 2ion/mutt-1.5.22
static void format_line (FILE *f, int ismacro,
			 const char *t1, const char *t2, const char *t3)
{
  int col;
  int col_a, col_b;
  int split;
  int n;

  fputs (t1, f);

  /* don't try to press string into one line with less than 40 characters.
     The double paranthesis avoid a gcc warning, sigh ... */
  if ((split = COLS < 40))
  {
    col_a = col = 0;
    col_b = LONG_STRING;
    fputc ('\n', f);
  }
  else
  {
    col_a = COLS > 83 ? (COLS - 32) >> 2 : 12;
    col_b = COLS > 49 ? (COLS - 10) >> 1 : 19;
    col = pad (f, mutt_strwidth(t1), col_a);
  }

  if (ismacro > 0)
  {
    if (!mutt_strcmp (Pager, "builtin"))
      fputs ("_\010", f);
    fputs ("M ", f);
    col += 2;

    if (!split)
    {
      col += print_macro (f, col_b - col - 4, &t2);
      if (mutt_strwidth (t2) > col_b - col)
	t2 = "...";
    }
  }

  col += print_macro (f, col_b - col - 1, &t2);
  if (split)
    fputc ('\n', f);
  else
    col = pad (f, col, col_b);

  if (split)
  {
    print_macro (f, LONG_STRING, &t3);
    fputc ('\n', f);
  }
  else
  {
    while (*t3)
    {
      n = COLS - col;

      if (ismacro >= 0)
      {
	SKIPWS(t3);
	n = get_wrapped_width (t3, n);
      }

      n = print_macro (f, n, &t3);

      if (*t3)
      {
        if (mutt_strcmp (Pager, "builtin"))
	{
	  fputc ('\n', f);
	  n = 0;
	}
	else
	{
	  n += col - COLS;
	  if (option (OPTMARKERS))
	    ++n;
	}
	col = pad (f, n, col_b);
      }
    }
  }

  fputc ('\n', f);
}