#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "mutt_commands.h"
#include "sort.h"
#include "gui.h"
Go to the source code of this file.
|
void | alias_init (void) |
| Set up the Alias globals. More...
|
|
void | alias_shutdown (void) |
| Clean up the Alias globals. More...
|
|
void | alias_create (struct AddressList *al, const struct ConfigSubset *sub) |
| Create a new Alias from an Address. More...
|
|
struct AddressList * | alias_lookup (const char *name) |
| Find an Alias. More...
|
|
bool | mutt_addr_is_user (const struct Address *addr) |
| Does the address belong to the user. More...
|
|
void | mutt_expand_aliases_env (struct Envelope *env) |
| Expand aliases in all the fields of an Envelope. More...
|
|
void | mutt_expand_aliases (struct AddressList *al) |
| Expand aliases in a List of Addresses. More...
|
|
struct AddressList * | mutt_get_address (struct Envelope *env, const char **prefix) |
| Get an Address from an Envelope. More...
|
|
enum CommandResult | parse_alias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err) |
| Parse the 'alias' command - Implements Command::parse() More...
|
|
enum CommandResult | parse_unalias (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err) |
| Parse the 'unalias' command - Implements Command::parse() More...
|
|
int | alias_complete (char *buf, size_t buflen, struct ConfigSubset *sub) |
| alias completion routine More...
|
|
int | query_complete (char *buf, size_t buflen, struct ConfigSubset *sub) |
| Perform auto-complete using an Address Query. More...
|
|
void | query_index (struct ConfigSubset *sub) |
| Perform an Alias Query and display the results. More...
|
|
struct Address * | alias_reverse_lookup (const struct Address *addr) |
| Does the user have an alias for the given address. More...
|
|
void | alias_array_sort (struct AliasViewArray *ava, const struct ConfigSubset *sub) |
| Sort and reindex an AliasViewArray. More...
|
|
Email Aliases
- Authors
-
- Copyright
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
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 lib.h.
◆ alias_init()
◆ alias_shutdown()
void alias_shutdown |
( |
void |
| ) |
|
◆ alias_create()
void alias_create |
( |
struct AddressList * |
al, |
|
|
const struct ConfigSubset * |
sub |
|
) |
| |
Create a new Alias from an Address.
- Parameters
-
Definition at line 366 of file alias.c.
369 char buf[1024], tmp[1024] = { 0 }, prompt[2048];
380 pc = strchr(tmp,
'@');
392 false, NULL, NULL) != 0) ||
401 mutt_error(
_(
"You already have an alias defined with that name"));
433 false, NULL, NULL) != 0) ||
457 false, NULL, NULL) != 0)
466 false, NULL, NULL) == 0)
475 snprintf(prompt,
sizeof(prompt),
"[%s = %s # %s] %s", alias->
name, buf,
480 snprintf(prompt,
sizeof(prompt),
"[%s = %s] %s", alias->
name, buf,
_(
"Accept?"));
500 FILE *fp_alias = fopen(buf,
"a+");
508 if (fseek(fp_alias, 0, SEEK_END))
510 if (ftell(fp_alias) > 0)
512 if (fseek(fp_alias, -1, SEEK_CUR) < 0)
514 if (fread(buf, 1, 1, fp_alias) != 1)
520 if (fseek(fp_alias, 0, SEEK_END) < 0)
523 fputc(
'\n', fp_alias);
531 fprintf(fp_alias,
"alias %s ", buf);
537 fprintf(fp_alias,
" # %s", alias->
comment);
538 fputc(
'\n', fp_alias);
◆ alias_lookup()
struct AddressList* alias_lookup |
( |
const char * |
name | ) |
|
Find an Alias.
- Parameters
-
- Return values
-
- Note
- The search is case-insensitive
Definition at line 276 of file alias.c.
278 struct Alias *a = NULL;
◆ mutt_addr_is_user()
bool mutt_addr_is_user |
( |
const struct Address * |
addr | ) |
|
Does the address belong to the user.
- Parameters
-
- Return values
-
true | if the given address belongs to the user |
Definition at line 556 of file alias.c.
◆ mutt_expand_aliases_env()
void mutt_expand_aliases_env |
( |
struct Envelope * |
env | ) |
|
Expand aliases in all the fields of an Envelope.
- Parameters
-
Definition at line 308 of file alias.c.
◆ mutt_expand_aliases()
void mutt_expand_aliases |
( |
struct AddressList * |
al | ) |
|
Expand aliases in a List of Addresses.
- Parameters
-
Duplicate addresses are dropped
Definition at line 294 of file alias.c.
296 struct ListHead expn;
◆ mutt_get_address()
struct AddressList* mutt_get_address |
( |
struct Envelope * |
env, |
|
|
const char ** |
prefix |
|
) |
| |
Get an Address from an Envelope.
- Parameters
-
- Return values
-
- Note
- The caller must NOT free the returned AddressList
Definition at line 326 of file alias.c.
328 struct AddressList *al = NULL;
329 const char *pfx = NULL;
◆ parse_alias()
Parse the 'alias' command - Implements Command::parse()
e.g. "alias jim James Smith <js@example.com> # Pointy-haired boss"
Definition at line 49 of file commands.c.
52 struct Alias *tmp = NULL;
139 char *comment = s->
dptr + 1;
◆ parse_unalias()
◆ alias_complete()
int alias_complete |
( |
char * |
buf, |
|
|
size_t |
buflen, |
|
|
struct ConfigSubset * |
sub |
|
) |
| |
alias completion routine
- Parameters
-
buf | Partial Alias to complete |
buflen | Length of buffer |
sub | Config items |
- Return values
-
Given a partial alias, this routine attempts to fill in the alias from the alias list as much as possible. if given empty search string or found nothing, present all aliases
Definition at line 375 of file dlgalias.c.
377 struct Alias *np = NULL;
378 char bestname[8192] = { 0 };
389 if (bestname[0] ==
'\0')
397 for (i = 0; np->
name[i] && (np->
name[i] == bestname[i]); i++)
405 if (bestname[0] !=
'\0')
450 if (bestname[0] !=
'\0')
◆ query_complete()
int query_complete |
( |
char * |
buf, |
|
|
size_t |
buflen, |
|
|
struct ConfigSubset * |
sub |
|
) |
| |
Perform auto-complete using an Address Query.
- Parameters
-
buf | Buffer for completion |
buflen | Length of buffer |
sub | Config item |
- Return values
-
Definition at line 606 of file dlgquery.c.
◆ query_index()
Perform an Alias Query and display the results.
- Parameters
-
Definition at line 646 of file dlgquery.c.
655 char buf[256] = { 0 };
◆ alias_reverse_lookup()
Does the user have an alias for the given address.
- Parameters
-
- Return values
-
Definition at line 105 of file reverse.c.
◆ alias_array_sort()
void alias_array_sort |
( |
struct AliasViewArray * |
ava, |
|
|
const struct ConfigSubset * |
sub |
|
) |
| |
Sort and reindex an AliasViewArray.
- Parameters
-
ava | Array of Aliases |
sub | Config items |
Definition at line 158 of file sort.c.
169 avp->
num = ARRAY_FOREACH_IDX;
struct AddressList bcc
Email's 'Bcc' list.
#define STAILQ_INIT(head)
void mutt_beep(bool force)
Irritate the user.
static void dlg_select_query(char *buf, size_t buflen, struct AliasList *all, bool retbuf, struct ConfigSubset *sub)
Get the user to enter an Address Query.
NotifyAlias
Alias notification types.
void mutt_grouplist_add_addrlist(struct GroupList *gl, struct AddressList *al)
Add Address list to a GroupList.
#define MUTT_TOKEN_SEMICOLON
Don't treat ; as special.
void aliaslist_free(struct AliasList *al)
Free a List of Aliases.
struct AddressList addr
List of Addresses the Alias expands to.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
void alias_array_sort(struct AliasViewArray *ava, const struct ConfigSubset *sub)
Sort and reindex an AliasViewArray.
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
static bool string_is_address(const char *str, const char *user, const char *domain)
Does an email address match a user and domain?
struct Alias * alias_new(void)
Create a new Alias.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
int alias_array_alias_add(struct AliasViewArray *ava, struct Alias *alias)
Add an Alias to the AliasViewArray.
void alias_reverse_init(void)
Set up the Reverse Alias Hash Table.
size_t mutt_addrlist_write(const struct AddressList *al, char *buf, size_t buflen, bool display)
Write an Address to a buffer.
struct Notify * notify
Notifications handler.
#define TAILQ_EMPTY(head)
#define TAILQ_FOREACH(var, head, field)
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool is_visible
Is visible?
#define ARRAY_SORT(head, fn)
Sort an array.
struct Alias * alias
Alias.
int num
Index number in list.
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
#define TAILQ_INSERT_TAIL(head, elm, field)
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
void alias_free(struct Alias **ptr)
Free an Alias.
@ NT_ALIAS_CHANGED
An Alias has been changed.
char * dptr
Current read/write position.
@ LL_DEBUG5
Log at debug level 5.
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
void alias_reverse_add(struct Alias *alias)
Add an email address lookup for an Alias.
@ MUTT_LIMIT
Messages in limited view.
WHERE char * Username
User's login name.
#define ARRAY_GET(head, idx)
Return the element at index.
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
void alias_reverse_shutdown(void)
Clear up the Reverse Alias Hash Table.
GUI data wrapping an Alias.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
bool mutt_is_mail_list(const struct Address *addr)
Is this the email address of a mailing list? - Implements addr_predicate_t.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
struct AddressList reply_to
Email's 'reply-to'.
#define TAILQ_HEAD_INITIALIZER(head)
#define MUTT_FILE
Do file completion.
#define TAILQ_REMOVE(head, elm, field)
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
#define TAILQ_FIRST(head)
struct AddressList cc
Email's 'Cc' list.
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
void mutt_grouplist_destroy(struct GroupList *gl)
Free a GroupList.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
static void expand_aliases_r(struct AddressList *al, struct ListHead *expn)
Expand aliases, recursively.
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
int parse_grouplist(struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
Parse a group context.
#define ARRAY_FREE(head)
Release all memory.
struct AddressList to
Email's 'To' list.
#define mutt_debug(LEVEL,...)
@ MUTT_CMD_SUCCESS
Success: Command worked.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
struct AliasList Aliases
List of all the user's email aliases.
static sort_t alias_get_sort_function(short sort)
Sorting function decision logic.
@ MUTT_CMD_ERROR
Error: Can't help the user.
static int query_run(char *s, bool verbose, struct AliasList *al, const struct ConfigSubset *sub)
Run an external program to find Addresses.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
char * mailbox
Mailbox and host address.
#define STAILQ_HEAD_INITIALIZER(head)
@ NT_ALIAS_NEW
A new Alias has been created.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
@ MUTT_CMD_WARNING
Warning: Help given to the user.
#define ARRAY_EMPTY(head)
Check if an array is empty.
struct AddressList from
Email's 'From' list.
short C_DebugLevel
Config: Logging level for debug logs.
#define TAILQ_NEXT(elm, field)
static void recode_buf(char *buf, size_t buflen)
Convert some text between two character sets.
char * comment
Free-form comment string.
WHERE char * ShortHostname
Short version of the hostname.
struct AddressList * alias_lookup(const char *name)
Find an Alias.
Container for Accounts, Notifications.
#define MUTT_TOKEN_QUOTE
Don't interpret quotes.
@ NT_ALIAS
Alias has changed, NotifyAlias, EventAlias.
int mutt_pattern_alias_func(int op, char *prompt, char *title, struct AliasMenuData *mdata, struct Context *ctx, struct Menu *menu)
Perform some Pattern matching for Alias.
#define MUTT_CLEAR
Clear input if printable character is pressed.
struct ConfigSubset * sub
Inherited config items.
WHERE struct Address * C_From
Config: Default 'From' address to use, if isn't otherwise set.
A shortcut for an email address or addresses.
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
int mutt_get_field(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
static bool alias_to_addrlist(struct AddressList *al, struct Alias *alias)
Turn an Alias into an AddressList.
static struct HashTable * ReverseAliases
Hash Table of aliases (email address -> alias)
void alias_reverse_delete(struct Alias *alias)
Remove an email address lookup for an Alias.
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
char * data
Pointer to data.
#define mutt_message(...)
@ LL_DEBUG4
Log at debug level 4.
int mutt_str_asprintf(char **strp, const char *fmt,...)
static void dlg_select_alias(char *buf, size_t buflen, struct AliasMenuData *mdata)
Display a menu of Aliases.
size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen)
Quote a filename to survive the shell's quoting rules.
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
Does a string match any Regex in the list?
#define mutt_warning(...)
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
static int check_alias_name(const char *s, char *dest, size_t destlen)
Sanity-check an alias name.
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
bool is_deleted
Is it deleted?
#define MUTT_TOKEN_SPACE
Don't treat whitespace as a term.
bool mutt_addr_is_user(const struct Address *addr)
Does the address belong to the user.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
static void write_safe_address(FILE *fp, char *s)
Defang malicious email addresses.
#define MUTT_COMP_NO_FLAGS
No flags are set.