NeoMutt  2021-02-05-666-ge300cd
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() -If the mailbox has been changed then re-compress the tmp file. 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() -Nothing to do. 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 667 of file compress.c.

668 {
669  if (!m->compress_info)
670  return MX_STATUS_ERROR;
671 
672  struct CompressInfo *ci = m->compress_info;
673 
674  const struct MxOps *ops = ci->child_ops;
675  if (!ops)
676  {
678  return MX_STATUS_ERROR;
679  }
680 
681  ops->mbox_close(m);
682 
683  /* sync has already been called, so we only need to delete some files */
684  if (m->append)
685  {
686  const char *append = NULL;
687  const char *msg = NULL;
688 
689  /* The file exists and we can append */
690  if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
691  {
692  append = ci->cmd_append;
693  msg = _("Compressed-appending to %s...");
694  }
695  else
696  {
697  append = ci->cmd_close;
698  msg = _("Compressing %s");
699  }
700 
701  int rc = execute_command(m, append, msg);
702  if (rc == 0)
703  {
705  mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
706  }
707  else
708  remove(mailbox_path(m));
709 
710  unlock_realpath(m);
711  }
712  else
713  {
714  /* If the file was removed, remove the compressed folder too */
715  const bool c_save_empty = cs_subset_bool(NeoMutt->sub, "save_empty");
716  if ((access(mailbox_path(m), F_OK) != 0) && !c_save_empty)
717  {
718  remove(m->realpath);
719  }
720  else
721  {
722  remove(mailbox_path(m));
723  }
724  }
725 
727 
728  return MX_STATUS_OK;
729 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:215
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
const char * cmd_append
append-hook command
Definition: lib.h:48
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:226
#define mutt_error(...)
Definition: logging.h:88
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:36
const char * cmd_close
close-hook command
Definition: lib.h:49
No changes.
Definition: mxapi.h:78
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:113
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:124
Private data for compress.
Definition: lib.h:46
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:319
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:455
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
enum MxStatus(* mbox_close)(struct Mailbox *m)
Definition: mxapi.h:220
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:52
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Definition: mxapi.h:103
An error occurred.
Definition: mxapi.h:77
+ 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 2183 of file imap.c.

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

1449 {
1450  return MX_STATUS_OK;
1451 }
No changes.
Definition: mxapi.h:78

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

1105 {
1106  return MX_STATUS_OK;
1107 }
No changes.
Definition: mxapi.h:78

◆ mbox_mbox_close()

static enum MxStatus mbox_mbox_close ( struct Mailbox m)
static

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

Definition at line 1524 of file mbox.c.

1525 {
1526  struct MboxAccountData *adata = mbox_adata_get(m);
1527  if (!adata)
1528  return MX_STATUS_ERROR;
1529 
1530  if (!adata->fp)
1531  return MX_STATUS_OK;
1532 
1533  if (adata->append)
1534  {
1535  mutt_file_unlock(fileno(adata->fp));
1536  mutt_sig_unblock();
1537  }
1538 
1539  mutt_file_fclose(&adata->fp);
1540 
1541  /* fix up the times so mailbox won't get confused */
1542  if (m->peekonly && !mutt_buffer_is_empty(&m->pathbuf) &&
1543  (mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0))
1544  {
1545 #ifdef HAVE_UTIMENSAT
1546  struct timespec ts[2];
1547  ts[0] = adata->atime;
1548  ts[1] = m->mtime;
1549  utimensat(AT_FDCWD, m->path, ts, 0);
1550 #else
1551  struct utimbuf ut;
1552  ut.actime = adata->atime.tv_sec;
1553  ut.modtime = m->mtime.tv_sec;
1554  utime(mailbox_path(m), &ut);
1555 #endif
1556  }
1557 
1558  return MX_STATUS_OK;
1559 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:215
int mutt_file_timespec_compare(struct timespec *a, struct timespec *b)
Compare to time values.
Definition: file.c:1518
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:168
bool append
mailbox is opened in append mode
Definition: lib.h:54
bool peekonly
Just taking a glance, revert atime.
Definition: mailbox.h:117
Mbox-specific Account data -.
Definition: lib.h:48
struct timespec atime
File's last-access time.
Definition: lib.h:51
struct timespec mtime
Time Mailbox was last changed.
Definition: mailbox.h:107
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1226
time_t tv_sec
Definition: file.h:50
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
No changes.
Definition: mxapi.h:78
static struct MboxAccountData * mbox_adata_get(struct Mailbox *m)
Get the private data associated with a Mailbox.
Definition: mbox.c:100
Time value with nanosecond precision.
Definition: file.h:48
struct Buffer pathbuf
Definition: mailbox.h:83
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
FILE * fp
Mailbox file.
Definition: lib.h:50
An error occurred.
Definition: mxapi.h:77
+ 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 2549 of file nntp.c.

2550 {
2551  struct NntpMboxData *mdata = m->mdata;
2552  struct NntpMboxData *tmp_mdata = NULL;
2553  if (!mdata)
2554  return MX_STATUS_OK;
2555 
2556  mdata->unread = m->msg_unread;
2557 
2558  nntp_acache_free(mdata);
2559  if (!mdata->adata || !mdata->adata->groups_hash || !mdata->group)
2560  return MX_STATUS_OK;
2561 
2562  tmp_mdata = mutt_hash_find(mdata->adata->groups_hash, mdata->group);
2563  if (!tmp_mdata || (tmp_mdata != mdata))
2564  nntp_mdata_free((void **) &mdata);
2565  return MX_STATUS_OK;
2566 }
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:354
int msg_unread
Number of unread messages.
Definition: mailbox.h:92
struct NntpAccountData * adata
Definition: mdata.h:47
void nntp_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
Definition: mdata.c:38
struct HashTable * groups_hash
Definition: adata.h:62
char * group
Definition: mdata.h:34
void * mdata
Driver specific data.
Definition: mailbox.h:136
No changes.
Definition: mxapi.h:78
NNTP-specific Mailbox data -.
Definition: mdata.h:32
anum_t unread
Definition: mdata.h:40
void nntp_acache_free(struct NntpMboxData *mdata)
Remove all temporarily cache files.
Definition: newsrc.c:102
+ 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 2356 of file notmuch.c.

2357 {
2358  return MX_STATUS_OK;
2359 }
No changes.
Definition: mxapi.h:78

◆ pop_mbox_close()

static enum MxStatus pop_mbox_close ( struct Mailbox m)
static

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

Definition at line 956 of file pop.c.

957 {
958  struct PopAccountData *adata = pop_adata_get(m);
959  if (!adata)
960  return MX_STATUS_OK;
961 
962  pop_logout(m);
963 
964  if (adata->status != POP_NONE)
965  {
966  mutt_socket_close(adata->conn);
967  // FREE(&adata->conn);
968  }
969 
970  adata->status = POP_NONE;
971 
972  adata->clear_cache = true;
973  pop_clear_cache(adata);
974 
975  mutt_bcache_close(&adata->bcache);
976 
977  return MX_STATUS_OK;
978 }
struct BodyCache * bcache
body cache
Definition: adata.h:55
struct Connection * conn
Definition: adata.h:38
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:64
static void pop_clear_cache(struct PopAccountData *adata)
delete all cached messages
Definition: pop.c:495
No connected to server.
Definition: private.h:49
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
bool clear_cache
Definition: adata.h:49
No changes.
Definition: mxapi.h:78
unsigned int status
Definition: adata.h:39
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:97
POP-specific Account data -.
Definition: adata.h:36
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
Definition: bcache.c:164
void pop_logout(struct Mailbox *m)
logout from a POP server
Definition: lib.c:420
+ Here is the call graph for this function: