Compile on demand and get data for a predefined regex.
101{
103
104 {
107
108#ifdef HAVE_PCRE2
109#define UNR_PCTENC_SUBDEL "][\\p{L}\\p{N}._~%!$&'()*+,;="
110#else
111#define UNR_PCTENC_SUBDEL "][[:alnum:]._~%!$&'()*+,;="
112#endif
113#define PATH ":@/ "
114 "^([[:alpha:]][-+.[:alnum:]]+):"
115 "("
116 "("
117
118 "(//"
119 "("
122 "@)?"
123 "("
125 "|"
126 "(\\[[[:xdigit:]:.]+\\])"
127 ")"
128 "(:([[:digit:]]+))?"
130 ")"
131 "|"
132 "("
134 ")"
135 ")"
136
137 "(\\?([^#]*))?"
138 ")$"
139#undef PATH
140#undef UNR_PCTENC_SUBDEL
141 },
142 {
145#define QUERY_PART "^&="
147#undef QUERY_PART
148 },
149 {
152 "=\\?"
153 "([^][()<>@,;:\\\"/?. =]+)"
154 "\\?"
155 "([qQbB])"
156 "\\?"
157 "([^?]+)"
158 "\\?="
159 },
160 {
163 "^\\#H ([[:alnum:]_\\.-]+) ([[:alnum:]]{4}( [[:alnum:]]{4}){7})[ \t]*$"
164 },
165 {
168
169#define FWS " *"
170#define C "(\\(.*\\))?"
171#define CFWS FWS C FWS
172 "^"
174 "(([[:alpha:]]+)" CFWS ", *)?"
175 CFWS "([[:digit:]]{1,2}) "
177 CFWS "([[:digit:]]{2,4}) "
178 CFWS "([[:digit:]]{1,2})"
179 ":" CFWS "([[:digit:]]{1,2})"
181 "(:" CFWS "([[:digit:]]{1,2}))?"
183 "("
184 "([+-][[:digit:]]{4})|"
185 "([[:alpha:]]+)"
186 ")?"
187#undef CFWS
188#undef C
189#undef FWS
190 },
191 {
194 "( ([[:digit:]])|([[:digit:]]{2}))"
198 " ([+-][[:digit:]]{4})"
199 },
200 {
203
204 "^From "
205 "([^[:space:]]+) +"
207 " +"
209 " ( ([[:digit:]])|([[:digit:]]{2}))"
210 " +"
212 " +"
214 },
215 {
218
219 "^From "
220 "("
221 "[^[:space:]]+"
222 "( at [^[:space:]]+)?"
223 ")?"
224 " *"
226 " +"
228 " +"
229 "( "
230 "([[:digit:]])|"
231 "([[:digit:]]{2})"
232 ")"
233 " +"
234 "("
236 "|"
237 "([[:digit:]]{2}"
238 ":[[:digit:]]{2})"
239 ")"
240 " +"
241 "("
242 "([[:alpha:] ]+)|"
243 "([+][[:digit:]]{4} )"
244 ")?"
245 "("
247 "|"
248 "([[:digit:]]{2})"
249 ")"
250 },
251 {
254 "^([[:alpha:]]+): (.*)$"
255 },
256 {
259 "^(.*)(tags:)([[:alnum:],]*) ?(.*)$"
260 },
261
262 };
263
268 {
269#ifdef HAVE_PCRE2
270 uint32_t opt = pcre2_has_unicode() ? PCRE2_UTF : 0;
271 int eno = 0;
272 PCRE2_SIZE eoff = 0;
273 h->
re = pcre2_compile((PCRE2_SPTR8) h->
str, PCRE2_ZERO_TERMINATED, opt,
274 &eno, &eoff, NULL);
276 h->mdata = pcre2_match_data_create_from_pattern(h->
re, NULL);
277 uint32_t ccount = 0;
278 pcre2_pattern_info(h->
re, PCRE2_INFO_CAPTURECOUNT, &ccount);
279 ASSERT(((ccount + 1) == h->
nmatches) &&
"Number of matches do not match (...)");
281#else
283 const int rc = regcomp(h->
re, h->
str, REG_EXTENDED);
284 ASSERT(rc == 0 &&
"Fix your RE");
286#endif
287 }
288 return h;
289}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
#define UNR_PCTENC_SUBDEL
@ PREX_MBOX_FROM_LAX_MATCH_MAX
@ PREX_ACCOUNT_CMD_MATCH_MAX
@ PREX_IMAP_DATE_MATCH_MAX
@ PREX_MBOX_FROM_MATCH_MAX
@ PREX_RFC2047_ENCODED_WORD_MATCH_MAX
@ PREX_URL_QUERY_KEY_VAL_MATCH_MAX
@ PREX_GNUTLS_CERT_HOST_HASH
[#H foo.com A76D 954B EB79 1F49 5B3A 0A0E 0681 65B1]
@ PREX_MBOX_FROM_LAX
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
@ PREX_URL
[imaps://user:pass@example.com/INBOX?foo=bar]
@ PREX_MBOX_FROM
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
@ PREX_ACCOUNT_CMD
key: value
@ PREX_ALIAS_TAGS
tags:a,b,c
@ PREX_IMAP_DATE
[16-MAR-2020 15:09:35 -0700]
@ PREX_RFC5322_DATE_LAX
[Mon, (Comment) 16 Mar 2020 15:09:35 -0700]
@ PREX_URL_QUERY_KEY_VAL
https://example.com/?[q=foo]
@ PREX_RFC2047_ENCODED_WORD
[=?utf-8?Q?=E8=81=AA=E6=98=8E=E7=9A=84?=]
@ PREX_RFC5322_DATE_LAX_MATCH_MAX
@ PREX_GNUTLS_CERT_HOST_HASH_MATCH_MAX
@ PREX_ALIAS_TAGS_MATCH_MAX
A predefined / precompiled regex.
const char * str
Regex string.
enum Prex which
Regex type, e.g. PREX_URL.
size_t nmatches
Number of regex matches.
regex_t * re
Compiled regex.
regmatch_t * matches
Resulting matches.