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

Alternate address handling. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "alternates.h"
#include "attachments.h"
#include "command_parse.h"
#include "init.h"
#include "mutt_commands.h"
+ Include dependency graph for alternates.c:

Go to the source code of this file.

Functions

void alternates_free (void)
 Free the alternates lists. More...
 
void alternates_init (void)
 Set up the alternates lists. More...
 
void mutt_alternates_reset (struct Mailbox *m)
 Clear the recipient valid flag of all emails. More...
 
enum CommandResult parse_alternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'alternates' command - Implements Command::parse() More...
 
enum CommandResult parse_unalternates (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unalternates' command - Implements Command::parse() More...
 
bool mutt_alternates_match (const char *addr)
 Compare an Address to the Un/Alternates lists. More...
 

Variables

struct RegexList Alternates = STAILQ_HEAD_INITIALIZER(Alternates)
 List of regexes to match the user's alternate email addresses. More...
 
struct RegexList UnAlternates = STAILQ_HEAD_INITIALIZER(UnAlternates)
 List of regexes to blacklist false matches in Alternates. More...
 
static struct NotifyAlternatesNotify = NULL
 

Detailed Description

Alternate address 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 alternates.c.

Function Documentation

◆ alternates_free()

void alternates_free ( void  )

Free the alternates lists.

Definition at line 51 of file alternates.c.

52 {
54 
57 }
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:45
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
static struct Notify * AlternatesNotify
Definition: alternates.c:46
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:44
void mutt_regexlist_free(struct RegexList *rl)
Free a RegexList object.
Definition: regex.c:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alternates_init()

void alternates_init ( void  )

Set up the alternates lists.

Definition at line 62 of file alternates.c.

63 {
64  if (AlternatesNotify)
65  return;
66 
69 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
static struct Notify * AlternatesNotify
Definition: alternates.c:46
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:

◆ mutt_alternates_reset()

void mutt_alternates_reset ( struct Mailbox m)

Clear the recipient valid flag of all emails.

Definition at line 74 of file alternates.c.

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 }
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
bool recip_valid
Is_recipient is valid.
Definition: email.h:58
+ Here is the caller graph for this function:

◆ parse_alternates()

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

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

Definition at line 91 of file alternates.c.

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 
115 
116  return MUTT_CMD_SUCCESS;
117 
118 bail:
120  return MUTT_CMD_ERROR;
121 }
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 mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
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
#define MoreArgs(buf)
Definition: buffer.h:40
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
static struct Notify * AlternatesNotify
Definition: alternates.c:46
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
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:44
Success: Command worked.
Definition: mutt_commands.h:38
Attachment regex has been added.
Definition: attachments.h:36
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
Definition: group.c:157
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
#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
+ Here is the call graph for this function:

◆ parse_unalternates()

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

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

Definition at line 126 of file alternates.c.

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 
143 
144  return MUTT_CMD_SUCCESS;
145 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:45
int mutt_regexlist_remove(struct RegexList *rl, const char *str)
Remove a Regex from a list.
Definition: regex.c:227
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
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
#define MoreArgs(buf)
Definition: buffer.h:40
Attachment regex has been deleted.
Definition: attachments.h:37
static struct Notify * AlternatesNotify
Definition: alternates.c:46
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
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:44
Success: Command worked.
Definition: mutt_commands.h:38
#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
+ Here is the call graph for this function:

◆ mutt_alternates_match()

bool mutt_alternates_match ( const char *  addr)

Compare an Address to the Un/Alternates lists.

Parameters
addrAddress to check
Return values
trueAddress matches

Definition at line 152 of file alternates.c.

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 }
struct RegexList UnAlternates
List of regexes to blacklist false matches in Alternates.
Definition: alternates.c:45
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition: regex.c:192
struct RegexList Alternates
List of regexes to match the user&#39;s alternate email addresses.
Definition: alternates.c:44
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Log at debug level 5.
Definition: logging.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ Alternates

struct RegexList Alternates = STAILQ_HEAD_INITIALIZER(Alternates)

List of regexes to match the user's alternate email addresses.

Definition at line 44 of file alternates.c.

◆ UnAlternates

struct RegexList UnAlternates = STAILQ_HEAD_INITIALIZER(UnAlternates)

List of regexes to blacklist false matches in Alternates.

Definition at line 45 of file alternates.c.

◆ AlternatesNotify

struct Notify* AlternatesNotify = NULL
static

Definition at line 46 of file alternates.c.