NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c File Reference

Mailing-list functions. More...

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

Go to the source code of this file.

Functions

void mlist_init_keys (struct NeoMutt *n, struct SubMenu *sm_generic)
 Initialise the Mlist Keybindings - Implements ::init_keys_api.
 
struct ListHead * mlist_action_value (struct Rfc2369ListHeaders *headers, const struct ListAction *action)
 Get the stored value for a mailing-list action.
 
static bool compose_list_action (struct ListData *ld, const struct ListEntry *entry)
 Compose a message for a mailing-list action.
 
static int op_quit (struct ListData *ld, const struct KeyEvent *event)
 Save changes and exit this dialog - Implements mlist_function_t -.
 
static int op_select_action (struct ListData *ld, const struct KeyEvent *event)
 Execute the selected mailing-list action - Implements mlist_function_t -.
 
int mlist_function_dispatcher (struct MuttWindow *win, const struct KeyEvent *event)
 Perform a List dialog function - Implements function_dispatcher_t -.
 

Variables

const struct ListAction ListActions []
 Mailing-list actions shown in the dialog.
 
const int ListActionsCount = countof(ListActions)
 Number of entries in ListActions.
 
static const struct MenuFuncOp OpList []
 Functions for the List Dialog.
 
static const struct MenuOpSeq ListDefaultBindings []
 Key bindings for the List Dialog.
 
static const struct MlistFunction MlistFunctions []
 All the NeoMutt functions that the List Dialog supports.
 

Detailed Description

Mailing-list functions.

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

Function Documentation

◆ mlist_init_keys()

void mlist_init_keys ( struct NeoMutt * n,
struct SubMenu * sm_generic )

Initialise the Mlist Keybindings - Implements ::init_keys_api.

Definition at line 90 of file functions.c.

91{
92 struct MenuDefinition *md = NULL;
93 struct MenuDefinition *md_list = NULL;
94 struct SubMenu *sm_list = NULL;
95
96 sm_list = km_register_submenu(OpList);
97 md_list = km_register_menu(MENU_LIST, "list");
98 km_menu_add_submenu(md_list, sm_list);
99 km_menu_add_submenu(md_list, sm_generic);
101
103 ASSERT(mod_data);
104 mod_data->menu_mlist = md;
105}
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:123
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:88
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:105
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:136
static const struct MenuFuncOp OpList[]
Functions for the List Dialog.
Definition functions.c:63
static const struct MenuOpSeq ListDefaultBindings[]
Key bindings for the List Dialog.
Definition functions.c:76
@ MODULE_ID_MLIST
ModuleMlist, Mailing-list
Definition module_api.h:80
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
#define ASSERT(COND)
Definition signal2.h:59
Functions for a Dialog or Window.
Definition menudef.h:44
Mlist private Module data.
Definition module_data.h:32
struct MenuDefinition * menu_mlist
Mlist menu definition.
Definition module_data.h:33
Collection of related functions.
Definition menudef.h:33
@ MENU_LIST
Mailing-list actions.
Definition type.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mlist_action_value()

struct ListHead * mlist_action_value ( struct Rfc2369ListHeaders * headers,
const struct ListAction * action )

Get the stored value for a mailing-list action.

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

Definition at line 113 of file functions.c.

115{
116 return (struct ListHead *) (((char *) headers) + action->offset);
117}
size_t offset
Offset into struct Rfc2369ListHeaders.
Definition functions.h:41
+ Here is the caller graph for this function:

◆ compose_list_action()

static bool compose_list_action ( struct ListData * ld,
const struct ListEntry * entry )
static

Compose a message for a mailing-list action.

Parameters
ldDialog state
entryMailing-list entry
Return values
trueThe dialog should exit
falseThe dialog should remain open

Definition at line 126 of file functions.c.

127{
128 if (!entry || !entry->value)
129 {
130 mutt_error(_("No list action available"));
131 return false;
132 }
133
134 const char *uri = entry->value;
135 if (!mutt_istr_startswith(uri, "mailto:"))
136 return false;
137
138 struct Email *e = email_new();
139 e->env = mutt_env_new();
140
141 char *body = NULL;
142 if (!mutt_parse_mailto(e->env, &body, uri))
143 {
144 mutt_error(_("Could not parse mailto: URI"));
145 FREE(&body);
146 email_free(&e);
147 return true;
148 }
149
150 e->body = mutt_body_new();
151 char ctype[] = "text/plain";
152 mutt_parse_content_type(ctype, e->body);
153 e->body->use_disp = false;
155
156 struct Buffer *tempfile = buf_pool_get();
157 buf_mktemp_draft(tempfile);
158 FILE *fp = mutt_file_fopen(buf_string(tempfile), "w+");
159 if (!fp)
160 {
161 mutt_perror("%s", buf_string(tempfile));
162 FREE(&body);
163 email_free(&e);
164 buf_pool_release(&tempfile);
165 return true;
166 }
167
168 if (body)
169 fprintf(fp, "%s\n", body);
170 mutt_file_fclose(&fp);
171 FREE(&body);
172
173 e->body->filename = buf_strdup(tempfile);
174 e->body->unlink = true;
175 buf_pool_release(&tempfile);
176
177 (void) mutt_send_message(SEND_DRAFT_FILE, e, NULL, ld->mailbox, NULL, NeoMutt->sub);
178 return true;
179}
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
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:1876
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
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
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:2029
@ 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
struct Mailbox * mailbox
Source mailbox.
Definition functions.h:66
const char * value
URI to use.
Definition functions.h:50
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ ListActions

const struct ListAction ListActions[]
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) },
}
#define N_(a)
Definition message.h:32
Mailing-list actions from RFC 2369 headers.
Definition parse.h:41

Mailing-list actions shown in the dialog.

Definition at line 45 of file functions.c.

45 {
46 // clang-format off
47 { N_("Help"), OP_LIST_HELP, offsetof(struct Rfc2369ListHeaders, help) },
48 { N_("Post"), OP_LIST_POST, offsetof(struct Rfc2369ListHeaders, post) },
49 { N_("Subscribe"), OP_LIST_SUBSCRIBE, offsetof(struct Rfc2369ListHeaders, subscribe) },
50 { N_("Unsubscribe"), OP_LIST_UNSUBSCRIBE, offsetof(struct Rfc2369ListHeaders, unsubscribe) },
51 { N_("Archives"), OP_LIST_ARCHIVE, offsetof(struct Rfc2369ListHeaders, archive) },
52 { N_("Owner"), OP_LIST_OWNER, offsetof(struct Rfc2369ListHeaders, owner) },
53 // clang-format on
54};

◆ ListActionsCount

const int ListActionsCount = countof(ListActions)

Number of entries in ListActions.

Definition at line 57 of file functions.c.

◆ OpList

const struct MenuFuncOp OpList[]
static
Initial value:
= {
{ "list-archive", OP_LIST_ARCHIVE },
{ "list-help", OP_LIST_HELP },
{ "list-owner", OP_LIST_OWNER },
{ "list-post", OP_LIST_POST },
{ "list-subscribe", OP_LIST_SUBSCRIBE },
{ "list-unsubscribe", OP_LIST_UNSUBSCRIBE },
{ NULL, 0 },
}

Functions for the List Dialog.

Definition at line 63 of file functions.c.

63 { /* map: list */
64 { "list-archive", OP_LIST_ARCHIVE },
65 { "list-help", OP_LIST_HELP },
66 { "list-owner", OP_LIST_OWNER },
67 { "list-post", OP_LIST_POST },
68 { "list-subscribe", OP_LIST_SUBSCRIBE },
69 { "list-unsubscribe", OP_LIST_UNSUBSCRIBE },
70 { NULL, 0 },
71};

◆ ListDefaultBindings

const struct MenuOpSeq ListDefaultBindings[]
static
Initial value:
= {
{ OP_LIST_ARCHIVE, "a" },
{ OP_LIST_HELP, "h" },
{ OP_LIST_OWNER, "o" },
{ OP_LIST_POST, "p" },
{ OP_LIST_SUBSCRIBE, "s" },
{ OP_LIST_UNSUBSCRIBE, "u" },
{ 0, NULL },
}

Key bindings for the List Dialog.

Definition at line 76 of file functions.c.

76 { /* map: list */
77 { OP_LIST_ARCHIVE, "a" },
78 { OP_LIST_HELP, "h" },
79 { OP_LIST_OWNER, "o" },
80 { OP_LIST_POST, "p" },
81 { OP_LIST_SUBSCRIBE, "s" },
82 { OP_LIST_UNSUBSCRIBE, "u" },
83 { 0, NULL },
84};

◆ MlistFunctions

const struct MlistFunction MlistFunctions[]
static
Initial value:
= {
{ OP_EXIT, op_quit },
{ 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 },
{ OP_QUIT, op_quit },
{ 0, NULL },
}
static int op_quit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Save changes and exit this dialog - Implements alias_function_t -.
Definition functions.c:308
static int op_select_action(struct ListData *ld, const struct KeyEvent *event)
Execute the selected mailing-list action - Implements mlist_function_t -.
Definition functions.c:204

All the NeoMutt functions that the List Dialog supports.

Definition at line 251 of file functions.c.

251 {
252 // clang-format off
253 { OP_EXIT, op_quit },
254 { OP_GENERIC_SELECT_ENTRY, op_select_action },
255 { OP_LIST_ARCHIVE, op_select_action },
256 { OP_LIST_HELP, op_select_action },
257 { OP_LIST_OWNER, op_select_action },
258 { OP_LIST_POST, op_select_action },
259 { OP_LIST_SUBSCRIBE, op_select_action },
260 { OP_LIST_UNSUBSCRIBE, op_select_action },
261 { OP_QUIT, op_quit },
262 { 0, NULL },
263 // clang-format on
264};