NeoMutt  2025-12-11-872-g385a04
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.c File Reference

Alias commands. More...

#include "config.h"
#include <stdio.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "parse/lib.h"
#include "alias.h"
#include "alternates.h"
#include "group.h"
#include "module_data.h"
#include "reverse.h"
+ Include dependency graph for commands.c:

Go to the source code of this file.

Functions

void mutt_auto_subscribe (const char *mailto)
 Check if user is subscribed to mailing list.
 
void alias_tags_to_buffer (struct TagList *tl, struct Buffer *buf)
 Write a comma-separated list of tags to a Buffer.
 
void parse_alias_tags (const char *tags, struct TagList *tl)
 Parse a comma-separated list of tags.
 
void parse_alias_comments (struct Alias *alias, const char *com)
 Parse the alias/query comment field.
 
enum CommandResult parse_alias (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'alias' command - Implements Command::parse() -.
 
enum CommandResult parse_unalias (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'unalias' command - Implements Command::parse() -.
 

Variables

const struct Command AliasCommands []
 Alias Commands.
 

Detailed Description

Alias commands.

Authors
  • Pietro Cerutti
  • 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 commands.c.

Function Documentation

◆ mutt_auto_subscribe()

void mutt_auto_subscribe ( const char * mailto)

Check if user is subscribed to mailing list.

Parameters
mailtoURL of mailing list subscribe

Definition at line 49 of file commands.c.

50{
51 if (!mailto)
52 return;
53
55 ASSERT(mod_data);
56
57 if (!mod_data->auto_subscribe_cache)
59
60 if (mutt_hash_find(mod_data->auto_subscribe_cache, mailto))
61 return;
62
64
65 struct Envelope *lpenv = mutt_env_new(); /* parsed envelope from the List-Post mailto: URL */
66
67 if (mutt_parse_mailto(lpenv, NULL, mailto) && !TAILQ_EMPTY(&lpenv->to))
68 {
69 const char *mailbox = buf_string(TAILQ_FIRST(&lpenv->to)->mailbox);
70 if (mailbox && !mutt_regexlist_match(&mod_data->subscribed, mailbox) &&
71 !mutt_regexlist_match(&mod_data->unmail, mailbox) &&
72 !mutt_regexlist_match(&mod_data->unsubscribed, mailbox))
73 {
74 /* mutt_regexlist_add() detects duplicates, so it is safe to
75 * try to add here without any checks. */
76 mutt_regexlist_add(&mod_data->mail, mailbox, REG_ICASE, NULL);
77 mutt_regexlist_add(&mod_data->subscribed, mailbox, REG_ICASE, NULL);
78 }
79 }
80
81 mutt_env_free(&lpenv);
82}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition parse.c:1726
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition envelope.c:125
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition envelope.c:45
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
Definition hash.c:337
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition hash.c:364
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
Definition hash.c:261
@ MUTT_HASH_STRCASECMP
use strcasecmp() to compare keys
Definition hash.h:116
@ MUTT_HASH_STRDUP_KEYS
make a copy of the keys
Definition hash.h:117
@ MODULE_ID_ALIAS
ModuleAlias, Alias
Definition module_api.h:48
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:140
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
Definition regex.c:200
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
#define TAILQ_FIRST(head)
Definition queue.h:780
#define TAILQ_EMPTY(head)
Definition queue.h:778
#define ASSERT(COND)
Definition signal2.h:59
Alias private Module data.
Definition module_data.h:33
struct RegexList subscribed
Regexes to match subscribed mailing lists.
Definition module_data.h:49
struct RegexList mail
Regexes to match mailing lists.
Definition module_data.h:48
struct HashTable * auto_subscribe_cache
Hash Table: "mailto:" (no value)
Definition module_data.h:47
struct RegexList unmail
Regexes to exclude false matches in mail.
Definition module_data.h:50
struct RegexList unsubscribed
Regexes to exclude false matches in subscribed.
Definition module_data.h:51
The header of an Email.
Definition envelope.h:57
struct AddressList to
Email's 'To' list.
Definition envelope.h:60
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ alias_tags_to_buffer()

void alias_tags_to_buffer ( struct TagList * tl,
struct Buffer * buf )

Write a comma-separated list of tags to a Buffer.

Parameters
tlTags
bufBuffer for the result

Definition at line 89 of file commands.c.

90{
91 struct Tag *tag = NULL;
92 STAILQ_FOREACH(tag, tl, entries)
93 {
94 buf_addstr(buf, tag->name);
95 if (STAILQ_NEXT(tag, entries))
96 buf_addch(buf, ',');
97 }
98}
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
#define STAILQ_NEXT(elm, field)
Definition queue.h:439
LinkedList Tag Element.
Definition tags.h:41
char * name
Tag name.
Definition tags.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_alias_tags()

void parse_alias_tags ( const char * tags,
struct TagList * tl )

Parse a comma-separated list of tags.

Parameters
tagsComma-separated string
tlTagList for the results

Definition at line 105 of file commands.c.

106{
107 if (!tags || !tl)
108 return;
109
110 struct Slist *sl = slist_parse(tags, D_SLIST_SEP_COMMA);
111 if (slist_is_empty(sl))
112 {
113 slist_free(&sl);
114 return;
115 }
116
117 struct ListNode *np = NULL;
118 STAILQ_FOREACH(np, &sl->head, entries)
119 {
120 struct Tag *tag = tag_new();
121 tag->name = np->data; // Transfer string
122 np->data = NULL;
123 STAILQ_INSERT_TAIL(tl, tag, entries);
124 }
125 slist_free(&sl);
126}
struct Slist * slist_parse(const char *str, uint32_t flags)
Parse a list of strings into a list.
Definition slist.c:177
bool slist_is_empty(const struct Slist *list)
Is the slist empty?
Definition slist.c:140
void slist_free(struct Slist **ptr)
Free an Slist object.
Definition slist.c:124
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:427
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
String list.
Definition slist.h:37
struct ListHead head
List containing values.
Definition slist.h:38
struct Tag * tag_new(void)
Create a new Tag.
Definition tags.c:62
#define D_SLIST_SEP_COMMA
Slist items are comma-separated.
Definition types.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_alias_comments()

void parse_alias_comments ( struct Alias * alias,
const char * com )

Parse the alias/query comment field.

Parameters
aliasAlias for the result
comComment string

If the comment contains a 'tags:' field, the result will be put in alias.tags

Definition at line 135 of file commands.c.

136{
137 if (!com || (com[0] == '\0'))
138 return;
139
140 const regmatch_t *match = mutt_prex_capture(PREX_ALIAS_TAGS, com);
141 if (match)
142 {
143 const regmatch_t *pre = &match[PREX_ALIAS_TAGS_MATCH_PRE];
144 const regmatch_t *tags = &match[PREX_ALIAS_TAGS_MATCH_TAGS];
145 const regmatch_t *post = &match[PREX_ALIAS_TAGS_MATCH_POST];
146
147 struct Buffer *tmp = buf_pool_get();
148
149 // Extract the tags
150 buf_addstr_n(tmp, com + mutt_regmatch_start(tags),
152 parse_alias_tags(buf_string(tmp), &alias->tags);
153 buf_reset(tmp);
154
155 // Collect all the other text as "comments"
156 buf_addstr_n(tmp, com + mutt_regmatch_start(pre),
158 buf_addstr_n(tmp, com + mutt_regmatch_start(post),
160 alias->comment = buf_strdup(tmp);
161
162 buf_pool_release(&tmp);
163 }
164 else
165 {
166 alias->comment = mutt_str_dup(com);
167 }
168}
void parse_alias_tags(const char *tags, struct TagList *tl)
Parse a comma-separated list of tags.
Definition commands.c:105
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition buffer.c:96
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
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
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
Match a precompiled regex against a string.
Definition prex.c:301
@ PREX_ALIAS_TAGS
tags:a,b,c
Definition prex.h:43
@ PREX_ALIAS_TAGS_MATCH_POST
... tags:a,b,c[ ...]
Definition prex.h:240
@ PREX_ALIAS_TAGS_MATCH_PRE
[... ]tags:a,b,c ...
Definition prex.h:237
@ PREX_ALIAS_TAGS_MATCH_TAGS
... tags:[a,b,c] ...
Definition prex.h:239
static regoff_t mutt_regmatch_end(const regmatch_t *match)
Return the end of a match.
Definition regex3.h:66
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition regex3.h:56
struct TagList tags
Tags.
Definition alias.h:39
char * comment
Free-form comment string.
Definition alias.h:38
String manipulation buffer.
Definition buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AliasCommands

const struct Command AliasCommands[]

Alias Commands.

Definition at line 361 of file commands.c.

361 {
362 // clang-format off
363 { "alias", CMD_ALIAS, parse_alias,
364 N_("Define an alias (name to email address)"),
365 N_("alias [ -group <name> ... ] <key> <address> [,...] [ # <comments> ]"),
366 "configuration.html#alias" },
367 { "alternates", CMD_ALTERNATES, parse_alternates,
368 N_("Define a list of alternate email addresses for the user"),
369 N_("alternates [ -group <name> ... ] <regex> [ <regex> ... ]"),
370 "configuration.html#alternates" },
371 { "group", CMD_GROUP, parse_group,
372 N_("Add addresses to an address group"),
373 N_("group [ -group <name> ... ] { -rx <regex> ... | -addr <address> ... }"),
374 "configuration.html#addrgroup" },
375 { "lists", CMD_LISTS, parse_lists,
376 N_("Add address to the list of mailing lists"),
377 N_("lists [ -group <name> ... ] <regex> [ ... ]"),
378 "configuration.html#lists" },
379 { "subscribe", CMD_SUBSCRIBE, parse_subscribe,
380 N_("Add address to the list of subscribed mailing lists"),
381 N_("subscribe [ -group <name> ... ] <regex> [ ... ]"),
382 "configuration.html#lists" },
383 { "unalias", CMD_UNALIAS, parse_unalias,
384 N_("Remove an alias definition"),
385 N_("unalias { * | <key> ... }"),
386 "configuration.html#alias" },
387 { "unalternates", CMD_UNALTERNATES, parse_unalternates,
388 N_("Remove addresses from `alternates` list"),
389 N_("unalternates { * | <regex> ... }"),
390 "configuration.html#alternates" },
391 { "ungroup", CMD_UNGROUP, parse_group,
392 N_("Remove addresses from an address `group`"),
393 N_("ungroup [ -group <name> ... ] { * | -rx <regex> ... | -addr <address> ... }"),
394 "configuration.html#addrgroup" },
395 { "unlists", CMD_UNLISTS, parse_unlists,
396 N_("Remove address from the list of mailing lists"),
397 N_("unlists { * | <regex> ... }"),
398 "configuration.html#lists" },
399 { "unsubscribe", CMD_UNSUBSCRIBE, parse_unsubscribe,
400 N_("Remove address from the list of subscribed mailing lists"),
401 N_("unsubscribe { * | <regex> ... }"),
402 "configuration.html#lists" },
403
404 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
405 // clang-format on
406};
@ CF_NONE
No flags are set.
Definition command.h:49
@ CMD_SUBSCRIBE
:subscribe
Definition command.h:120
@ CMD_UNSUBSCRIBE
:unsubscribe
Definition command.h:148
@ CMD_UNALIAS
:unalias
Definition command.h:126
@ CMD_GROUP
:group
Definition command.h:82
@ CMD_ALIAS
:alias
Definition command.h:64
@ CMD_LISTS
:lists
Definition command.h:90
@ CMD_UNGROUP
:ungroup
Definition command.h:133
@ CMD_NONE
No Command.
Definition command.h:62
@ CMD_ALTERNATES
:alternates
Definition command.h:65
@ CMD_UNLISTS
:unlists
Definition command.h:137
@ CMD_UNALTERNATES
:unalternates
Definition command.h:127
enum CommandResult parse_unalias(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unalias' command - Implements Command::parse() -.
Definition commands.c:308
enum CommandResult parse_subscribe(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'subscribe' command - Implements Command::parse() -.
Definition group.c:239
enum CommandResult parse_unlists(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unlists' command - Implements Command::parse() -.
Definition group.c:291
enum CommandResult parse_alternates(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'alternates' command - Implements Command::parse() -.
Definition alternates.c:68
enum CommandResult parse_lists(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'lists' command - Implements Command::parse() -.
Definition group.c:191
enum CommandResult parse_group(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'group' and 'ungroup' commands - Implements Command::parse() -.
Definition group.c:90
enum CommandResult parse_unalternates(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unalternates' command - Implements Command::parse() -.
Definition alternates.c:119
enum CommandResult parse_unsubscribe(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unsubscribe' command - Implements Command::parse() -.
Definition group.c:335
enum CommandResult parse_alias(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'alias' command - Implements Command::parse() -.
Definition commands.c:178
#define N_(a)
Definition message.h:32