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

Subject Regex handling. More...

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

Go to the source code of this file.

Functions

void subjrx_cleanup (void)
 Free the Subject Regex List.
 
void subjrx_init (void)
 Create new 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 subjrx_apply_mods (struct Envelope *env)
 Apply regex modifications to the subject.
 
void subjrx_clear_mods (struct MailboxView *mv)
 Clear out all modified email subjects.
 
enum CommandResult parse_subjectrx_list (const struct Command *cmd, struct Buffer *line, struct Buffer *err)
 Parse the 'subjectrx' command - Implements Command::parse() -.
 
enum CommandResult parse_unsubjectrx_list (const struct Command *cmd, struct Buffer *line, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements Command::parse() -.
 

Variables

static struct ReplaceList SubjectRegexList = STAILQ_HEAD_INITIALIZER(SubjectRegexList)
 List of subjectrx rules for modifying the Subject:
 
static struct NotifySubjRxNotify = NULL
 Notifications: NotifySubjRx.
 

Detailed Description

Subject Regex handling.

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

◆ subjrx_cleanup()

void subjrx_cleanup ( void )

Free the Subject Regex List.

Definition at line 45 of file subjectrx.c.

46{
49}
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:449
static struct Notify * SubjRxNotify
Notifications: NotifySubjRx.
Definition subjectrx.c:40
static struct ReplaceList SubjectRegexList
List of subjectrx rules for modifying the Subject:
Definition subjectrx.c:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjrx_init()

void subjrx_init ( void )

Create new Subject Regex List.

Definition at line 54 of file subjectrx.c.

55{
56 if (SubjRxNotify)
57 return;
58
61}
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
Container for Accounts, Notifications.
Definition neomutt.h:43
struct Notify * notify
Notifications handler.
Definition neomutt.h:44
+ 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 71 of file subjectrx.c.

74{
75 if (!MoreArgs(line))
76 {
77 buf_printf(err, _("%s: too few arguments"), cmd->name);
78 return MUTT_CMD_WARNING;
79 }
80
81 struct Buffer *token = buf_pool_get();
82
83 /* First token is a regex. */
85
86 /* "*" is a special case. */
87 if (mutt_str_equal(buf_string(token), "*"))
88 {
90 buf_pool_release(&token);
91 return MUTT_CMD_SUCCESS;
92 }
93
95 buf_pool_release(&token);
96 return MUTT_CMD_SUCCESS;
97}
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:38
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition command.h:37
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:48
#define MoreArgs(buf)
Definition extract.h:30
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:44
#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:565
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:660
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the command.
Definition command.h:59
+ 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 107 of file subjectrx.c.

109{
110 struct Buffer *templ = buf_pool_get();
111 struct Buffer *regex = buf_pool_get();
112 int rc = MUTT_CMD_WARNING;
113
114 if (!MoreArgs(line))
115 {
116 buf_printf(err, _("%s: too few arguments"), cmd->name);
117 goto done;
118 }
119
120 /* First token is a regex. */
122
123 if (!MoreArgs(line))
124 {
125 buf_printf(err, _("%s: too few arguments"), cmd->name);
126 goto done;
127 }
128
129 /* Second token is a replacement template */
131
132 if (mutt_replacelist_add(list, buf_string(regex), buf_string(templ), err) != 0)
133 {
134 rc = MUTT_CMD_ERROR;
135 goto done;
136 }
137
138 rc = MUTT_CMD_SUCCESS;
139
140done:
141 buf_pool_release(&regex);
142 buf_pool_release(&templ);
143 return rc;
144}
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:36
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:270
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjrx_apply_mods()

bool subjrx_apply_mods ( struct Envelope * env)

Apply regex modifications to the subject.

Parameters
envEnvelope of Email
Return values
trueSubject modified

Definition at line 151 of file subjectrx.c.

152{
153 if (!env || !env->subject || (*env->subject == '\0'))
154 return false;
155
156 if (env->disp_subj)
157 return true;
158
160 return false;
161
163 return true;
164}
char * mutt_replacelist_apply(struct ReplaceList *rl, const char *str)
Apply replacements to a buffer.
Definition regex.c:368
#define STAILQ_EMPTY(head)
Definition queue.h:382
char *const subject
Email's subject.
Definition envelope.h:70
char * disp_subj
Display subject (modified copy of subject)
Definition envelope.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjrx_clear_mods()

void subjrx_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)
Definition memory.h:62
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:79
int msg_count
Total number of messages.
Definition mailbox.h:88
struct Email ** emails
Array of Emails.
Definition mailbox.h:96
+ Here is the caller graph for this function:

Variable Documentation

◆ SubjectRegexList

struct ReplaceList SubjectRegexList = STAILQ_HEAD_INITIALIZER(SubjectRegexList)
static

List of subjectrx rules for modifying the Subject:

Definition at line 39 of file subjectrx.c.

◆ SubjRxNotify

struct Notify* SubjRxNotify = NULL
static

Notifications: NotifySubjRx.

Definition at line 40 of file subjectrx.c.