NeoMutt  2025-12-11-911-gd8d604
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 640 of file compress.c.

641{
642 if (!m->compress_info)
643 return MX_STATUS_ERROR;
644
645 struct CompressInfo *ci = m->compress_info;
646
647 const struct MxOps *ops = ci->child_ops;
648 if (!ops)
649 {
651 return MX_STATUS_ERROR;
652 }
653
654 ops->mbox_close(m);
655
656 /* sync has already been called, so we only need to delete some files */
657 if (m->append)
658 {
659 const struct Expando *append = NULL;
660 const char *msg = NULL;
661
662 /* The file exists and we can append */
663 if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
664 {
665 append = ci->cmd_append;
666 msg = _("Compressed-appending to %s...");
667 }
668 else
669 {
670 append = ci->cmd_close;
671 msg = _("Compressing %s");
672 }
673
674 if (!execute_command(m, append, msg))
675 {
677 mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
678 }
679 else
680 {
681 if (remove(mailbox_path(m)) < 0)
682 {
683 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
684 mailbox_path(m), strerror(errno), errno);
685 }
686 }
687
689 }
690 else
691 {
692 /* If the file was removed, remove the compressed folder too */
693 if (access(mailbox_path(m), F_OK) != 0)
694 {
695 const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
696 if (!c_save_empty)
697 {
698 if (remove(m->realpath) < 0)
699 {
700 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
701 m->realpath, strerror(errno), errno);
702 }
703 }
704 }
705 else
706 {
707 if (remove(mailbox_path(m)) < 0)
708 {
709 mutt_debug(LL_DEBUG1, "remove failed: %s: %s (errno %d)\n",
710 mailbox_path(m), strerror(errno), errno);
711 }
712 }
713 }
714
716
717 return MX_STATUS_OK;
718}
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:153
static bool execute_command(struct Mailbox *m, const struct Expando *exp, const char *progress)
Run a system command.
Definition compress.c:295
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:216
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition curs_lib.c:175
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define _(a)
Definition message.h:28
@ MX_STATUS_ERROR
An error occurred.
Definition mxapi.h:71
@ MX_STATUS_OK
No changes.
Definition mxapi.h:72
Private data for compress.
Definition lib.h:61
struct Expando * cmd_append
append-hook command
Definition lib.h:62
const struct MxOps * child_ops
callbacks of de-compressed file
Definition lib.h:66
struct Expando * cmd_close
close-hook command
Definition lib.h:63
Parsed Expando trees.
Definition expando.h:41
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:83
bool append
Mailbox is opened in append mode.
Definition mailbox.h:111
void * compress_info
Compressed mbox module private data.
Definition mailbox.h:123
Definition mxapi.h:98
enum MxStatus(* mbox_close)(struct Mailbox *m)
Definition mxapi.h:206
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ 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 2456 of file imap.c.

2457{
2459 struct ImapMboxData *mdata = imap_mdata_get(m);
2460
2461 /* Check to see if the mailbox is actually open */
2462 if (!adata || !mdata)
2463 return MX_STATUS_OK;
2464
2465 /* imap_mbox_open_append() borrows the struct ImapAccountData temporarily,
2466 * just for the connection.
2467 *
2468 * So when these are equal, it means we are actually closing the
2469 * mailbox and should clean up adata. Otherwise, we don't want to
2470 * touch adata - it's still being used. */
2471 if (m == adata->mailbox)
2472 {
2473 if ((adata->status != IMAP_FATAL) && (adata->state >= IMAP_SELECTED))
2474 {
2475 /* mx_mbox_close won't sync if there are no deleted messages
2476 * and the mailbox is unchanged, so we may have to close here */
2477 if (m->msg_deleted == 0)
2478 {
2479 adata->closing = true;
2480 imap_exec(adata, "CLOSE", IMAP_CMD_NONE);
2481 }
2482 adata->state = IMAP_AUTHENTICATED;
2483 }
2484
2485 mutt_debug(LL_DEBUG3, "closing %s, restoring %p\n", m->pathbuf.data,
2486 (void *) adata->prev_mailbox);
2487 adata->mailbox = adata->prev_mailbox;
2488 adata->prev_mailbox = NULL;
2489 imap_mbox_select(adata->mailbox);
2491 }
2492
2493 return MX_STATUS_OK;
2494}
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:162
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:1420
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition mdata.c:61
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition private.h:120
@ IMAP_SELECTED
Mailbox is selected.
Definition private.h:121
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition util.c:111
@ IMAP_FATAL
Unrecoverable error occurred.
Definition private.h:108
@ IMAP_CMD_NONE
No flags are set.
Definition private.h:82
static void imap_mbox_select(struct Mailbox *m)
Select a Mailbox.
Definition imap.c:1980
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
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:81
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:45
struct Mailbox * mailbox
Current selected mailbox.
Definition adata.h:80
unsigned char status
ImapFlags, e.g. IMAP_FATAL.
Definition adata.h:46
IMAP-specific Mailbox data -.
Definition mdata.h:40
void * mdata
Driver specific data.
Definition mailbox.h:134
struct Buffer pathbuf
Path of the Mailbox.
Definition mailbox.h:82
int msg_deleted
Number of deleted messages.
Definition mailbox.h:95
+ 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 909 of file mailbox.c.

910{
911 return MX_STATUS_OK;
912}

◆ mbox_mbox_close()

static enum MxStatus mbox_mbox_close ( struct Mailbox * m)
static

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

Definition at line 1460 of file mbox.c.

1461{
1463 if (!adata)
1464 return MX_STATUS_ERROR;
1465
1466 if (!adata->fp)
1467 return MX_STATUS_OK;
1468
1469 if (adata->append)
1470 {
1471 mutt_file_unlock(fileno(adata->fp));
1473 }
1474
1475 mutt_file_fclose(&adata->fp);
1476
1477 /* fix up the times so mailbox won't get confused */
1478 if (m->peekonly && !buf_is_empty(&m->pathbuf) &&
1479 (mutt_file_timespec_compare(&adata->mtime, &adata->atime) > 0))
1480 {
1481#ifdef HAVE_UTIMENSAT
1482 struct timespec ts[2] = { { 0 }, { 0 } };
1483 ts[0] = adata->atime;
1484 ts[1] = adata->mtime;
1485 utimensat(AT_FDCWD, mailbox_path(m), ts, 0);
1486#else
1487 struct utimbuf ut = { 0 };
1488 ut.actime = adata->atime.tv_sec;
1489 ut.modtime = adata->mtime.tv_sec;
1490 utime(mailbox_path(m), &ut);
1491#endif
1492 }
1493
1494 return MX_STATUS_OK;
1495}
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:1452
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition file.c:1135
#define mutt_file_fclose(FP)
Definition file.h:144
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition mbox.c:121
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition signal.c:245
bool peekonly
Just taking a glance, revert atime.
Definition mailbox.h:116
Mbox-specific Account data -.
Definition lib.h:50
struct timespec atime
File's last-access time.
Definition lib.h:53
struct timespec mtime
Time Mailbox was last changed.
Definition lib.h:52
+ 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 1137 of file mh.c.

1138{
1139 return MX_STATUS_OK;
1140}

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

2626{
2627 struct NntpMboxData *mdata = m->mdata;
2628 struct NntpMboxData *tmp_mdata = NULL;
2629 if (!mdata)
2630 return MX_STATUS_OK;
2631
2632 mdata->unread = m->msg_unread;
2633
2635 if (!mdata->adata || !mdata->adata->groups_hash || !mdata->group)
2636 return MX_STATUS_OK;
2637
2638 tmp_mdata = mutt_hash_find(mdata->adata->groups_hash, mdata->group);
2639 if (!tmp_mdata || (tmp_mdata != mdata))
2640 nntp_mdata_free((void **) &mdata);
2641 return MX_STATUS_OK;
2642}
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:364
void nntp_acache_free(struct NntpMboxData *mdata)
Remove all temporarily cache files.
Definition newsrc.c:105
int msg_unread
Number of unread messages.
Definition mailbox.h:91
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 2430 of file notmuch.c.

2431{
2432 return MX_STATUS_OK;
2433}

◆ pop_mbox_close()

static enum MxStatus pop_mbox_close ( struct Mailbox * m)
static

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

Definition at line 963 of file pop.c.

964{
966 if (!adata)
967 return MX_STATUS_OK;
968
969 pop_logout(m);
970
971 if (adata->status != POP_NONE)
972 {
974 }
975
976 adata->status = POP_NONE;
977
978 adata->clear_cache = true;
980
981 mutt_bcache_close(&adata->bcache);
982
983 return MX_STATUS_OK;
984}
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
Definition bcache.c:167
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:47
static void pop_clear_cache(struct PopAccountData *adata)
Delete all cached messages.
Definition pop.c:509
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: