NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_mlist.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdio.h>
31#include "mutt/lib.h"
32#include "email/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "lib.h"
36#include "key/lib.h"
37#include "menu/lib.h"
38#include "functions.h"
39#include "mutt_logging.h"
40#include "mx.h"
41
43static const struct Mapping MlistHelp[] = {
44 // clang-format off
45 { N_("Exit"), OP_EXIT },
46 { N_("Archive"), OP_LIST_ARCHIVE },
47 { N_("Help"), OP_LIST_HELP },
48 { N_("Owner"), OP_LIST_OWNER },
49 { N_("Post"), OP_LIST_POST },
50 { N_("Subscribe"), OP_LIST_SUBSCRIBE },
51 { N_("Unsubscribe"), OP_LIST_UNSUBSCRIBE },
52 { NULL, 0 },
53 // clang-format on
54};
55
59static void mlist_data_free(struct Menu *menu, void **ptr)
60{
61 struct ListData *ld = *ptr;
62 if (!ld)
63 return;
64
65 ARRAY_FREE(&ld->entries);
67 FREE(ptr);
68}
69
75static void mlist_data_add_entries(struct ListData *ld, const struct ListAction *action)
76{
77 struct ListHead *values = mlist_action_value(&ld->headers, action);
78 struct ListNode *np = NULL;
79 STAILQ_FOREACH(np, values, entries)
80 {
81 if (!mutt_istr_startswith(np->data, "mailto:"))
82 continue;
83
84 const struct ListEntry entry = { action, np->data };
85 ARRAY_ADD(&ld->entries, entry);
86 }
87}
88
92static int mlist_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
93{
94 struct ListData *ld = menu->mdata;
95 if (!ld)
96 return 0;
97
98 const struct ListEntry *entry = ARRAY_GET(&ld->entries, line);
99 if (!entry)
100 return 0;
101
102 const char *name = _(entry->action->name);
103
104 buf_strcpy(buf, name);
105 for (int i = mutt_strwidth(name); i < ld->label_width; i++)
106 buf_addch(buf, ' ');
107 buf_addstr(buf, ": ");
108 buf_addstr(buf, entry->value);
109
110 return mutt_strwidth(buf_string(buf));
111}
112
118void dlg_mlist(struct Mailbox *m, struct Email *e)
119{
120 if (!m || !e)
121 return;
122
123 struct MenuDefinition *md_list = menu_find(MENU_LIST);
124 ASSERT(md_list);
125
126 struct ListData *ld = MUTT_MEM_CALLOC(1, struct ListData);
127 ld->mailbox = m;
128
129 struct Message *msg = mx_msg_open(m, e);
130 if (!msg)
131 {
132 FREE(&ld);
133 return;
134 }
135
136 if (!mutt_file_seek(msg->fp, e->offset, SEEK_SET))
137 {
138 mutt_error(_("Unable to read mailing list headers"));
139 mx_msg_close(m, &msg);
140 FREE(&ld);
141 return;
142 }
143
145 mx_msg_close(m, &msg);
146
147 for (int i = 0; i < ListActionsCount; i++)
149
150 if (ARRAY_EMPTY(&ld->entries))
151 {
152 mutt_warning(_("No mailing list actions available"));
154 FREE(&ld);
155 return;
156 }
157
158 for (int i = 0; i < ListActionsCount; i++)
160
162 struct Menu *menu = sdw.menu;
163 ld->menu = menu;
164 menu->max = ARRAY_SIZE(&ld->entries);
166 menu->mdata = ld;
168
169 sbar_set_title(sdw.sbar, _("Available mailing list actions"));
170
171 struct MuttWindow *old_focus = window_set_focus(menu->win);
172 // ---------------------------------------------------------------------------
173 // Event Loop
174 int op = OP_NULL;
175 struct KeyEvent event = { 0, OP_NULL };
176 do
177 {
178 menu_tagging_dispatcher(menu->win, &event);
179 window_redraw(NULL);
180
181 event = km_dokey(md_list, GETCH_NONE);
182 op = event.op;
183 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
184 if (op < 0)
185 continue;
186 if (op == OP_NULL)
187 {
188 km_error_key(md_list);
189 continue;
190 }
192
193 int rc = mlist_function_dispatcher(sdw.dlg, &event);
194 if (rc == FR_UNKNOWN)
195 rc = menu_function_dispatcher(menu->win, &event);
196 if (rc == FR_UNKNOWN)
197 rc = global_function_dispatcher(menu->win, &event);
198 } while (!ld->done);
199 // ---------------------------------------------------------------------------
200
201 window_set_focus(old_focus);
203}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#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
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:248
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:401
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Convenience wrapper for the core headers.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition curs_lib.c:445
@ FR_UNKNOWN
Unknown function.
Definition dispatcher.h:34
static void mlist_data_add_entries(struct ListData *ld, const struct ListAction *action)
Add menu rows for one mailing-list action.
Definition dlg_mlist.c:75
static const struct Mapping MlistHelp[]
Help Bar for the Mailing-list action dialog.
Definition dlg_mlist.c:43
Structs that make up an email.
void mutt_rfc2369_list_headers_free(struct Rfc2369ListHeaders *headers)
Free RFC 2369 mailing-list header values.
Definition parse.c:704
void mutt_rfc2369_read_headers(FILE *fp, struct Rfc2369ListHeaders *headers)
Read RFC 2369 mailing-list headers.
Definition parse.c:724
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition file.c:648
struct KeyEvent km_dokey(const struct MenuDefinition *md, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:518
void km_error_key(const struct MenuDefinition *md)
Handle an unbound key sequence.
Definition get.c:328
@ GETCH_NONE
No flags are set.
Definition get.h:38
int mlist_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a List dialog function - Implements function_dispatcher_t -.
Definition functions.c:269
int menu_tagging_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition tagging.c:239
int global_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Global function - Implements function_dispatcher_t -.
Definition global.c:182
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:366
void dlg_mlist(struct Mailbox *m, struct Email *e)
Display mailing-list actions for an email -.
Definition dlg_mlist.c:118
#define mutt_warning(...)
Definition logging2.h:92
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int mlist_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format a mailing-list action for the dialog - Implements Menu::make_entry() -.
Definition dlg_mlist.c:92
static void mlist_data_free(struct Menu *menu, void **ptr)
Free list dialog data - Implements Menu::mdata_free() -.
Definition dlg_mlist.c:59
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition simple.c:169
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
Manage keymappings.
struct MenuDefinition * menu_find(int menu)
Find a Menu Definition by Menu type.
Definition menu.c:231
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
GUI present the user with a selectable list.
const int ListActionsCount
Number of entries in ListActions.
Definition functions.c:57
const struct ListAction ListActions[]
Mailing-list actions shown in the dialog.
Definition functions.c:45
struct ListHead * mlist_action_value(struct Rfc2369ListHeaders *headers, const struct ListAction *action)
Get the stored value for a mailing-list action.
Definition functions.c:113
Mailing-list functions.
Mailing-list action dialog.
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition string.c:246
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
NeoMutt Logging.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
@ WT_DLG_MLIST
Mailing List Dialog, dlg_mlist()
Definition mutt_window.h:87
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
Definition mx.c:1183
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
Definition mx.c:1137
API for mailboxes.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
#define ASSERT(COND)
Definition signal2.h:59
String manipulation buffer.
Definition buffer.h:36
The envelope/body of an email.
Definition email.h:39
LOFF_T offset
Where in the stream does this message begin?
Definition email.h:71
An event such as a keypress.
Definition get.h:75
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
A mailing-list action in the dialog.
Definition functions.h:38
const char * name
Label for the action.
Definition functions.h:39
Private data for the Mailing-list action dialog.
Definition functions.h:64
int label_width
Width of the longest action label.
Definition functions.h:69
struct Menu * menu
Dialog menu.
Definition functions.h:65
struct Mailbox * mailbox
Source mailbox.
Definition functions.h:66
struct ListEntryArray entries
Menu rows.
Definition functions.h:68
struct Rfc2369ListHeaders headers
Parsed List-* headers.
Definition functions.h:67
bool done
Exit the dialog.
Definition functions.h:70
A mailing-list action in the dialog.
Definition functions.h:48
const char * value
URI to use.
Definition functions.h:50
const struct ListAction * action
Action definition.
Definition functions.h:49
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
A mailbox.
Definition mailbox.h:81
Mapping between user-readable string and a constant.
Definition mapping.h:33
Functions for a Dialog or Window.
Definition menudef.h:44
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(* 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
A local copy of an email.
Definition message.h:34
FILE * fp
pointer to the message data
Definition message.h:35
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
struct MuttWindow * dlg
Main Dialog Window.
Definition simple.h:36
@ MENU_LIST
Mailing-list actions.
Definition type.h:46