Ejemplo n.º 1
0
static int edit_address_list (int line, ADDRESS **addr)
{
  char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */
  char *err = NULL;
  
  mutt_addrlist_to_local (*addr);
  rfc822_write_address (buf, sizeof (buf), *addr, 0);
  if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
  {
    rfc822_free_address (addr);
    *addr = mutt_parse_adrlist (*addr, buf);
    *addr = mutt_expand_aliases (*addr);
  }

  if (option (OPTNEEDREDRAW))
  {
    unset_option (OPTNEEDREDRAW);
    return (REDRAW_FULL);
  }

  if (mutt_addrlist_to_intl (*addr, &err) != 0)
  {
    mutt_error (_("Warning: '%s' is a bad IDN."), err);
    mutt_refresh();
    FREE (&err);
  }

  /* redraw the expanded list so the user can see the result */
  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), *addr, 1);
  move (line, HDR_XOFFSET);
  mutt_paddstr (W, buf);
  
  return 0;
}
Ejemplo n.º 2
0
static int edit_address_list (int line, ADDRESS **addr)
{
  char buf[HUGE_STRING] = ""; /* needs to be large for alias expansion */

  rfc822_write_address (buf, sizeof (buf), *addr);
  if (mutt_get_field (Prompts[line - 1], buf, sizeof (buf), M_ALIAS) == 0)
  {
    rfc822_free_address (addr);
    *addr = mutt_parse_adrlist (*addr, buf);
    *addr = mutt_expand_aliases (*addr);
  }

  if (option (OPTNEEDREDRAW))
  {
    unset_option (OPTNEEDREDRAW);
    return (REDRAW_FULL);
  }

  /* redraw the expanded list so the user can see the result */
  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), *addr);
  mvprintw (line, HDR_XOFFSET, "%-*.*s", W, W, buf);

  return 0;
}
Ejemplo n.º 3
0
static int edit_address (ADDRESS **a, /* const */ char *field)
{
  char buf[HUGE_STRING];
  char *err = NULL;
  int idna_ok = 0;
  
  do
  {
    buf[0] = 0;
    mutt_addrlist_to_local (*a);
    rfc822_write_address (buf, sizeof (buf), *a, 0);
    if (mutt_get_field (field, buf, sizeof (buf), M_ALIAS) != 0)
      return (-1);
    rfc822_free_address (a);
    *a = mutt_expand_aliases (mutt_parse_adrlist (NULL, buf));
    if ((idna_ok = mutt_addrlist_to_idna (*a, &err)) != 0)
    {
      mutt_error (_("Error: '%s' is a bad IDN."), err);
      mutt_refresh ();
      mutt_sleep (2);
      FREE (&err);
    }
  } 
  while (idna_ok != 0);
  return 0;
}
Ejemplo n.º 4
0
int mutt_query_complete(char *buf, size_t buflen)
{
    QUERY *results = NULL;
    ADDRESS *tmpa;

    if (!QueryCmd) {
        mutt_error _("Query command not defined.");
        return 0;
    }

    results = run_query(buf, 1);

    if (results) {
        /* only one response? */
        if (results->next == NULL) {
            tmpa = result_to_addr(results);
            mutt_addrlist_to_local(tmpa);
            buf[0] = '\0';
            rfc822_write_address(buf, buflen, tmpa, 0);
            rfc822_free_address(&tmpa);
            free_query(&results);
            mutt_clear_error();
            return 0;
        }

        /* multiple results, choose from query menu */
        query_menu(buf, buflen, results, 1);
    }
    return 0;
}
Ejemplo n.º 5
0
static void draw_envelope_addr (int line, ADDRESS *addr)
{
  char buf[STRING];

  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), addr);
  mvprintw (line, 0, TITLE_FMT "%-*.*s", Prompts[line - 1], W, W, buf);
}
Ejemplo n.º 6
0
static void format_address_header (char **h, ADDRESS *a)
{
  char buf[HUGE_STRING];
  char cbuf[STRING];
  char c2buf[STRING];
  char *p = NULL;
  int l, linelen, buflen, count, cbuflen, c2buflen, plen;

  linelen = mutt_strlen (*h);
  plen = linelen;
  buflen  = linelen + 3;

  safe_realloc (h, buflen);
  for (count = 0; a; a = a->next, count++)
  {
    ADDRESS *tmp = a->next;
    a->next = NULL;
    *buf = *cbuf = *c2buf = '\0';
    l = rfc822_write_address (buf, sizeof (buf), a, 0);
    a->next = tmp;
    
    if (count && linelen + l > 74) 
    {
      strcpy (cbuf, "\n\t");  	/* __STRCPY_CHECKED__ */
      linelen = l + 8;
    }
    else
    {
      if (a->mailbox)
      {
	strcpy (cbuf, " ");	/* __STRCPY_CHECKED__ */
	linelen++;
      }
      linelen += l;
    }
    if (!a->group && a->next && a->next->mailbox)
    {
      linelen++;
      buflen++;
      strcpy (c2buf, ",");	/* __STRCPY_CHECKED__ */
    }

    cbuflen = mutt_strlen (cbuf);
    c2buflen = mutt_strlen (c2buf);
    buflen += l + cbuflen + c2buflen;
    safe_realloc (h, buflen);
    p = *h;
    strcat (p + plen, cbuf);		/* __STRCAT_CHECKED__ */
    plen += cbuflen;
    strcat (p + plen, buf);		/* __STRCAT_CHECKED__ */
    plen += l;
    strcat (p + plen, c2buf);		/* __STRCAT_CHECKED__ */
    plen += c2buflen;
  }
  
  /* Space for this was allocated in the beginning of this function. */
  strcat (p + plen, "\n");		/* __STRCAT_CHECKED__ */
}
Ejemplo n.º 7
0
static void draw_envelope_addr (int line, ADDRESS *addr)
{
  char buf[LONG_STRING];

  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), addr, 1);
  mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
  mutt_paddstr (W, buf);
}
Ejemplo n.º 8
0
static char *_php_rfc822_write_address(ADDRESS *addresslist) {
  char address[SENDBUFLEN];
  if (_php_imap_address_size(addresslist) >= SENDBUFLEN) {
    Logger::Error("Address buffer overflow");
    return NULL;
  }
  address[0] = 0;
  rfc822_write_address(address, addresslist);
  return strdup(address);
}
Ejemplo n.º 9
0
void mutt_forward_intro (FILE *fp, HEADER *cur)
{
  char buffer[STRING];
  
  fputs ("----- Forwarded message from ", fp);
  buffer[0] = 0;
  rfc822_write_address (buffer, sizeof (buffer), cur->env->from, 1);
  fputs (buffer, fp);
  fputs (" -----\n\n", fp);
}
Ejemplo n.º 10
0
int main (int argc, char **argv)
{
  ADDRESS *list;
  char buf[256];
  char *str = "michael, Michael Elkins <*****@*****.**>, testing a really complex address: this example <@[email protected]:[email protected]>;, [email protected] (lothar)";
  
  list = rfc822_parse_adrlist (NULL, str);
  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), list);
  rfc822_free_address (&list);
  puts (buf);
  exit (0);
}
Ejemplo n.º 11
0
static const char * query_format_str (char *dest, size_t destlen, size_t col,
char op, const char *src,
const char *fmt, const char *ifstring,
const char *elsestring,
unsigned long data, format_flag flags)
{
        ENTRY *entry = (ENTRY *)data;
        QUERY *query = entry->data;
        char tmp[SHORT_STRING];
        char buf2[STRING] = "";
        int optional = (flags & M_FORMAT_OPTIONAL);

        switch (op) {
                case 'a':
                        rfc822_write_address (buf2, sizeof (buf2), query->addr, 1);
                        snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
                        snprintf (dest, destlen, tmp, buf2);
                        break;
                case 'c':
                        snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
                        snprintf (dest, destlen, tmp, query->num + 1);
                        break;
                case 'e':
                        if (!optional) {
                                snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
                                snprintf (dest, destlen, tmp, NONULL (query->other));
                        }
                        else if (!query->other || !*query->other)
                                optional = 0;
                        break;
                case 'n':
                        snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
                        snprintf (dest, destlen, tmp, NONULL (query->name));
                        break;
                case 't':
                        snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
                        snprintf (dest, destlen, tmp, entry->tagged ? '*' : ' ');
                        break;
                default:
                        snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
                        snprintf (dest, destlen, tmp, op);
                        break;
        }

        if (optional)
                mutt_FormatString (dest, destlen, col, ifstring, query_format_str, data, 0);
        else if (flags & M_FORMAT_OPTIONAL)
                mutt_FormatString (dest, destlen, col, elsestring, query_format_str, data, 0);

        return src;
}
Ejemplo n.º 12
0
void mutt_display_address (ENVELOPE *env)
{
  char *pfx = NULL;
  char buf[SHORT_STRING];
  ADDRESS *adr = NULL;

  adr = mutt_get_address (env, &pfx);

  if (!adr) return;
  
  /* 
   * Note: We don't convert IDNA to local representation this time.
   * That is intentional, so the user has an opportunity to copy &
   * paste the on-the-wire form of the address to other, IDN-unable
   * software. 
   */
  
  buf[0] = 0;
  rfc822_write_address (buf, sizeof (buf), adr, 0);
  mutt_message ("%s: %s", pfx, buf);
}
Ejemplo n.º 13
0
/* %a = address of author
 * %A = reply-to address (if present; otherwise: address of author
 * %b = filename of the originating folder
 * %B = the list to which the letter was sent
 * %c = size of message in bytes
 * %C = current message number
 * %d = date and time of message using $date_format and sender's timezone
 * %D = date and time of message using $date_format and local timezone
 * %e = current message number in thread
 * %E = number of messages in current thread
 * %f = entire from line
 * %F = like %n, unless from self
 * %i = message-id
 * %l = number of lines in the message
 * %L = like %F, except `lists' are displayed first
 * %m = number of messages in the mailbox
 * %n = name of author
 * %N = score
 * %O = like %L, except using address instead of name
 * %P = progress indicator for builtin pager
 * %s = subject
 * %S = short message status (e.g., N/O/D/!/r/-)
 * %t = `to:' field (recipients)
 * %T = $to_chars
 * %u = user (login) name of author
 * %v = first name of author, unless from self
 * %X = number of MIME attachments
 * %y = `x-label:' field (if present)
 * %Y = `x-label:' field (if present, tree unfolded, and != parent's x-label)
 * %Z = status flags	*/
static const char *
hdr_format_str(char          *dest,
               size_t        destlen,
               size_t        col,
               char          op,
               const char    *src,
               const char    *prefix,
               const char    *ifstring,
               const char    *elsestring,
               unsigned long data,
               format_flag   flags)
{
    struct hdr_format_info *hfi = (struct hdr_format_info *)data;
    HEADER *hdr, *htmp;
    CONTEXT *ctx;
    char fmt[SHORT_STRING], buf2[LONG_STRING], ch, *p;
    int do_locales, i;
    int optional = (flags & M_FORMAT_OPTIONAL);
    int threads = ((Sort & SORT_MASK) == SORT_THREADS);
    int is_index = (flags & M_FORMAT_INDEX);

#define THREAD_NEW (threads                \
                    && hdr->collapsed      \
                    && hdr->num_hidden > 1 \
                    && mutt_thread_contains_unread(ctx, hdr) == 1)
#define THREAD_OLD (threads                \
                    && hdr->collapsed      \
                    && hdr->num_hidden > 1 \
                    && mutt_thread_contains_unread(ctx, hdr) == 2)
    size_t len;

    hdr = hfi->hdr;
    ctx = hfi->ctx;

    dest[0] = 0;

    switch (op) {
    case 'A':

        if (hdr->env->reply_to
            && hdr->env->reply_to->mailbox) {
            mutt_format_s(dest, destlen, prefix,
                          mutt_addr_for_display(hdr->env->reply_to));
            break;
        }

    /* fall through if 'A' returns nothing */

    case 'a':

        if (hdr->env->from
            && hdr->env->from->mailbox) {
            mutt_format_s(dest, destlen, prefix,
                          mutt_addr_for_display(hdr->env->from));
        } else
            dest[0] = '\0';
        break;

    case 'B':

        if (!first_mailing_list(dest, destlen, hdr->env->to)
            && !first_mailing_list(dest, destlen, hdr->env->cc))
            dest[0] = 0;

        if (dest[0]) {
            strfcpy(buf2, dest, sizeof(buf2));
            mutt_format_s(dest, destlen, prefix, buf2);
            break;
        }

    /* fall through if 'B' returns nothing */

    case 'b':

        if (ctx) {
            if ((p = strrchr(ctx->path, '/')))
                strfcpy(dest, p + 1, destlen);
            else
                strfcpy(dest, ctx->path, destlen);
        } else
            strfcpy(dest, "(null)", destlen);
        strfcpy(buf2, dest, sizeof(buf2));
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'c':
        mutt_pretty_size(buf2, sizeof(buf2), (long)hdr->content->length);
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'C':
        snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
        snprintf(dest, destlen,     fmt,     hdr->msgno + 1);
        break;

    case 'd':
    case 'D':
    case '{':
    case '[':
    case '(':
    case '<':

        /* preprocess $date_format to handle %Z */
    {
        const char *cp;
        struct tm *tm;
        time_t T;

        p = dest;

        cp = (op == 'd'
              || op == 'D') ? (NONULL(DateFmt)) : src;

        if (*cp == '!') {
            do_locales = 0;
            cp++;
        } else
            do_locales = 1;

        len = destlen - 1;

        while (len > 0
               && (((op == 'd'
                     || op == 'D')
                    && *cp)
                   || (op == '{'
                       && *cp != '}')
                   || (op == '['
                       && *cp != ']')
                   || (op == '('
                       && *cp != ')')
                   || (op == '<'
                       && *cp != '>'))) {
            if (*cp == '%') {
                cp++;

                if (((*cp == 'Z')
                     || (*cp == 'z'))
                    && ((op == 'd')
                        || (op == '{'))) {
                    if (len >= 5) {
                        sprintf(p, "%c%02u%02u", hdr->zoccident ? '-' : '+',
                                hdr->zhours, hdr->zminutes);
                        p += 5;
                        len -= 5;
                    } else
                        break;  /* not enough space left */
                } else {
                    if (len >= 2) {
                        *p++ = '%';
                        *p++ = *cp;
                        len -= 2;
                    } else
                        break;  /* not enough space */
                }
                cp++;
            } else {
                *p++ = *cp++;
                len--;
            }
        }
        *p = 0;

        if (do_locales
            && Locale)
            setlocale(LC_TIME, Locale);

        if ((op == '[')
            || (op == 'D'))
            tm = localtime(&hdr->date_sent);
        else if (op == '(')
            tm = localtime(&hdr->received);
        else if (op == '<') {
            T = time(NULL);
            tm = localtime(&T);
        } else {
            /* restore sender's time zone */
            T = hdr->date_sent;

            if (hdr->zoccident)
                T -= (hdr->zhours * 3600 + hdr->zminutes * 60);
            else
                T += (hdr->zhours * 3600 + hdr->zminutes * 60);
            tm = gmtime(&T);
        }

        strftime(buf2, sizeof(buf2), dest, tm);

        if (do_locales)
            setlocale(LC_TIME, "C");

        mutt_format_s(dest, destlen, prefix, buf2);

        if ((len > 0)
            && (op != 'd')
            && (op != 'D')) /* Skip ending op */
            src = cp + 1;
        break;
    }

    case 'e':
        snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
        snprintf(dest, destlen,     fmt,     mutt_messages_in_thread(ctx,
                                                                     hdr,
                                                                     1));
        break;

    case 'E':

        if (!optional) {
            snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
            snprintf(dest, destlen,     fmt,
                     mutt_messages_in_thread(ctx, hdr, 0));
        } else if (mutt_messages_in_thread(ctx, hdr, 0) <= 1)
            optional = 0;
        break;

    case 'f':
        buf2[0] = 0;
        rfc822_write_address(buf2, sizeof(buf2), hdr->env->from, 1);
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'F':

        if (!optional) {
            make_from(hdr->env, buf2, sizeof(buf2), 0);
            mutt_format_s(dest, destlen, prefix, buf2);
        } else if (mutt_addr_is_user(hdr->env->from))
            optional = 0;
        break;

    case 'H':

        /* (Hormel) spam score */
        if (optional)
            optional = hdr->env->spam ? 1 : 0;

        if (hdr->env->spam)
            mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->spam->data));
        else
            mutt_format_s(dest, destlen, prefix, "");

        break;

    case 'i':
        mutt_format_s(dest,
                      destlen,
                      prefix,
                      hdr->env->message_id ? hdr->env->message_id : "<no.id>");
        break;

    case 'l':

        if (!optional) {
            snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
            snprintf(dest, destlen,     fmt,     (int)hdr->lines);
        } else if (hdr->lines <= 0)
            optional = 0;
        break;

    case 'L':

        if (!optional) {
            make_from(hdr->env, buf2, sizeof(buf2), 1);
            mutt_format_s(dest, destlen, prefix, buf2);
        } else if (!check_for_mailing_list(hdr->env->to, NULL, NULL, 0)
                   && !check_for_mailing_list(hdr->env->cc, NULL, NULL, 0)) {
            optional = 0;
        }
        break;

    case 'm':

        if (ctx) {
            snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
            snprintf(dest, destlen,     fmt,     ctx->msgcount);
        } else
            strfcpy(dest, "(null)", destlen);
        break;

    case 'n':
        mutt_format_s(dest, destlen, prefix, mutt_get_name(hdr->env->from));
        break;

    case 'N':

        if (!optional) {
            snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
            snprintf(dest, destlen,     fmt,     hdr->score);
        } else {
            if (hdr->score == 0)
                optional = 0;
        }
        break;

    case 'O':

        if (!optional) {
            make_from_addr(hdr->env, buf2, sizeof(buf2), 1);

            if (!globals.has_option(OPTSAVEADDRESS) && (p = strpbrk(buf2, "%@")))
                *p = 0;
            mutt_format_s(dest, destlen, prefix, buf2);
        } else if (!check_for_mailing_list_addr(hdr->env->to, NULL, 0)
                   && !check_for_mailing_list_addr(hdr->env->cc, NULL, 0)) {
            optional = 0;
        }
        break;

    case 'M':
        snprintf(fmt, sizeof(fmt), "%%%sd", prefix);

        if (!optional) {
            if (threads
                && is_index
                && hdr->collapsed
                && (hdr->num_hidden > 1))
                snprintf(dest, destlen, fmt, hdr->num_hidden);
            else if (is_index
                     && threads)
                mutt_format_s(dest, destlen, prefix, " ");
            else
                *dest = '\0';
        } else {
            if (!(threads
                  && is_index
                  && hdr->collapsed
                  && (hdr->num_hidden > 1)))
                optional = 0;
        }
        break;

    case 'P':
        strfcpy(dest, NONULL(hfi->pager_progress), destlen);
        break;

    case 's':

        if (flags & M_FORMAT_TREE
            && !hdr->collapsed) {
            if (flags & M_FORMAT_FORCESUBJ) {
                mutt_format_s(dest, destlen, "", NONULL(hdr->env->subject));
                snprintf(buf2, sizeof(buf2), "%s%s", hdr->tree, dest);
                mutt_format_s_tree(dest, destlen, prefix, buf2);
            } else
                mutt_format_s_tree(dest, destlen, prefix, hdr->tree);
        } else
            mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->subject));
        break;

    case 'S':

        if (hdr->deleted)
            ch = 'D';
        else if (hdr->attach_del)
            ch = 'd';
        else if (hdr->tagged)
            ch = '*';
        else if (hdr->flagged)
            ch = '!';
        else if (hdr->replied)
            ch = 'r';
        else if (hdr->read
                 && (ctx
                     && (ctx->msgnotreadyet != hdr->msgno)))
            ch = '-';
        else if (hdr->old)
            ch = 'O';
        else
            ch = 'N';

        /* FOO - this is probably unsafe, but we are not likely to have such
           a short string passed into this routine */
        *dest = ch;
        *(dest + 1) = 0;
        break;

    case 't':
        buf2[0] = 0;

        if (!check_for_mailing_list(hdr->env->to, "To ", buf2, sizeof(buf2))
            && !check_for_mailing_list(hdr->env->cc, "Cc ", buf2,
                                       sizeof(buf2))) {
            if (hdr->env->to)
                snprintf(buf2, sizeof(buf2), "To %s", mutt_get_name(
                             hdr->env->to));
            else if (hdr->env->cc)
                snprintf(buf2, sizeof(buf2), "Cc %s", mutt_get_name(
                             hdr->env->cc));
        }
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'T':
        snprintf(fmt,  sizeof(fmt), "%%%sc", prefix);
        snprintf(dest, destlen,     fmt,
                 (Tochars
                  && ((i = mutt_user_is_recipient(hdr))) < mutt_strlen(
                      Tochars)) ? Tochars[i] : ' ');
        break;

    case 'u':

        if (hdr->env->from
            && hdr->env->from->mailbox) {
            strfcpy(buf2, mutt_addr_for_display(hdr->env->from), sizeof(buf2));

            if ((p = strpbrk(buf2, "%@")))
                *p = 0;
        } else
            buf2[0] = 0;
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'v':

        if (mutt_addr_is_user(hdr->env->from)) {
            if (hdr->env->to)
                mutt_format_s(buf2, sizeof(buf2), prefix,
                              mutt_get_name(hdr->env->to));
            else if (hdr->env->cc)
                mutt_format_s(buf2, sizeof(buf2), prefix,
                              mutt_get_name(hdr->env->cc));
            else
                *buf2 = 0;
        } else
            mutt_format_s(buf2, sizeof(buf2), prefix,
                          mutt_get_name(hdr->env->from));

        if ((p = strpbrk(buf2, " %@")))
            *p = 0;
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'Z':

        ch = ' ';

        if (WithCrypto
            && hdr->security & GOODSIGN)
            ch = 'S';
        else if (WithCrypto
                 && hdr->security & ENCRYPT)
            ch = 'P';
        else if (WithCrypto
                 && hdr->security & SIGN)
            ch = 's';
        else if ((WithCrypto & APPLICATION_PGP)
                 && hdr->security & PGPKEY)
            ch = 'K';

        snprintf(buf2, sizeof(buf2),
                 "%c%c%c", (THREAD_NEW ? 'n' : (THREAD_OLD ? 'o' :
                                                ((hdr->read
                                                  && (ctx
                                                      && ctx->msgnotreadyet !=
                                                      hdr->msgno))
                                                 ? (hdr->replied ? 'r' : ' ') : (
                                                     hdr->old ? 'O' : 'N')))),
                 hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch),
                 hdr->tagged ? '*' :
                 (hdr->flagged ? '!' :
                  (Tochars
                   && ((i = mutt_user_is_recipient(hdr)) <
                       mutt_strlen(Tochars)) ? Tochars[i] : ' ')));
        mutt_format_s(dest, destlen, prefix, buf2);
        break;

    case 'X':
    {
        int count = mutt_count_body_parts(ctx, hdr);

        /* The recursion allows messages without depth to return 0. */
        if (optional)
            optional = count != 0;

        snprintf(fmt,  sizeof(fmt), "%%%sd", prefix);
        snprintf(dest, destlen,     fmt,     count);
        break;
    }

    case 'y':

        if (optional)
            optional = hdr->env->x_label ? 1 : 0;

        mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->x_label));
        break;

    case 'Y':

        if (hdr->env->x_label) {
            i = 1; /* reduce reuse recycle */
            htmp = NULL;

            if (flags & M_FORMAT_TREE
                && (hdr->thread->prev
                    && hdr->thread->prev->message
                    && hdr->thread->prev->message->env->x_label))
                htmp = hdr->thread->prev->message;
            else if (flags & M_FORMAT_TREE
                     && (hdr->thread->parent
                         && hdr->thread->parent->message
                         && hdr->thread->parent->message->env->x_label))
                htmp = hdr->thread->parent->message;

            if (htmp
                && (mutt_strcasecmp(hdr->env->x_label,
                                    htmp->env->x_label) == 0))
                i = 0;
        } else
            i = 0;

        if (optional)
            optional = i;

        if (i)
            mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->x_label));
        else
            mutt_format_s(dest, destlen, prefix, "");

        break;

    default:
        snprintf(dest, destlen, "%%%s%c", prefix, op);
        break;
    }

    if (optional)
        mutt_FormatString(dest, destlen, col, ifstring, hdr_format_str,
                          (unsigned long)hfi, flags);
    else if (flags & M_FORMAT_OPTIONAL)
        mutt_FormatString(dest, destlen, col, elsestring, hdr_format_str,
                          (unsigned long)hfi, flags);

    return src;

#undef THREAD_NEW
#undef THREAD_OLD
}
Ejemplo n.º 14
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!"));
}
Ejemplo n.º 15
0
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."));
}
Ejemplo n.º 16
0
Archivo: recvcmd.c Proyecto: 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!"));
}
Ejemplo n.º 17
0
static void query_menu(char *buf, size_t buflen, QUERY *results, int retbuf)
{
    MUTTMENU *menu;
    HEADER *msg = NULL;
    ENTRY *QueryTable = NULL;
    QUERY *queryp = NULL;
    int i, done = 0;
    int op;
    char helpstr[LONG_STRING];
    char title[STRING];

    snprintf(title, sizeof(title), _("Query")); /* FIXME */

    menu = mutt_new_menu(MENU_QUERY);
    menu->make_entry = query_entry;
    menu->search = query_search;
    menu->tag = query_tag;
    menu->title = title;
    menu->help = mutt_compile_help(helpstr,
                                   sizeof(helpstr),
                                   MENU_QUERY,
                                   QueryHelp);

    if (results == NULL) {
        /* Prompt for Query */
        if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0)
            && buf[0]) {
            results = run_query(buf, 0);
        }
    }

    if (results) {
        snprintf(title, sizeof(title), _("Query '%s'"), buf);

        /* count the number of results */
        for (queryp = results; queryp; queryp = queryp->next)
            menu->max++;

        menu->data = QueryTable =
                         (ENTRY *)safe_calloc(menu->max, sizeof(ENTRY));

        for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
            QueryTable[i].data = queryp;

        while (!done) {
            switch ((op = mutt_menuLoop(menu))) {
            case OP_QUERY_APPEND:
            case OP_QUERY:

                if ((mutt_get_field(_("Query: "), buf, buflen, 0) == 0)
                    && buf[0]) {
                    QUERY *newresults = NULL;

                    newresults = run_query(buf, 0);

                    menu->redraw = REDRAW_FULL;

                    if (newresults) {
                        snprintf(title, sizeof(title), _("Query '%s'"), buf);

                        if (op == OP_QUERY) {
                            free_query(&results);
                            results = newresults;
                            safe_free(&QueryTable);
                        } else {
                            /* append */
                            for (queryp = results; queryp->next;
                                 queryp = queryp->next) ;

                            queryp->next = newresults;
                        }


                        menu->current = 0;
                        mutt_menuDestroy(&menu);
                        menu = mutt_new_menu(MENU_QUERY);
                        menu->make_entry = query_entry;
                        menu->search = query_search;
                        menu->tag = query_tag;
                        menu->title = title;
                        menu->help = mutt_compile_help(helpstr,
                                                       sizeof(helpstr),
                                                       MENU_QUERY,
                                                       QueryHelp);

                        /* count the number of results */
                        for (queryp = results; queryp; queryp = queryp->next)
                            menu->max++;

                        if (op == OP_QUERY) {
                            menu->data = QueryTable =
                                             (ENTRY *)safe_calloc(menu->max,
                                                                  sizeof(ENTRY));

                            for (i = 0, queryp = results; queryp;
                                 queryp = queryp->next, i++)
                                QueryTable[i].data = queryp;
                        } else {
                            int clear = 0;

                            /* append */
                            safe_realloc(&QueryTable,
                                         menu->max * sizeof(ENTRY));

                            menu->data = QueryTable;

                            for (i = 0, queryp = results; queryp;
                                 queryp = queryp->next, i++) {
                                /* once we hit new entries, clear/init the tag
                                   */
                                if (queryp == newresults)
                                    clear = 1;

                                QueryTable[i].data = queryp;

                                if (clear)
                                    QueryTable[i].tagged = 0;
                            }
                        }
                    }
                }
                break;

            case OP_CREATE_ALIAS:

                if (menu->tagprefix) {
                    ADDRESS *naddr = NULL;

                    for (i = 0; i < menu->max; i++)
                        if (QueryTable[i].tagged) {
                            ADDRESS *a = result_to_addr(QueryTable[i].data);
                            rfc822_append(&naddr, a, 0);
                            rfc822_free_address(&a);
                        }

                    mutt_create_alias(NULL, naddr);
                } else {
                    ADDRESS *a = result_to_addr(QueryTable[menu->current].data);
                    mutt_create_alias(NULL, a);
                    rfc822_free_address(&a);
                }
                break;

            case OP_GENERIC_SELECT_ENTRY:

                if (retbuf) {
                    done = 2;
                    break;
                }

            /* fall through to OP_MAIL */

            case OP_MAIL:
                msg = mutt_new_header();
                msg->env = mutt_new_envelope();

                if (!menu->tagprefix) {
                    msg->env->to =
                        result_to_addr(QueryTable[menu->current].data);
                } else {
                    for (i = 0; i < menu->max; i++)
                        if (QueryTable[i].tagged) {
                            ADDRESS *a = result_to_addr(QueryTable[i].data);
                            rfc822_append(&msg->env->to, a, 0);
                            rfc822_free_address(&a);
                        }
                }
                ci_send_message(0, msg, NULL, Context, NULL);
                menu->redraw = REDRAW_FULL;
                break;

            case OP_EXIT:
                done = 1;
                break;
            }
        }

        /* if we need to return the selected entries */
        if (retbuf
            && (done == 2)) {
            int tagged = 0;
            size_t curpos = 0;

            memset(buf, 0, buflen);

            /* check for tagged entries */
            for (i = 0; i < menu->max; i++) {
                if (QueryTable[i].tagged) {
                    if (curpos == 0) {
                        ADDRESS *tmpa = result_to_addr(QueryTable[i].data);
                        mutt_addrlist_to_local(tmpa);
                        tagged = 1;
                        rfc822_write_address(buf, buflen, tmpa, 0);
                        curpos = mutt_strlen(buf);
                        rfc822_free_address(&tmpa);
                    } else if (curpos + 2 < buflen) {
                        ADDRESS *tmpa = result_to_addr(QueryTable[i].data);
                        mutt_addrlist_to_local(tmpa);
                        strcat(buf, ", "); /* __STRCAT_CHECKED__ */
                        rfc822_write_address((char *)buf + curpos + 1,
                                             buflen - curpos - 1,
                                             tmpa,
                                             0);
                        curpos = mutt_strlen(buf);
                        rfc822_free_address(&tmpa);
                    }
                }
            }

            /* then enter current message */
            if (!tagged) {
                ADDRESS *tmpa = result_to_addr(QueryTable[menu->current].data);
                mutt_addrlist_to_local(tmpa);
                rfc822_write_address(buf, buflen, tmpa, 0);
                rfc822_free_address(&tmpa);
            }
        }

        free_query(&results);
        safe_free(&QueryTable);

        /* tell whoever called me to redraw the screen when I return */
        globals.set_option(OPTNEEDREDRAW);
    }

    mutt_menuDestroy(&menu);
}
Ejemplo n.º 18
0
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."));
}