forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maillist.c
136 lines (129 loc) · 3.72 KB
/
maillist.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
/**
* @file
* Handle mailing lists
*
* @authors
* Copyright (C) 2020 Richard Russon <[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 neo_maillist Handle mailing lists
*
* Handle mailing lists
*/
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "email/lib.h"
#include "maillist.h"
#include "muttlib.h"
#include "sort.h"
/**
* mutt_is_mail_list - Is this the email address of a mailing list? - Implements ::addr_predicate_t - @ingroup addr_predicate_api
* @param addr Address to test
* @retval true It's a mailing list
*/
bool mutt_is_mail_list(const struct Address *addr)
{
if (!mutt_regexlist_match(&UnMailLists, addr->mailbox))
return mutt_regexlist_match(&MailLists, addr->mailbox);
return false;
}
/**
* mutt_is_subscribed_list - Is this the email address of a user-subscribed mailing list? - Implements ::addr_predicate_t - @ingroup addr_predicate_api
* @param addr Address to test
* @retval true It's a subscribed mailing list
*/
bool mutt_is_subscribed_list(const struct Address *addr)
{
if (!mutt_regexlist_match(&UnMailLists, addr->mailbox) &&
!mutt_regexlist_match(&UnSubscribedLists, addr->mailbox))
{
return mutt_regexlist_match(&SubscribedLists, addr->mailbox);
}
return false;
}
/**
* check_for_mailing_list - Search list of addresses for a mailing list
* @param al AddressList to search
* @param pfx Prefix string
* @param buf Buffer to store results
* @param buflen Buffer length
* @retval 1 Mailing list found
* @retval 0 No list found
*
* Search for a mailing list in the list of addresses pointed to by addr.
* If one is found, print pfx and the name of the list into buf.
*/
bool check_for_mailing_list(struct AddressList *al, const char *pfx, char *buf, int buflen)
{
struct Address *a = NULL;
TAILQ_FOREACH(a, al, entries)
{
if (mutt_is_subscribed_list(a))
{
if (pfx && buf && buflen)
snprintf(buf, buflen, "%s%s", pfx, mutt_get_name(a));
return true;
}
}
return false;
}
/**
* check_for_mailing_list_addr - Check an address list for a mailing list
* @param al AddressList
* @param buf Buffer for the result
* @param buflen Length of buffer
* @retval true Mailing list found
*
* If one is found, print the address of the list into buf.
*/
bool check_for_mailing_list_addr(struct AddressList *al, char *buf, int buflen)
{
struct Address *a = NULL;
TAILQ_FOREACH(a, al, entries)
{
if (mutt_is_subscribed_list(a))
{
if (buf && buflen)
snprintf(buf, buflen, "%s", a->mailbox);
return true;
}
}
return false;
}
/**
* first_mailing_list - Get the first mailing list in the list of addresses
* @param buf Buffer for the result
* @param buflen Length of buffer
* @param al AddressList
* @retval true A mailing list was found
*/
bool first_mailing_list(char *buf, size_t buflen, struct AddressList *al)
{
struct Address *a = NULL;
TAILQ_FOREACH(a, al, entries)
{
if (mutt_is_subscribed_list(a))
{
mutt_save_path(buf, buflen, a);
return true;
}
}
return false;
}