- 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)
- {
- queryp = results;
- while (queryp)
- {
- rfc822_free_address (&queryp->addr);
- FREE (&queryp->name);
- FREE (&queryp->other);
- results = queryp->next;
- FREE (&queryp);
- queryp = results;
- }
- results = newresults;
- 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->make_entry = query_entry;
- menu->search = query_search;
- menu->tag = query_tag;
- menu->menu = MENU_QUERY;
- 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);
- 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);
- rfc822_free_address (&a);
- }
- }
- ci_send_message (0, msg, NULL, Context, NULL);
- menu->redraw = REDRAW_FULL;
- break;
-
- case OP_EXIT:
- done = 1;
- break;
+ 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) {
+ queryp = results;
+ while (queryp) {
+ rfc822_free_address (&queryp->addr);
+ p_delete(&queryp->name);
+ p_delete(&queryp->other);
+ results = queryp->next;
+ p_delete(&queryp);
+ queryp = results;
+ }
+ results = newresults;
+ p_delete(&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->make_entry = query_entry;
+ menu->search = query_search;
+ menu->tag = query_tag;
+ menu->menu = MENU_QUERY;
+ 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 *) mem_calloc (menu->max, sizeof (ENTRY));
+
+ for (i = 0, queryp = results; queryp;
+ queryp = queryp->next, i++)
+ QueryTable[i].data = queryp;
+ }
+ else {
+ int clear = 0;
+
+ /* append */
+ mem_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);
+ 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);
+ rfc822_free_address (&a);
+ }
+ }
+ ci_send_message (0, msg, NULL, Context, NULL);
+ menu->redraw = REDRAW_FULL;
+ break;
+
+ case OP_EXIT:
+ done = 1;
+ break;