~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to query.c

  • Committer: Bazaar Package Importer
  • Author(s): Antonio Radici
  • Date: 2009-06-14 20:53:18 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (2.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090614205318-wf0sqy1o3km636li
Tags: 1.5.20-1
* New upstream release, includes the following features:
  + Bounced messages contains From: headers (Closes: 93268)
  + Attachments displayed based on Content-Disposition (Closes: 199709)
  + fcc to a mailbox does not raise the 'new' flag (Closes: 209390)
  + '!' supported as suffix in gpg keys (Closes: 277945)
  + failed attachment saving shows an error message (Closes: 292350)
  + inline signed messages sent honouring $send_charset (Closes: 307819)
  + support for <clear-flag> and <set-flag> in the pager (Closes: 436007)
  + fcc_attach is a quad option (Closes: 478861)
  + Content-Description header not included in reply (Closes: 500766)
  + imap_sync_mailbox fix for a segfault (Closes: 516364)
  + better threading support with particular Message-ID's (Closes: 520735)
  + no crash on IMAP folder refresh (Closes: 528465)
  + undisclosed-recipients not passed in the envelope (Closes: 529090)
* debian/patches/series:
  + commented all references to upstream/*, they should be included in 1.5.20
  + removed debian-specific/529838-gnutls-autoconf.patch, ditto
  + removed misc/manpage-typos.patch, ditto 
  + modified misc/hyphen-as-minus.patch, a big part was integrated upstream
  + features/trash-folder: do not reupload messages to $trash if IMAP is used
    (Closes: #448241)
  + added misc/hg.pmdef.debugtime, see upstream #3263
* debian/control: added DM-Upload-Allowed: yes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
 
2
 * Copyright (C) 1996-2000,2003 Michael R. Elkins <me@mutt.org>
3
3
 * 
4
4
 *     This program is free software; you can redistribute it and/or modify
5
5
 *     it under the terms of the GNU General Public License as published by
24
24
#include "mutt_menu.h"
25
25
#include "mutt_idna.h"
26
26
#include "mapping.h"
27
 
#include "sort.h"
28
27
 
29
28
#include <string.h>
30
29
#include <stdlib.h>
32
31
 
33
32
typedef struct query
34
33
{
 
34
  int num;
35
35
  ADDRESS *addr;
36
36
  char *name;
37
37
  char *other;
51
51
  { N_("Make Alias"), OP_CREATE_ALIAS },
52
52
  { N_("Search"), OP_SEARCH },
53
53
  { N_("Help"),   OP_HELP },
54
 
  { NULL }
 
54
  { NULL,         0 }
55
55
};
56
56
 
57
 
/* Variables for outsizing output format */
58
 
static int FirstColumn;
59
 
static int SecondColumn;
60
 
 
61
57
static void query_menu (char *buf, size_t buflen, QUERY *results, int retbuf);
62
58
 
63
59
static ADDRESS *result_to_addr (QUERY *r)
64
60
{
65
61
  static ADDRESS *tmp;
66
62
  
67
 
  if (!(tmp = rfc822_cpy_adr (r->addr)))
 
63
  if (!(tmp = rfc822_cpy_adr (r->addr, 0)))
68
64
    return NULL;
69
65
  
70
66
  if(!tmp->next && !tmp->personal)
86
82
  char msg[STRING];
87
83
  char *p;
88
84
  pid_t thepid;
89
 
  int l;
90
85
 
91
86
 
92
87
  mutt_expand_file_fmt (cmd, sizeof(cmd), QueryCmd, s);
101
96
  fgets (msg, sizeof (msg), fp);
102
97
  if ((p = strrchr (msg, '\n')))
103
98
    *p = '\0';
104
 
  while ((buf = mutt_read_line (buf, &buflen, fp, &dummy)) != NULL)
 
99
  while ((buf = mutt_read_line (buf, &buflen, fp, &dummy, 0)) != NULL)
105
100
  {
106
101
    if ((p = strtok(buf, "\t\n")))
107
102
    {
108
103
      if (first == NULL)
109
104
      {
110
 
        FirstColumn = 0;
111
 
        SecondColumn = 0;
112
105
        first = (QUERY *) safe_calloc (1, sizeof (QUERY));
113
106
        cur = first;
114
107
      }
118
111
        cur = cur->next;
119
112
      }
120
113
 
121
 
      l = mutt_strwidth (p);
122
 
      if (l > SecondColumn)
123
 
        SecondColumn = l;
124
 
        
125
114
      cur->addr = rfc822_parse_adrlist (cur->addr, p);
126
115
      p = strtok(NULL, "\t\n");
127
116
      if (p)
128
117
      {
129
 
        l = mutt_strwidth (p);
130
 
        if (l > FirstColumn)
131
 
          FirstColumn = l;
132
118
        cur->name = safe_strdup (p);
133
119
        p = strtok(NULL, "\t\n");
134
120
        if (p)
135
 
        {
136
121
          cur->other = safe_strdup (p);
137
 
        }
138
122
      }
139
123
    }
140
124
  }
141
125
  FREE (&buf);
142
 
  fclose (fp);
 
126
  safe_fclose (&fp);
143
127
  if (mutt_wait_filter (thepid))
144
128
  {
145
129
    dprint (1, (debugfile, "Error: %s\n", msg));
180
164
  return REG_NOMATCH;
181
165
}
182
166
 
183
 
/* This is the callback routine from mutt_menuLoop() which is used to generate
184
 
 * a menu entry for the requested item number.
185
 
 */
186
 
#define QUERY_MIN_COLUMN_LENGHT 20 /* Must be < 70/2 */
 
167
static const char * query_format_str (char *dest, size_t destlen, size_t col,
 
168
                                      char op, const char *src,
 
169
                                      const char *fmt, const char *ifstring,
 
170
                                      const char *elsestring,
 
171
                                      unsigned long data, format_flag flags)
 
172
{
 
173
  ENTRY *entry = (ENTRY *)data;
 
174
  QUERY *query = entry->data;
 
175
  char tmp[SHORT_STRING];
 
176
  char buf2[STRING] = "";
 
177
  int optional = (flags & M_FORMAT_OPTIONAL);
 
178
 
 
179
  switch (op)
 
180
  {
 
181
  case 'a':
 
182
    rfc822_write_address (buf2, sizeof (buf2), query->addr, 1);
 
183
    snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
 
184
    snprintf (dest, destlen, tmp, buf2);
 
185
    break;
 
186
  case 'c':
 
187
    snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
 
188
    snprintf (dest, destlen, tmp, query->num + 1);
 
189
    break;
 
190
  case 'e':
 
191
    if (!optional)
 
192
    {
 
193
      snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
 
194
      snprintf (dest, destlen, tmp, NONULL (query->other));
 
195
    }
 
196
    else if (!query->other || !*query->other)
 
197
      optional = 0;
 
198
    break;
 
199
  case 'n':
 
200
    snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
 
201
    snprintf (dest, destlen, tmp, NONULL (query->name));
 
202
    break;
 
203
  case 't':
 
204
    snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
 
205
    snprintf (dest, destlen, tmp, entry->tagged ? '*' : ' ');
 
206
    break;
 
207
  default:
 
208
    snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
 
209
    snprintf (dest, destlen, tmp, op);
 
210
    break;
 
211
  }
 
212
 
 
213
  if (optional)
 
214
    mutt_FormatString (dest, destlen, col, ifstring, query_format_str, data, 0);
 
215
  else if (flags & M_FORMAT_OPTIONAL)
 
216
    mutt_FormatString (dest, destlen, col, elsestring, query_format_str, data, 0);
 
217
 
 
218
  return src;
 
219
}
 
220
 
187
221
static void query_entry (char *s, size_t slen, MUTTMENU *m, int num)
188
222
{
189
 
  ENTRY *table = (ENTRY *) m->data;
190
 
  char buf2[SHORT_STRING], buf[SHORT_STRING] = "";
191
 
 
192
 
  /* need a query format ... hard coded constants are not good */
193
 
  while (FirstColumn + SecondColumn > 70)
194
 
  {
195
 
    FirstColumn = FirstColumn * 3 / 4;
196
 
    SecondColumn = SecondColumn * 3 / 4;
197
 
    if (FirstColumn < QUERY_MIN_COLUMN_LENGHT)
198
 
      FirstColumn = QUERY_MIN_COLUMN_LENGHT;
199
 
    if (SecondColumn < QUERY_MIN_COLUMN_LENGHT)
200
 
      SecondColumn = QUERY_MIN_COLUMN_LENGHT;
201
 
  }
202
 
 
203
 
  rfc822_write_address (buf, sizeof (buf), table[num].data->addr, 1);
204
 
 
205
 
  mutt_format_string (buf2, sizeof (buf2),
206
 
                      FirstColumn + 2, FirstColumn + 2,
207
 
                      FMT_LEFT, ' ', table[num].data->name,
208
 
                      mutt_strlen (table[num].data->name), 0);
209
 
 
210
 
  snprintf (s, slen, " %c %3d %s %-*.*s %s", 
211
 
            table[num].tagged ? '*':' ',
212
 
            num+1,
213
 
            buf2,
214
 
            SecondColumn+2,
215
 
            SecondColumn+2,
216
 
            buf,
217
 
            NONULL (table[num].data->other));
 
223
  ENTRY *entry = &((ENTRY *) m->data)[num];
 
224
 
 
225
  entry->data->num = num;
 
226
  mutt_FormatString (s, slen, 0, NONULL (QueryFormat), query_format_str,
 
227
                     (unsigned long) entry, M_FORMAT_ARROWCURSOR);
218
228
}
219
229
 
220
230
static int query_tag (MUTTMENU *menu, int n, int m)
290
300
 
291
301
  snprintf (title, sizeof (title), _("Query")); /* FIXME */
292
302
 
293
 
  menu = mutt_new_menu ();
 
303
  menu = mutt_new_menu (MENU_QUERY);
294
304
  menu->make_entry = query_entry;
295
305
  menu->search = query_search;
296
306
  menu->tag = query_tag;
297
 
  menu->menu = MENU_QUERY;
298
307
  menu->title = title;
299
308
  menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_QUERY, QueryHelp);
300
309
 
363
372
 
364
373
              menu->current = 0;
365
374
              mutt_menuDestroy (&menu);
366
 
              menu = mutt_new_menu ();
 
375
              menu = mutt_new_menu (MENU_QUERY);
367
376
              menu->make_entry = query_entry;
368
377
              menu->search = query_search;
369
378
              menu->tag = query_tag;
370
 
              menu->menu = MENU_QUERY;
371
379
              menu->title = title;
372
380
              menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_QUERY, QueryHelp);
373
381
 
418
426
              if (QueryTable[i].tagged)
419
427
              {
420
428
                ADDRESS *a = result_to_addr(QueryTable[i].data);
421
 
                rfc822_append (&naddr, a);
 
429
                rfc822_append (&naddr, a, 0);
422
430
                rfc822_free_address (&a);
423
431
              }
424
432
 
453
461
              if (QueryTable[i].tagged)
454
462
              {
455
463
                ADDRESS *a = result_to_addr(QueryTable[i].data);
456
 
                rfc822_append (&msg->env->to, a);
 
464
                rfc822_append (&msg->env->to, a, 0);
457
465
                rfc822_free_address (&a);
458
466
              }
459
467
          }