NeoMutt  2021-02-05-329-g9e03b7
Teaching an old dog new tricks
DOXYGEN
alternates.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdbool.h>
31 #include <stdint.h>
32 #include <stdio.h>
33 #include "mutt/lib.h"
34 #include "address/lib.h"
35 #include "email/lib.h"
36 #include "core/lib.h"
37 #include "mutt.h"
38 #include "alternates.h"
39 #include "attachments.h"
40 #include "command_parse.h"
41 #include "init.h"
42 #include "mutt_commands.h"
43 
46 static struct Notify *AlternatesNotify = NULL;
47 
51 void alternates_free(void)
52 {
53  notify_free(&AlternatesNotify);
54 
57 }
58 
62 void alternates_init(void)
63 {
64  if (AlternatesNotify)
65  return;
66 
67  AlternatesNotify = notify_new();
68  notify_set_parent(AlternatesNotify, NeoMutt->notify);
69 }
70 
75 {
76  if (!m)
77  return;
78 
79  for (int i = 0; i < m->msg_count; i++)
80  {
81  struct Email *e = m->emails[i];
82  if (!e)
83  break;
84  e->recip_valid = false;
85  }
86 }
87 
91 enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s,
92  intptr_t data, struct Buffer *err)
93 {
94  struct GroupList gl = STAILQ_HEAD_INITIALIZER(gl);
95 
96  do
97  {
99 
100  if (parse_grouplist(&gl, buf, s, err) == -1)
101  goto bail;
102 
104 
105  if (mutt_regexlist_add(&Alternates, buf->data, REG_ICASE, err) != 0)
106  goto bail;
107 
108  if (mutt_grouplist_add_regex(&gl, buf->data, REG_ICASE, err) != 0)
109  goto bail;
110  } while (MoreArgs(s));
111 
113 
114  notify_send(AlternatesNotify, NT_ATTACH, NT_ATTACH_ADD, NULL);
115 
116  return MUTT_CMD_SUCCESS;
117 
118 bail:
120  return MUTT_CMD_ERROR;
121 }
122 
126 enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s,
127  intptr_t data, struct Buffer *err)
128 {
129  do
130  {
133 
134  if (!mutt_str_equal(buf->data, "*") &&
135  (mutt_regexlist_add(&UnAlternates, buf->data, REG_ICASE, err) != 0))
136  {
137  return MUTT_CMD_ERROR;
138  }
139 
140  } while (MoreArgs(s));
141 
142  notify_send(AlternatesNotify, NT_ATTACH, NT_ATTACH_DELETE, NULL);
143 
144  return MUTT_CMD_SUCCESS;
145 }
146 
152 bool mutt_alternates_match(const char *addr)
153 {
154  if (!addr)
155  return false;
156 
157  if (mutt_regexlist_match(&Alternates, addr))
158  {
159  mutt_debug(LL_DEBUG5, "yes, %s matched by alternates\n", addr);
161  mutt_debug(LL_DEBUG5, "but, %s matched by unalternates\n", addr);
162  else
163  return true;
164  }
165 
166  return false;
167 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:45
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:34
Config/command parsing.
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Structs that make up an email.
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
Attachment command changed, NotifyAttach.
Definition: notify_type.h:37
int mutt_regexlist_add(struct RegexList *rl, const char *str, uint16_t flags, struct Buffer *err)
Compile a regex string and add it to a list.
Definition: regex.c:132
bool mutt_alternates_match(const char *addr)
Compare an Address to the Un/Alternates lists.
Definition: alternates.c:152
String manipulation buffer.
Definition: buffer.h:33
Alternate address handling.
Container for Accounts, Notifications.
Definition: neomutt.h:36
Email Address Handling.
#define MoreArgs(buf)
Definition: buffer.h:40
Many unsorted constants and some structs.
Convenience wrapper for the core headers.
int mutt_grouplist_add_regex(struct GroupList *gl, const char *s, uint16_t flags, struct Buffer *err)
Add matching Addresses to a GroupList.
Definition: group.c:276
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:192
Attachment regex has been deleted.
Definition: attachments.h:37
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
A mailbox.
Definition: mailbox.h:81
Functions to parse commands in a config file.
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
Definitions of NeoMutt commands.
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:44
void mutt_alternates_reset(struct Mailbox *m)
Clear the recipient valid flag of all emails.
Definition: alternates.c:74
Notification API.
Definition: notify.c:39
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;unalternates&#39; command - Implements Command::parse()
Definition: alternates.c:126
enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;alternates&#39; command - Implements Command::parse()
Definition: alternates.c:91
Success: Command worked.
Definition: mutt_commands.h:38
Attachment regex has been added.
Definition: attachments.h:36
void alternates_init(void)
Set up the alternates lists.
Definition: alternates.c:62
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
bool recip_valid
Is_recipient is valid.
Definition: email.h:58
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void alternates_free(void)
Free the alternates lists.
Definition: alternates.c:51
Log at debug level 5.
Definition: logging.h:44
Convenience wrapper for the library headers.
Miscellaneous email parsing routines.
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:171
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
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