1 diff -urNp -x '*.orig' mutt-2.0.6.org/Makefile.am mutt-2.0.6/Makefile.am
2 --- mutt-2.0.6.org/Makefile.am 2021-03-06 20:06:37.000000000 +0100
3 +++ mutt-2.0.6/Makefile.am 2021-04-18 19:23:38.363346256 +0200
4 @@ -36,7 +36,7 @@ mutt_SOURCES = \
5 main.c mbox.c menu.c mh.c mx.c pager.c parse.c pattern.c \
6 postpone.c query.c recvattach.c recvcmd.c \
7 rfc822.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \
8 - score.c send.c sendlib.c signal.c sort.c \
9 + score.c send.c sendlib.c signal.c signature.c sort.c \
10 status.c system.c thread.c charset.c history.c lib.c \
11 mutt_lisp.c muttlib.c editmsg.c mbyte.c \
12 url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c \
13 diff -urNp -x '*.orig' mutt-2.0.6.org/OPS mutt-2.0.6/OPS
14 --- mutt-2.0.6.org/OPS 2021-03-06 20:06:37.000000000 +0100
15 +++ mutt-2.0.6/OPS 2021-04-18 19:23:38.363346256 +0200
18 OP_COMPOSE_EDIT_TO N_("edit the TO list")
20 +/* L10N: Help screen description for OP_COMPOSE_SIG
21 + compose menu: <signature-menu>
23 +OP_COMPOSE_SIG N_("choose a signature")
25 /* L10N: Help screen description for OP_CREATE_MAILBOX
26 browser menu: <create-mailbox>
30 OP_NEXT_PAGE N_("move to the next page")
32 +/* L10N: Help screen description for OP_NEXT_SIG
33 + generic menu: <next-signature>
34 + pager menu: <next-signature>
36 +OP_NEXT_SIG N_("move to the next signature")
38 /* L10N: Help screen description for OP_PAGER_BOTTOM
43 OP_PREV_PAGE N_("move to the previous page")
45 +/* L10N: Help screen description for OP_PREV_SIG
46 + generic menu: <prev-signature>
47 + pager menu: <prev-signature>
49 +OP_PREV_SIG N_("move to the previous signature")
51 /* L10N: Help screen description for OP_PRINT
52 index menu: <print-message>
53 pager menu: <print-message>
54 @@ -1006,6 +1006,12 @@
56 OP_QUIT N_("save changes to mailbox and quit")
58 +/* L10N: Help screen description for OP_RANDOM_SIG
59 + index menu: <random-sig>
60 + pager menu: <random-sig>
62 +OP_RANDOM_SIG N_("use random signature")
64 /* L10N: Help screen description for OP_RECALL_MESSAGE
65 index menu: <recall-message>
66 pager menu: <recall-message>
67 @@ -1055,6 +1072,12 @@
69 OP_SEARCH_OPPOSITE N_("search for next match in opposite direction")
71 +/* L10N: Help screen description for OP_SIG_SEARCH
72 + generic menu: <search-sig>
73 + pager menu: <search-sig>
75 +OP_SIG_SEARCH N_("search signatures matching a pattern")
77 /* L10N: Help screen description for OP_SEARCH_TOGGLE
78 pager menu: <search-toggle>
80 diff -urNp -x '*.orig' mutt-2.0.6.org/PATCHES mutt-2.0.6/PATCHES
81 --- mutt-2.0.6.org/PATCHES 2021-04-18 19:23:38.230011162 +0200
82 +++ mutt-2.0.6/PATCHES 2021-04-18 19:23:38.366679633 +0200
85 +patch-1.3.27.cd.signatures_menu.2.1
86 diff -urNp -x '*.orig' mutt-2.0.6.org/compose.c mutt-2.0.6/compose.c
87 --- mutt-2.0.6.org/compose.c 2020-12-01 04:05:21.000000000 +0100
88 +++ mutt-2.0.6/compose.c 2021-04-18 19:23:38.363346256 +0200
89 @@ -1747,6 +1747,11 @@ int mutt_compose_menu (SEND_CONTEXT *sct
90 /* no send2hook, since this doesn't modify the message */
93 + case OP_COMPOSE_SIG:
94 + mutt_signature(msg->content->filename);
95 + mutt_update_encoding (msg->content);
101 diff -urNp -x '*.orig' mutt-2.0.6.org/doc/manual.xml.head mutt-2.0.6/doc/manual.xml.head
102 --- mutt-2.0.6.org/doc/manual.xml.head 2021-03-06 20:06:37.000000000 +0100
103 +++ mutt-2.0.6/doc/manual.xml.head 2021-04-18 19:23:38.363346256 +0200
104 @@ -525,6 +525,7 @@ linkend="tab-keys-nav-page"/> for page-b
108 +ESC s signature-menu select a signature and append it to your mail
112 diff -urNp -x '*.orig' mutt-2.0.6.org/functions.h mutt-2.0.6/functions.h
113 --- mutt-2.0.6.org/functions.h 2021-03-06 20:06:37.000000000 +0100
114 +++ mutt-2.0.6/functions.h 2021-04-18 19:23:38.363346256 +0200
115 @@ -308,6 +308,7 @@ const struct binding_t OpPager[] = { /*
117 { "what-key", OP_WHAT_KEY, NULL },
118 { "check-stats", OP_CHECK_STATS, NULL },
119 + { "signature-menu", OP_COMPOSE_SIG, "\033s" },
122 { "sidebar-first", OP_SIDEBAR_FIRST, NULL },
123 @@ -458,6 +459,19 @@ const struct binding_t OpQuery[] = { /*
127 +/* Signature Menu */
128 +struct binding_t OpSig[] = {
129 + { "next-sig", OP_NEXT_SIG, "j" },
130 + { "previous-sig", OP_PREV_SIG, "k" },
131 + { "random-sig", OP_RANDOM_SIG, "r" },
135 +struct binding_t OpSigDir[] = {
136 + { "search-sig", OP_SIG_SEARCH, "/" },
140 const struct binding_t OpEditor[] = { /* map: editor */
141 { "bol", OP_EDITOR_BOL, "\001" },
142 { "backward-char", OP_EDITOR_BACKWARD_CHAR, "\002" },
143 diff -urNp -x '*.orig' mutt-2.0.6.org/globals.h mutt-2.0.6/globals.h
144 --- mutt-2.0.6.org/globals.h 2021-04-18 19:23:38.230011162 +0200
145 +++ mutt-2.0.6/globals.h 2021-04-18 19:23:38.363346256 +0200
146 @@ -145,6 +145,7 @@ WHERE char *SidebarFormat;
147 WHERE char *SidebarIndentString;
149 WHERE char *Signature;
150 +WHERE char *SigDirectory;
151 WHERE char *SimpleSearch;
153 WHERE char *SmtpAuthenticators;
154 diff -urNp -x '*.orig' mutt-2.0.6.org/init.h mutt-2.0.6/init.h
155 --- mutt-2.0.6.org/init.h 2021-04-18 19:23:38.230011162 +0200
156 +++ mutt-2.0.6/init.h 2021-04-18 19:23:38.363346256 +0200
157 @@ -1953,6 +1953,14 @@ struct option_t MuttVars[] = {
158 ** automatically generated with \fI<mark-message>a\fP will be composed
159 ** from this prefix and the letter \fIa\fP.
161 + { "signatures_directory", DT_PATH, R_NONE, {.p=&SigDirectory}, {.p=""} },
164 + ** Specifies the path where your signatures are located. In the files of
165 + ** this directory, the signatures are separated by blank lines and/or
166 + ** sig_dashes (``-- '').
167 + ** You can choose between these signatures from the compose menu.
169 { "mark_old", DT_BOOL, R_BOTH, {.l=OPTMARKOLD}, {.l=1} },
172 diff -urNp -x '*.orig' mutt-2.0.6.org/keymap.c mutt-2.0.6/keymap.c
173 --- mutt-2.0.6.org/keymap.c 2021-03-06 20:06:37.000000000 +0100
174 +++ mutt-2.0.6/keymap.c 2021-04-18 19:23:38.366679633 +0200
175 @@ -49,6 +49,8 @@ const struct mapping_t Menus[] = {
176 { "pager", MENU_PAGER },
177 { "postpone", MENU_POST },
179 + { "signature", MENU_SIG },
180 + { "sig_directory", MENU_SIG_DIR },
181 { "smime", MENU_SMIME },
182 #ifdef CRYPT_BACKEND_GPGME
183 { "key_select_pgp", MENU_KEY_SELECT_PGP },
184 @@ -749,6 +751,8 @@ void km_init (void)
185 create_bindings (OpPost, MENU_POST);
186 create_bindings (OpQuery, MENU_QUERY);
187 create_bindings (OpAlias, MENU_ALIAS);
188 + create_bindings (OpSig, MENU_SIG);
189 + create_bindings (OpSigDir, MENU_SIG_DIR);
192 if ((WithCrypto & APPLICATION_PGP))
193 @@ -851,6 +855,9 @@ void km_init (void)
194 km_bindkey ("<enter>", MENU_ATTACH, OP_VIEW_ATTACH);
195 km_bindkey ("<enter>", MENU_COMPOSE, OP_VIEW_ATTACH);
197 + km_bindkey ("<up>", MENU_SIG, OP_PREV_SIG);
198 + km_bindkey ("<down>", MENU_SIG, OP_NEXT_SIG);
200 /* edit-to (default "t") hides generic tag-entry in Compose menu
201 This will bind tag-entry to "T" in the Compose menu */
202 km_bindkey ("T", MENU_COMPOSE, OP_TAG);
203 @@ -1015,6 +1022,10 @@ const struct binding_t *km_get_table (in
213 return (WithCrypto & APPLICATION_PGP)? OpPgp:NULL;
214 diff -urNp -x '*.orig' mutt-2.0.6.org/keymap.h mutt-2.0.6/keymap.h
215 --- mutt-2.0.6.org/keymap.h 2021-03-06 20:06:37.000000000 +0100
216 +++ mutt-2.0.6/keymap.h 2021-04-18 19:23:38.366679633 +0200
217 @@ -63,6 +63,8 @@ enum
226 @@ -105,6 +107,8 @@ const struct binding_t *km_get_table (in
227 extern const struct binding_t OpGeneric[];
228 extern const struct binding_t OpPost[];
229 extern const struct binding_t OpMain[];
230 +extern struct binding_t OpSig[];
231 +extern struct binding_t OpSigDir[];
232 extern const struct binding_t OpAttach[];
233 extern const struct binding_t OpPager[];
234 extern const struct binding_t OpCompose[];
235 diff -urNp -x '*.orig' mutt-2.0.6.org/menu.c mutt-2.0.6/menu.c
236 --- mutt-2.0.6.org/menu.c 2021-04-18 19:23:38.230011162 +0200
237 +++ mutt-2.0.6/menu.c 2021-04-18 19:23:38.366679633 +0200
238 @@ -683,7 +683,7 @@ void menu_current_bottom (MUTTMENU *menu
239 mutt_error _("No entries.");
242 -static void menu_next_entry (MUTTMENU *menu)
243 +void menu_next_entry (MUTTMENU *menu)
245 if (menu->current < menu->max - 1)
247 @@ -694,7 +694,7 @@ static void menu_next_entry (MUTTMENU *m
248 mutt_error _("You are on the last entry.");
251 -static void menu_prev_entry (MUTTMENU *menu)
252 +void menu_prev_entry (MUTTMENU *menu)
256 diff -urNp -x '*.orig' mutt-2.0.6.org/protos.h mutt-2.0.6/protos.h
257 --- mutt-2.0.6.org/protos.h 2021-03-06 20:06:37.000000000 +0100
258 +++ mutt-2.0.6/protos.h 2021-04-18 19:23:38.366679633 +0200
259 @@ -224,6 +224,7 @@ void mutt_free_body (BODY **);
260 void mutt_free_body (BODY **);
261 void mutt_free_enter_state (ENTER_STATE **);
262 void mutt_free_envelope (ENVELOPE **);
263 +void mutt_signature (char *);
264 void mutt_free_header (HEADER **);
265 void mutt_free_parameter (PARAMETER **);
266 void mutt_free_regexp (REGEXP **);
267 diff -urNp -x '*.orig' mutt-2.0.6.org/signature.c mutt-2.0.6/signature.c
268 --- mutt-2.0.6.org/signature.c 1970-01-01 01:00:00.000000000 +0100
269 +++ mutt-2.0.6/signature.c 2021-04-18 19:23:38.366679633 +0200
272 + * Copyright (C) 2001 Cedric Duval <cedricduval@free.fr>
274 + * This program is free software; you can redistribute it and/or modify
275 + * it under the terms of the GNU General Public License as published by
276 + * the Free Software Foundation; either version 2 of the License, or
277 + * (at your option) any later version.
279 + * This program is distributed in the hope that it will be useful,
280 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
281 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
282 + * GNU General Public License for more details.
284 + * You should have received a copy of the GNU General Public License
285 + * along with this program; if not, write to the Free Software
286 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
290 +# include "config.h"
294 +#include "mutt_menu.h"
295 +#include "mapping.h"
296 +#include "mutt_curses.h"
302 +#include <sys/stat.h>
304 +#define SIG_DISPLAY_LINES 4
305 +#define SEPARATOR(x) ((*x == '\n') || (mutt_strcmp (x, "-- \n") == 0))
306 +#define SIG_ADD_LINE(x,y) mutt_add_list (x, strtok (y, "\n"))
308 +typedef struct sig_list
310 + struct sig_list *next;
314 +typedef struct sig_dir
316 + struct sig_dir *next;
320 +typedef LIST * ENTRY;
322 +typedef struct entry_dir
328 +static struct mapping_t SigHelp[] = {
329 + { N_("Exit"), OP_EXIT },
330 + { N_("Search"), OP_SEARCH },
331 + { N_("Random"), OP_RANDOM_SIG },
332 + { N_("Help"), OP_HELP },
336 +static struct mapping_t SigDirHelp[] = {
337 + { N_("Exit"), OP_EXIT },
338 + { N_("Search signature"), OP_SIG_SEARCH },
339 + { N_("Help"), OP_HELP },
343 +void menu_next_entry (MUTTMENU *menu);
344 +void menu_prev_entry (MUTTMENU *menu);
347 +static int sig_match (LIST *s, regex_t *re)
351 + if (regexec (re, s->data, (size_t)0, NULL, (int)0) == 0)
358 +static void read_sig_file (char *name, SIG_LIST **begin, regex_t *re)
363 + SIG_LIST *first, *cur;
366 + if (!(fp = safe_fopen (name, "r")))
368 + mutt_error (_("Can't open signature file %s"), name);
372 + for (first = *begin; first && first->next; first = first->next, append++)
373 + ; /* append results to an existing list */
376 + while (fgets (buf, sizeof (buf), fp))
378 + if (buf[0] && !SEPARATOR (buf))
380 + sig = SIG_ADD_LINE (NULL, buf);
382 + while (fgets (buf, sizeof (buf), fp) && buf[0] && !SEPARATOR (buf))
383 + SIG_ADD_LINE (sig, buf);
385 + if (re && !sig_match (sig, re))
386 + mutt_free_list (&sig); /* previous sig didn't match the regexp */
389 + /* add signature */
391 + first = cur = (SIG_LIST *) safe_calloc (1, sizeof (SIG_LIST));
394 + cur->next = (SIG_LIST *) safe_calloc (1, sizeof (SIG_LIST));
410 +static void sig_make_entry (char *s, size_t slen, MUTTMENU *menu, int num)
412 + ENTRY *table = (ENTRY *) menu->data;
414 + snprintf (s, slen, "%3d %s",
419 +static int sig_menu_search (MUTTMENU *menu, regex_t *re, int num)
421 + return (sig_match (((ENTRY *)menu->data)[num], re) ? 0 : REG_NOMATCH);
424 +static void draw_sig_frame (LIST *s)
428 + for (i = 1; i <= SIG_DISPLAY_LINES; i++)
432 + mvaddstr (i, 0, s->data);
441 + SETCOLOR (MT_COLOR_STATUS);
442 + mvaddstr (SIG_DISPLAY_LINES + 1, 0, _("-- Signature"));
443 + SETCOLOR (MT_COLOR_STATUS);
449 +static void free_sig_list (SIG_LIST **sigs)
456 + *sigs = (*sigs)->next;
457 + mutt_free_list (&cur->sig);
458 + safe_free ((void **)&cur);
462 +static void append_signature (char *msg_file, LIST *s)
466 + if ((fp = safe_fopen (msg_file, "a")) == 0)
467 + mutt_perror (msg_file);
470 + if (option (OPTSIGDASHES))
471 + fputs ("\n-- \n", fp);
473 + for (; s; s = s->next)
474 + fprintf (fp, "%s\n", s->data);
476 + mutt_message (_("Signature appended to your mail"));
481 +static LIST *sig_list_menu (char *file, SIG_LIST *list)
483 + LIST *result = NULL;
487 + char helpstr[SHORT_STRING], title[SHORT_STRING];
490 + snprintf (title, sizeof (title), _("Signature : %s"), file);
492 + menu = mutt_new_menu (MENU_SIG);
493 + menu->make_entry = sig_make_entry;
495 + menu->search = sig_menu_search;
496 + menu->title = title;
497 + menu->help = mutt_compile_help (helpstr, sizeof (helpstr),
498 + MENU_SIG, SigHelp);
499 + menu->offset = SIG_DISPLAY_LINES + 2;
500 + menu->pagelen = LINES - SIG_DISPLAY_LINES - 4;
502 + for (sigl = list; sigl; sigl = sigl->next)
505 + menu->data = SigTable = (ENTRY *) safe_calloc (menu->max, sizeof (ENTRY));
507 + for (i = 0, sigl = list; sigl; i++, sigl = sigl->next)
508 + SigTable[i] = sigl->sig;
512 + switch (mutt_menuLoop (menu))
514 + case OP_GENERIC_SELECT_ENTRY:
515 + result = SigTable[menu->current];
520 + menu_prev_entry (menu);
521 + draw_sig_frame (SigTable[menu->current]);
525 + menu_next_entry (menu);
526 + draw_sig_frame (SigTable[menu->current]);
530 + menu->offset = SIG_DISPLAY_LINES + 2;
531 + menu->pagelen = LINES - SIG_DISPLAY_LINES - 4;
532 + draw_sig_frame (SigTable[menu->current]);
535 + case OP_RANDOM_SIG:
536 + menu->current = LRAND () % menu->max;
537 + draw_sig_frame (SigTable[menu->current]);
538 + menu->redraw |= REDRAW_MOTION;
547 + mutt_menuDestroy (&menu);
548 + safe_free ((void **)&SigTable);
552 +extern char* SearchBuffers[MENU_MAX];
554 +static SIG_LIST *sig_search_filter (MUTTMENU *menu, char *path)
558 + SIG_LIST *result = NULL;
560 + char* searchBuf = menu->menu >= 0 && menu->menu < MENU_MAX ?
561 + SearchBuffers[menu->menu] : NULL;
563 + snprintf (buf, sizeof(buf), searchBuf ? searchBuf : "");
564 + if (mutt_get_field (_("Search for: "), buf,
565 + sizeof (buf), MUTT_CLEAR) != 0 || !buf[0])
567 + if (menu->menu >= 0 && menu->menu < MENU_MAX)
569 + mutt_str_replace (&SearchBuffers[menu->menu], buf);
570 + searchBuf = SearchBuffers[menu->menu];
573 + if ((i = regcomp (&re, searchBuf, REG_NOSUB | REG_EXTENDED | REG_WORDS
574 + | mutt_which_case (searchBuf))) != 0)
576 + regerror (i, &re, buf, sizeof (buf));
578 + mutt_error ("%s", buf);
582 + /* building list of sigs matching the regexp */
583 + for (i = 0; i < menu->max; i++)
585 + /* search in every file if none is tagged */
586 + if (((ENTRY_DIR *) menu->data)[i].tagged || (menu->tagged == 0))
588 + snprintf (buf, sizeof (buf), "%s/%s", path,
589 + ((ENTRY_DIR *) menu->data)[i].data->name);
590 + read_sig_file (buf, &result, &re);
596 + mutt_error (_("Not found."));
601 +/* returns the list of files in this directory */
602 +static SIG_DIR *sig_directory (char *path)
607 + SIG_DIR *first = NULL, *cur = NULL;
608 + char file[_POSIX_PATH_MAX + SHORT_STRING];
610 + if ((dp = opendir (path)) == NULL)
612 + mutt_perror (path);
616 + while ((de = readdir (dp)))
618 + if ((de->d_name)[0] == '.') /* no hidden files */
621 + snprintf (file, sizeof (file), "%s/%s", path, de->d_name);
622 + if (lstat (file, &s) == -1)
625 + if ((!S_ISREG (s.st_mode)) && (!S_ISLNK (s.st_mode)))
629 + cur = first = safe_calloc (1, sizeof (SIG_DIR));
632 + cur->next = safe_calloc (1, sizeof (SIG_DIR));
635 + cur->name = safe_strdup (de->d_name);
642 +static void sig_dir_make_entry (char *s, size_t slen, MUTTMENU *menu, int num)
644 + ENTRY_DIR *table = (ENTRY_DIR *) menu->data;
646 + snprintf (s, slen, "%c %3d - %s",
647 + table[num].tagged ? '*' : ' ',
649 + table[num].data->name);
652 +static int sig_dir_tag (MUTTMENU *menu, int n, int m)
654 + ENTRY_DIR *cur = &((ENTRY_DIR *) menu->data)[n];
655 + int ot = cur->tagged;
657 + cur->tagged = m >= 0 ? m : !cur->tagged;
658 + return cur->tagged - ot;
662 +static int sig_dir_sort (const void *a, const void *b)
664 + ENTRY_DIR *pa = (ENTRY_DIR *) a;
665 + ENTRY_DIR *pb = (ENTRY_DIR *) b;
667 + return (mutt_strcmp (pa->data->name, pb->data->name));
670 +static int sig_dir_menu (char *path, char *msg_file)
674 + LIST *result = NULL;
675 + ENTRY_DIR *FileTable;
676 + SIG_DIR *list, *files;
677 + char buf[STRING], helpstr[SHORT_STRING], title[SHORT_STRING];
680 + if ((list = sig_directory (path)) == NULL)
683 + snprintf (title, sizeof (title), "Signature directory : %s", path);
685 + menu = mutt_new_menu (MENU_SIG_DIR);
686 + menu->make_entry = sig_dir_make_entry;
687 + menu->search = NULL; /* search within files with sig_search_filter() */
688 + menu->tag = sig_dir_tag;
689 + menu->title = title;
690 + menu->help = mutt_compile_help (helpstr, sizeof (helpstr),
691 + MENU_SIG_DIR, SigDirHelp);
693 + for (files = list; files; files = files->next)
696 + menu->data = FileTable = (ENTRY_DIR *) safe_calloc (menu->max,
697 + sizeof (ENTRY_DIR));
699 + for (i = 0, files = list; files; i++, files = files->next)
700 + FileTable[i].data = files;
702 + qsort (FileTable, menu->max, sizeof (ENTRY_DIR), sig_dir_sort);
706 + switch (mutt_menuLoop (menu))
708 + case OP_SIG_SEARCH:
709 + sigl = sig_search_filter (menu, path);
713 + if ((result = sig_list_menu (_("query results"), sigl)) != NULL)
715 + append_signature (msg_file, result);
719 + free_sig_list (&sigl);
723 + case OP_GENERIC_SELECT_ENTRY:
724 + snprintf (buf, sizeof (buf), "%s/%s", path,
725 + FileTable[menu->current].data->name);
727 + read_sig_file (buf, &sigl, NULL);
731 + if ((result = sig_list_menu (buf, sigl)) != NULL)
733 + append_signature (msg_file, result);
737 + free_sig_list (&sigl);
749 + safe_free ((void **)&list->name);
752 + safe_free ((void **)&files);
754 + safe_free ((void **)&FileTable);
755 + mutt_menuDestroy (&menu);
759 +void mutt_signature (char *msg_file)
763 + mutt_error (_("variable 'signatures_directory' is unset"));
767 + if (sig_dir_menu (SigDirectory, msg_file) == -1)
768 + mutt_error (_("%s: no files in this directory"), SigDirectory);