NeoMutt  2021-02-05-329-g9e03b7
Teaching an old dog new tricks
DOXYGEN
subjectrx.c File Reference

Subject Regex handling. More...

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

Go to the source code of this file.

Functions

void subjrx_free (void)
 Free the Subject Regex List. More...
 
void subjrx_init (void)
 Create new Subject Regex List. More...
 
static enum CommandResult parse_unreplace_list (struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
 Remove a string replacement rule - Implements Command::parse() More...
 
static enum CommandResult parse_replace_list (struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
 Parse a string replacement rule - Implements Command::parse() More...
 
bool subjrx_apply_mods (struct Envelope *env)
 Apply regex modifications to the subject. More...
 
void subjrx_clear_mods (struct Mailbox *m)
 Clear out all modified email subjects. More...
 
enum CommandResult parse_subjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subjectrx' command - Implements Command::parse() More...
 
enum CommandResult parse_unsubjectrx_list (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubjectrx' command - Implements Command::parse() More...
 

Variables

static struct ReplaceList SubjectRegexList = STAILQ_HEAD_INITIALIZER(SubjectRegexList)
 
static struct NotifySubjRxNotify = NULL
 

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_free()

void subjrx_free ( void  )

Free the Subject Regex List.

Definition at line 46 of file subjectrx.c.

47 {
50 }
static struct ReplaceList SubjectRegexList
Definition: subjectrx.c:40
static struct Notify * SubjRxNotify
Definition: subjectrx.c:41
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:448
+ 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 55 of file subjectrx.c.

56 {
57  if (SubjRxNotify)
58  return;
59 
62 }
static struct Notify * SubjRxNotify
Definition: subjectrx.c:41
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
+ 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 ( struct Buffer buf,
struct Buffer s,
struct ReplaceList *  list,
struct Buffer err 
)
static

Remove a string replacement rule - Implements Command::parse()

Definition at line 67 of file subjectrx.c.

69 {
70  /* First token is a regex. */
71  if (!MoreArgs(s))
72  {
73  mutt_buffer_printf(err, _("%s: too few arguments"), "unsubjectrx");
74  return MUTT_CMD_WARNING;
75  }
76 
78 
79  /* "*" is a special case. */
80  if (mutt_str_equal(buf->data, "*"))
81  {
83  return MUTT_CMD_SUCCESS;
84  }
85 
86  mutt_replacelist_remove(list, buf->data);
87  return MUTT_CMD_SUCCESS;
88 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
void mutt_replacelist_free(struct ReplaceList *rl)
Free a ReplaceList object.
Definition: regex.c:448
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
int mutt_replacelist_remove(struct ReplaceList *rl, const char *pat)
Remove a pattern from a list.
Definition: regex.c:565
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ 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 ( struct Buffer buf,
struct Buffer s,
struct ReplaceList *  list,
struct Buffer err 
)
static

Parse a string replacement rule - Implements Command::parse()

Definition at line 93 of file subjectrx.c.

95 {
96  struct Buffer templ = mutt_buffer_make(0);
97 
98  /* First token is a regex. */
99  if (!MoreArgs(s))
100  {
101  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
102  return MUTT_CMD_WARNING;
103  }
105 
106  /* Second token is a replacement template */
107  if (!MoreArgs(s))
108  {
109  mutt_buffer_printf(err, _("%s: too few arguments"), "subjectrx");
110  return MUTT_CMD_WARNING;
111  }
113 
114  if (mutt_replacelist_add(list, buf->data, templ.data, err) != 0)
115  {
116  FREE(&templ.data);
117  return MUTT_CMD_ERROR;
118  }
119  FREE(&templ.data);
120 
121  return MUTT_CMD_SUCCESS;
122 }
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:263
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define MoreArgs(buf)
Definition: buffer.h:40
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
#define FREE(x)
Definition: memory.h:40
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ 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 129 of file subjectrx.c.

130 {
131  if (!env || !env->subject || (*env->subject == '\0'))
132  return false;
133 
134  if (env->disp_subj)
135  return true;
136 
138  return false;
139 
141  return true;
142 }
static struct ReplaceList SubjectRegexList
Definition: subjectrx.c:40
char * disp_subj
Display subject (modified copy of subject)
Definition: envelope.h:68
char * mutt_replacelist_apply(struct ReplaceList *rl, char *buf, size_t buflen, const char *str)
Apply replacements to a buffer.
Definition: regex.c:353
char * subject
Email&#39;s subject.
Definition: envelope.h:66
#define STAILQ_EMPTY(head)
Definition: queue.h:345
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subjrx_clear_mods()

void subjrx_clear_mods ( struct Mailbox m)

Clear out all modified email subjects.

Definition at line 147 of file subjectrx.c.

148 {
149  if (!m)
150  return;
151 
152  for (int i = 0; i < m->msg_count; i++)
153  {
154  struct Email *e = m->emails[i];
155  if (!e || !e->env)
156  continue;
157  FREE(&e->env->disp_subj);
158  }
159 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
char * disp_subj
Display subject (modified copy of subject)
Definition: envelope.h:68
struct Envelope * env
Envelope information.
Definition: email.h:90
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ parse_subjectrx_list()

enum CommandResult parse_subjectrx_list ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'subjectrx' command - Implements Command::parse()

Definition at line 164 of file subjectrx.c.

166 {
167  enum CommandResult rc;
168 
169  rc = parse_replace_list(buf, s, &SubjectRegexList, err);
170  if (rc == MUTT_CMD_SUCCESS)
171  {
173  }
174  return rc;
175 }
static struct ReplaceList SubjectRegexList
Definition: subjectrx.c:40
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
static struct Notify * SubjRxNotify
Definition: subjectrx.c:41
static enum CommandResult parse_replace_list(struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
Parse a string replacement rule - Implements Command::parse()
Definition: subjectrx.c:93
Subject Regex has changed, NotifySubjRx.
Definition: notify_type.h:50
Subject Regex has been added.
Definition: subjectrx.h:39
Success: Command worked.
Definition: mutt_commands.h:38
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:

◆ parse_unsubjectrx_list()

enum CommandResult parse_unsubjectrx_list ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'unsubjectrx' command - Implements Command::parse()

Definition at line 180 of file subjectrx.c.

182 {
183  enum CommandResult rc;
184 
185  rc = parse_unreplace_list(buf, s, &SubjectRegexList, err);
186  if (rc == MUTT_CMD_SUCCESS)
187  {
189  }
190  return rc;
191 }
static struct ReplaceList SubjectRegexList
Definition: subjectrx.c:40
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
static struct Notify * SubjRxNotify
Definition: subjectrx.c:41
Subject Regex has changed, NotifySubjRx.
Definition: notify_type.h:50
Subject Regex has been deleted.
Definition: subjectrx.h:40
Success: Command worked.
Definition: mutt_commands.h:38
static enum CommandResult parse_unreplace_list(struct Buffer *buf, struct Buffer *s, struct ReplaceList *list, struct Buffer *err)
Remove a string replacement rule - Implements Command::parse()
Definition: subjectrx.c:67
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:

Variable Documentation

◆ SubjectRegexList

struct ReplaceList SubjectRegexList = STAILQ_HEAD_INITIALIZER(SubjectRegexList)
static

Definition at line 40 of file subjectrx.c.

◆ SubjRxNotify

struct Notify* SubjRxNotify = NULL
static

Definition at line 41 of file subjectrx.c.