• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neomutt / neomutt / 21576993800

02 Feb 2026 01:15AM UTC coverage: 42.169% (+0.2%) from 42.019%
21576993800

push

github

flatcap
build: force all-docs before validation

11846 of 28092 relevant lines covered (42.17%)

447.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/pattern/flags.c
1
/**
2
 * @file
3
 * Pattern definitions
4
 *
5
 * @authors
6
 * Copyright (C) 2019 Pietro Cerutti <gahr@gahr.ch>
7
 * Copyright (C) 2020 Richard Russon <rich@flatcap.org>
8
 *
9
 * @copyright
10
 * This program is free software: you can redistribute it and/or modify it under
11
 * the terms of the GNU General Public License as published by the Free Software
12
 * Foundation, either version 2 of the License, or (at your option) any later
13
 * version.
14
 *
15
 * This program is distributed in the hope that it will be useful, but WITHOUT
16
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU General Public License along with
21
 * this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23

24
/**
25
 * @page pattern_flags Pattern definitions
26
 *
27
 * Pattern definitions
28
 */
29

30
#include "config.h"
31
#include <stddef.h>
32
#include "private.h"
33
#include "mutt/lib.h"
34
#include "mutt.h"
35
#include "lib.h"
36

37
/**
38
 * Flags - Lookup table for all patterns
39
 *
40
 * Patterns in use:
41
 * - `~` `.bcdefghi.klmn.p.rstuvwxyz`
42
 * - `~` `ABCDEFGHI..LMNOPQRSTUV.XY.`
43
 * - `~#` `~$` `~()` `~<()` `~=` `~>()`
44
 * - Group patterns - `%c` `%C` `%e` `%f` `%L`
45
 * - IMAP patterns  - `=b` `=B` `=h` `=/`
46
 */
47
const struct PatternFlags Flags[] = {
48
  // clang-format off
49
  { '~', 'A', MUTT_ALL, 0, EAT_NONE,
50
    // L10N: Pattern Completion Menu description for ~A
51
    N_("all messages") },
52
  { '~', 'b', MUTT_PAT_BODY, MUTT_PC_FULL_MSG | MUTT_PC_SEND_MODE_SEARCH, EAT_REGEX,
53
    // L10N: Pattern Completion Menu description for ~b
54
    N_("messages whose body matches REGEX") },
55
  { '=', 'b', MUTT_PAT_BODY, MUTT_PC_FULL_MSG | MUTT_PC_SEND_MODE_SEARCH, EAT_STRING,
56
    // L10N: Pattern Completion Menu description for =b
57
    N_("IMAP: messages whose body contains STRING") },
58
  { '~', 'B', MUTT_PAT_WHOLE_MSG, MUTT_PC_FULL_MSG | MUTT_PC_SEND_MODE_SEARCH, EAT_REGEX,
59
    // L10N: Pattern Completion Menu description for ~B
60
    N_("messages whose body or headers match REGEX") },
61
  { '=', 'B', MUTT_PAT_WHOLE_MSG, MUTT_PC_FULL_MSG | MUTT_PC_SEND_MODE_SEARCH, EAT_STRING,
62
    // L10N: Pattern Completion Menu description for =B
63
    N_("IMAP: messages whose body or headers contain STRING") },
64
  { '~', 'c', MUTT_PAT_CC, 0, EAT_REGEX,
65
    // L10N: Pattern Completion Menu description for ~c
66
    N_("messages whose Cc: header matches REGEX") },
67
  { '%', 'c', MUTT_PAT_CC, 0, EAT_GROUP,
68
    // L10N: Pattern Completion Menu description for %c
69
    N_("messages whose Cc: is a member of GROUP") },
70
  { '~', 'C', MUTT_PAT_RECIPIENT, 0, EAT_REGEX,
71
    // L10N: Pattern Completion Menu description for ~C
72
    N_("messages whose To:, Cc: or Bcc: header matches REGEX") },
73
  { '%', 'C', MUTT_PAT_RECIPIENT, 0, EAT_GROUP,
74
    // L10N: Pattern Completion Menu description for %C
75
    N_("messages whose To:, Cc: or Bcc: is a member of GROUP") },
76
  { '~', 'd', MUTT_PAT_DATE, 0, EAT_DATE,
77
    // L10N: Pattern Completion Menu description for ~d
78
    N_("messages sent in DATERANGE") },
79
  { '~', 'D', MUTT_DELETED, 0, EAT_NONE,
80
    // L10N: Pattern Completion Menu description for ~D
81
    N_("deleted messages") },
82
  { '~', 'e', MUTT_PAT_SENDER, 0, EAT_REGEX,
83
    // L10N: Pattern Completion Menu description for ~e
84
    N_("messages whose Sender: header matches REGEX") },
85
  { '%', 'e', MUTT_PAT_SENDER, 0, EAT_GROUP,
86
    // L10N: Pattern Completion Menu description for %e
87
    N_("messages whose Sender: is a member of GROUP") },
88
  { '~', 'E', MUTT_EXPIRED, 0, EAT_NONE,
89
    // L10N: Pattern Completion Menu description for ~E
90
    N_("expired messages") },
91
  { '~', 'f', MUTT_PAT_FROM, 0, EAT_REGEX,
92
    // L10N: Pattern Completion Menu description for ~f
93
    N_("messages whose From: header matches REGEX") },
94
  { '%', 'f', MUTT_PAT_FROM, 0, EAT_GROUP,
95
    // L10N: Pattern Completion Menu description for %f
96
    N_("messages whose From: is a member of GROUP") },
97
  { '~', 'F', MUTT_FLAG, 0, EAT_NONE,
98
    // L10N: Pattern Completion Menu description for ~F
99
    N_("flagged messages") },
100
  { '~', 'g', MUTT_PAT_CRYPT_SIGN, 0, EAT_NONE,
101
    // L10N: Pattern Completion Menu description for ~g
102
    N_("cryptographically signed messages") },
103
  { '~', 'G', MUTT_PAT_CRYPT_ENCRYPT, 0, EAT_NONE,
104
    // L10N: Pattern Completion Menu description for ~G
105
    N_("cryptographically encrypted messages") },
106
  { '~', 'h', MUTT_PAT_HEADER, MUTT_PC_FULL_MSG | MUTT_PC_SEND_MODE_SEARCH, EAT_REGEX,
107
    // L10N: Pattern Completion Menu description for ~h
108
    N_("messages whose header matches REGEX") },
109
  { '=', 'h', MUTT_PAT_HEADER, MUTT_PC_FULL_MSG | MUTT_PC_SEND_MODE_SEARCH, EAT_STRING,
110
    // L10N: Pattern Completion Menu description for =h
111
    N_("IMAP: messages whose header contains STRING") },
112
  { '~', 'H', MUTT_PAT_HORMEL, 0, EAT_REGEX,
113
    // L10N: Pattern Completion Menu description for ~H
114
    N_("messages whose spam header matches REGEX") },
115
  { '~', 'i', MUTT_PAT_ID, 0, EAT_REGEX,
116
    // L10N: Pattern Completion Menu description for ~i
117
    N_("messages whose Message-Id: header matches REGEX") },
118
  { '~', 'I', MUTT_PAT_ID_EXTERNAL, 0, EAT_QUERY,
119
    // L10N: Pattern Completion Menu description for ~I
120
    N_("messages whose Message-Id: is included in results from $external_search_command") },
121
  { '~', 'k', MUTT_PAT_PGP_KEY, 0, EAT_NONE,
122
    // L10N: Pattern Completion Menu description for ~k
123
    N_("messages which contain a PGP key") },
124
  { '~', 'K', MUTT_PAT_BCC, 0, EAT_REGEX,
125
    // L10N: Pattern Completion Menu description for ~K
126
    N_("messages whose Bcc: header matches REGEX") },
127
  { '~', 'l', MUTT_PAT_LIST, 0, EAT_NONE,
128
    // L10N: Pattern Completion Menu description for ~l
129
    N_("messages addressed to known mailing lists") },
130
  { '~', 'L', MUTT_PAT_ADDRESS, 0, EAT_REGEX,
131
    // L10N: Pattern Completion Menu description for ~L
132
    N_("messages whose From:, Sender:, To: or Cc: header matches REGEX") },
133
  { '%', 'L', MUTT_PAT_ADDRESS, 0, EAT_GROUP,
134
    // L10N: Pattern Completion Menu description for %L
135
    N_("messages whose From:, Sender:, To: or Cc: is a member of GROUP") },
136
  { '~', 'm', MUTT_PAT_MESSAGE, 0, EAT_MESSAGE_RANGE,
137
    // L10N: Pattern Completion Menu description for ~m
138
    N_("messages whose number is in RANGE") },
139
  { '~', 'M', MUTT_PAT_MIMETYPE, MUTT_PC_FULL_MSG, EAT_REGEX,
140
    // L10N: Pattern Completion Menu description for ~M
141
    N_("messages with a Content-Type matching REGEX") },
142
  { '~', 'n', MUTT_PAT_SCORE, 0, EAT_RANGE,
143
    // L10N: Pattern Completion Menu description for ~n
144
    N_("messages whose score is in RANGE") },
145
  { '~', 'N', MUTT_NEW, 0, EAT_NONE,
146
    // L10N: Pattern Completion Menu description for ~N
147
    N_("new messages") },
148
  { '~', 'O', MUTT_OLD, 0, EAT_NONE,
149
    // L10N: Pattern Completion Menu description for ~O
150
    N_("old messages") },
151
  { '~', 'p', MUTT_PAT_PERSONAL_RECIP, 0, EAT_NONE,
152
    // L10N: Pattern Completion Menu description for ~p
153
    N_("messages addressed to you") },
154
  { '~', 'P', MUTT_PAT_PERSONAL_FROM, 0, EAT_NONE,
155
    // L10N: Pattern Completion Menu description for ~P
156
    N_("messages from you") },
157
  { '~', 'Q', MUTT_REPLIED, 0, EAT_NONE,
158
    // L10N: Pattern Completion Menu description for ~Q
159
    N_("messages which have been replied to") },
160
  { '~', 'r', MUTT_PAT_DATE_RECEIVED, 0, EAT_DATE,
161
    // L10N: Pattern Completion Menu description for ~r
162
    N_("messages received in DATERANGE") },
163
  { '~', 'R', MUTT_READ, 0, EAT_NONE,
164
    // L10N: Pattern Completion Menu description for ~R
165
    N_("read messages") },
166
  { '~', 's', MUTT_PAT_SUBJECT, 0, EAT_REGEX,
167
    // L10N: Pattern Completion Menu description for ~s
168
    N_("messages whose Subject: header matches REGEX") },
169
  { '~', 'S', MUTT_SUPERSEDED, 0, EAT_NONE,
170
    // L10N: Pattern Completion Menu description for ~S
171
    N_("superseded messages") },
172
  { '~', 't', MUTT_PAT_TO, 0, EAT_REGEX,
173
    // L10N: Pattern Completion Menu description for ~t
174
    N_("messages whose To: header matches REGEX") },
175
  { '~', 'T', MUTT_TAG, 0, EAT_NONE,
176
    // L10N: Pattern Completion Menu description for ~T
177
    N_("tagged messages") },
178
  { '~', 'u', MUTT_PAT_SUBSCRIBED_LIST, 0, EAT_NONE,
179
    // L10N: Pattern Completion Menu description for ~u
180
    N_("messages addressed to subscribed mailing lists") },
181
  { '~', 'U', MUTT_UNREAD, 0, EAT_NONE,
182
    // L10N: Pattern Completion Menu description for ~U
183
    N_("unread messages") },
184
  { '~', 'v', MUTT_PAT_COLLAPSED, 0, EAT_NONE,
185
    // L10N: Pattern Completion Menu description for ~v
186
    N_("messages in collapsed threads") },
187
  { '~', 'V', MUTT_PAT_CRYPT_VERIFIED, 0, EAT_NONE,
188
    // L10N: Pattern Completion Menu description for ~V
189
    N_("cryptographically verified messages") },
190
  { '~', 'w', MUTT_PAT_NEWSGROUPS, 0, EAT_REGEX,
191
    // L10N: Pattern Completion Menu description for ~w
192
    N_("newsgroups matching REGEX") },
193
  { '~', 'x', MUTT_PAT_REFERENCE, 0, EAT_REGEX,
194
    // L10N: Pattern Completion Menu description for ~x
195
    N_("messages whose References: or In-Reply-To: header matches REGEX") },
196
  { '~', 'X', MUTT_PAT_MIMEATTACH, 0, EAT_RANGE,
197
    // L10N: Pattern Completion Menu description for ~X
198
    N_("messages with RANGE attachments") },
199
  { '~', 'y', MUTT_PAT_XLABEL, 0, EAT_REGEX,
200
    // L10N: Pattern Completion Menu description for ~y
201
    N_("messages whose X-Label: header matches REGEX") },
202
  { '~', 'Y', MUTT_PAT_DRIVER_TAGS, 0, EAT_REGEX,
203
    // L10N: Pattern Completion Menu description for ~Y
204
    N_("messages whose tags match REGEX") },
205
  { '~', 'z', MUTT_PAT_SIZE, 0, EAT_RANGE,
206
    // L10N: Pattern Completion Menu description for ~z
207
    N_("messages whose size is in RANGE") },
208
  { '~', '#', MUTT_PAT_BROKEN, 0, EAT_NONE,
209
    // L10N: Pattern Completion Menu description for ~#
210
    N_("broken threads") },
211
  { '~', '$', MUTT_PAT_UNREFERENCED, 0, EAT_NONE,
212
    // L10N: Pattern Completion Menu description for ~$
213
    N_("unreferenced messages") },
214
  { '=', '/', MUTT_PAT_SERVERSEARCH, 0, EAT_STRING,
215
    // L10N: Pattern Completion Menu description for =/
216
    N_("GMail: custom server-side search for STRING") },
217
  { '~', '=', MUTT_PAT_DUPLICATED, 0, EAT_NONE,
218
    // L10N: Pattern Completion Menu description for ~=
219
    N_("duplicated messages") },
220
  { 0, 0, 0, 0, EAT_NONE, NULL, },
221
  // clang-format on
222
};
223

224
/**
225
 * lookup_tag - Lookup a pattern modifier
226
 * @param prefix Pattern prefix, e.g. '~', '%', or '='
227
 * @param tag    Letter, e.g. 'b' for pattern '~b'
228
 * @retval ptr Pattern data
229
 *
230
 * This function first looks for an exact match with the given prefix and tag.
231
 * If not found and prefix is '%' or '=', it falls back to looking for the
232
 * tag with '~' prefix to maintain backward compatibility where '=' means
233
 * string-match and '%' means group-match modifier.
234
 */
235
const struct PatternFlags *lookup_tag(char prefix, char tag)
109✔
236
{
237
  // First, try exact match
238
  for (int i = 0; Flags[i].tag; i++)
3,091✔
239
    if ((Flags[i].prefix == prefix) && (Flags[i].tag == tag))
3,076✔
240
      return &Flags[i];
94✔
241

242
  // Fall back to '~' prefix for '%' and '=' modifiers
243
  if ((prefix == '%') || (prefix == '='))
15✔
244
  {
245
    for (int i = 0; Flags[i].tag; i++)
600✔
246
      if ((Flags[i].prefix == '~') && (Flags[i].tag == tag))
600✔
247
        return &Flags[i];
15✔
248
  }
249

250
  return NULL;
251
}
252

253
/**
254
 * lookup_op - Lookup the Pattern Flags for an op
255
 * @param op Operation, e.g. #MUTT_PAT_SENDER
256
 * @retval ptr PatternFlags
257
 */
258
const struct PatternFlags *lookup_op(int op)
×
259
{
260
  for (int i = 0; Flags[i].tag; i++)
×
261
    if (Flags[i].op == op)
×
262
      return (&Flags[i]);
×
263
  return NULL;
264
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc