NeoMutt  2023-05-17-56-ga67199
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...
 
static enum MxStatus maildir_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -. More...
 
static 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
Precondition
m is not NULL

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 674 of file compress.c.

675{
676 if (!m->compress_info)
677 return MX_STATUS_ERROR;
678
679 struct CompressInfo *ci = m->compress_info;
680
681 const struct MxOps *ops = ci->child_ops;
682 if (!ops)
683 {
685 return MX_STATUS_ERROR;
686 }
687
688 ops->mbox_close(m);
689
690 /* sync has already been called, so we only need to delete some files */
691 if (m->append)
692 {
693 const char *append = NULL;
694 const char *msg = NULL;
695
696 /* The file exists and we can append */
697 if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
698 {
699 append = ci->cmd_append;
700 msg = _("Compressed-appending to %s...");
701 }
702 else
703 {
704 append = ci->cmd_close;
705 msg = _("Compressing %s");
706 }
707
708 int rc = execute_command(m, append, msg);
709 if (rc == 0)
710 {
712 mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
713 }
714 else
715 {
716 remove(mailbox_path(m));
717 }
718
720 }
721 else
722 {
723 /* If the file was removed, remove the compressed folder too */
724 if (access(mailbox_path(m), F_OK) != 0)
725 {
726 const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
727 if (!c_save_empty)
728 {
729 remove(m->realpath);
730 }
731 }
732 else
733 {
734 remove(mailbox_path(m));
735 }
736 }
737
739
740 return MX_STATUS_OK;
741}
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:231
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:326
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:129
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:388
#define mutt_error(...)
Definition: logging2.h:90
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:209
#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:220
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 2106 of file imap.c.

2107{
2109 struct ImapMboxData *mdata = imap_mdata_get(m);
2110
2111 /* Check to see if the mailbox is actually open */
2112 if (!adata || !mdata)
2113 return MX_STATUS_OK;
2114
2115 /* imap_mbox_open_append() borrows the struct ImapAccountData temporarily,
2116 * just for the connection.
2117 *
2118 * So when these are equal, it means we are actually closing the
2119 * mailbox and should clean up adata. Otherwise, we don't want to
2120 * touch adata - it's still being used. */
2121 if (m == adata->mailbox)
2122 {
2123 if ((adata->status != IMAP_FATAL) && (adata->state >= IMAP_SELECTED))
2124 {
2125 /* mx_mbox_close won't sync if there are no deleted messages
2126 * and the mailbox is unchanged, so we may have to close here */
2127 if (m->msg_deleted == 0)
2128 {
2129 adata->closing = true;
2130 imap_exec(adata, "CLOSE", IMAP_CMD_NO_FLAGS);
2131 }
2132 adata->state = IMAP_AUTHENTICATED;
2133 }
2134
2135 mutt_debug(LL_DEBUG3, "closing %s, restoring %s\n", m->pathbuf.data,
2136 (adata->prev_mailbox ? adata->prev_mailbox->pathbuf.data : "(none)"));
2137 adata->mailbox = adata->prev_mailbox;
2140 }
2141
2142 return MX_STATUS_OK;
2143}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
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 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:71
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition: private.h:107
@ IMAP_SELECTED
Mailbox is selected.
Definition: private.h:108
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition: util.c:105
@ IMAP_FATAL
Unrecoverable error occurred.
Definition: private.h:95
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition: imap.c:1729
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
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()

static enum MxStatus maildir_mbox_close ( struct Mailbox m)
static

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

Return values
MX_STATUS_OKAlways

Definition at line 1452 of file maildir.c.

1453{
1454 return MX_STATUS_OK;
1455}

◆ mh_mbox_close()

static enum MxStatus mh_mbox_close ( struct Mailbox m)
static

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

Return values
MX_STATUS_OKAlways

Definition at line 1104 of file mh.c.

1105{
1106 return MX_STATUS_OK;
1107}

◆ mbox_mbox_close()

static enum MxStatus mbox_mbox_close ( struct Mailbox m)
static

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

Definition at line 1544 of file mbox.c.

1545{
1547 if (!adata)
1548 return MX_STATUS_ERROR;
1549
1550 if (!adata->fp)
1551 return MX_STATUS_OK;
1552
1553 if (adata->append)
1554 {
1555 mutt_file_unlock(fileno(adata->fp));
1557 }
1558
1559 mutt_file_fclose(&adata->fp);
1560
1561 /* fix up the times so mailbox won't get confused */
1562 if (m->peekonly && !buf_is_empty(&m->pathbuf) &&
1563 (mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0))
1564 {
1565#ifdef HAVE_UTIMENSAT
1566 struct timespec ts[2];
1567 ts[0] = adata->atime;
1568 ts[1] = m->mtime;
1569 utimensat(AT_FDCWD, m->path, ts, 0);
1570#else
1571 struct utimbuf ut;
1572 ut.actime = adata->atime.tv_sec;
1573 ut.modtime = m->mtime.tv_sec;
1574 utime(mailbox_path(m), &ut);
1575#endif
1576 }
1577
1578 return MX_STATUS_OK;
1579}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1576
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1266
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:182
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:50
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:51
+ 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 2579 of file nntp.c.

2580{
2581 struct NntpMboxData *mdata = m->mdata;
2582 struct NntpMboxData *tmp_mdata = NULL;
2583 if (!mdata)
2584 return MX_STATUS_OK;
2585
2586 mdata->unread = m->msg_unread;
2587
2589 if (!mdata->adata || !mdata->adata->groups_hash || !mdata->group)
2590 return MX_STATUS_OK;
2591
2592 tmp_mdata = mutt_hash_find(mdata->adata->groups_hash, mdata->group);
2593 if (!tmp_mdata || (tmp_mdata != mdata))
2594 nntp_mdata_free((void **) &mdata);
2595 return MX_STATUS_OK;
2596}
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 2344 of file notmuch.c.

2345{
2346 return MX_STATUS_OK;
2347}

◆ pop_mbox_close()

static enum MxStatus pop_mbox_close ( struct Mailbox m)
static

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

Definition at line 950 of file pop.c.

951{
953 if (!adata)
954 return MX_STATUS_OK;
955
956 pop_logout(m);
957
958 if (adata->status != POP_NONE)
959 {
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:164
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:73
void pop_logout(struct Mailbox *m)
Logout from a POP server.
Definition: lib.c:424
@ 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:492
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:101
POP-specific Account data -.
Definition: adata.h:37
+ Here is the call graph for this function: