NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
expando.c
Go to the documentation of this file.
1
29#include <stdbool.h>
30#include <stdio.h>
31#include <string.h>
32#include "mutt/lib.h"
33#include "address/lib.h"
34#include "email/lib.h"
35#include "expando.h"
36#include "expando/lib.h"
37
41static void greeting_real_name(const struct ExpandoNode *node, void *data,
42 MuttFormatFlags flags, struct Buffer *buf)
43{
44 const struct Email *e = data;
45 const struct Address *to = TAILQ_FIRST(&e->env->to);
46
47 const char *s = mutt_get_name(to);
48 buf_strcpy(buf, s);
49}
50
54static void greeting_login_name(const struct ExpandoNode *node, void *data,
55 MuttFormatFlags flags, struct Buffer *buf)
56{
57 const struct Email *e = data;
58 const struct Address *to = TAILQ_FIRST(&e->env->to);
59
60 char tmp[128] = { 0 };
61 char *p = NULL;
62
63 if (to)
64 {
65 mutt_str_copy(tmp, mutt_addr_for_display(to), sizeof(tmp));
66 if ((p = strpbrk(tmp, "%@")))
67 {
68 *p = '\0';
69 }
70 }
71
72 buf_strcpy(buf, tmp);
73}
74
78static void greeting_first_name(const struct ExpandoNode *node, void *data,
79 MuttFormatFlags flags, struct Buffer *buf)
80{
81 const struct Email *e = data;
82 const struct Address *to = TAILQ_FIRST(&e->env->to);
83 const struct Address *cc = TAILQ_FIRST(&e->env->cc);
84
85 char tmp[128] = { 0 };
86 char *p = NULL;
87
88 if (to)
89 {
90 const char *s = mutt_get_name(to);
91 mutt_str_copy(tmp, s, sizeof(tmp));
92 }
93 else if (cc)
94 {
95 const char *s = mutt_get_name(cc);
96 mutt_str_copy(tmp, s, sizeof(tmp));
97 }
98
99 if ((p = strpbrk(tmp, " %@")))
100 *p = '\0';
101
102 buf_strcpy(buf, tmp);
103}
104
111 // clang-format off
115 { -1, -1, NULL, NULL },
116 // clang-format on
117};
const char * mutt_addr_for_display(const struct Address *a)
Convert an Address for display purposes.
Definition: address.c:1012
Email Address Handling.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
@ ED_ENVELOPE
Envelope ED_ENV_ ExpandoDataEnvelope.
Definition: domain.h:42
Structs that make up an email.
const char * mutt_get_name(const struct Address *a)
Pick the best name to display from an address.
Definition: sort.c:139
@ ED_ENV_REAL_NAME
Envelope.to (first)
Definition: envelope.h:111
@ ED_ENV_USER_NAME
Envelope.to (first)
Definition: envelope.h:122
@ ED_ENV_FIRST_NAME
Envelope.from, Envelope.to, Envelope.cc.
Definition: envelope.h:101
Parse Expando string.
static void greeting_login_name(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Greeting: Login name - Implements get_string_t -.
Definition: expando.c:54
static void greeting_real_name(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Greeting: Real name - Implements get_string_t -.
Definition: expando.c:41
static void greeting_first_name(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, struct Buffer *buf)
Greeting: First name - Implements get_string_t -.
Definition: expando.c:78
Convenience wrapper for the library headers.
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
#define TAILQ_FIRST(head)
Definition: queue.h:741
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
const struct ExpandoRenderCallback GreetingRenderCallbacks[]
Callbacks for Greeting Expandos.
Definition: expando.c:110
Sidebar Expando definitions.
An email address.
Definition: address.h:36
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 AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
Basic Expando Node.
Definition: node.h:67