NeoMutt  2024-11-14-34-g5aaf0d
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 "functions.h"
#include "gui.h"
#include "mutt_logging.h"
+ Include dependency graph for dlg_alias.c:

Go to the source code of this file.

Functions

void alias_a (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Alias: Alias name - Implements ExpandoRenderData::get_string() -.
 
void alias_c (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Alias: Comment - Implements ExpandoRenderData::get_string() -.
 
long alias_f_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Alias: Flags - Implements ExpandoRenderData::get_number() -.
 
void alias_f (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Alias: Flags - Implements ExpandoRenderData::get_string() -.
 
long alias_n_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Alias: Index number - Implements ExpandoRenderData::get_number() -.
 
void alias_r (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Alias: Address - Implements ExpandoRenderData::get_string() -.
 
long alias_t_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Alias: Tagged char - Implements ExpandoRenderData::get_number() -.
 
void alias_t (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Alias: Tagged char - Implements ExpandoRenderData::get_string() -.
 
void alias_Y (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
 Alias: Tags - Implements ExpandoRenderData::get_string() -.
 
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 Buffer *buf, 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

const struct ExpandoRenderData AliasRenderData []
 Callbacks for Alias Expandos.
 
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()

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

336{
338
339 struct Menu *menu = sdw.menu;
340
342 menu->tag = alias_tag;
343 menu->max = alias_array_count_visible(&mdata->ava);
344 menu->mdata = mdata;
345 menu->mdata_free = NULL; // Menu doesn't own the data
346
347 struct MuttWindow *win_menu = menu->win;
348
349 // Override the Simple Dialog's recalc()
350 win_menu->recalc = alias_recalc;
351
352 alias_set_title(sdw.sbar, mdata->title, mdata->limit);
353
354 // NT_COLOR is handled by the SimpleDialog
358
359 return sdw;
360}
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:221
static int alias_tag(struct Menu *menu, int sel, int act)
Tag some aliases - Implements Menu::tag() -.
Definition: dlg_alias.c:243
static int alias_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: dlg_alias.c:306
static int alias_alias_observer(struct NotifyCallback *nc)
Notification that an Alias has changed - Implements observer_t -.
Definition: dlg_alias.c:259
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:92
struct SimpleDialogWindows simple_dialog_new(enum MenuType mtype, 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
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
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_ALIAS
Alias has changed, NotifyAlias, EventAlias.
Definition: notify_type.h:37
char * limit
Limit being used.
Definition: gui.h:60
char * title
Title for the status bar.
Definition: gui.h:62
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:131
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
void * mdata
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:137
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:172
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct Notify * notify
Notifications handler.
Definition: neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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
@ MENU_ALIAS
Select an email address by its alias.
Definition: type.h:37
+ 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 441 of file dlg_alias.c.

442{
443 struct Alias *np = NULL;
444 char bestname[8192] = { 0 };
445
446 struct AliasMenuData mdata = { ARRAY_HEAD_INITIALIZER, NULL, sub };
447 mdata.limit = buf_strdup(buf);
448 mdata.search_state = search_state_new();
449
450 if (buf_at(buf, 0) != '\0')
451 {
452 TAILQ_FOREACH(np, &Aliases, entries)
453 {
454 if (np->name && mutt_strn_equal(np->name, buf_string(buf), buf_len(buf)))
455 {
456 if (bestname[0] == '\0') /* init */
457 {
458 mutt_str_copy(bestname, np->name,
459 MIN(mutt_str_len(np->name) + 1, sizeof(bestname)));
460 }
461 else
462 {
463 int i;
464 for (i = 0; np->name[i] && (np->name[i] == bestname[i]); i++)
465 ; // do nothing
466
467 bestname[i] = '\0';
468 }
469 }
470 }
471
472 if (bestname[0] == '\0')
473 {
474 // Create a View Array of all the Aliases
475 FREE(&mdata.limit);
476 TAILQ_FOREACH(np, &Aliases, entries)
477 {
479 }
480 }
481 else
482 {
483 /* fake the pattern for menu title */
484 char *mtitle = NULL;
485 mutt_str_asprintf(&mtitle, "~f ^%s", buf_string(buf));
486 FREE(&mdata.limit);
487 mdata.limit = mtitle;
488
489 if (!mutt_str_equal(bestname, buf_string(buf)))
490 {
491 /* we are adding something to the completion */
492 buf_strcpy_n(buf, bestname, mutt_str_len(bestname) + 1);
493 FREE(&mdata.limit);
494 search_state_free(&mdata.search_state);
495 return 1;
496 }
497
498 /* build alias list and show it */
499 TAILQ_FOREACH(np, &Aliases, entries)
500 {
501 int aasize = alias_array_alias_add(&mdata.ava, np);
502
503 struct AliasView *av = ARRAY_GET(&mdata.ava, aasize - 1);
504
505 if (np->name && !mutt_strn_equal(np->name, buf_string(buf), buf_len(buf)))
506 {
507 av->is_visible = false;
508 }
509 }
510 }
511 }
512
513 if (ARRAY_EMPTY(&mdata.ava))
514 {
515 TAILQ_FOREACH(np, &Aliases, entries)
516 {
517 alias_array_alias_add(&mdata.ava, np);
518 }
519
520 mutt_pattern_alias_func(NULL, &mdata, PAA_VISIBLE, NULL);
521 }
522
523 if (!dlg_alias(NULL, &mdata))
524 goto done;
525
526 buf_reset(buf);
527
528 // Extract the selected aliases
529 struct Buffer *tmpbuf = buf_pool_get();
530 struct AliasView *avp = NULL;
531 ARRAY_FOREACH(avp, &mdata.ava)
532 {
533 if (!avp->is_tagged)
534 continue;
535
536 mutt_addrlist_write(&avp->alias->addr, tmpbuf, true);
537 buf_addstr(tmpbuf, ", ");
538 }
539 buf_copy(buf, tmpbuf);
540 buf_pool_release(&tmpbuf);
541
542done:
543 // Process any deleted aliases
544 ARRAY_FOREACH(avp, &mdata.ava)
545 {
546 if (!avp->is_deleted)
547 continue;
548
549 TAILQ_REMOVE(&Aliases, avp->alias, entries);
550 alias_free(&avp->alias);
551 }
552
553 ARRAY_FREE(&mdata.ava);
554 FREE(&mdata.limit);
555 FREE(&mdata.title);
557
558 return 0;
559}
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
Definition: address.c:1206
void alias_free(struct Alias **ptr)
Free an Alias.
Definition: alias.c:672
struct AliasList Aliases
List of all the user's email aliases.
Definition: alias.c:62
int alias_array_alias_add(struct AliasViewArray *ava, struct Alias *alias)
Add an Alias to the AliasViewArray.
Definition: array.c:47
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#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:491
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
Definition: buffer.c:670
size_t buf_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:416
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:601
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:571
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 Buffer *buf, struct AliasMenuData *mdata)
Display a menu of Aliases -.
Definition: dlg_alias.c:371
#define FREE(x)
Definition: memory.h:55
#define MIN(a, b)
Definition: memory.h:32
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:803
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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:425
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
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:581
@ PAA_VISIBLE
Set AliasView.is_visible and hide the rest.
Definition: lib.h:189
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:191
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
void search_state_free(struct SearchState **ptr)
Free a SearchState.
Definition: search_state.c:51
struct SearchState * search_state_new(void)
Create a new SearchState.
Definition: search_state.c:39
AliasView array wrapper with Pattern information -.
Definition: gui.h:54
struct AliasViewArray ava
All Aliases/Queries.
Definition: gui.h:55
struct SearchState * search_state
State of the current search.
Definition: gui.h:63
struct ConfigSubset * sub
Config items.
Definition: gui.h:57
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 566 of file dlg_alias.c.

567{
568 struct Alias *np = NULL;
569
570 struct AliasMenuData mdata = { ARRAY_HEAD_INITIALIZER, NULL, sub };
571 mdata.search_state = search_state_new();
572
573 // Create a View Array of all the Aliases
574 TAILQ_FOREACH(np, &Aliases, entries)
575 {
577 }
578
579 if (!dlg_alias(NULL, &mdata))
580 goto done;
581
582 // Prepare the "To:" field of a new email
583 struct Email *e = email_new();
584 e->env = mutt_env_new();
585
586 struct AliasView *avp = NULL;
587 ARRAY_FOREACH(avp, &mdata.ava)
588 {
589 if (!avp->is_tagged)
590 continue;
591
592 struct AddressList al_copy = TAILQ_HEAD_INITIALIZER(al_copy);
593 if (alias_to_addrlist(&al_copy, avp->alias))
594 {
595 mutt_addrlist_copy(&e->env->to, &al_copy, false);
596 mutt_addrlist_clear(&al_copy);
597 }
598 }
599
600 mutt_send_message(SEND_REVIEW_TO, e, NULL, m, NULL, sub);
601
602done:
603 // Process any deleted aliases
604 ARRAY_FOREACH(avp, &mdata.ava)
605 {
606 if (avp->is_deleted)
607 {
608 TAILQ_REMOVE(&Aliases, avp->alias, entries);
609 alias_free(&avp->alias);
610 }
611 }
612
613 ARRAY_FREE(&mdata.ava);
614 FREE(&mdata.limit);
615 FREE(&mdata.title);
617}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:765
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1460
bool alias_to_addrlist(struct AddressList *al, struct Alias *alias)
Turn an Alias into an AddressList.
Definition: dlg_query.c:121
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:46
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
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:2102
#define SEND_REVIEW_TO
Allow the user to edit the To field.
Definition: send.h:56
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

◆ AliasRenderData

const struct ExpandoRenderData AliasRenderData
Initial value:
= {
{ -1, -1, NULL, NULL },
}
@ ED_ALIAS
Alias ED_ALI_ ExpandoDataAlias.
Definition: domain.h:35
long alias_t_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Alias: Tagged char - Implements ExpandoRenderData::get_number() -.
Definition: dlg_alias.c:186
long alias_f_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Alias: Flags - Implements ExpandoRenderData::get_number() -.
Definition: dlg_alias.c:142
long alias_n_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Alias: Index number - Implements ExpandoRenderData::get_number() -.
Definition: dlg_alias.c:164
void alias_t(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Tagged char - Implements ExpandoRenderData::get_string() -.
Definition: dlg_alias.c:195
void alias_Y(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Tags - Implements ExpandoRenderData::get_string() -.
Definition: dlg_alias.c:208
void alias_c(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Comment - Implements ExpandoRenderData::get_string() -.
Definition: dlg_alias.c:129
void alias_a(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Alias name - Implements ExpandoRenderData::get_string() -.
Definition: dlg_alias.c:116
void alias_f(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Flags - Implements ExpandoRenderData::get_string() -.
Definition: dlg_alias.c:151
void alias_r(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Alias: Address - Implements ExpandoRenderData::get_string() -.
Definition: dlg_alias.c:174
@ ED_ALI_FLAGS
Alias.flags.
Definition: gui.h:75
@ ED_ALI_NUMBER
AliasView.num.
Definition: gui.h:77
@ ED_ALI_NAME
Alias.name.
Definition: gui.h:76
@ ED_ALI_ADDRESS
Alias.addr.
Definition: gui.h:73
@ ED_ALI_COMMENT
Alias.comment.
Definition: gui.h:74
@ ED_ALI_TAGGED
AliasView.tagged.
Definition: gui.h:78
@ ED_ALI_TAGS
Alias.tags.
Definition: gui.h:79

Callbacks for Alias Expandos.

See also
AliasFormatDef, ExpandoDataAlias, ExpandoDataGlobal

Definition at line 97 of file dlg_alias.c.

◆ 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.