forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias.c
771 lines (696 loc) · 19.5 KB
/
alias.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
/**
* @file
* Representation of a single alias to an email address
*
* @authors
* Copyright (C) 1996-2002 Michael R. Elkins <[email protected]>
* Copyright (C) 2019 Pietro Cerutti <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @page alias Representation of a single alias to an email address
*
* Representation of a single alias to an email address
*/
#include "config.h"
#include <stddef.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "alias.h"
#include "addrbook.h"
#include "globals.h"
#include "hdrline.h"
#include "muttlib.h"
#include "sendlib.h"
/**
* expand_aliases_r - Expand aliases, recursively
* @param[in] al Address List
* @param[out] expn Alias List
* @retval ptr Address List with aliases expanded
*
* ListHead expn is used as temporary storage for already-expanded aliases.
*/
static void expand_aliases_r(struct AddressList *al, struct ListHead *expn)
{
struct Address *a = TAILQ_FIRST(al);
while (a)
{
if (!a->group && !a->personal && a->mailbox && !strchr(a->mailbox, '@'))
{
struct AddressList *alias = mutt_alias_lookup(a->mailbox);
if (alias)
{
bool duplicate = false;
struct ListNode *np = NULL;
STAILQ_FOREACH(np, expn, entries)
{
if (mutt_str_strcmp(a->mailbox, np->data) == 0) /* alias already found */
{
mutt_debug(LL_DEBUG1, "loop in alias found for '%s'\n", a->mailbox);
duplicate = true;
break;
}
}
if (duplicate)
{
// We've already seen this alias, so drop it
struct Address *next = TAILQ_NEXT(a, entries);
TAILQ_REMOVE(al, a, entries);
mutt_addr_free(&a);
a = next;
continue;
}
// Keep a list of aliases that we've already seen
mutt_list_insert_head(expn, mutt_str_strdup(a->mailbox));
/* The alias may expand to several addresses,
* some of which may themselves be aliases.
* Create a copy and recursively expand any aliases within. */
struct AddressList copy = TAILQ_HEAD_INITIALIZER(copy);
mutt_addrlist_copy(©, alias, false);
expand_aliases_r(©, expn);
/* Next, move the expanded addresses
* from the copy into the original list (before the alias) */
struct Address *a2 = NULL, *tmp = NULL;
TAILQ_FOREACH_SAFE(a2, ©, entries, tmp)
{
TAILQ_INSERT_BEFORE(a, a2, entries);
}
a = TAILQ_PREV(a, AddressList, entries);
// Finally, remove the alias itself
struct Address *next = TAILQ_NEXT(a, entries);
TAILQ_REMOVE(al, next, entries);
mutt_addr_free(&next);
}
else
{
struct passwd *pw = getpwnam(a->mailbox);
if (pw)
{
char namebuf[256];
mutt_gecos_name(namebuf, sizeof(namebuf), pw);
mutt_str_replace(&a->personal, namebuf);
}
}
}
a = TAILQ_NEXT(a, entries);
}
const char *fqdn = NULL;
if (C_UseDomain && (fqdn = mutt_fqdn(true)))
{
/* now qualify all local addresses */
mutt_addrlist_qualify(al, fqdn);
}
}
/**
* mutt_alias_new - Create a new Alias
* @retval ptr Newly allocated Alias
*
* Free the result with mutt_alias_free()
*/
struct Alias *mutt_alias_new(void)
{
struct Alias *a = mutt_mem_calloc(1, sizeof(struct Alias));
TAILQ_INIT(&a->addr);
return a;
}
/**
* write_safe_address - Defang malicious email addresses
* @param fp File to write to
* @param s Email address to defang
*
* if someone has an address like
* From: Michael `/bin/rm -f ~` Elkins <[email protected]>
* and the user creates an alias for this, NeoMutt could wind up executing
* the backticks because it writes aliases like
* alias me Michael `/bin/rm -f ~` Elkins <[email protected]>
* To avoid this problem, use a backslash (\) to quote any backticks. We also
* need to quote backslashes as well, since you could defeat the above by
* doing
* From: Michael \`/bin/rm -f ~\` Elkins <[email protected]>
* since that would get aliased as
* alias me Michael \\`/bin/rm -f ~\\` Elkins <[email protected]>
* which still gets evaluated because the double backslash is not a quote.
*
* Additionally, we need to quote ' and " characters - otherwise, neomutt will
* interpret them on the wrong parsing step.
*
* $ wants to be quoted since it may indicate the start of an environment
* variable.
*/
static void write_safe_address(FILE *fp, char *s)
{
while (*s)
{
if ((*s == '\\') || (*s == '`') || (*s == '\'') || (*s == '"') || (*s == '$'))
fputc('\\', fp);
fputc(*s, fp);
s++;
}
}
/**
* recode_buf - Convert some text between two character sets
* @param buf Buffer to convert
* @param buflen Length of buffer
*
* The 'from' charset is controlled by the 'charset' config variable.
* The 'to' charset is controlled by the 'config_charset' config variable.
*/
static void recode_buf(char *buf, size_t buflen)
{
if (!C_ConfigCharset || !C_Charset)
return;
char *s = mutt_str_strdup(buf);
if (!s)
return;
if (mutt_ch_convert_string(&s, C_Charset, C_ConfigCharset, 0) == 0)
mutt_str_strfcpy(buf, s, buflen);
FREE(&s);
}
/**
* check_alias_name - Sanity-check an alias name
* @param s Alias to check
* @param dest Buffer for the result
* @param destlen Length of buffer
* @retval 0 Success
* @retval -1 Error
*
* Only characters which are non-special to both the RFC822 and the neomutt
* configuration parser are permitted.
*/
static int check_alias_name(const char *s, char *dest, size_t destlen)
{
wchar_t wc;
mbstate_t mb;
size_t l;
int rc = 0;
bool dry = !dest || !destlen;
memset(&mb, 0, sizeof(mbstate_t));
if (!dry)
destlen--;
for (; s && *s && (dry || destlen) && (l = mbrtowc(&wc, s, MB_CUR_MAX, &mb)) != 0;
s += l, destlen -= l)
{
bool bad = (l == (size_t)(-1)) || (l == (size_t)(-2)); /* conversion error */
bad = bad || (!dry && l > destlen); /* too few room for mb char */
if (l == 1)
bad = bad || (!strchr("-_+=.", *s) && !iswalnum(wc));
else
bad = bad || !iswalnum(wc);
if (bad)
{
if (dry)
return -1;
if (l == (size_t)(-1))
memset(&mb, 0, sizeof(mbstate_t));
*dest++ = '_';
rc = -1;
}
else if (!dry)
{
memcpy(dest, s, l);
dest += l;
}
}
if (!dry)
*dest = '\0';
return rc;
}
/**
* string_is_address - Does an email address match a user and domain?
* @param str Address string to test
* @param u User name
* @param d Domain name
* @retval true They match
*/
static bool string_is_address(const char *str, const char *u, const char *d)
{
char buf[1024];
snprintf(buf, sizeof(buf), "%s@%s", NONULL(u), NONULL(d));
if (mutt_str_strcasecmp(str, buf) == 0)
return true;
return false;
}
/**
* mutt_alias_lookup - Find an Alias
* @param s Alias string to find
* @retval ptr Address for the Alias
* @retval NULL No such Alias
*
* @note The search is case-insensitive
*/
struct AddressList *mutt_alias_lookup(const char *s)
{
struct Alias *a = NULL;
TAILQ_FOREACH(a, &Aliases, entries)
{
if (mutt_str_strcasecmp(s, a->name) == 0)
return &a->addr;
}
return NULL;
}
/**
* mutt_expand_aliases - Expand aliases in a List of Addresses
* @param al AddressList
*
* Duplicate addresses are dropped
*/
void mutt_expand_aliases(struct AddressList *al)
{
struct ListHead expn; /* previously expanded aliases to avoid loops */
STAILQ_INIT(&expn);
expand_aliases_r(al, &expn);
mutt_list_free(&expn);
mutt_addrlist_dedupe(al);
}
/**
* mutt_expand_aliases_env - Expand aliases in all the fields of an Envelope
* @param env Envelope to expand
*/
void mutt_expand_aliases_env(struct Envelope *env)
{
mutt_expand_aliases(&env->from);
mutt_expand_aliases(&env->to);
mutt_expand_aliases(&env->cc);
mutt_expand_aliases(&env->bcc);
mutt_expand_aliases(&env->reply_to);
mutt_expand_aliases(&env->mail_followup_to);
}
/**
* mutt_get_address - Get an Address from an Envelope
* @param[in] env Envelope to examine
* @param[out] pfxp Prefix for the Address, e.g. "To:"
* @retval ptr AddressList in the Envelope
*
* @note The caller must NOT free the returned AddressList
*/
struct AddressList *mutt_get_address(struct Envelope *env, const char **pfxp)
{
struct AddressList *al = NULL;
const char *pfx = NULL;
if (mutt_addr_is_user(TAILQ_FIRST(&env->from)))
{
if (!TAILQ_EMPTY(&env->to) && !mutt_is_mail_list(TAILQ_FIRST(&env->to)))
{
pfx = "To";
al = &env->to;
}
else
{
pfx = "Cc";
al = &env->cc;
}
}
else if (!TAILQ_EMPTY(&env->reply_to) && !mutt_is_mail_list(TAILQ_FIRST(&env->reply_to)))
{
pfx = "Reply-To";
al = &env->reply_to;
}
else
{
al = &env->from;
pfx = "From";
}
if (pfxp)
*pfxp = pfx;
return al;
}
/**
* mutt_alias_create - Create a new Alias from an Envelope or an Address
* @param cur Envelope to use
* @param al Address to use
*/
void mutt_alias_create(struct Envelope *cur, struct AddressList *al)
{
struct Address *addr = NULL;
char buf[1024], tmp[1024] = { 0 }, prompt[128];
char *pc = NULL;
char *err = NULL;
char fixed[1024];
if (cur)
{
al = mutt_get_address(cur, NULL);
}
if (al)
{
addr = TAILQ_FIRST(al);
if (addr && addr->mailbox)
{
mutt_str_strfcpy(tmp, addr->mailbox, sizeof(tmp));
pc = strchr(tmp, '@');
if (pc)
*pc = '\0';
}
}
/* Don't suggest a bad alias name in the event of a strange local part. */
check_alias_name(tmp, buf, sizeof(buf));
retry_name:
/* L10N: prompt to add a new alias */
if ((mutt_get_field(_("Alias as: "), buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0) ||
!buf[0])
{
return;
}
/* check to see if the user already has an alias defined */
if (mutt_alias_lookup(buf))
{
mutt_error(_("You already have an alias defined with that name"));
return;
}
if (check_alias_name(buf, fixed, sizeof(fixed)))
{
switch (mutt_yesorno(_("Warning: This alias name may not work. Fix it?"), MUTT_YES))
{
case MUTT_YES:
mutt_str_strfcpy(buf, fixed, sizeof(buf));
goto retry_name;
case MUTT_ABORT:
return;
default:; // do nothing
}
}
struct Alias *alias = mutt_alias_new();
alias->name = mutt_str_strdup(buf);
mutt_addrlist_to_local(al);
if (addr && addr->mailbox)
mutt_str_strfcpy(buf, addr->mailbox, sizeof(buf));
else
buf[0] = '\0';
mutt_addrlist_to_intl(al, NULL);
do
{
if ((mutt_get_field(_("Address: "), buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0) ||
!buf[0])
{
mutt_alias_free(&alias);
return;
}
mutt_addrlist_parse(&alias->addr, buf);
if (TAILQ_EMPTY(&alias->addr))
mutt_beep(false);
if (mutt_addrlist_to_intl(&alias->addr, &err))
{
mutt_error(_("Bad IDN: '%s'"), err);
FREE(&err);
continue;
}
} while (TAILQ_EMPTY(&alias->addr));
if (addr && addr->personal && !mutt_is_mail_list(addr))
mutt_str_strfcpy(buf, addr->personal, sizeof(buf));
else
buf[0] = '\0';
if (mutt_get_field(_("Personal name: "), buf, sizeof(buf), MUTT_COMP_NO_FLAGS) != 0)
{
mutt_alias_free(&alias);
return;
}
mutt_str_replace(&TAILQ_FIRST(&alias->addr)->personal, buf);
buf[0] = '\0';
mutt_addrlist_write(&alias->addr, buf, sizeof(buf), true);
snprintf(prompt, sizeof(prompt), _("[%s = %s] Accept?"), alias->name, buf);
if (mutt_yesorno(prompt, MUTT_YES) != MUTT_YES)
{
mutt_alias_free(&alias);
return;
}
mutt_alias_add_reverse(alias);
TAILQ_INSERT_TAIL(&Aliases, alias, entries);
mutt_str_strfcpy(buf, C_AliasFile, sizeof(buf));
if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), MUTT_FILE) != 0)
return;
mutt_expand_path(buf, sizeof(buf));
FILE *fp_alias = fopen(buf, "a+");
if (!fp_alias)
{
mutt_perror(buf);
return;
}
/* terminate existing file with \n if necessary */
if (fseek(fp_alias, 0, SEEK_END))
goto fseek_err;
if (ftell(fp_alias) > 0)
{
if (fseek(fp_alias, -1, SEEK_CUR) < 0)
goto fseek_err;
if (fread(buf, 1, 1, fp_alias) != 1)
{
mutt_perror(_("Error reading alias file"));
mutt_file_fclose(&fp_alias);
return;
}
if (fseek(fp_alias, 0, SEEK_END) < 0)
goto fseek_err;
if (buf[0] != '\n')
fputc('\n', fp_alias);
}
if (check_alias_name(alias->name, NULL, 0))
mutt_file_quote_filename(alias->name, buf, sizeof(buf));
else
mutt_str_strfcpy(buf, alias->name, sizeof(buf));
recode_buf(buf, sizeof(buf));
fprintf(fp_alias, "alias %s ", buf);
buf[0] = '\0';
mutt_addrlist_write(&alias->addr, buf, sizeof(buf), false);
recode_buf(buf, sizeof(buf));
write_safe_address(fp_alias, buf);
fputc('\n', fp_alias);
if (mutt_file_fsync_close(&fp_alias) != 0)
mutt_perror(_("Trouble adding alias"));
else
mutt_message(_("Alias added"));
return;
fseek_err:
mutt_perror(_("Error seeking in alias file"));
mutt_file_fclose(&fp_alias);
}
/**
* mutt_alias_reverse_lookup - Does the user have an alias for the given address
* @param a Address to lookup
* @retval ptr Matching Address
*/
struct Address *mutt_alias_reverse_lookup(const struct Address *a)
{
if (!a || !a->mailbox)
return NULL;
return mutt_hash_find(ReverseAliases, a->mailbox);
}
/**
* mutt_alias_add_reverse - Add an email address lookup for an Alias
* @param t Alias to use
*/
void mutt_alias_add_reverse(struct Alias *t)
{
if (!t)
return;
/* Note that the address mailbox should be converted to intl form
* before using as a key in the hash. This is currently done
* by all callers, but added here mostly as documentation. */
mutt_addrlist_to_intl(&t->addr, NULL);
struct Address *a = NULL;
TAILQ_FOREACH(a, &t->addr, entries)
{
if (!a->group && a->mailbox)
mutt_hash_insert(ReverseAliases, a->mailbox, a);
}
}
/**
* mutt_alias_delete_reverse - Remove an email address lookup for an Alias
* @param t Alias to use
*/
void mutt_alias_delete_reverse(struct Alias *t)
{
if (!t)
return;
/* If the alias addresses were converted to local form, they won't
* match the hash entries. */
mutt_addrlist_to_intl(&t->addr, NULL);
struct Address *a = NULL;
TAILQ_FOREACH(a, &t->addr, entries)
{
if (!a->group && a->mailbox)
mutt_hash_delete(ReverseAliases, a->mailbox, a);
}
}
/**
* mutt_alias_complete - alias completion routine
* @param buf Partial Alias to complete
* @param buflen Length of buffer
* @retval 1 Success
* @retval 0 Error
*
* Given a partial alias, this routine attempts to fill in the alias
* from the alias list as much as possible. if given empty search string
* or found nothing, present all aliases
*/
int mutt_alias_complete(char *buf, size_t buflen)
{
struct Alias *a = NULL, *tmp = NULL;
struct AliasList a_list = TAILQ_HEAD_INITIALIZER(a_list);
char bestname[8192] = { 0 };
if (buf[0] != '\0') /* avoid empty string as strstr argument */
{
TAILQ_FOREACH(a, &Aliases, entries)
{
if (a->name && (strncmp(a->name, buf, strlen(buf)) == 0))
{
if (bestname[0] == '\0') /* init */
{
mutt_str_strfcpy(bestname, a->name,
MIN(mutt_str_strlen(a->name) + 1, sizeof(bestname)));
}
else
{
int i;
for (i = 0; a->name[i] && (a->name[i] == bestname[i]); i++)
;
bestname[i] = '\0';
}
}
}
if (bestname[0] != '\0')
{
if (mutt_str_strcmp(bestname, buf) != 0)
{
/* we are adding something to the completion */
mutt_str_strfcpy(buf, bestname, mutt_str_strlen(bestname) + 1);
return 1;
}
/* build alias list and show it */
TAILQ_FOREACH(a, &Aliases, entries)
{
if (a->name && (strncmp(a->name, buf, strlen(buf)) == 0))
{
tmp = mutt_mem_calloc(1, sizeof(struct Alias));
memcpy(tmp, a, sizeof(struct Alias));
TAILQ_INSERT_TAIL(&a_list, tmp, entries);
}
}
}
}
bestname[0] = '\0';
mutt_alias_menu(bestname, sizeof(bestname), !TAILQ_EMPTY(&a_list) ? &a_list : &Aliases);
if (bestname[0] != '\0')
mutt_str_strfcpy(buf, bestname, buflen);
/* free the alias list */
TAILQ_FOREACH_SAFE(a, &a_list, entries, tmp)
{
TAILQ_REMOVE(&a_list, a, entries);
FREE(&a);
}
/* remove any aliases marked for deletion */
TAILQ_FOREACH_SAFE(a, &Aliases, entries, tmp)
{
if (a->del)
{
TAILQ_REMOVE(&Aliases, a, entries);
mutt_alias_free(&a);
}
}
return 0;
}
/**
* mutt_addr_is_user - Does the address belong to the user
* @param addr Address to check
* @retval true if the given address belongs to the user
*/
bool mutt_addr_is_user(const struct Address *addr)
{
if (!addr)
{
mutt_debug(LL_DEBUG5, "no, NULL address\n");
return false;
}
if (!addr->mailbox)
{
mutt_debug(LL_DEBUG5, "no, no mailbox\n");
return false;
}
if (mutt_str_strcasecmp(addr->mailbox, Username) == 0)
{
mutt_debug(LL_DEBUG5, "#1 yes, %s = %s\n", addr->mailbox, Username);
return true;
}
if (string_is_address(addr->mailbox, Username, ShortHostname))
{
mutt_debug(LL_DEBUG5, "#2 yes, %s = %s @ %s\n", addr->mailbox, Username, ShortHostname);
return true;
}
const char *fqdn = mutt_fqdn(false);
if (string_is_address(addr->mailbox, Username, fqdn))
{
mutt_debug(LL_DEBUG5, "#3 yes, %s = %s @ %s\n", addr->mailbox, Username, NONULL(fqdn));
return true;
}
fqdn = mutt_fqdn(true);
if (string_is_address(addr->mailbox, Username, fqdn))
{
mutt_debug(LL_DEBUG5, "#4 yes, %s = %s @ %s\n", addr->mailbox, Username, NONULL(fqdn));
return true;
}
if (C_From && (mutt_str_strcasecmp(C_From->mailbox, addr->mailbox) == 0))
{
mutt_debug(LL_DEBUG5, "#5 yes, %s = %s\n", addr->mailbox, C_From->mailbox);
return true;
}
if (mutt_regexlist_match(&Alternates, addr->mailbox))
{
mutt_debug(LL_DEBUG5, "yes, %s matched by alternates\n", addr->mailbox);
if (mutt_regexlist_match(&UnAlternates, addr->mailbox))
mutt_debug(LL_DEBUG5, "but, %s matched by unalternates\n", addr->mailbox);
else
return true;
}
mutt_debug(LL_DEBUG5, "no, all failed\n");
return false;
}
/**
* mutt_alias_free - Free an Alias
* @param[out] ptr Alias to free
*/
void mutt_alias_free(struct Alias **ptr)
{
if (!ptr || !*ptr)
return;
struct Alias *a = *ptr;
mutt_alias_delete_reverse(a);
FREE(&a->name);
mutt_addrlist_clear(&(a->addr));
FREE(ptr);
}
/**
* mutt_aliaslist_free - Free a List of Aliases
* @param a_list AliasList to free
*/
void mutt_aliaslist_free(struct AliasList *a_list)
{
struct Alias *a = NULL, *tmp = NULL;
TAILQ_FOREACH_SAFE(a, a_list, entries, tmp)
{
TAILQ_REMOVE(a_list, a, entries);
mutt_alias_free(&a);
}
TAILQ_INIT(a_list);
}