]> git.pld-linux.org Git - packages/mutt.git/blob - mutt-cd.signatures_menu.patch
- 1.5.21
[packages/mutt.git] / mutt-cd.signatures_menu.patch
1 diff -pruN2 mutt-1.3.27.orig/Makefile.am mutt-1.3.27/Makefile.am
2 --- mutt-1.3.27.orig/Makefile.am        Fri Nov  9 01:18:28 2001
3 +++ mutt-1.3.27/Makefile.am     Wed Jan 23 22:35:32 2002
4 @@ -25,5 +25,5 @@ mutt_SOURCES = $(BUILT_SOURCES) \
5         postpone.c query.c recvattach.c recvcmd.c \
6         rfc822.c rfc1524.c rfc2047.c rfc2231.c \
7 -       score.c send.c sendlib.c signal.c sort.c \
8 +       score.c send.c sendlib.c signal.c signature.c sort.c \
9         status.c system.c thread.c charset.c history.c lib.c \
10         muttlib.c editmsg.c utf8.c mbyte.c wcwidth.c \
11 diff -pruN2 mutt-1.3.27.orig/OPS mutt-1.3.27/OPS
12 --- mutt-1.3.27.orig/OPS        Tue Sep 11 12:50:50 2001
13 +++ mutt-1.3.27/OPS     Wed Jan 23 22:35:32 2002
14 @@ -37,4 +37,5 @@ OP_COMPOSE_POSTPONE_MESSAGE "save this m
15  OP_COMPOSE_RENAME_FILE "rename/move an attached file"
16  OP_COMPOSE_SEND_MESSAGE "send the message"
17 +OP_COMPOSE_SIG "choose a signature"
18  OP_COMPOSE_TOGGLE_DISPOSITION "toggle disposition between inline/attachment"
19  OP_COMPOSE_TOGGLE_UNLINK "toggle whether to delete file after sending it"
20 @@ -126,4 +127,5 @@ OP_NEXT_ENTRY "move to the next entry"
21  OP_NEXT_LINE "scroll down one line"
22  OP_NEXT_PAGE "move to the next page"
23 +OP_NEXT_SIG "move to the next signature"
24  OP_PAGER_BOTTOM "jump to the bottom of the message"
25  OP_PAGER_HIDE_QUOTED "toggle display of quoted text"
26 @@ -134,9 +136,11 @@ OP_PREV_ENTRY "move to the previous entr
27  OP_PREV_LINE "scroll up one line"
28  OP_PREV_PAGE "move to the previous page"
29 +OP_PREV_SIG "move to the previous signature"
30  OP_PRINT "print the current entry"
31  OP_PURGE_MESSAGE "really delete the current entry, bypassing the trash folder"
32  OP_QUERY "query external program for addresses"
33  OP_QUERY_APPEND "append new query results to current results"
34  OP_QUIT "save changes to mailbox and quit"
35 +OP_RANDOM_SIG "pick a signature at random"
36  OP_RECALL_MESSAGE "recall a postponed message"
37  OP_REDRAW "clear and redraw the screen"
38 @@ -150,4 +154,5 @@ OP_SEARCH_OPPOSITE "search for next matc
39  OP_SEARCH_TOGGLE "toggle search pattern coloring"
40  OP_SHELL_ESCAPE "invoke a command in a subshell"
41 +OP_SIG_SEARCH "search signatures matching a pattern"
42  OP_SORT "sort messages"
43  OP_SORT_REVERSE "sort messages in reverse order"
44 diff -pruN2 mutt-1.3.27.orig/compose.c mutt-1.3.27/compose.c
45 --- mutt-1.3.27.orig/compose.c  Mon Dec  3 11:17:57 2001
46 +++ mutt-1.3.27/compose.c       Wed Jan 23 22:35:32 2002
47 @@ -1103,4 +1103,10 @@ int mutt_compose_menu (HEADER *msg,   /*
48         break;
49  
50 +      case OP_COMPOSE_SIG:
51 +       mutt_signature(msg->content->filename);
52 +       MAYBE_REDRAW (menu->redraw);
53 +       mutt_update_encoding (msg->content);
54 +       break;
55 +
56        case OP_PIPE:
57        case OP_FILTER:
58 diff -pruN2 mutt-1.3.27.orig/doc/manual.sgml.head mutt-1.3.27/doc/manual.sgml.head
59 --- mutt-1.3.27.orig/doc/manual.xml.head        Sat Jan 12 12:35:43 2002
60 +++ mutt-1.3.27/doc/manual.xml.head     Wed Jan 23 22:35:32 2002
61 @@ -526,4 +526,5 @@ c       edit-cc                 edit the
62  b       edit-bcc                edit the Bcc field
63  y       send-message            send the message
64 +ESC s  signature-menu          select a signature and append it to your mail
65  s       edit-subject            edit the Subject
66  f       edit-fcc                specify an ``Fcc'' mailbox
67 diff -pruN2 mutt-1.3.27.orig/functions.h mutt-1.3.27/functions.h
68 --- mutt-1.3.27.orig/functions.h        Tue Sep 11 12:51:39 2001
69 +++ mutt-1.3.27/functions.h     Wed Jan 23 22:35:32 2002
70 @@ -309,4 +309,5 @@ struct binding_t OpCompose[] = {
71    { "send-message",    OP_COMPOSE_SEND_MESSAGE,        "y" },
72    { "pipe-entry",      OP_PIPE,                        "|" },
73 +  { "signature-menu",  OP_COMPOSE_SIG,                 "\033s" },
74  
75  #ifdef HAVE_PGP
76 @@ -363,4 +364,17 @@ struct binding_t OpQuery[] = {
77    { "query",           OP_QUERY,               "Q" },
78    { "query-append",    OP_QUERY_APPEND,        "A" },
79 +  { NULL,              0,                      NULL }
80 +};
81 +
82 +/* Signature Menu */
83 +struct binding_t OpSig[] = {
84 +  { "next-sig",                OP_NEXT_SIG,            "j" },
85 +  { "previous-sig",    OP_PREV_SIG,            "k" },
86 +  { "random-sig",      OP_RANDOM_SIG,          "r" },
87 +  { NULL,              0,                      NULL }
88 +};
89 +
90 +struct binding_t OpSigDir[] = {
91 +  { "search-sig",      OP_SIG_SEARCH,          "/" },
92    { NULL,              0,                      NULL }
93  };
94 diff -pruN2 mutt-1.3.27.orig/globals.h mutt-1.3.27/globals.h
95 --- mutt-1.3.27.orig/globals.h  Thu Jan  3 21:56:46 2002
96 +++ mutt-1.3.27/globals.h       Wed Jan 23 22:35:32 2002
97 @@ -100,4 +100,5 @@ WHERE char *Sendmail;
98  WHERE char *Shell;
99  WHERE char *Signature;
100 +WHERE char *SigDirectory;
101  WHERE char *SimpleSearch;
102  WHERE char *Spoolfile;
103 diff -pruN2 mutt-1.3.27.orig/init.h mutt-1.3.27/init.h
104 --- mutt-1.3.27.orig/init.h     Mon Dec 10 11:09:03 2001
105 +++ mutt-1.3.27/init.h  Wed Jan 23 22:35:32 2002
106 @@ -1954,4 +1954,12 @@ struct option_t MuttVars[] = {
107    ** its stdout.
108    */
109 +  { "signatures_directory",    DT_PATH, R_NONE, UL &SigDirectory, UL "" },
110 +  /*
111 +  ** .pp
112 +  ** Specifies the path where your signatures are located. In the files of
113 +  ** this directory, the signatures are separated by blank lines and/or
114 +  ** sig_dashes (``-- '').
115 +  ** You can choose between these signatures from the compose menu.
116 +  */
117    { "simple_search",   DT_STR,  R_NONE, UL &SimpleSearch, UL "~f %s | ~s %s" },
118    /*
119 diff -pruN2 mutt-1.3.27.orig/keymap.c mutt-1.3.27/keymap.c
120 --- mutt-1.3.27.orig/keymap.c   Tue Oct 16 16:29:02 2001
121 +++ mutt-1.3.27/keymap.c        Wed Jan 23 22:35:32 2002
122 @@ -50,4 +50,6 @@ struct mapping_t Menus[] = {
123  
124   { "query",    MENU_QUERY },
125 + { "signature",        MENU_SIG },
126 + { "sig_directory",    MENU_SIG_DIR },
127   { "generic",  MENU_GENERIC },
128   { NULL,       0 }
129 @@ -528,4 +530,6 @@ void km_init (void)
130    create_bindings (OpQuery, MENU_QUERY);
131    create_bindings (OpAlias, MENU_ALIAS);
132 +  create_bindings (OpSig, MENU_SIG);
133 +  create_bindings (OpSigDir, MENU_SIG_DIR);
134  
135  
136 @@ -619,4 +623,7 @@ void km_init (void)
137    km_bindkey ("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
138  
139 +  km_bindkey ("<up>", MENU_SIG, OP_PREV_SIG);
140 +  km_bindkey ("<down>", MENU_SIG, OP_NEXT_SIG);
141 +
142    /* edit-to (default "t") hides generic tag-entry in Compose menu
143       This will bind tag-entry to  "T" in the Compose menu */
144 @@ -739,4 +746,8 @@ struct binding_t *km_get_table (int menu
145      case MENU_QUERY:
146        return OpQuery;
147 +    case MENU_SIG:
148 +      return OpSig;
149 +    case MENU_SIG_DIR:
150 +      return OpSigDir;
151  
152  
153 diff -pruN2 mutt-1.3.27.orig/keymap.h mutt-1.3.27/keymap.h
154 --- mutt-1.3.27.orig/keymap.h   Tue Sep 11 12:50:12 2001
155 +++ mutt-1.3.27/keymap.h        Wed Jan 23 22:35:32 2002
156 @@ -60,4 +60,6 @@ enum
157    MENU_POST,
158    MENU_QUERY,
159 +  MENU_SIG,
160 +  MENU_SIG_DIR,
161  
162    
163 @@ -102,4 +104,6 @@ extern struct binding_t OpEditor[];
164  extern struct binding_t OpQuery[];
165  extern struct binding_t OpAlias[];
166 +extern struct binding_t OpSig[];
167 +extern struct binding_t OpSigDir[];
168  
169  #ifdef HAVE_PGP
170 diff -pruN2 mutt-1.3.27.orig/protos.h mutt-1.3.27/protos.h
171 --- mutt-1.3.27.orig/protos.h   Wed Jan 16 21:43:58 2002
172 +++ mutt-1.3.27/protos.h        Wed Jan 23 22:35:32 2002
173 @@ -225,4 +225,5 @@ void mutt_shell_escape (void);
174  void mutt_show_error (void);
175  void mutt_signal_init (void);
176 +void mutt_signature (char *);
177  void mutt_stamp_attachment (BODY *a);
178  void mutt_tabs_to_spaces (char *);
179 diff -pruN2 mutt-1.3.27.orig/signature.c mutt-1.3.27/signature.c
180 --- mutt-1.3.27.orig/signature.c        Thu Jan  1 01:00:00 1970
181 +++ mutt-1.3.27/signature.c     Wed Jan 23 22:35:32 2002
182 @@ -0,0 +1,505 @@
183 +/*
184 + * Copyright (C) 2001 Cedric Duval <cedricduval@free.fr>
185 + * 
186 + *     This program is free software; you can redistribute it and/or modify
187 + *     it under the terms of the GNU General Public License as published by
188 + *     the Free Software Foundation; either version 2 of the License, or
189 + *     (at your option) any later version.
190 + * 
191 + *     This program is distributed in the hope that it will be useful,
192 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
193 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
194 + *     GNU General Public License for more details.
195 + * 
196 + *     You should have received a copy of the GNU General Public License
197 + *     along with this program; if not, write to the Free Software
198 + *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
199 + */
200 +
201 +#if HAVE_CONFIG_H
202 +# include "config.h"
203 +#endif
204 +
205 +#include "mutt.h"
206 +#include "mutt_menu.h"
207 +#include "mapping.h"
208 +#include "mutt_curses.h"
209 +
210 +#include <stdio.h>
211 +#include <string.h>
212 +#include <stdlib.h>
213 +#include <dirent.h>
214 +#include <sys/stat.h>
215 +
216 +#define SIG_DISPLAY_LINES 4
217 +#define SEPARATOR(x) ((*x == '\n') || (mutt_strcmp (x, "-- \n") == 0))
218 +#define SIG_ADD_LINE(x,y) mutt_add_list (x, strtok (y, "\n"))
219 +
220 +typedef struct sig_list
221 +{
222 +  struct sig_list *next;
223 +  LIST *sig;
224 +} SIG_LIST;
225 +
226 +typedef struct sig_dir
227 +{
228 +  struct sig_dir *next;
229 +  char *name;
230 +} SIG_DIR;
231 +
232 +typedef LIST * ENTRY;
233 +
234 +typedef struct entry_dir
235 +{
236 +  int tagged;
237 +  SIG_DIR *data;
238 +} ENTRY_DIR;
239 +
240 +static struct mapping_t SigHelp[] = {
241 +  { N_("Exit"),   OP_EXIT },
242 +  { N_("Search"), OP_SEARCH },
243 +  { N_("Random"), OP_RANDOM_SIG },
244 +  { N_("Help"),   OP_HELP },
245 +  { NULL }
246 +};
247 +
248 +static struct mapping_t SigDirHelp[] = {
249 +  { N_("Exit"),   OP_EXIT },
250 +  { N_("Search signature"), OP_SIG_SEARCH },
251 +  { N_("Help"),   OP_HELP },
252 +  { NULL }
253 +};
254 +
255 +void menu_next_entry (MUTTMENU *menu);
256 +void menu_prev_entry (MUTTMENU *menu);
257 +
258 +
259 +static int sig_match (LIST *s, regex_t *re)
260 +{
261 +  while (s)
262 +  {
263 +    if (regexec (re, s->data, (size_t)0, NULL, (int)0) == 0)
264 +      return 1;
265 +    s = s->next;
266 +  }
267 +  return 0;
268 +}
269 +
270 +static void read_sig_file (char *name, SIG_LIST **begin, regex_t *re)
271 +{
272 +  FILE *fp;
273 +  char buf[STRING];
274 +  LIST *sig = NULL;
275 +  SIG_LIST *first, *cur;
276 +  int append = 0;
277 +
278 +  if (!(fp = safe_fopen (name, "r")))
279 +  {
280 +    mutt_error (_("Can't open signature file %s"), name);
281 +    return;
282 +  }
283 +
284 +  for (first = *begin; first && first->next; first = first->next, append++)
285 +    ; /* append results to an existing list */
286 +  cur = first;
287 +
288 +  while (fgets (buf, sizeof (buf), fp))
289 +  {
290 +    if (buf[0] && !SEPARATOR (buf))
291 +    {
292 +      sig = SIG_ADD_LINE (NULL, buf);
293 +
294 +      while (fgets (buf, sizeof (buf), fp) && buf[0] && !SEPARATOR (buf))
295 +       SIG_ADD_LINE (sig, buf);
296 +
297 +      if (re && !sig_match (sig, re))
298 +       mutt_free_list (&sig); /* previous sig didn't match the regexp */
299 +      else
300 +      {
301 +       /* add signature */
302 +       if (first == NULL)
303 +         first = cur = (SIG_LIST *) safe_calloc (1, sizeof (SIG_LIST));
304 +       else
305 +       {
306 +         cur->next = (SIG_LIST *) safe_calloc (1, sizeof (SIG_LIST));
307 +         cur = cur->next;
308 +       }
309 +
310 +       cur->sig = sig;
311 +       cur->next = NULL;
312 +      }
313 +    }
314 +  }
315 +
316 +  if (!append)
317 +    *begin = first;
318 +
319 +  safe_fclose (&fp);
320 +}
321 +
322 +static void sig_make_entry (char *s, size_t slen, MUTTMENU *menu, int num)
323 +{
324 +  ENTRY *table = (ENTRY *) menu->data;
325 +
326 +  snprintf (s, slen, "%3d %s",
327 +           num + 1,
328 +           table[num]->data);
329 +}
330 +
331 +static int sig_menu_search (MUTTMENU *menu, regex_t *re, int num)
332 +{
333 +  return (sig_match (((ENTRY *)menu->data)[num], re) ? 0 : REG_NOMATCH);
334 +}
335 +
336 +static void draw_sig_frame (LIST *s)
337 +{
338 +  int i;
339 +
340 +  for (i = 1; i <= SIG_DISPLAY_LINES; i++)
341 +  {
342 +    if (s)
343 +    {
344 +      mvaddstr (i, 0, s->data);
345 +      s = s->next;
346 +    }
347 +    else
348 +      move (i, 0);
349 +
350 +    clrtoeol ();
351 +  }
352 +
353 +  SETCOLOR (MT_COLOR_STATUS);
354 +  mvaddstr (SIG_DISPLAY_LINES + 1, 0, _("-- Signature"));
355 +  BKGDSET (MT_COLOR_STATUS);
356 +  clrtoeol ();
357 +
358 +  BKGDSET (MT_COLOR_NORMAL);
359 +  SETCOLOR (MT_COLOR_NORMAL);
360 +}
361 +
362 +static void free_sig_list (SIG_LIST **sigs)
363 +{
364 +  SIG_LIST *cur;
365 +
366 +  while (*sigs)
367 +  {
368 +    cur = *sigs;
369 +    *sigs = (*sigs)->next;
370 +    mutt_free_list (&cur->sig);
371 +    safe_free ((void **)&cur);
372 +  }
373 +}
374 +
375 +static void append_signature (char *msg_file, LIST *s)
376 +{
377 +  FILE *fp;
378 +
379 +  if ((fp = safe_fopen (msg_file, "a")) == 0)
380 +    mutt_perror (msg_file);
381 +  else
382 +  {
383 +    if (option (OPTSIGDASHES))
384 +      fputs ("\n-- \n", fp);
385 +
386 +    for (; s; s = s->next)
387 +      fprintf (fp, "%s\n", s->data);
388 +
389 +    mutt_message (_("Signature appended to your mail"));
390 +    safe_fclose (&fp);
391 +  }
392 +}
393 +
394 +static LIST *sig_list_menu (char *file, SIG_LIST *list)
395 +{
396 +  LIST *result = NULL;
397 +  SIG_LIST *sigl;
398 +  MUTTMENU *menu;
399 +  ENTRY *SigTable;
400 +  char helpstr[SHORT_STRING], title[SHORT_STRING];
401 +  int i, done = 0;
402 +
403 +  snprintf (title, sizeof (title), _("Signature : %s"), file);
404 +
405 +  menu = mutt_new_menu (MENU_SIG);
406 +  menu->make_entry = sig_make_entry;
407 +  menu->tag = NULL;
408 +  menu->search = sig_menu_search;
409 +  menu->title = title;
410 +  menu->help = mutt_compile_help (helpstr, sizeof (helpstr),
411 +                                 MENU_SIG, SigHelp);
412 +  menu->offset = SIG_DISPLAY_LINES + 2;
413 +  menu->pagelen = LINES - SIG_DISPLAY_LINES - 4;
414 +  
415 +  for (sigl = list; sigl; sigl = sigl->next)
416 +    menu->max++;
417 +
418 +  menu->data = SigTable = (ENTRY *) safe_calloc (menu->max, sizeof (ENTRY));
419 +
420 +  for (i = 0, sigl = list; sigl; i++, sigl = sigl->next)
421 +    SigTable[i] = sigl->sig;
422 +
423 +  while (!done)
424 +  {
425 +    switch (mutt_menuLoop (menu))
426 +    {
427 +      case OP_GENERIC_SELECT_ENTRY:
428 +        result = SigTable[menu->current];
429 +       done = 1;
430 +       break;
431 +
432 +      case OP_PREV_SIG:
433 +       menu_prev_entry (menu);
434 +       draw_sig_frame (SigTable[menu->current]);
435 +       break;
436 +
437 +      case OP_NEXT_SIG:
438 +       menu_next_entry (menu);
439 +       draw_sig_frame (SigTable[menu->current]);
440 +       break;
441 +
442 +      case OP_REDRAW:
443 +       menu->offset = SIG_DISPLAY_LINES + 2;
444 +       menu->pagelen = LINES - SIG_DISPLAY_LINES - 4;
445 +       draw_sig_frame (SigTable[menu->current]);
446 +       break;
447 +
448 +      case OP_RANDOM_SIG:
449 +       menu->current = LRAND () % menu->max;
450 +       draw_sig_frame (SigTable[menu->current]);
451 +       menu->redraw |= REDRAW_MOTION;
452 +       break;
453 +
454 +      case OP_EXIT:
455 +       set_option (OPTNEEDREDRAW);
456 +        done = 1;
457 +        break;
458 +    }
459 +  }
460 +  
461 +  mutt_menuDestroy (&menu);
462 +  safe_free ((void **)&SigTable);
463 +  return result;
464 +}
465 +
466 +extern char* SearchBuffers[MENU_MAX];
467 +
468 +static SIG_LIST *sig_search_filter (MUTTMENU *menu, char *path)
469 +{
470 +  regex_t re;
471 +  char buf[STRING];
472 +  SIG_LIST *result = NULL;
473 +  int i;
474 +  char* searchBuf = menu->menu >= 0 && menu->menu < MENU_MAX ?
475 +                    SearchBuffers[menu->menu] : NULL;
476 +
477 +  snprintf (buf, sizeof(buf), searchBuf ? searchBuf : "");
478 +  if (mutt_get_field (_("Search for: "), buf,
479 +                     sizeof (buf), M_CLEAR) != 0 || !buf[0])
480 +    return (NULL);
481 +  if (menu->menu >= 0 && menu->menu < MENU_MAX)
482 +  {
483 +    mutt_str_replace (&SearchBuffers[menu->menu], buf);
484 +    searchBuf = SearchBuffers[menu->menu];
485 +  }
486 +
487 +  if ((i = regcomp (&re, searchBuf, REG_NOSUB | REG_EXTENDED | REG_WORDS
488 +                   | mutt_which_case (searchBuf))) != 0)
489 +  {
490 +    regerror (i, &re, buf, sizeof (buf));
491 +    regfree (&re);
492 +    mutt_error ("%s", buf);
493 +    return (NULL);
494 +  }
495 +
496 +  /* building list of sigs matching the regexp */
497 +  for (i = 0; i < menu->max; i++)
498 +  {
499 +    /* search in every file if none is tagged */
500 +    if (((ENTRY_DIR *) menu->data)[i].tagged || (menu->tagged == 0))
501 +    {
502 +      snprintf (buf, sizeof (buf), "%s/%s", path,
503 +               ((ENTRY_DIR *) menu->data)[i].data->name);
504 +      read_sig_file (buf, &result, &re);
505 +    }
506 +  }
507 +
508 +  regfree (&re);
509 +  if (!result)
510 +    mutt_error (_("Not found."));
511 +
512 +  return (result);
513 +}
514 +
515 +/* returns the list of files in this directory */
516 +static SIG_DIR *sig_directory (char *path)
517 +{
518 +  DIR *dp;
519 +  struct dirent *de;
520 +  struct stat s;
521 +  SIG_DIR *first = NULL, *cur = NULL;
522 +  char file[_POSIX_PATH_MAX + SHORT_STRING];
523 +
524 +  if ((dp = opendir (path)) == NULL)
525 +  {
526 +    mutt_perror (path);
527 +    return (NULL);
528 +  }
529 +  
530 +  while ((de = readdir (dp)))
531 +  {
532 +    if ((de->d_name)[0] == '.') /* no hidden files */
533 +      continue;
534 +
535 +    snprintf (file, sizeof (file), "%s/%s", path, de->d_name);
536 +    if (lstat (file, &s) == -1)
537 +      continue;
538 +
539 +    if ((!S_ISREG (s.st_mode)) && (!S_ISLNK (s.st_mode)))
540 +      continue;
541 +
542 +    if (first == NULL)
543 +      cur = first = safe_calloc (1, sizeof (SIG_DIR));
544 +    else
545 +    {
546 +      cur->next = safe_calloc (1, sizeof (SIG_DIR));
547 +      cur = cur->next;
548 +    }
549 +    cur->name = safe_strdup (de->d_name);
550 +    cur->next = NULL;
551 +  }
552 +  closedir (dp);
553 +  return first;
554 +}
555 +
556 +static void sig_dir_make_entry (char *s, size_t slen, MUTTMENU *menu, int num)
557 +{
558 +  ENTRY_DIR *table = (ENTRY_DIR *) menu->data;
559 +
560 +  snprintf (s, slen, "%c %3d - %s",
561 +           table[num].tagged ? '*' : ' ',
562 +           num + 1,
563 +           table[num].data->name);
564 +}
565 +
566 +static int sig_dir_tag (MUTTMENU *menu, int n, int m)
567 +{
568 +  ENTRY_DIR *cur = &((ENTRY_DIR *) menu->data)[n];
569 +  int ot = cur->tagged;
570 +  
571 +  cur->tagged = m >= 0 ? m : !cur->tagged;
572 +  return cur->tagged - ot;
573 +
574 +}
575 +
576 +static int sig_dir_sort (const void *a, const void *b)
577 +{
578 +  ENTRY_DIR *pa = (ENTRY_DIR *) a;
579 +  ENTRY_DIR *pb = (ENTRY_DIR *) b;
580 +
581 +  return (mutt_strcmp (pa->data->name, pb->data->name));
582 +}
583 +
584 +static int sig_dir_menu (char *path, char *msg_file)
585 +{
586 +  MUTTMENU *menu;
587 +  SIG_LIST *sigl;
588 +  LIST *result = NULL;
589 +  ENTRY_DIR *FileTable;
590 +  SIG_DIR *list, *files;
591 +  char buf[STRING], helpstr[SHORT_STRING], title[SHORT_STRING];
592 +  int i, done = 0;
593 +
594 +  if ((list = sig_directory (path)) == NULL)
595 +    return -1;
596 +
597 +  snprintf (title, sizeof (title), "Signature directory : %s", path);
598 +
599 +  menu = mutt_new_menu (MENU_SIG_DIR);
600 +  menu->make_entry = sig_dir_make_entry;
601 +  menu->search = NULL; /* search within files with sig_search_filter() */
602 +  menu->tag = sig_dir_tag;
603 +  menu->title = title;
604 +  menu->help = mutt_compile_help (helpstr, sizeof (helpstr),
605 +                                 MENU_SIG_DIR, SigDirHelp);
606 +
607 +  for (files = list; files; files = files->next)
608 +    menu->max++;
609 +
610 +  menu->data = FileTable = (ENTRY_DIR *) safe_calloc (menu->max,
611 +                                                     sizeof (ENTRY_DIR));
612 +
613 +  for (i = 0, files = list; files; i++, files = files->next)
614 +    FileTable[i].data = files;
615 +
616 +  qsort (FileTable, menu->max, sizeof (ENTRY_DIR), sig_dir_sort);
617 +
618 +  while (!done)
619 +  {
620 +    switch (mutt_menuLoop (menu))
621 +    {
622 +      case OP_SIG_SEARCH:
623 +       sigl = sig_search_filter (menu, path);
624 +
625 +       if (sigl)
626 +       {
627 +         if ((result = sig_list_menu (_("query results"), sigl)) != NULL)
628 +         {
629 +           append_signature (msg_file, result);
630 +           done = 1;
631 +         }
632 +
633 +         MAYBE_REDRAW (menu->redraw);
634 +         free_sig_list (&sigl);
635 +       }
636 +       break;
637 +
638 +      case OP_GENERIC_SELECT_ENTRY:
639 +       snprintf (buf, sizeof (buf), "%s/%s", path,
640 +                 FileTable[menu->current].data->name);
641 +       sigl = NULL;
642 +       read_sig_file (buf, &sigl, NULL);
643 +
644 +       if (sigl)
645 +       {
646 +         if ((result = sig_list_menu (buf, sigl)) != NULL)
647 +         {
648 +           append_signature (msg_file, result);
649 +           done = 1;
650 +         }
651 +
652 +         MAYBE_REDRAW (menu->redraw);
653 +         free_sig_list (&sigl);
654 +       }
655 +       break;
656 +
657 +      case OP_EXIT:
658 +        done = 1;
659 +        break;
660 +    }
661 +  }
662 +
663 +  while (list)
664 +  {
665 +    safe_free ((void **)&list->name);
666 +    files = list;
667 +    list = list->next;
668 +    safe_free ((void **)&files);
669 +  }
670 +  safe_free ((void **)&FileTable);
671 +  mutt_menuDestroy (&menu);
672 +  return 0;
673 +}
674 +
675 +void mutt_signature (char *msg_file)
676 +{
677 +  if (!SigDirectory)
678 +  {
679 +    mutt_error (_("variable 'signatures_directory' is unset"));
680 +    return;
681 +  }
682 +
683 +  if (sig_dir_menu (SigDirectory, msg_file) == -1)
684 +    mutt_error (_("%s: no files in this directory"), SigDirectory);
685 +  else
686 +    set_option (OPTNEEDREDRAW);
687 +}
688 diff -pruN mutt-1.3.27.orig/PATCHES mutt-1.3.27/PATCHES
689 --- mutt-1.3.27.orig/PATCHES    Mon Nov 26 20:16:52 2001
690 +++ mutt-1.3.27/PATCHES Thu Dec  6 16:27:55 2001
691 @@ -1,0 +1 @@
692 +patch-1.3.27.cd.signatures_menu.2.1
693 diff --git a/menu.c b/menu.c
694 --- a/menu.c
695 +++ b/menu.c
696 @@ -642,7 +640,7 @@
697      mutt_error _("No entries.");
698  }
699  
700 -static void menu_next_entry (MUTTMENU *menu)
701 +void menu_next_entry (MUTTMENU *menu)
702  {
703    if (menu->current < menu->max - 1)
704    {
705 @@ -653,7 +651,7 @@
706      mutt_error _("You are on the last entry.");
707  }
708  
709 -static void menu_prev_entry (MUTTMENU *menu)
710 +void menu_prev_entry (MUTTMENU *menu)
711  {
712    if (menu->current)
713    {
This page took 0.114858 seconds and 3 git commands to generate.