NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
tags_commit()

Save the tags to a message. More...

+ Collaboration diagram for tags_commit():

Functions

static int comp_tags_commit (struct Mailbox *m, struct Email *e, char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -. More...
 
static int imap_tags_commit (struct Mailbox *m, struct Email *e, char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -This method update the server flags on the server by removing the last know custom flags of a header and adds the local flags. More...
 
static int nm_tags_commit (struct Mailbox *m, struct Email *e, char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -. More...
 

Detailed Description

Save the tags to a message.

Parameters
mMailbox
eEmail
bufBuffer containing tags
Return values
0Success
-1Failure

Contract

Function Documentation

◆ comp_tags_commit()

static int comp_tags_commit ( struct Mailbox m,
struct Email e,
char *  buf 
)
static

Save the tags to a message - Implements MxOps::tags_commit() -.

Definition at line 857 of file compress.c.

858 {
859  if (!m->compress_info)
860  return 0;
861 
862  struct CompressInfo *ci = m->compress_info;
863 
864  const struct MxOps *ops = ci->child_ops;
865  if (!ops || !ops->tags_commit)
866  return 0;
867 
868  return ops->tags_commit(m, e, buf);
869 }
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
int(* tags_commit)(struct Mailbox *m, struct Email *e, char *buf)
Definition: mxapi.h:353

◆ imap_tags_commit()

static int imap_tags_commit ( struct Mailbox m,
struct Email e,
char *  buf 
)
static

Save the tags to a message - Implements MxOps::tags_commit() -This method update the server flags on the server by removing the last know custom flags of a header and adds the local flags.

If everything success we push the local flags to the last know custom flags (flags_remote).

Also this method check that each flags is support by the server first and remove unsupported one.

Definition at line 2337 of file imap.c.

2338 {
2339  char uid[11];
2340 
2341  struct ImapAccountData *adata = imap_adata_get(m);
2342 
2343  if (*buf == '\0')
2344  buf = NULL;
2345 
2346  if (!(adata->mailbox->rights & MUTT_ACL_WRITE))
2347  return 0;
2348 
2349  snprintf(uid, sizeof(uid), "%u", imap_edata_get(e)->uid);
2350 
2351  /* Remove old custom flags */
2352  if (imap_edata_get(e)->flags_remote)
2353  {
2354  struct Buffer cmd = mutt_buffer_make(128); // just a guess
2355  mutt_buffer_addstr(&cmd, "UID STORE ");
2356  mutt_buffer_addstr(&cmd, uid);
2357  mutt_buffer_addstr(&cmd, " -FLAGS.SILENT (");
2358  mutt_buffer_addstr(&cmd, imap_edata_get(e)->flags_remote);
2359  mutt_buffer_addstr(&cmd, ")");
2360 
2361  /* Should we return here, or we are fine and we could
2362  * continue to add new flags */
2363  int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
2364  mutt_buffer_dealloc(&cmd);
2365  if (rc != IMAP_EXEC_SUCCESS)
2366  {
2367  return -1;
2368  }
2369  }
2370 
2371  /* Add new custom flags */
2372  if (buf)
2373  {
2374  struct Buffer cmd = mutt_buffer_make(128); // just a guess
2375  mutt_buffer_addstr(&cmd, "UID STORE ");
2376  mutt_buffer_addstr(&cmd, uid);
2377  mutt_buffer_addstr(&cmd, " +FLAGS.SILENT (");
2378  mutt_buffer_addstr(&cmd, buf);
2379  mutt_buffer_addstr(&cmd, ")");
2380 
2381  int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
2382  mutt_buffer_dealloc(&cmd);
2383  if (rc != IMAP_EXEC_SUCCESS)
2384  {
2385  mutt_debug(LL_DEBUG1, "fail to add new flags\n");
2386  return -1;
2387  }
2388  }
2389 
2390  /* We are good sync them */
2391  mutt_debug(LL_DEBUG1, "NEW TAGS: %s\n", buf);
2392  driver_tags_replace(&e->tags, buf);
2393  FREE(&imap_edata_get(e)->flags_remote);
2395  imap_msg_save_hcache(m, e);
2396  return 0;
2397 }
int imap_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache() -.
Definition: message.c:2153
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
struct Mailbox * mailbox
Current selected mailbox.
Definition: adata.h:76
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:64
Imap command executed or queued successfully.
Definition: private.h:84
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:74
struct TagList tags
For drivers that support server tagging.
Definition: email.h:109
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1250
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
char * flags_remote
Definition: edata.h:48
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
char * data
Pointer to data.
Definition: buffer.h:35
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:121
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: private.h:73
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:90
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
IMAP-specific Account data -.
Definition: adata.h:39
char * driver_tags_get_with_hidden(struct TagList *list)
Get tags with hiddens.
Definition: tags.c:158
Log at debug level 1.
Definition: logging.h:40
char * buf
Definition: adata.h:59
#define FREE(x)
Definition: memory.h:40
bool driver_tags_replace(struct TagList *head, char *tags)
Replace all tags.
Definition: tags.c:186
+ Here is the call graph for this function:

◆ nm_tags_commit()

static int nm_tags_commit ( struct Mailbox m,
struct Email e,
char *  buf 
)
static

Save the tags to a message - Implements MxOps::tags_commit() -.

Definition at line 2419 of file notmuch.c.

2420 {
2421  if (*buf == '\0')
2422  return 0; /* no tag change, so nothing to do */
2423 
2424  struct NmMboxData *mdata = nm_mdata_get(m);
2425  if (!mdata)
2426  return -1;
2427 
2428  notmuch_database_t *db = NULL;
2429  notmuch_message_t *msg = NULL;
2430  int rc = -1;
2431 
2432  if (!(db = nm_db_get(m, true)) || !(msg = get_nm_message(db, e)))
2433  goto done;
2434 
2435  mutt_debug(LL_DEBUG1, "nm: tags modify: '%s'\n", buf);
2436 
2437  update_tags(msg, buf);
2438  update_email_flags(m, e, buf);
2439  update_email_tags(e, msg);
2440  mutt_set_header_color(m, e);
2441 
2442  rc = 0;
2443  e->changed = true;
2444 done:
2445  nm_db_release(m);
2446  if (e->changed)
2447  {
2448  m->mtime.tv_sec = mutt_date_epoch();
2449  m->mtime.tv_nsec = 0;
2450  }
2451  mutt_debug(LL_DEBUG1, "nm: tags modify done [rc=%d]\n", rc);
2452  return rc;
2453 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
void mutt_set_header_color(struct Mailbox *m, struct Email *e)
Select a colour for a message.
Definition: dlg_index.c:1382
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
static int update_email_flags(struct Mailbox *m, struct Email *e, const char *tag_str)
Update the Email's flags.
Definition: notmuch.c:1149
bool changed
Email has been edited.
Definition: email.h:48
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:172
time_t tv_sec
Definition: file.h:50
Notmuch-specific Mailbox data -.
Definition: mdata.h:33
static int update_tags(notmuch_message_t *msg, const char *tag_str)
Update the tags on a message.
Definition: notmuch.c:1095
long tv_nsec
Definition: file.h:51
void * mdata
Driver specific data.
Definition: mailbox.h:136
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition: notmuch.c:1037
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:98
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:196
static int update_email_tags(struct Email *e, notmuch_message_t *msg)
Update the Email's tags from Notmuch.
Definition: notmuch.c:472
+ Here is the call graph for this function: