NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_list.c File Reference

Mailing-list action dialog. More...

#include "config.h"
#include <stddef.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "index/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "send/lib.h"
#include "module_data.h"
#include "mutt_logging.h"
#include "mx.h"
+ Include dependency graph for dlg_list.c:

Go to the source code of this file.

Data Structures

struct  ListAction
 A mailing-list action in the dialog. More...
 
struct  ListData
 Private data for the Mailing-list action dialog. More...
 
struct  ListFunction
 A list dialog function. More...
 

Functions

static char ** get_action_value (struct Rfc2369ListHeaders *headers, const struct ListAction *action)
 Get the stored value for a mailing-list action.
 
static void list_data_free (struct Menu *menu, void **ptr)
 Free list dialog data - Implements Menu::mdata_free() -.
 
static int list_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() -.
 
static bool compose_list_action (struct ListData *ld, const struct ListAction *action)
 Compose a message for a mailing-list action.
 
static int op_exit (struct ListData *ld, const struct KeyEvent *event)
 Exit the list dialog.
 
static int op_select_action (struct ListData *ld, const struct KeyEvent *event)
 Execute the selected mailing-list action.
 
static int list_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform a List dialog function - Implements function_dispatcher_t -.
 
void dlg_list (struct Mailbox *m, struct Email *e)
 Display mailing-list actions for an email -.
 

Variables

static const struct Mapping ListHelp []
 Help Bar for the Mailing-list action dialog.
 
static const struct ListAction ListActions []
 Mailing-list actions shown in the dialog.
 
static const struct ListFunction ListFunctions []
 Functions handled by the list dialog.
 

Detailed Description

Mailing-list action dialog.

Authors
  • 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 dlg_list.c.

Function Documentation

◆ get_action_value()

static char ** get_action_value ( struct Rfc2369ListHeaders * headers,
const struct ListAction * action )
static

Get the stored value for a mailing-list action.

Parameters
headersParsed List-* headers
actionAction definition
Return values
ptrPointer to the stored header value

Definition at line 92 of file dlg_list.c.

94{
95 return (char **) (((char *) headers) + action->offset);
96}
size_t offset
Offset into struct Rfc2369ListHeaders.
Definition dlg_list.c:59
+ Here is the caller graph for this function:

◆ compose_list_action()

static bool compose_list_action ( struct ListData * ld,
const struct ListAction * action )
static

Compose a message for a mailing-list action.

Parameters
ldDialog state
actionMailing-list action
Return values
trueThe dialog should exit
falseThe dialog should remain open

Definition at line 139 of file dlg_list.c.

140{
141 char *mailto = *get_action_value(&ld->headers, action);
142 if (!mailto)
143 {
144 mutt_error(_("No list action available for %s"), _(action->name));
145 return false;
146 }
147
148 if (url_check_scheme(mailto) != U_MAILTO)
149 {
150 mutt_error(_("List actions only support mailto: URIs. (Try a browser?)"));
151 return true;
152 }
153
154 struct Email *e = email_new();
155 e->env = mutt_env_new();
156
157 char *body = NULL;
158 if (!mutt_parse_mailto(e->env, &body, mailto))
159 {
160 mutt_error(_("Could not parse mailto: URI"));
161 FREE(&body);
162 email_free(&e);
163 return true;
164 }
165
166 e->body = mutt_body_new();
167 char ctype[] = "text/plain";
168 mutt_parse_content_type(ctype, e->body);
169 e->body->use_disp = false;
171
172 struct Buffer *tempfile = buf_pool_get();
173 buf_mktemp_draft(tempfile);
174 FILE *fp = mutt_file_fopen(buf_string(tempfile), "w+");
175 if (!fp)
176 {
177 mutt_perror("%s", buf_string(tempfile));
178 FREE(&body);
179 email_free(&e);
180 buf_pool_release(&tempfile);
181 return true;
182 }
183
184 if (body)
185 fprintf(fp, "%s\n", body);
186 mutt_file_fclose(&fp);
187 FREE(&body);
188
189 e->body->filename = buf_strdup(tempfile);
190 e->body->unlink = true;
191 buf_pool_release(&tempfile);
192
193 (void) mutt_send_message(SEND_DRAFT_FILE, e, NULL, ld->mailbox, NULL, NeoMutt->sub);
194 return true;
195}
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 char ** get_action_value(struct Rfc2369ListHeaders *headers, const struct ListAction *action)
Get the stored value for a mailing-list action.
Definition dlg_list.c:92
struct Body * mutt_body_new(void)
Create a new Body.
Definition body.c:44
struct Email * email_new(void)
Create a new Email.
Definition email.c:77
void email_free(struct Email **ptr)
Free an Email.
Definition email.c:46
void mutt_parse_content_type(const char *s, struct Body *b)
Parse a content type.
Definition parse.c:433
bool mutt_parse_mailto(struct Envelope *env, char **body, const char *src)
Parse a mailto:// url.
Definition parse.c:1812
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition envelope.c:45
#define mutt_file_fclose(FP)
Definition file.h:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
#define mutt_error(...)
Definition logging2.h:94
#define mutt_perror(...)
Definition logging2.h:95
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
@ DISP_INLINE
Content is inline.
Definition mime.h:62
#define _(a)
Definition message.h:28
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
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:2030
@ SEND_DRAFT_FILE
Used by the -H flag.
Definition send.h:56
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition body.h:68
bool use_disp
Content-Disposition uses filename= ?
Definition body.h:47
unsigned int disposition
content-disposition, ContentDisposition
Definition body.h:42
char * filename
When sending a message, this is the file to which this structure refers.
Definition body.h:59
String manipulation buffer.
Definition buffer.h:36
The envelope/body of an email.
Definition email.h:39
struct Envelope * env
Envelope information.
Definition email.h:68
struct Body * body
List of MIME parts.
Definition email.h:69
const char * name
Label for the action.
Definition dlg_list.c:57
struct Mailbox * mailbox
Source mailbox.
Definition dlg_list.c:80
struct Rfc2369ListHeaders headers
Parsed List-* headers.
Definition dlg_list.c:81
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
#define buf_mktemp_draft(buf)
Definition tmp.h:34
enum UrlScheme url_check_scheme(const char *str)
Check the protocol of a URL.
Definition url.c:229
@ U_MAILTO
Url is mailto://.
Definition url.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ op_exit()

static int op_exit ( struct ListData * ld,
const struct KeyEvent * event )
static

Exit the list dialog.

Parameters
ldDialog state
eventEvent being handled
Return values
enumFunctionRetval

Definition at line 203 of file dlg_list.c.

204{
205 ld->done = true;
206 return FR_SUCCESS;
207}
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
bool done
Exit the dialog.
Definition dlg_list.c:83

◆ op_select_action()

static int op_select_action ( struct ListData * ld,
const struct KeyEvent * event )
static

Execute the selected mailing-list action.

Parameters
ldDialog state
eventEvent being handled
Return values
enumFunctionRetval

Definition at line 215 of file dlg_list.c.

216{
217 const int index = menu_get_index(ld->menu);
218 if ((index < 0) || (index >= (int) countof(ListActions)))
219 return FR_NO_ACTION;
220
221 ld->done = compose_list_action(ld, &ListActions[index]);
222 return FR_SUCCESS;
223}
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
static const struct ListAction ListActions[]
Mailing-list actions shown in the dialog.
Definition dlg_list.c:63
static bool compose_list_action(struct ListData *ld, const struct ListAction *action)
Compose a message for a mailing-list action.
Definition dlg_list.c:139
#define countof(x)
Definition memory.h:49
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:155
struct Menu * menu
Dialog menu.
Definition dlg_list.c:79
+ Here is the call graph for this function:

Variable Documentation

◆ ListHelp

const struct Mapping ListHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Archive"), OP_LIST_ARCHIVE },
{ N_("Help"), OP_LIST_HELP },
{ N_("Owner"), OP_LIST_OWNER },
{ N_("Post"), OP_LIST_POST },
{ N_("Subscribe"), OP_LIST_SUBSCRIBE },
{ N_("Unsubscribe"), OP_LIST_UNSUBSCRIBE },
{ NULL, 0 },
}
#define N_(a)
Definition message.h:32

Help Bar for the Mailing-list action dialog.

Definition at line 39 of file dlg_list.c.

39 {
40 // clang-format off
41 { N_("Exit"), OP_EXIT },
42 { N_("Archive"), OP_LIST_ARCHIVE },
43 { N_("Help"), OP_LIST_HELP },
44 { N_("Owner"), OP_LIST_OWNER },
45 { N_("Post"), OP_LIST_POST },
46 { N_("Subscribe"), OP_LIST_SUBSCRIBE },
47 { N_("Unsubscribe"), OP_LIST_UNSUBSCRIBE },
48 { NULL, 0 },
49 // clang-format on
50};

◆ ListActions

const struct ListAction ListActions[]
static
Initial value:
= {
{ N_("Help"), OP_LIST_HELP, offsetof(struct Rfc2369ListHeaders, help) },
{ N_("Post"), OP_LIST_POST, offsetof(struct Rfc2369ListHeaders, post) },
{ N_("Subscribe"), OP_LIST_SUBSCRIBE, offsetof(struct Rfc2369ListHeaders, subscribe) },
{ N_("Unsubscribe"), OP_LIST_UNSUBSCRIBE, offsetof(struct Rfc2369ListHeaders, unsubscribe) },
{ N_("Archives"), OP_LIST_ARCHIVE, offsetof(struct Rfc2369ListHeaders, archive) },
{ N_("Owner"), OP_LIST_OWNER, offsetof(struct Rfc2369ListHeaders, owner) },
}
Mailing-list actions from RFC 2369 headers.
Definition parse.h:41

Mailing-list actions shown in the dialog.

Definition at line 63 of file dlg_list.c.

63 {
64 // clang-format off
65 { N_("Help"), OP_LIST_HELP, offsetof(struct Rfc2369ListHeaders, help) },
66 { N_("Post"), OP_LIST_POST, offsetof(struct Rfc2369ListHeaders, post) },
67 { N_("Subscribe"), OP_LIST_SUBSCRIBE, offsetof(struct Rfc2369ListHeaders, subscribe) },
68 { N_("Unsubscribe"), OP_LIST_UNSUBSCRIBE, offsetof(struct Rfc2369ListHeaders, unsubscribe) },
69 { N_("Archives"), OP_LIST_ARCHIVE, offsetof(struct Rfc2369ListHeaders, archive) },
70 { N_("Owner"), OP_LIST_OWNER, offsetof(struct Rfc2369ListHeaders, owner) },
71 // clang-format on
72};

◆ ListFunctions

const struct ListFunction ListFunctions[]
static
Initial value:
= {
{ OP_EXIT, op_exit },
{ OP_GENERIC_SELECT_ENTRY, op_select_action },
{ OP_LIST_ARCHIVE, op_select_action },
{ OP_LIST_HELP, op_select_action },
{ OP_LIST_OWNER, op_select_action },
{ OP_LIST_POST, op_select_action },
{ OP_LIST_SUBSCRIBE, op_select_action },
{ OP_LIST_UNSUBSCRIBE, op_select_action },
{ 0, NULL },
}
static int op_select_action(struct ListData *ld, const struct KeyEvent *event)
Execute the selected mailing-list action.
Definition dlg_list.c:215
static int op_exit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
exit this menu - Implements alias_function_t -
Definition functions.c:312

Functions handled by the list dialog.

Definition at line 235 of file dlg_list.c.

235 {
236 // clang-format off
237 { OP_EXIT, op_exit },
238 { OP_GENERIC_SELECT_ENTRY, op_select_action },
239 { OP_LIST_ARCHIVE, op_select_action },
240 { OP_LIST_HELP, op_select_action },
241 { OP_LIST_OWNER, op_select_action },
242 { OP_LIST_POST, op_select_action },
243 { OP_LIST_SUBSCRIBE, op_select_action },
244 { OP_LIST_UNSUBSCRIBE, op_select_action },
245 { 0, NULL },
246 // clang-format on
247};