NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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() -.
 
static enum MxStatus imap_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 
enum MxStatus maildir_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 
static enum MxStatus mbox_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 
static enum MxStatus mh_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 
static enum MxStatus nntp_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 
static enum MxStatus nm_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 
static enum MxStatus pop_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() -.
 

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 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 struct Expando *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 if (!execute_command(m, append, msg))
705 {
707 mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
708 }
709 else
710 {
711 if (remove(mailbox_path(m)) < 0)
712 {
713 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
714 mailbox_path(m), strerror(errno), errno);
715 }
716 }
717
719 }
720 else
721 {
722 /* If the file was removed, remove the compressed folder too */
723 if (access(mailbox_path(m), F_OK) != 0)
724 {
725 const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
726 if (!c_save_empty)
727 {
728 if (remove(m->realpath) < 0)
729 {
730 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
731 m->realpath, strerror(errno), errno);
732 }
733 }
734 }
735 else
736 {
737 if (remove(mailbox_path(m)) < 0)
738 {
739 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
740 mailbox_path(m), strerror(errno), errno);
741 }
742 }
743 }
744
746
747 return MX_STATUS_OK;
748}
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:269
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:148
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition: compress.c:323
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:173
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define _(a)
Definition: message.h:28
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:64
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:65
Private data for compress.
Definition: lib.h:59
struct Expando * cmd_append
append-hook command
Definition: lib.h:60
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:64
struct Expando * cmd_close
close-hook command
Definition: lib.h:61
Parsed Expando trees.
Definition: expando.h:41
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:121
Definition: mxapi.h:91
enum MxStatus(* mbox_close)(struct Mailbox *m)
Definition: mxapi.h:199
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 2123 of file imap.c.

2124{
2126 struct ImapMboxData *mdata = imap_mdata_get(m);
2127
2128 /* Check to see if the mailbox is actually open */
2129 if (!adata || !mdata)
2130 return MX_STATUS_OK;
2131
2132 /* imap_mbox_open_append() borrows the struct ImapAccountData temporarily,
2133 * just for the connection.
2134 *
2135 * So when these are equal, it means we are actually closing the
2136 * mailbox and should clean up adata. Otherwise, we don't want to
2137 * touch adata - it's still being used. */
2138 if (m == adata->mailbox)
2139 {
2140 if ((adata->status != IMAP_FATAL) && (adata->state >= IMAP_SELECTED))
2141 {
2142 /* mx_mbox_close won't sync if there are no deleted messages
2143 * and the mailbox is unchanged, so we may have to close here */
2144 if (m->msg_deleted == 0)
2145 {
2146 adata->closing = true;
2147 imap_exec(adata, "CLOSE", IMAP_CMD_NO_FLAGS);
2148 }
2149 adata->state = IMAP_AUTHENTICATED;
2150 }
2151
2152 mutt_debug(LL_DEBUG3, "closing %s, restoring %s\n", m->pathbuf.data,
2153 (adata->prev_mailbox ? adata->prev_mailbox->pathbuf.data : "(none)"));
2154 adata->mailbox = adata->prev_mailbox;
2157 }
2158
2159 return MX_STATUS_OK;
2160}
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:123
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:1304
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:61
#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:110
@ IMAP_FATAL
Unrecoverable error occurred.
Definition: private.h:95
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition: imap.c:1744
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
char * data
Pointer to data.
Definition: buffer.h:37
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:40
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 898 of file mailbox.c.

899{
900 return MX_STATUS_OK;
901}

◆ mbox_mbox_close()

static enum MxStatus mbox_mbox_close ( struct Mailbox m)
static

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

Definition at line 1434 of file mbox.c.

1435{
1437 if (!adata)
1438 return MX_STATUS_ERROR;
1439
1440 if (!adata->fp)
1441 return MX_STATUS_OK;
1442
1443 if (adata->append)
1444 {
1445 mutt_file_unlock(fileno(adata->fp));
1447 }
1448
1449 mutt_file_fclose(&adata->fp);
1450
1451 /* fix up the times so mailbox won't get confused */
1452 if (m->peekonly && !buf_is_empty(&m->pathbuf) &&
1453 (mutt_file_timespec_compare(&adata->mtime, &adata->atime) > 0))
1454 {
1455#ifdef HAVE_UTIMENSAT
1456 struct timespec ts[2] = { { 0 }, { 0 } };
1457 ts[0] = adata->atime;
1458 ts[1] = adata->mtime;
1459 utimensat(AT_FDCWD, m->path, ts, 0);
1460#else
1461 struct utimbuf ut = { 0 };
1462 ut.actime = adata->atime.tv_sec;
1463 ut.modtime = adata->mtime.tv_sec;
1464 utime(mailbox_path(m), &ut);
1465#endif
1466 }
1467
1468 return MX_STATUS_OK;
1469}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1557
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1249
#define mutt_file_fclose(FP)
Definition: file.h:138
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:125
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:230
bool peekonly
Just taking a glance, revert atime.
Definition: mailbox.h:114
Mbox-specific Account data -.
Definition: lib.h:49
struct timespec atime
File's last-access time.
Definition: lib.h:52
struct timespec mtime
Time Mailbox was last changed.
Definition: lib.h:51
+ Here is the call graph for this function:

◆ 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 1135 of file mh.c.

1136{
1137 return MX_STATUS_OK;
1138}

◆ 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 2624 of file nntp.c.

2625{
2626 struct NntpMboxData *mdata = m->mdata;
2627 struct NntpMboxData *tmp_mdata = NULL;
2628 if (!mdata)
2629 return MX_STATUS_OK;
2630
2631 mdata->unread = m->msg_unread;
2632
2634 if (!mdata->adata || !mdata->adata->groups_hash || !mdata->group)
2635 return MX_STATUS_OK;
2636
2637 tmp_mdata = mutt_hash_find(mdata->adata->groups_hash, mdata->group);
2638 if (!tmp_mdata || (tmp_mdata != mdata))
2639 nntp_mdata_free((void **) &mdata);
2640 return MX_STATUS_OK;
2641}
void nntp_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free() -.
Definition: mdata.c:38
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:106
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
NNTP-specific Mailbox data -.
Definition: mdata.h:34
+ 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 2358 of file notmuch.c.

2359{
2360 return MX_STATUS_OK;
2361}

◆ 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 **ptr)
Close an Email-Body Cache.
Definition: bcache.c:169
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:425
@ 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:493
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:100
POP-specific Account data -.
Definition: adata.h:37
+ Here is the call graph for this function: