Ejemplo n.º 1
0
void mutt_set_followup_to (ENVELOPE *e)
{
  ADDRESS *t = NULL;
  ADDRESS *from;

  /* 
   * Only generate the Mail-Followup-To if the user has requested it, and
   * it hasn't already been set
   */

  if (option (OPTFOLLOWUPTO) && !e->mail_followup_to)
  {
    if (mutt_is_list_cc (0, e->to, e->cc))
    {
      /* 
       * this message goes to known mailing lists, so create a proper
       * mail-followup-to header
       */

      t = rfc822_append (&e->mail_followup_to, e->to, 0);
      rfc822_append (&t, e->cc, 1);
    }

    /* remove ourselves from the mail-followup-to header */
    e->mail_followup_to = remove_user (e->mail_followup_to, 0);

    /*
     * If we are not subscribed to any of the lists in question,
     * re-add ourselves to the mail-followup-to header.  The 
     * mail-followup-to header generated is a no-op with group-reply,
     * but makes sure list-reply has the desired effect.
     */

    if (e->mail_followup_to && !mutt_is_list_recipient (0, e->to, e->cc))
    {
      if (e->reply_to)
	from = rfc822_cpy_adr (e->reply_to, 0);
      else if (e->from)
	from = rfc822_cpy_adr (e->from, 0);
      else
	from = mutt_default_from ();
      
      if (from)
      {
	/* Normally, this loop will not even be entered. */
	for (t = from; t && t->next; t = t->next)
	  ;
	
	t->next = e->mail_followup_to; 	/* t cannot be NULL at this point. */
	e->mail_followup_to = from;
      }
    }
    
    e->mail_followup_to = mutt_remove_duplicates (e->mail_followup_to);
    
  }
}
Ejemplo n.º 2
0
int mutt_fetch_recips (ENVELOPE *out, ENVELOPE *in, int flags)
{
  char prompt[STRING];
  ADDRESS *tmp;
  int hmfupto = -1;

  if ((flags & (SENDLISTREPLY|SENDGROUPREPLY)) && in->mail_followup_to)
  {
    snprintf (prompt, sizeof (prompt), _("Follow-up to %s%s?"),
	      in->mail_followup_to->mailbox,
	      in->mail_followup_to->next ? ",..." : "");

    if ((hmfupto = query_quadoption (OPT_MFUPTO, prompt)) == -1)
      return -1;
  }

  if (flags & SENDLISTREPLY)
  {
    tmp = find_mailing_lists (in->to, in->cc);
    rfc822_append (&out->to, tmp, 0);
    rfc822_free_address (&tmp);

    if (in->mail_followup_to && hmfupto == M_YES &&
        default_to (&out->cc, in, flags & SENDLISTREPLY, hmfupto) == -1)
      return (-1); /* abort */
  }
  else
  {
    if (default_to (&out->to, in, flags & SENDGROUPREPLY, hmfupto) == -1)
      return (-1); /* abort */

    if ((flags & SENDGROUPREPLY) && (!in->mail_followup_to || hmfupto != M_YES))
    {
      /* if(!mutt_addr_is_user(in->to)) */
      rfc822_append (&out->cc, in->to, 1);
      rfc822_append (&out->cc, in->cc, 1);
    }
  }
  return 0;
}
Ejemplo n.º 3
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.º 4
0
static int default_to (ADDRESS **to, ENVELOPE *env, int flags, int hmfupto)
{
  char prompt[STRING];

  if (flags && env->mail_followup_to && hmfupto == M_YES) 
  {
    rfc822_append (to, env->mail_followup_to, 1);
    return 0;
  }

  /* Exit now if we're setting up the default Cc list for list-reply
   * (only set if Mail-Followup-To is present and honoured).
   */
  if (flags & SENDLISTREPLY)
    return 0;

  if (!option(OPTREPLYSELF) && mutt_addr_is_user (env->from))
  {
    /* mail is from the user, assume replying to recipients */
    rfc822_append (to, env->to, 1);
  }
  else if (env->reply_to)
  {
    if ((mutt_addrcmp (env->from, env->reply_to) && !env->reply_to->next) || 
	(option (OPTIGNORELISTREPLYTO) &&
	mutt_is_mail_list (env->reply_to) &&
	(mutt_addrsrc (env->reply_to, env->to) ||
	mutt_addrsrc (env->reply_to, env->cc))))
    {
      /* If the Reply-To: address is a mailing list, assume that it was
       * put there by the mailing list, and use the From: address
       * 
       * We also take the from header if our correspondant has a reply-to
       * header which is identical to the electronic mail address given
       * in his From header.
       * 
       */
      rfc822_append (to, env->from, 0);
    }
    else if (!(mutt_addrcmp (env->from, env->reply_to) && 
	       !env->reply_to->next) &&
	     quadoption (OPT_REPLYTO) != M_YES)
    {
      /* There are quite a few mailing lists which set the Reply-To:
       * header field to the list address, which makes it quite impossible
       * to send a message to only the sender of the message.  This
       * provides a way to do that.
       */
      snprintf (prompt, sizeof (prompt), _("Reply to %s%s?"),
		env->reply_to->mailbox, 
		env->reply_to->next?",...":"");
      switch (query_quadoption (OPT_REPLYTO, prompt))
      {
      case M_YES:
	rfc822_append (to, env->reply_to, 0);
	break;

      case M_NO:
	rfc822_append (to, env->from, 0);
	break;

      default:
	return (-1); /* abort */
      }
    }
    else
      rfc822_append (to, env->reply_to, 0);
  }
  else
    rfc822_append (to, env->from, 0);

  return (0);
}