NeoMutt  2022-04-29-178-g3b62e6
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

Contract

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 846 of file compress.c.

847{
848 if (!m->compress_info)
849 return 0;
850
851 struct CompressInfo *ci = m->compress_info;
852
853 const struct MxOps *ops = ci->child_ops;
854 if (!ops || !ops->tags_edit)
855 return 0;
856
857 return ops->tags_edit(m, tags, buf);
858}
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:121
Definition: mxapi.h:112
int(* tags_edit)(struct Mailbox *m, const char *tags, struct Buffer *buf)
Definition: mxapi.h:342

◆ 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 2248 of file imap.c.

2249{
2250 struct ImapMboxData *mdata = imap_mdata_get(m);
2251 if (!mdata)
2252 return -1;
2253
2254 char *new_tag = NULL;
2255 char *checker = NULL;
2256
2257 /* Check for \* flags capability */
2258 if (!imap_has_flag(&mdata->flags, NULL))
2259 {
2260 mutt_error(_("IMAP server doesn't support custom flags"));
2261 return -1;
2262 }
2263
2264 mutt_buffer_reset(buf);
2265 if (tags)
2266 mutt_buffer_strcpy(buf, tags);
2267
2268 if (mutt_buffer_get_field("Tags: ", buf, MUTT_COMP_NO_FLAGS, false, NULL, NULL, NULL) != 0)
2269 return -1;
2270
2271 /* each keyword must be atom defined by rfc822 as:
2272 *
2273 * atom = 1*<any CHAR except specials, SPACE and CTLs>
2274 * CHAR = ( 0.-127. )
2275 * specials = "(" / ")" / "<" / ">" / "@"
2276 * / "," / ";" / ":" / "\" / <">
2277 * / "." / "[" / "]"
2278 * SPACE = ( 32. )
2279 * CTLS = ( 0.-31., 127.)
2280 *
2281 * And must be separated by one space.
2282 */
2283
2284 new_tag = buf->data;
2285 checker = buf->data;
2286 SKIPWS(checker);
2287 while (*checker != '\0')
2288 {
2289 if ((*checker < 32) || (*checker >= 127) || // We allow space because it's the separator
2290 (*checker == 40) || // (
2291 (*checker == 41) || // )
2292 (*checker == 60) || // <
2293 (*checker == 62) || // >
2294 (*checker == 64) || // @
2295 (*checker == 44) || // ,
2296 (*checker == 59) || // ;
2297 (*checker == 58) || // :
2298 (*checker == 92) || // backslash
2299 (*checker == 34) || // "
2300 (*checker == 46) || // .
2301 (*checker == 91) || // [
2302 (*checker == 93)) // ]
2303 {
2304 mutt_error(_("Invalid IMAP flags"));
2305 return 0;
2306 }
2307
2308 /* Skip duplicate space */
2309 while ((checker[0] == ' ') && (checker[1] == ' '))
2310 checker++;
2311
2312 /* copy char to new_tag and go the next one */
2313 *new_tag++ = *checker++;
2314 }
2315 *new_tag = '\0';
2316 new_tag = buf->data; /* rewind */
2318
2319 return !mutt_str_equal(tags, mutt_buffer_string(buf));
2320}
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:310
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:81
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
int mutt_buffer_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: logging.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:878
#define _(a)
Definition: message.h:28
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:613
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:52
#define SKIPWS(ch)
Definition: string2.h:46
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:133
+ 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 2379 of file notmuch.c.

2380{
2381 mutt_buffer_reset(buf);
2382 if (mutt_buffer_get_field("Add/remove labels: ", buf, MUTT_COMP_NM_TAG, false,
2383 NULL, NULL, NULL) != 0)
2384 {
2385 return -1;
2386 }
2387 return 1;
2388}
#define MUTT_COMP_NM_TAG
Notmuch tag +/- mode.
Definition: mutt.h:60
+ Here is the call graph for this function: