NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
mbox_close()

Close a Mailbox. More...

+ Collaboration diagram for mbox_close():

Functions

static enum MxStatus comp_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
static enum MxStatus imap_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
enum MxStatus maildir_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
enum MxStatus mh_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
static enum MxStatus mbox_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
static enum MxStatus nntp_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
static enum MxStatus nm_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
static enum MxStatus pop_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 

Detailed Description

Close a Mailbox.

Parameters
mMailbox to close
Return values
enumMxStatus

Contract

Function Documentation

◆ comp_mbox_close()

static enum MxStatus comp_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close() -.

If the mailbox has been changed then re-compress the tmp file. Then delete the tmp file.

Definition at line 670 of file compress.c.

671{
672 if (!m->compress_info)
673 return MX_STATUS_ERROR;
674
675 struct CompressInfo *ci = m->compress_info;
676
677 const struct MxOps *ops = ci->child_ops;
678 if (!ops)
679 {
681 return MX_STATUS_ERROR;
682 }
683
684 ops->mbox_close(m);
685
686 /* sync has already been called, so we only need to delete some files */
687 if (m->append)
688 {
689 const char *append = NULL;
690 const char *msg = NULL;
691
692 /* The file exists and we can append */
693 if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
694 {
695 append = ci->cmd_append;
696 msg = _("Compressed-appending to %s...");
697 }
698 else
699 {
700 append = ci->cmd_close;
701 msg = _("Compressing %s");
702 }
703
704 int rc = execute_command(m, append, msg);
705 if (rc == 0)
706 {
708 mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
709 }
710 else
711 remove(mailbox_path(m));
712
714 }
715 else
716 {
717 /* If the file was removed, remove the compressed folder too */
718 if (access(mailbox_path(m), F_OK) != 0)
719 {
720 const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
721 if (!c_save_empty)
722 {
723 remove(m->realpath);
724 }
725 }
726 else
727 {
728 remove(mailbox_path(m));
729 }
730 }
731
733
734 return MX_STATUS_OK;
735}
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:227
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:322
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:125
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:387
#define mutt_error(...)
Definition: logging.h:87
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
#define _(a)
Definition: message.h:28
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:85
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:86
Private data for compress.
Definition: lib.h:47
const char * cmd_append
append-hook command
Definition: lib.h:48
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
const char * cmd_close
close-hook command
Definition: lib.h:49
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:109
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:120
Definition: mxapi.h:112
enum MxStatus(* mbox_close)(struct Mailbox *m)
Definition: mxapi.h:228
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:

◆ imap_mbox_close()

static enum MxStatus imap_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close() -.

Definition at line 2181 of file imap.c.

2182{
2184 struct ImapMboxData *mdata = imap_mdata_get(m);
2185
2186 /* Check to see if the mailbox is actually open */
2187 if (!adata || !mdata)
2188 return MX_STATUS_OK;
2189
2190 /* imap_mbox_open_append() borrows the struct ImapAccountData temporarily,
2191 * just for the connection.
2192 *
2193 * So when these are equal, it means we are actually closing the
2194 * mailbox and should clean up adata. Otherwise, we don't want to
2195 * touch adata - it's still being used. */
2196 if (m == adata->mailbox)
2197 {
2198 if ((adata->status != IMAP_FATAL) && (adata->state >= IMAP_SELECTED))
2199 {
2200 /* mx_mbox_close won't sync if there are no deleted messages
2201 * and the mailbox is unchanged, so we may have to close here */
2202 if (m->msg_deleted == 0)
2203 {
2204 adata->closing = true;
2205 imap_exec(adata, "CLOSE", IMAP_CMD_NO_FLAGS);
2206 }
2207 adata->state = IMAP_AUTHENTICATED;
2208 }
2209
2210 mutt_debug(LL_DEBUG3, "closing %s, restoring %s\n", m->pathbuf.data,
2211 (adata->prev_mailbox ? adata->prev_mailbox->pathbuf.data : "(none)"));
2212 adata->mailbox = adata->prev_mailbox;
2215 }
2216
2217 return MX_STATUS_OK;
2218}
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:89
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:1247
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:60
#define IMAP_CMD_NO_FLAGS
No flags are set.
Definition: private.h:73
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition: private.h:109
@ IMAP_SELECTED
Mailbox is selected.
Definition: private.h:110
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition: util.c:106
@ IMAP_FATAL
Unrecoverable error occurred.
Definition: private.h:97
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition: imap.c:1815
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
char * data
Pointer to data.
Definition: buffer.h:35
IMAP-specific Account data -.
Definition: adata.h:40
struct Mailbox * prev_mailbox
Previously selected mailbox.
Definition: adata.h:77
bool closing
If true, we are waiting for CLOSE completion.
Definition: adata.h:43
unsigned char state
ImapState, e.g. IMAP_AUTHENTICATED.
Definition: adata.h:44
struct Mailbox * mailbox
Current selected mailbox.
Definition: adata.h:76
unsigned char status
ImapFlags, e.g. IMAP_FATAL.
Definition: adata.h:45
IMAP-specific Mailbox data -.
Definition: mdata.h:39
void * mdata
Driver specific data.
Definition: mailbox.h:132
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
int msg_deleted
Number of deleted messages.
Definition: mailbox.h:93
+ Here is the call graph for this function:

◆ maildir_mbox_close()

enum MxStatus maildir_mbox_close ( struct Mailbox m)

Close a Mailbox - Implements MxOps::mbox_close() -.

Return values
MX_STATUS_OKAlways

Definition at line 1446 of file maildir.c.

1447{
1448 return MX_STATUS_OK;
1449}

◆ mh_mbox_close()

enum MxStatus mh_mbox_close ( struct Mailbox m)

Close a Mailbox - Implements MxOps::mbox_close() -.

Return values
MX_STATUS_OKAlways

Definition at line 1111 of file mh.c.

1112{
1113 return MX_STATUS_OK;
1114}

◆ mbox_mbox_close()

static enum MxStatus mbox_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close() -.

Definition at line 1534 of file mbox.c.

1535{
1537 if (!adata)
1538 return MX_STATUS_ERROR;
1539
1540 if (!adata->fp)
1541 return MX_STATUS_OK;
1542
1543 if (adata->append)
1544 {
1545 mutt_file_unlock(fileno(adata->fp));
1547 }
1548
1549 mutt_file_fclose(&adata->fp);
1550
1551 /* fix up the times so mailbox won't get confused */
1552 if (m->peekonly && !mutt_buffer_is_empty(&m->pathbuf) &&
1553 (mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0))
1554 {
1555#ifdef HAVE_UTIMENSAT
1556 struct timespec ts[2];
1557 ts[0] = adata->atime;
1558 ts[1] = m->mtime;
1559 utimensat(AT_FDCWD, m->path, ts, 0);
1560#else
1561 struct utimbuf ut;
1562 ut.actime = adata->atime.tv_sec;
1563 ut.modtime = m->mtime.tv_sec;
1564 utime(mailbox_path(m), &ut);
1565#endif
1566 }
1567
1568 return MX_STATUS_OK;
1569}
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:260
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1589
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1279
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:119
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:168
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:104
bool peekonly
Just taking a glance, revert atime.
Definition: mailbox.h:113
Mbox-specific Account data -.
Definition: lib.h:49
struct timespec atime
File's last-access time.
Definition: lib.h:51
Time value with nanosecond precision.
Definition: file.h:49
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:50
+ Here is the call graph for this function:

◆ nntp_mbox_close()

static enum MxStatus nntp_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close() -.

Return values
0Always

Definition at line 2538 of file nntp.c.

2539{
2540 struct NntpMboxData *mdata = m->mdata;
2541 struct NntpMboxData *tmp_mdata = NULL;
2542 if (!mdata)
2543 return MX_STATUS_OK;
2544
2545 mdata->unread = m->msg_unread;
2546
2548 if (!mdata->adata || !mdata->adata->groups_hash || !mdata->group)
2549 return MX_STATUS_OK;
2550
2551 tmp_mdata = mutt_hash_find(mdata->adata->groups_hash, mdata->group);
2552 if (!tmp_mdata || (tmp_mdata != mdata))
2553 nntp_mdata_free((void **) &mdata);
2554 return MX_STATUS_OK;
2555}
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
void nntp_acache_free(struct NntpMboxData *mdata)
Remove all temporarily cache files.
Definition: newsrc.c:102
void nntp_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:38
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
NNTP-specific Mailbox data -.
Definition: mdata.h:33
+ Here is the call graph for this function:

◆ nm_mbox_close()

static enum MxStatus nm_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close() -.

Nothing to do.

Definition at line 2330 of file notmuch.c.

2331{
2332 return MX_STATUS_OK;
2333}

◆ pop_mbox_close()

static enum MxStatus pop_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close() -.

Definition at line 949 of file pop.c.

950{
952 if (!adata)
953 return MX_STATUS_OK;
954
955 pop_logout(m);
956
957 if (adata->status != POP_NONE)
958 {
960 // FREE(&adata->conn);
961 }
962
963 adata->status = POP_NONE;
964
965 adata->clear_cache = true;
967
968 mutt_bcache_close(&adata->bcache);
969
970 return MX_STATUS_OK;
971}
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
Definition: bcache.c:165
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:64
void pop_logout(struct Mailbox *m)
Logout from a POP server.
Definition: lib.c:416
@ POP_NONE
No connected to server.
Definition: private.h:49
static void pop_clear_cache(struct PopAccountData *adata)
Delete all cached messages.
Definition: pop.c:491
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:98
POP-specific Account data -.
Definition: adata.h:37
+ Here is the call graph for this function: