NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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, const char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -.
 
static int imap_tags_commit (struct Mailbox *m, struct Email *e, const char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -.
 
static int nm_tags_commit (struct Mailbox *m, struct Email *e, const char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -.
 

Detailed Description

Save the tags to a message.

Parameters
mMailbox
eEmail
bufBuffer containing tags
Return values
0Success
-1Failure
Precondition
m is not NULL
e is not NULL
buf is not NULL

Function Documentation

◆ comp_tags_commit()

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

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

Definition at line 847 of file compress.c.

848{
849 if (!m->compress_info)
850 return 0;
851
852 struct CompressInfo *ci = m->compress_info;
853
854 const struct MxOps *ops = ci->child_ops;
855 if (!ops || !ops->tags_commit)
856 return 0;
857
858 return ops->tags_commit(m, e, buf);
859}
Private data for compress.
Definition lib.h:61
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:66
void * compress_info
Compressed mbox module private data.
Definition mailbox.h:120
Definition mxapi.h:87
int(* tags_commit)(struct Mailbox *m, struct Email *e, const char *buf)
Definition mxapi.h:319

◆ imap_tags_commit()

static int imap_tags_commit ( struct Mailbox * m,
struct Email * e,
const 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 2476 of file imap.c.

2477{
2478 char uid[11] = { 0 };
2479
2481 if (!adata)
2482 return -1;
2483
2484 if (*buf == '\0')
2485 buf = NULL;
2486
2487 if (!(m->rights & MUTT_ACL_WRITE))
2488 return 0;
2489
2490 snprintf(uid, sizeof(uid), "%u", imap_edata_get(e)->uid);
2491
2492 /* Remove old custom flags */
2493 if (imap_edata_get(e)->flags_remote)
2494 {
2495 struct Buffer *cmd = buf_pool_get();
2496 buf_addstr(cmd, "UID STORE ");
2497 buf_addstr(cmd, uid);
2498 buf_addstr(cmd, " -FLAGS.SILENT (");
2499 buf_addstr(cmd, imap_edata_get(e)->flags_remote);
2500 buf_addstr(cmd, ")");
2501
2502 /* Should we return here, or we are fine and we could
2503 * continue to add new flags */
2504 int rc = imap_exec(adata, buf_string(cmd), IMAP_CMD_NO_FLAGS);
2505 buf_pool_release(&cmd);
2506 if (rc != IMAP_EXEC_SUCCESS)
2507 {
2508 return -1;
2509 }
2510 }
2511
2512 /* Add new custom flags */
2513 if (buf)
2514 {
2515 struct Buffer *cmd = buf_pool_get();
2516 buf_addstr(cmd, "UID STORE ");
2517 buf_addstr(cmd, uid);
2518 buf_addstr(cmd, " +FLAGS.SILENT (");
2519 buf_addstr(cmd, buf);
2520 buf_addstr(cmd, ")");
2521
2522 int rc = imap_exec(adata, buf_string(cmd), IMAP_CMD_NO_FLAGS);
2523 buf_pool_release(&cmd);
2524 if (rc != IMAP_EXEC_SUCCESS)
2525 {
2526 mutt_debug(LL_DEBUG1, "fail to add new flags\n");
2527 return -1;
2528 }
2529 }
2530
2531 /* We are good sync them */
2532 mutt_debug(LL_DEBUG1, "NEW TAGS: %s\n", buf);
2533 driver_tags_replace(&e->tags, buf);
2534 FREE(&imap_edata_get(e)->flags_remote);
2535 struct Buffer *flags_remote = buf_pool_get();
2536 driver_tags_get_with_hidden(&e->tags, flags_remote);
2537 imap_edata_get(e)->flags_remote = buf_strdup(flags_remote);
2538 buf_pool_release(&flags_remote);
2540 return 0;
2541}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition mailbox.h:70
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
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:2220
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:158
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:1415
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:66
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition private.h:71
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition private.h:82
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
void * adata
Private data (for Mailbox backends)
Definition account.h:42
String manipulation buffer.
Definition buffer.h:36
struct TagList tags
For drivers that support server tagging.
Definition email.h:72
IMAP-specific Account data -.
Definition adata.h:40
char * buf
Command buffer.
Definition adata.h:60
char * flags_remote
Remote flags.
Definition edata.h:49
AclFlags rights
ACL bits, see AclFlags.
Definition mailbox.h:118
bool driver_tags_replace(struct TagList *tl, const char *tags)
Replace all tags.
Definition tags.c:202
void driver_tags_get_with_hidden(struct TagList *tl, struct Buffer *tags)
Get all tags, also hidden ones, separated by space.
Definition tags.c:175
+ Here is the call graph for this function:

◆ nm_tags_commit()

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

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

Definition at line 2476 of file notmuch.c.

2477{
2478 if (*buf == '\0')
2479 return 0; /* no tag change, so nothing to do */
2480
2481 struct NmMboxData *mdata = nm_mdata_get(m);
2482 if (!mdata)
2483 return -1;
2484
2485 notmuch_database_t *db = NULL;
2486 notmuch_message_t *msg = NULL;
2487 int rc = -1;
2488
2489 if (!(db = nm_db_get(m, true)) || !(msg = get_nm_message(db, e)))
2490 goto done;
2491
2492 mutt_debug(LL_DEBUG1, "nm: tags modify: '%s'\n", buf);
2493
2494 update_tags(msg, buf);
2495 update_email_flags(m, e, buf);
2496 update_email_tags(e, msg);
2497 email_set_color(m, e);
2498
2499 rc = 0;
2500 e->changed = true;
2501done:
2502 nm_db_release(m);
2503 if (e->changed)
2504 {
2505 mdata->mtime.tv_sec = mutt_date_now();
2506 mdata->mtime.tv_nsec = 0;
2507 }
2508 mutt_debug(LL_DEBUG1, "nm: tags modify done [rc=%d]\n", rc);
2509 return rc;
2510}
void email_set_color(struct Mailbox *m, struct Email *e)
Select an Index colour for an Email.
Definition dlg_index.c:1425
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition db.c:209
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition db.c:233
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition mdata.c:96
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition notmuch.c:1081
static int update_tags(notmuch_message_t *msg, const char *tag_str)
Update the tags on a message.
Definition notmuch.c:1141
static int update_email_tags(struct Email *e, notmuch_message_t *msg)
Update the Email's tags from Notmuch.
Definition notmuch.c:481
static int update_email_flags(struct Mailbox *m, struct Email *e, const char *tag_str)
Update the Email's flags.
Definition notmuch.c:1195
bool changed
Email has been edited.
Definition email.h:77
void * mdata
Driver specific data.
Definition mailbox.h:131
Notmuch-specific Mailbox data -.
Definition mdata.h:35
+ Here is the call graph for this function: