NeoMutt  2023-05-17-33-gce4425
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, const char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -. More...
 
static int imap_tags_commit (struct Mailbox *m, struct Email *e, const char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() -. More...
 
static int nm_tags_commit (struct Mailbox *m, struct Email *e, const 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
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 869 of file compress.c.

870{
871 if (!m->compress_info)
872 return 0;
873
874 struct CompressInfo *ci = m->compress_info;
875
876 const struct MxOps *ops = ci->child_ops;
877 if (!ops || !ops->tags_commit)
878 return 0;
879
880 return ops->tags_commit(m, e, buf);
881}
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_commit)(struct Mailbox *m, struct Email *e, const char *buf)
Definition: mxapi.h:344

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

2190{
2191 char uid[11] = { 0 };
2192
2194
2195 if (*buf == '\0')
2196 buf = NULL;
2197
2198 if (!(adata->mailbox->rights & MUTT_ACL_WRITE))
2199 return 0;
2200
2201 snprintf(uid, sizeof(uid), "%u", imap_edata_get(e)->uid);
2202
2203 /* Remove old custom flags */
2204 if (imap_edata_get(e)->flags_remote)
2205 {
2206 struct Buffer cmd = buf_make(128); // just a guess
2207 buf_addstr(&cmd, "UID STORE ");
2208 buf_addstr(&cmd, uid);
2209 buf_addstr(&cmd, " -FLAGS.SILENT (");
2210 buf_addstr(&cmd, imap_edata_get(e)->flags_remote);
2211 buf_addstr(&cmd, ")");
2212
2213 /* Should we return here, or we are fine and we could
2214 * continue to add new flags */
2215 int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
2216 buf_dealloc(&cmd);
2217 if (rc != IMAP_EXEC_SUCCESS)
2218 {
2219 return -1;
2220 }
2221 }
2222
2223 /* Add new custom flags */
2224 if (buf)
2225 {
2226 struct Buffer cmd = buf_make(128); // just a guess
2227 buf_addstr(&cmd, "UID STORE ");
2228 buf_addstr(&cmd, uid);
2229 buf_addstr(&cmd, " +FLAGS.SILENT (");
2230 buf_addstr(&cmd, buf);
2231 buf_addstr(&cmd, ")");
2232
2233 int rc = imap_exec(adata, cmd.data, IMAP_CMD_NO_FLAGS);
2234 buf_dealloc(&cmd);
2235 if (rc != IMAP_EXEC_SUCCESS)
2236 {
2237 mutt_debug(LL_DEBUG1, "fail to add new flags\n");
2238 return -1;
2239 }
2240 }
2241
2242 /* We are good sync them */
2243 mutt_debug(LL_DEBUG1, "NEW TAGS: %s\n", buf);
2244 driver_tags_replace(&e->tags, buf);
2245 FREE(&imap_edata_get(e)->flags_remote);
2248 return 0;
2249}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:352
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:68
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:236
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
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:2163
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:90
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:1284
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:65
#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:40
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:71
#define FREE(x)
Definition: memory.h:43
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
struct TagList tags
For drivers that support server tagging.
Definition: email.h:70
IMAP-specific Account data -.
Definition: adata.h:40
char * buf
Definition: adata.h:59
char * flags_remote
Definition: edata.h:48
bool driver_tags_replace(struct TagList *head, const char *tags)
Replace all tags.
Definition: tags.c:186
char * driver_tags_get_with_hidden(struct TagList *list)
Get tags with hiddens.
Definition: tags.c:158
+ 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 2411 of file notmuch.c.

2412{
2413 if (*buf == '\0')
2414 return 0; /* no tag change, so nothing to do */
2415
2416 struct NmMboxData *mdata = nm_mdata_get(m);
2417 if (!mdata)
2418 return -1;
2419
2420 notmuch_database_t *db = NULL;
2421 notmuch_message_t *msg = NULL;
2422 int rc = -1;
2423
2424 if (!(db = nm_db_get(m, true)) || !(msg = get_nm_message(db, e)))
2425 goto done;
2426
2427 mutt_debug(LL_DEBUG1, "nm: tags modify: '%s'\n", buf);
2428
2429 update_tags(msg, buf);
2430 update_email_flags(m, e, buf);
2431 update_email_tags(e, msg);
2433
2434 rc = 0;
2435 e->changed = true;
2436done:
2437 nm_db_release(m);
2438 if (e->changed)
2439 {
2440 m->mtime.tv_sec = mutt_date_now();
2441 m->mtime.tv_nsec = 0;
2442 }
2443 mutt_debug(LL_DEBUG1, "nm: tags modify done [rc=%d]\n", rc);
2444 return rc;
2445}
void mutt_set_header_color(struct Mailbox *m, struct Email *e)
Select a colour for a message.
Definition: dlg_index.c:1379
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
Definition: db.c:200
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
Definition: db.c:224
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Definition: mdata.c:97
static notmuch_message_t * get_nm_message(notmuch_database_t *db, struct Email *e)
Find a Notmuch message.
Definition: notmuch.c:1045
static int update_tags(notmuch_message_t *msg, const char *tag_str)
Update the tags on a message.
Definition: notmuch.c:1103
static int update_email_tags(struct Email *e, notmuch_message_t *msg)
Update the Email's tags from Notmuch.
Definition: notmuch.c:476
static int update_email_flags(struct Mailbox *m, struct Email *e, const char *tag_str)
Update the Email's flags.
Definition: notmuch.c:1157
bool changed
Email has been edited.
Definition: email.h:75
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:104
void * mdata
Driver specific data.
Definition: mailbox.h:132
Notmuch-specific Mailbox data -.
Definition: mdata.h:34
long tv_nsec
Number of nanosecond, on top.
Definition: file.h:52
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:51
+ Here is the call graph for this function: