NeoMutt  2021-02-05-666-ge300cd
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, char *buf, size_t buflen)
 Prompt and validate new messages tags - Implements MxOps::tags_edit() -. More...
 
static int imap_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen)
 Prompt and validate new messages tags - Implements MxOps::tags_edit() -. More...
 
static int nm_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen)
 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
buflenLength of buffer
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,
char *  buf,
size_t  buflen 
)
static

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

Definition at line 840 of file compress.c.

841 {
842  if (!m->compress_info)
843  return 0;
844 
845  struct CompressInfo *ci = m->compress_info;
846 
847  const struct MxOps *ops = ci->child_ops;
848  if (!ops || !ops->tags_edit)
849  return 0;
850 
851  return ops->tags_edit(m, tags, buf, buflen);
852 }
int(* tags_edit)(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Definition: mxapi.h:335
Private data for compress.
Definition: lib.h:46
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
Definition: mxapi.h:103

◆ imap_tags_edit()

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

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

Definition at line 2250 of file imap.c.

2251 {
2252  struct ImapMboxData *mdata = imap_mdata_get(m);
2253  if (!mdata)
2254  return -1;
2255 
2256  char *new_tag = NULL;
2257  char *checker = NULL;
2258 
2259  /* Check for \* flags capability */
2260  if (!imap_has_flag(&mdata->flags, NULL))
2261  {
2262  mutt_error(_("IMAP server doesn't support custom flags"));
2263  return -1;
2264  }
2265 
2266  *buf = '\0';
2267  if (tags)
2268  mutt_str_copy(buf, tags, buflen);
2269 
2270  if (mutt_get_field("Tags: ", buf, buflen, MUTT_COMP_NO_FLAGS, false, NULL, NULL) != 0)
2271  return -1;
2272 
2273  /* each keyword must be atom defined by rfc822 as:
2274  *
2275  * atom = 1*<any CHAR except specials, SPACE and CTLs>
2276  * CHAR = ( 0.-127. )
2277  * specials = "(" / ")" / "<" / ">" / "@"
2278  * / "," / ";" / ":" / "\" / <">
2279  * / "." / "[" / "]"
2280  * SPACE = ( 32. )
2281  * CTLS = ( 0.-31., 127.)
2282  *
2283  * And must be separated by one space.
2284  */
2285 
2286  new_tag = buf;
2287  checker = buf;
2288  SKIPWS(checker);
2289  while (*checker != '\0')
2290  {
2291  if ((*checker < 32) || (*checker >= 127) || // We allow space because it's the separator
2292  (*checker == 40) || // (
2293  (*checker == 41) || // )
2294  (*checker == 60) || // <
2295  (*checker == 62) || // >
2296  (*checker == 64) || // @
2297  (*checker == 44) || // ,
2298  (*checker == 59) || // ;
2299  (*checker == 58) || // :
2300  (*checker == 92) || // backslash
2301  (*checker == 34) || // "
2302  (*checker == 46) || // .
2303  (*checker == 91) || // [
2304  (*checker == 93)) // ]
2305  {
2306  mutt_error(_("Invalid IMAP flags"));
2307  return 0;
2308  }
2309 
2310  /* Skip duplicate space */
2311  while ((checker[0] == ' ') && (checker[1] == ' '))
2312  checker++;
2313 
2314  /* copy char to new_tag and go the next one */
2315  *new_tag++ = *checker++;
2316  }
2317  *new_tag = '\0';
2318  new_tag = buf; /* rewind */
2319  mutt_str_remove_trailing_ws(new_tag);
2320 
2321  return !mutt_str_equal(tags, buf);
2322 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
#define mutt_error(...)
Definition: logging.h:88
int mutt_get_field(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:335
#define _(a)
Definition: message.h:28
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:52
bool imap_has_flag(struct ListHead *flag_list, const char *flag)
Does the flag exist in the list.
Definition: imap.c:878
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:59
#define SKIPWS(ch)
Definition: string2.h:46
void * mdata
Driver specific data.
Definition: mailbox.h:136
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:733
struct ListHead flags
Definition: mdata.h:49
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:749
IMAP-specific Mailbox data -.
Definition: mdata.h:38
+ Here is the call graph for this function:

◆ nm_tags_edit()

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

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

Definition at line 2406 of file notmuch.c.

2407 {
2408  *buf = '\0';
2409  if (mutt_get_field("Add/remove labels: ", buf, buflen, MUTT_NM_TAG, false, NULL, NULL) != 0)
2410  {
2411  return -1;
2412  }
2413  return 1;
2414 }
int mutt_get_field(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:335
#define MUTT_NM_TAG
Notmuch tag +/- mode.
Definition: mutt.h:63
+ Here is the call graph for this function: