NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
subjectrx.c File Reference

Parse Subject-regex Commands. More...

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "subjectrx.h"
#include "parse/lib.h"
#include "module_data.h"
+ Include dependency graph for subjectrx.c:

Go to the source code of this file.

Functions

void subjectrx_init (struct NeoMutt *n, struct IndexModuleData *md)
 Create new Subject Regex List.
 
void subjectrx_cleanup (struct IndexModuleData *md)
 Free the Subject Regex List.
 
static enum CommandResult parse_unreplace_list (const struct Command *cmd, struct Buffer *line, struct ReplaceList *list, struct Buffer *err)
 Remove a string replacement rule.
 
static enum CommandResult parse_replace_list (const struct Command *cmd, struct Buffer *line, struct ReplaceList *list, struct Buffer *err)
 Parse a string replacement rule.
 
bool subjectrx_apply_mods (struct Envelope *env)
 Apply regex modifications to the subject.
 
void subjectrx_clear_mods (struct MailboxView *mv)
 Clear out all modified email subjects.
 
enum CommandResult parse_subjectrx_list (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'subject-regex' command - Implements Command::parse() -.
 
enum CommandResult parse_unsubjectrx_list (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'unsubject-regex' command - Implements Command::parse() -.
 

Detailed Description

Parse Subject-regex Commands.

Authors
  • Richard Russon

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/.

Definition in file subjectrx.c.

Function Documentation

◆ subjectrx_init()

void subjectrx_init ( struct NeoMutt * n,
struct IndexModuleData * md )

Create new Subject Regex List.

Definition at line 42 of file subjectrx.c.

43{
45
48}
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
#define STAILQ_INIT(head)
Definition queue.h:410
struct Notify * subject_rx_notify
List of subject-regex rules for modifying the Subject:
Definition module_data.h:34
struct ReplaceList subject_rx_list
Definition module_data.h:33
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjectrx_cleanup()

void subjectrx_cleanup ( struct IndexModuleData * md)

Free the Subject Regex List.

Definition at line 53 of file subjectrx.c.

54{
56
58}
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition regex.c:450
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unreplace_list()

static enum CommandResult parse_unreplace_list ( const struct Command * cmd,
struct Buffer * line,
struct ReplaceList * list,
struct Buffer * err )
static

Remove a string replacement rule.

Parameters
cmdCommand being parsed
lineBuffer containing string to be parsed
listReplaceList to be updated
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 68 of file subjectrx.c.

71{
72 if (!MoreArgs(line))
73 {
74 buf_printf(err, _("%s: too few arguments"), cmd->name);
75 return MUTT_CMD_WARNING;
76 }
77
78 struct Buffer *token = buf_pool_get();
79
80 /* First token is a regex. */
82
83 /* "*" is a special case. */
84 if (mutt_str_equal(buf_string(token), "*"))
85 {
87 buf_pool_release(&token);
88 return MUTT_CMD_SUCCESS;
89 }
90
92 buf_pool_release(&token);
93 return MUTT_CMD_SUCCESS;
94}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:40
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:39
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:49
#define MoreArgs(buf)
Definition extract.h:31
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:45
#define _(a)
Definition message.h:28
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition regex.c:566
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_replace_list()

static enum CommandResult parse_replace_list ( const struct Command * cmd,
struct Buffer * line,
struct ReplaceList * list,
struct Buffer * err )
static

Parse a string replacement rule.

Parameters
cmdCommand being parsed
lineBuffer containing string to be parsed
listReplaceList to be updated
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 104 of file subjectrx.c.

106{
107 struct Buffer *templ = buf_pool_get();
108 struct Buffer *regex = buf_pool_get();
109 int rc = MUTT_CMD_WARNING;
110
111 if (!MoreArgs(line))
112 {
113 buf_printf(err, _("%s: too few arguments"), cmd->name);
114 goto done;
115 }
116
117 /* First token is a regex. */
119
120 if (!MoreArgs(line))
121 {
122 buf_printf(err, _("%s: too few arguments"), cmd->name);
123 goto done;
124 }
125
126 /* Second token is a replacement template */
128
129 if (mutt_replacelist_add(list, buf_string(regex), buf_string(templ), err) != 0)
130 {
131 rc = MUTT_CMD_ERROR;
132 goto done;
133 }
134
135 rc = MUTT_CMD_SUCCESS;
136
137done:
138 buf_pool_release(&regex);
139 buf_pool_release(&templ);
140 return rc;
141}
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:38
int mutt_replacelist_add(struct ReplaceList *rl, const char *pat, const char *templ, struct Buffer *err)
Add a pattern and a template to a list.
Definition regex.c:271
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjectrx_apply_mods()

bool subjectrx_apply_mods ( struct Envelope * env)

Apply regex modifications to the subject.

Parameters
envEnvelope of Email
Return values
trueSubject modified

Definition at line 148 of file subjectrx.c.

149{
150 if (!env || !env->subject || (*env->subject == '\0'))
151 return false;
152
153 if (env->disp_subj)
154 return true;
155
157 ASSERT(md);
158
160 return false;
161
163 return true;
164}
@ MODULE_ID_INDEX
ModuleIndex, Index
Definition module_api.h:72
char * mutt_replacelist_apply(struct ReplaceList *rl, const char *str)
Apply replacements to a buffer.
Definition regex.c:369
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:585
#define STAILQ_EMPTY(head)
Definition queue.h:382
#define ASSERT(COND)
Definition signal2.h:59
char *const subject
Email's subject.
Definition envelope.h:70
char * disp_subj
Display subject (modified copy of subject)
Definition envelope.h:72
Index private Module data.
Definition module_data.h:32
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjectrx_clear_mods()

void subjectrx_clear_mods ( struct MailboxView * mv)

Clear out all modified email subjects.

Parameters
mvMailbox view

Definition at line 170 of file subjectrx.c.

171{
172 if (!mv || !mv->mailbox)
173 return;
174
175 struct Mailbox *m = mv->mailbox;
176
177 for (int i = 0; i < m->msg_count; i++)
178 {
179 struct Email *e = m->emails[i];
180 if (!e || !e->env)
181 continue;
182 FREE(&e->env->disp_subj);
183 }
184}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
The envelope/body of an email.
Definition email.h:39
struct Envelope * env
Envelope information.
Definition email.h:68
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:78
int msg_count
Total number of messages.
Definition mailbox.h:87
struct Email ** emails
Array of Emails.
Definition mailbox.h:95
+ Here is the caller graph for this function: