NeoMutt  2023-05-17-33-gce4425
Teaching an old dog new tricks
DOXYGEN
tags_edit()

Prompt and validate new messages tags. More...

+ Collaboration diagram for tags_edit():

Functions

static int comp_tags_edit (struct Mailbox *m, const char *tags, struct Buffer *buf)
 Prompt and validate new messages tags - Implements MxOps::tags_edit() -. More...
 
static int imap_tags_edit (struct Mailbox *m, const char *tags, struct Buffer *buf)
 Prompt and validate new messages tags - Implements MxOps::tags_edit() -. More...
 
static int nm_tags_edit (struct Mailbox *m, const char *tags, struct Buffer *buf)
 Prompt and validate new messages tags - Implements MxOps::tags_edit() -. More...
 

Detailed Description

Prompt and validate new messages tags.

Parameters
mMailbox
tagsExisting tags
bufBuffer to store the tags
Return values
-1Error
0No valid user input
1Buf set
Precondition
m is not NULL
buf is not NULL

Function Documentation

◆ comp_tags_edit()

static int comp_tags_edit ( struct Mailbox m,
const char *  tags,
struct Buffer buf 
)
static

Prompt and validate new messages tags - Implements MxOps::tags_edit() -.

Definition at line 852 of file compress.c.

853{
854 if (!m->compress_info)
855 return 0;
856
857 struct CompressInfo *ci = m->compress_info;
858
859 const struct MxOps *ops = ci->child_ops;
860 if (!ops || !ops->tags_edit)
861 return 0;
862
863 return ops->tags_edit(m, tags, buf);
864}
Private data for compress.
Definition: lib.h:47
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:120
Definition: mxapi.h:112
int(* tags_edit)(struct Mailbox *m, const char *tags, struct Buffer *buf)
Definition: mxapi.h:327

◆ imap_tags_edit()

static int imap_tags_edit ( struct Mailbox m,
const char *  tags,
struct Buffer buf 
)
static

Prompt and validate new messages tags - Implements MxOps::tags_edit() -.

Definition at line 2102 of file imap.c.

2103{
2104 struct ImapMboxData *mdata = imap_mdata_get(m);
2105 if (!mdata)
2106 return -1;
2107
2108 char *new_tag = NULL;
2109 char *checker = NULL;
2110
2111 /* Check for \* flags capability */
2112 if (!imap_has_flag(&mdata->flags, NULL))
2113 {
2114 mutt_error(_("IMAP server doesn't support custom flags"));
2115 return -1;
2116 }
2117
2118 buf_reset(buf);
2119 if (tags)
2120 buf_strcpy(buf, tags);
2121
2122 if (buf_get_field("Tags: ", buf, MUTT_COMP_NO_FLAGS, false, NULL, NULL, NULL) != 0)
2123 return -1;
2124
2125 /* each keyword must be atom defined by rfc822 as:
2126 *
2127 * atom = 1*<any CHAR except specials, SPACE and CTLs>
2128 * CHAR = ( 0.-127. )
2129 * specials = "(" / ")" / "<" / ">" / "@"
2130 * / "," / ";" / ":" / "\" / <">
2131 * / "." / "[" / "]"
2132 * SPACE = ( 32. )
2133 * CTLS = ( 0.-31., 127.)
2134 *
2135 * And must be separated by one space.
2136 */
2137
2138 new_tag = buf->data;
2139 checker = buf->data;
2140 SKIPWS(checker);
2141 while (*checker != '\0')
2142 {
2143 if ((*checker < 32) || (*checker >= 127) || // We allow space because it's the separator
2144 (*checker == 40) || // (
2145 (*checker == 41) || // )
2146 (*checker == 60) || // <
2147 (*checker == 62) || // >
2148 (*checker == 64) || // @
2149 (*checker == 44) || // ,
2150 (*checker == 59) || // ;
2151 (*checker == 58) || // :
2152 (*checker == 92) || // backslash
2153 (*checker == 34) || // "
2154 (*checker == 46) || // .
2155 (*checker == 91) || // [
2156 (*checker == 93)) // ]
2157 {
2158 mutt_error(_("Invalid IMAP flags"));
2159 return 0;
2160 }
2161
2162 /* Skip duplicate space */
2163 while ((checker[0] == ' ') && (checker[1] == ' '))
2164 checker++;
2165
2166 /* copy char to new_tag and go the next one */
2167 *new_tag++ = *checker++;
2168 }
2169 *new_tag = '\0';
2170 new_tag = buf->data; /* rewind */
2172
2173 return !mutt_str_equal(tags, buf_string(buf));
2174}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:86
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:370
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
int buf_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
Definition: window.c:180
#define mutt_error(...)
Definition: logging2.h:87
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:60
bool imap_has_flag(struct ListHead *flag_list, const char *flag)
Does the flag exist in the list.
Definition: imap.c:785
#define _(a)
Definition: message.h:28
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:637
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:55
#define SKIPWS(ch)
Definition: string2.h:45
char * data
Pointer to data.
Definition: buffer.h:35
IMAP-specific Mailbox data -.
Definition: mdata.h:39
void * mdata
Driver specific data.
Definition: mailbox.h:132
+ Here is the call graph for this function:

◆ nm_tags_edit()

static int nm_tags_edit ( struct Mailbox m,
const char *  tags,
struct Buffer buf 
)
static

Prompt and validate new messages tags - Implements MxOps::tags_edit() -.

Definition at line 2398 of file notmuch.c.

2399{
2400 buf_reset(buf);
2401 if (buf_get_field("Add/remove labels: ", buf, MUTT_COMP_NM_TAG, false, NULL, NULL, NULL) != 0)
2402 {
2403 return -1;
2404 }
2405 return 1;
2406}
#define MUTT_COMP_NM_TAG
Notmuch tag +/- mode.
Definition: mutt.h:63
+ Here is the call graph for this function: