NeoMutt  2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_alias.c File Reference

Address book. More...

#include "config.h"
#include <stdbool.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 "gui/lib.h"
#include "lib.h"
#include "expando/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "pattern/lib.h"
#include "send/lib.h"
#include "alias.h"
#include "expando.h"
#include "functions.h"
#include "gui.h"
#include "module_data.h"
#include "mutt_logging.h"
Include dependency graph for dlg_alias.c:

Go to the source code of this file.

Functions

static int alias_make_entry (struct Menu *menu, int line, int max_cols, struct Buffer *buf)
 Format an Alias for the Menu - Implements Menu::make_entry() -.
static int alias_tag (struct Menu *menu, int sel, int act)
 Tag some aliases - Implements Menu::tag() -.
static int alias_alias_observer (struct NotifyCallback *nc)
 Notification that an Alias has changed - Implements observer_t -.
static int alias_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
static struct SimpleDialogWindows alias_dialog_new (struct AliasMenuData *mdata)
 Create an Alias Selection Dialog.
static bool dlg_alias (struct AliasMenuData *mdata)
 Display a menu of Aliases -.
int alias_complete (struct Buffer *buf, struct ConfigSubset *sub)
 Alias completion routine.
void alias_dialog (struct Mailbox *m, struct ConfigSubset *sub)
 Open the aliases dialog.

Variables

static const struct Mapping AliasHelp []
 Help Bar for the Alias dialog (address book).

Detailed Description

Address book.

Authors
  • Richard Russon
  • Romeu Vieira
  • Pietro Cerutti
  • Anna Figueiredo Gomes
  • Dennis Schön
  • Tóth János

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 dlg_alias.c.

Function Documentation

◆ alias_dialog_new()

struct SimpleDialogWindows alias_dialog_new ( struct AliasMenuData * mdata)
static

Create an Alias Selection Dialog.

Parameters
mdataMenu data holding Aliases
Return values
objSimpleDialogWindows Tuple containing Dialog, SimpleBar and Menu pointers

Definition at line 232 of file dlg_alias.c.

233{
235 ASSERT(mod_data);
236
237 struct SimpleDialogWindows sdw = simple_dialog_new(mod_data->menu_alias,
239
240 struct Menu *menu = sdw.menu;
241
243 menu->tag = alias_tag;
244 menu->max = alias_array_count_visible(&mdata->ava);
245 menu->mdata = mdata;
246 menu->mdata_free = NULL; // Menu doesn't own the data
247
248 struct MuttWindow *win_menu = menu->win;
249
250 // Override the Simple Dialog's recalc()
251 win_menu->recalc = alias_recalc;
252
253 alias_set_title(sdw.sbar, mdata->title, mdata->limit);
254
255 // NT_COLOR is handled by the SimpleDialog
259
260 return sdw;
261}
int alias_array_count_visible(struct AliasViewArray *ava)
Count number of visible Aliases.
Definition array.c:95
static const struct Mapping AliasHelp[]
Help Bar for the Alias dialog (address book).
Definition dlg_alias.c:100
static int alias_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an Alias for the Menu - Implements Menu::make_entry() -.
Definition dlg_alias.c:118
static int alias_tag(struct Menu *menu, int sel, int act)
Tag some aliases - Implements Menu::tag() -.
Definition dlg_alias.c:140
static int alias_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition dlg_alias.c:203
static int alias_alias_observer(struct NotifyCallback *nc)
Notification that an Alias has changed - Implements observer_t -.
Definition dlg_alias.c:156
int alias_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition gui.c:43
int alias_recalc(struct MuttWindow *win)
Recalculate the display of the Alias Window - Implements MuttWindow::recalc() -.
Definition gui.c:96
struct SimpleDialogWindows simple_dialog_new(const struct MenuDefinition *md, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition simple.c:132
void alias_set_title(struct MuttWindow *sbar, char *menu_name, char *limit)
Create a title string for the Menu.
Definition gui.c:72
@ MODULE_ID_ALIAS
ModuleAlias, Alias
Definition module_api.h:48
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition notify.c:191
@ WT_DLG_ALIAS
Alias Dialog, dlg_alias().
Definition mutt_window.h:77
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ NT_ALIAS
Alias has changed, NotifyAlias, EventAlias.
Definition notify_type.h:37
#define ASSERT(COND)
Definition signal2.h:59
char * limit
Limit being used.
Definition gui.h:61
char * title
Title for the status bar.
Definition gui.h:63
Alias private Module data.
Definition module_data.h:33
struct MenuDefinition * menu_alias
Alias menu definition.
Definition module_data.h:42
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
int(* tag)(struct Menu *menu, int sel, int act)
Definition lib.h:139
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:114
void * mdata
Private data.
Definition lib.h:155
int max
Number of entries in the menu.
Definition lib.h:88
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
int(* recalc)(struct MuttWindow *win)
Container for Accounts, Notifications.
Definition neomutt.h:41
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Tuple for the results of simple_dialog_new().
Definition simple.h:35
struct MuttWindow * sbar
Simple Bar.
Definition simple.h:37
struct Menu * menu
Menu.
Definition simple.h:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ alias_complete()

int alias_complete ( struct Buffer * buf,
struct ConfigSubset * sub )

Alias completion routine.

Parameters
bufPartial Alias to complete
subConfig items
Return values
1Success
0Error

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 353 of file dlg_alias.c.

354{
355 char bestname[8192] = { 0 };
356 struct Alias *a_best = NULL;
357 int count = 0;
358
359 struct AliasMenuData mdata = { ARRAY_HEAD_INITIALIZER, NULL, sub };
360 mdata.limit = buf_strdup(buf);
361 mdata.search_state = search_state_new();
362
364 ASSERT(mod_data);
365
366 if (buf_at(buf, 0) != '\0')
367 {
368 struct Alias **ap = NULL;
369 ARRAY_FOREACH(ap, &mod_data->aliases)
370 {
371 struct Alias *a = *ap;
372 if (a->name && mutt_strn_equal(a->name, buf_string(buf), buf_len(buf)))
373 {
374 a_best = a;
375 count++;
376
377 if (bestname[0] == '\0') /* init */
378 {
379 mutt_str_copy(bestname, a->name, MIN(mutt_str_len(a->name) + 1, sizeof(bestname)));
380 }
381 else
382 {
383 int i;
384 for (i = 0; a->name[i] && (a->name[i] == bestname[i]); i++)
385 ; // do nothing
386
387 bestname[i] = '\0';
388 }
389 }
390 }
391
392 // Exactly one match, so expand the Alias and return
393 if (count == 1)
394 {
395 buf_reset(buf);
396 mutt_addrlist_write(&a_best->addr, buf, true);
397 buf_addstr(buf, ", ");
398 FREE(&mdata.limit);
400 return 1;
401 }
402
403 if (bestname[0] == '\0')
404 {
405 // Create a View Array of all the Aliases
406 FREE(&mdata.limit);
407 ARRAY_FOREACH(ap, &mod_data->aliases)
408 {
409 alias_array_alias_add(&mdata.ava, *ap);
410 }
411 }
412 else
413 {
414 /* fake the pattern for menu title */
415 char *mtitle = NULL;
416 mutt_str_asprintf(&mtitle, "~f ^%s", buf_string(buf));
417 FREE(&mdata.limit);
418 mdata.limit = mtitle;
419
420 if (!mutt_str_equal(bestname, buf_string(buf)))
421 {
422 /* we are adding something to the completion */
423 buf_strcpy_n(buf, bestname, mutt_str_len(bestname) + 1);
424 FREE(&mdata.limit);
426 return 1;
427 }
428
429 /* build alias list and show it */
430 ARRAY_FOREACH(ap, &mod_data->aliases)
431 {
432 struct Alias *a = *ap;
433 int aasize = alias_array_alias_add(&mdata.ava, a);
434
435 struct AliasView *av = ARRAY_GET(&mdata.ava, aasize - 1);
436
437 if (a->name && !mutt_strn_equal(a->name, buf_string(buf), buf_len(buf)))
438 {
439 av->is_visible = false;
440 }
441 }
442 }
443 }
444
445 if (ARRAY_EMPTY(&mdata.ava))
446 {
447 struct Alias **ap = NULL;
448 ARRAY_FOREACH(ap, &mod_data->aliases)
449 {
450 alias_array_alias_add(&mdata.ava, *ap);
451 }
452
453 mutt_pattern_alias_func(NULL, &mdata, PAA_VISIBLE, NULL);
454 }
455
456 if (!dlg_alias(&mdata))
457 goto done;
458
459 buf_reset(buf);
460
461 // Extract the selected aliases
462 struct Buffer *tmpbuf = buf_pool_get();
463 struct AliasView *avp = NULL;
464 ARRAY_FOREACH(avp, &mdata.ava)
465 {
466 if (!avp->is_tagged)
467 continue;
468
469 mutt_addrlist_write(&avp->alias->addr, tmpbuf, true);
470 buf_addstr(tmpbuf, ", ");
471 }
472 buf_copy(buf, tmpbuf);
473 buf_pool_release(&tmpbuf);
474
475done:
476 // Process any deleted aliases
477 ARRAY_FOREACH(avp, &mdata.ava)
478 {
479 if (!avp->is_deleted)
480 continue;
481
482 // Find and remove the alias from the Aliases array
483 struct Alias **ap = NULL;
484 ARRAY_FOREACH(ap, &mod_data->aliases)
485 {
486 if (*ap == avp->alias)
487 {
488 ARRAY_REMOVE(&mod_data->aliases, ap);
489 break;
490 }
491 }
492 alias_free(&avp->alias);
493 }
494
495 ARRAY_FREE(&mdata.ava);
496 FREE(&mdata.limit);
497 FREE(&mdata.title);
499
500 return 0;
501}
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition address.c:1217
void alias_free(struct Alias **ptr)
Free an Alias.
Definition alias.c:674
int alias_array_alias_add(struct AliasViewArray *ava, struct Alias *alias)
Add an Alias to the AliasViewArray.
Definition array.c:47
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:497
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:89
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition buffer.c:674
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition buffer.c:422
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:607
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:577
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
static bool dlg_alias(struct AliasMenuData *mdata)
Display a menu of Aliases -.
Definition dlg_alias.c:271
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MIN(a, b)
Return the minimum of two values.
Definition memory.h:40
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition string.c:809
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:666
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition string.c:429
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:503
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination).
Definition string.c:587
@ PAA_VISIBLE
Set AliasView.is_visible and hide the rest.
Definition lib.h:203
int mutt_pattern_alias_func(char *prompt, struct AliasMenuData *mdata, enum PatternAlias action, struct Menu *menu)
Perform some Pattern matching for Alias.
Definition pattern.c:170
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
void search_state_free(struct SearchState **ptr)
Free a SearchState.
struct SearchState * search_state_new(void)
Create a new SearchState.
AliasView array wrapper with Pattern information -.
Definition gui.h:55
struct AliasViewArray ava
All Aliases/Queries.
Definition gui.h:56
struct SearchState * search_state
State of the current search.
Definition gui.h:64
struct ConfigSubset * sub
Config items.
Definition gui.h:58
struct AliasArray aliases
User's email aliases.
Definition module_data.h:35
GUI data wrapping an Alias.
Definition gui.h:38
bool is_visible
Is visible?
Definition gui.h:45
struct Alias * alias
Alias.
Definition gui.h:46
bool is_deleted
Is it deleted?
Definition gui.h:44
bool is_tagged
Is it tagged?
Definition gui.h:43
A shortcut for an email address or addresses.
Definition alias.h:35
char * name
Short name.
Definition alias.h:36
struct AddressList addr
List of Addresses the Alias expands to.
Definition alias.h:37
String manipulation buffer.
Definition buffer.h:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ alias_dialog()

void alias_dialog ( struct Mailbox * m,
struct ConfigSubset * sub )

Open the aliases dialog.

Parameters
mMailbox
subConfig item

Definition at line 508 of file dlg_alias.c.

509{
510 struct Alias **ap = NULL;
511
512 struct AliasMenuData mdata = { ARRAY_HEAD_INITIALIZER, NULL, sub };
514
516 ASSERT(mod_data);
517
518 // Create a View Array of all the Aliases
519 ARRAY_FOREACH(ap, &mod_data->aliases)
520 {
521 alias_array_alias_add(&mdata.ava, *ap);
522 }
523
524 if (!dlg_alias(&mdata))
525 goto done;
526
527 // Prepare the "To:" field of a new email
528 struct Email *e = email_new();
529 e->env = mutt_env_new();
530
531 struct AliasView *avp = NULL;
532 ARRAY_FOREACH(avp, &mdata.ava)
533 {
534 if (!avp->is_tagged)
535 continue;
536
537 struct AddressList al_copy = TAILQ_HEAD_INITIALIZER(al_copy);
538 if (alias_to_addrlist(&al_copy, avp->alias))
539 {
540 mutt_addrlist_copy(&e->env->to, &al_copy, false);
541 mutt_addrlist_clear(&al_copy);
542 }
543 }
544
545 mutt_send_message(SEND_REVIEW_TO, e, NULL, m, NULL, sub);
546
547done:
548 // Process any deleted aliases
549 ARRAY_FOREACH(avp, &mdata.ava)
550 {
551 if (avp->is_deleted)
552 {
553 // Find and remove the alias from the Aliases array
554 ARRAY_FOREACH(ap, &mod_data->aliases)
555 {
556 if (*ap == avp->alias)
557 {
558 ARRAY_REMOVE(&mod_data->aliases, ap);
559 break;
560 }
561 }
562 alias_free(&avp->alias);
563 }
564 }
565
566 ARRAY_FREE(&mdata.ava);
567 FREE(&mdata.limit);
568 FREE(&mdata.title);
570}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition address.c:776
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition address.c:1473
bool alias_to_addrlist(struct AddressList *al, struct Alias *alias)
Turn an Alias into an AddressList.
Definition dlg_query.c:119
struct Email * email_new(void)
Create a new Email.
Definition email.c:77
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition envelope.c:45
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:694
int mutt_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile, struct Mailbox *m, struct EmailArray *ea, struct ConfigSubset *sub)
Send an email.
Definition send.c:2035
@ SEND_REVIEW_TO
Allow the user to edit the To field.
Definition send.h:60
The envelope/body of an email.
Definition email.h:39
struct Envelope * env
Envelope information.
Definition email.h:68
struct AddressList to
Email's 'To' list.
Definition envelope.h:60
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ AliasHelp

const struct Mapping AliasHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Del"), OP_DELETE },
{ N_("Undel"), OP_UNDELETE },
{ N_("Sort"), OP_SORT },
{ N_("Rev-Sort"), OP_SORT_REVERSE },
{ N_("Select"), OP_GENERIC_SELECT_ENTRY },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition message.h:32

Help Bar for the Alias dialog (address book).

Definition at line 100 of file dlg_alias.c.

100 {
101 // clang-format off
102 { N_("Exit"), OP_EXIT },
103 { N_("Del"), OP_DELETE },
104 { N_("Undel"), OP_UNDELETE },
105 { N_("Sort"), OP_SORT },
106 { N_("Rev-Sort"), OP_SORT_REVERSE },
107 { N_("Select"), OP_GENERIC_SELECT_ENTRY },
108 { N_("Help"), OP_HELP },
109 { NULL, 0 },
110 // clang-format on
111};