NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
compress.c File Reference

Compressed mbox local mailbox type. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "format_flags.h"
#include "hook.h"
#include "mutt_commands.h"
#include "mutt_globals.h"
#include "muttlib.h"
#include "mx.h"
#include "protos.h"
+ Include dependency graph for compress.c:

Go to the source code of this file.

Functions

void mutt_comp_init (void)
 Setup feature commands. More...
 
static bool lock_realpath (struct Mailbox *m, bool excl)
 Try to lock the ctx->realpath. More...
 
static void unlock_realpath (struct Mailbox *m)
 Unlock the mailbox->realpath. More...
 
static int setup_paths (struct Mailbox *m)
 Set the mailbox paths. More...
 
static void store_size (const struct Mailbox *m)
 Save the size of the compressed file. More...
 
static struct CompressInfoset_compress_info (struct Mailbox *m)
 Find the compress hooks for a mailbox. More...
 
static void compress_info_free (struct Mailbox *m)
 Frees the compress info members and structure. More...
 
static const char * compress_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Expand the filenames in a command string - Implements format_t. More...
 
static void expand_command_str (const struct Mailbox *m, const char *cmd, char *buf, int buflen)
 Expand placeholders in command string. More...
 
static int execute_command (struct Mailbox *m, const char *command, const char *progress)
 Run a system command. More...
 
bool mutt_comp_can_append (struct Mailbox *m)
 Can we append to this path? More...
 
bool mutt_comp_can_read (const char *path)
 Can we read from this file? More...
 
int mutt_comp_valid_command (const char *cmd)
 Is this command string allowed? More...
 
static struct Accountcomp_ac_find (struct Account *a, const char *path)
 Find an Account that matches a Mailbox path - Implements MxOps::ac_find() More...
 
static int comp_ac_add (struct Account *a, struct Mailbox *m)
 Add a Mailbox to an Account - Implements MxOps::ac_add() More...
 
static int comp_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() More...
 
static int comp_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags)
 Open a Mailbox for appending - Implements MxOps::mbox_open_append() More...
 
static int comp_mbox_check (struct Mailbox *m)
 Check for new mail - Implements MxOps::mbox_check() More...
 
static int comp_mbox_sync (struct Mailbox *m)
 Save changes to the Mailbox - Implements MxOps::mbox_sync() More...
 
static int comp_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() More...
 
static int comp_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() More...
 
static int comp_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e)
 Open a new message in a Mailbox - Implements MxOps::msg_open_new() More...
 
static int comp_msg_commit (struct Mailbox *m, struct Message *msg)
 Save changes to an email - Implements MxOps::msg_commit() More...
 
static int comp_msg_close (struct Mailbox *m, struct Message *msg)
 Close an email - Implements MxOps::msg_close() More...
 
static int comp_msg_padding_size (struct Mailbox *m)
 Bytes of padding between messages - Implements MxOps::msg_padding_size() More...
 
static int comp_msg_save_hcache (struct Mailbox *m, struct Email *e)
 Save message to the header cache - Implements MxOps::msg_save_hcache() More...
 
static int comp_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen)
 Prompt and validate new messages tags - Implements MxOps::tags_edit() More...
 
static int comp_tags_commit (struct Mailbox *m, struct Email *e, char *buf)
 Save the tags to a message - Implements MxOps::tags_commit() More...
 
static enum MailboxType comp_path_probe (const char *path, const struct stat *st)
 Is this a compressed Mailbox? - Implements MxOps::path_probe() More...
 
static int comp_path_canon (char *buf, size_t buflen)
 Canonicalise a Mailbox path - Implements MxOps::path_canon() More...
 
static int comp_path_pretty (char *buf, size_t buflen, const char *folder)
 Abbreviate a Mailbox path - Implements MxOps::path_pretty() More...
 
static int comp_path_parent (char *buf, size_t buflen)
 Find the parent of a Mailbox path - Implements MxOps::path_parent() More...
 

Variables

static const struct Command comp_commands []
 
struct MxOps MxCompOps
 Compressed Mailbox - Implements MxOps. More...
 

Detailed Description

Compressed mbox local mailbox type.

Authors
  • Alain Penders
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file compress.c.

Function Documentation

◆ mutt_comp_init()

void mutt_comp_init ( void  )

Setup feature commands.

Definition at line 66 of file compress.c.

67 {
69 }
#define COMMANDS_REGISTER(cmds)
Definition: mutt_commands.h:77
static const struct Command comp_commands[]
Definition: compress.c:55
+ Here is the caller graph for this function:

◆ lock_realpath()

static bool lock_realpath ( struct Mailbox m,
bool  excl 
)
static

Try to lock the ctx->realpath.

Parameters
mMailbox to lock
exclLock exclusively?
Return values
trueSuccess (locked or readonly)
falseError (can't lock the file)

Try to (exclusively) lock the mailbox. If we succeed, then we mark the mailbox as locked. If we fail, but we didn't want exclusive rights, then the mailbox will be marked readonly.

Definition at line 82 of file compress.c.

83 {
84  if (!m || !m->compress_info)
85  return false;
86 
87  struct CompressInfo *ci = m->compress_info;
88 
89  if (ci->locked)
90  return true;
91 
92  if (excl)
93  ci->fp_lock = fopen(m->realpath, "a");
94  else
95  ci->fp_lock = fopen(m->realpath, "r");
96  if (!ci->fp_lock)
97  {
99  return false;
100  }
101 
102  int r = mutt_file_lock(fileno(ci->fp_lock), excl, true);
103  if (r == 0)
104  ci->locked = true;
105  else if (excl)
106  {
108  m->readonly = true;
109  return true;
110  }
111 
112  return r == 0;
113 }
#define mutt_perror(...)
Definition: logging.h:85
FILE * fp_lock
fp used for locking
Definition: lib.h:56
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
bool locked
if realpath is locked
Definition: lib.h:55
int mutt_file_lock(int fd, bool excl, bool timeout)
(try to) lock a file using fcntl()
Definition: file.c:1175
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:119
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlock_realpath()

static void unlock_realpath ( struct Mailbox m)
static

Unlock the mailbox->realpath.

Parameters
mMailbox to unlock

Unlock a mailbox previously locked by lock_mailbox().

Definition at line 121 of file compress.c.

122 {
123  if (!m || !m->compress_info)
124  return;
125 
126  struct CompressInfo *ci = m->compress_info;
127 
128  if (!ci->locked)
129  return;
130 
131  mutt_file_unlock(fileno(ci->fp_lock));
132 
133  ci->locked = false;
135 }
FILE * fp_lock
fp used for locking
Definition: lib.h:56
bool locked
if realpath is locked
Definition: lib.h:55
int mutt_file_unlock(int fd)
Unlock a file previously locked by mutt_file_lock()
Definition: file.c:1223
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup_paths()

static int setup_paths ( struct Mailbox m)
static

Set the mailbox paths.

Parameters
mMailbox to modify
Return values
0Success
-1Error

Save the compressed filename in mailbox->realpath. Create a temporary filename and put its name in mailbox->path. The temporary file is created to prevent symlink attacks.

Definition at line 147 of file compress.c.

148 {
149  if (!m)
150  return -1;
151 
152  /* Setup the right paths */
154 
155  /* We will uncompress to /tmp */
156  struct Buffer *buf = mutt_buffer_pool_get();
157  mutt_buffer_mktemp(buf);
158  mutt_buffer_copy(&m->pathbuf, buf);
160 
161  FILE *fp = mutt_file_fopen(mailbox_path(m), "w");
162  if (!fp)
163  return -1;
164 
165  mutt_file_fclose(&fp);
166  return 0;
167 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:77
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer&#39;s contents to another Buffer.
Definition: buffer.c:445
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
struct Buffer pathbuf
Definition: mailbox.h:83
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ store_size()

static void store_size ( const struct Mailbox m)
static

Save the size of the compressed file.

Parameters
mMailbox

Save the compressed file size in the compress_info struct.

Definition at line 175 of file compress.c.

176 {
177  if (!m || !m->compress_info)
178  return;
179 
180  struct CompressInfo *ci = m->compress_info;
181 
182  ci->size = mutt_file_get_size(m->realpath);
183 }
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1495
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
long size
size of the compressed file
Definition: lib.h:53
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_compress_info()

static struct CompressInfo* set_compress_info ( struct Mailbox m)
static

Find the compress hooks for a mailbox.

Parameters
mMailbox to examine
Return values
ptrCompressInfo Hook info for the mailbox's path
NULLError

When a mailbox is opened, we check if there are any matching hooks.

Definition at line 193 of file compress.c.

194 {
195  if (!m)
196  return NULL;
197 
198  if (m->compress_info)
199  return m->compress_info;
200 
201  /* Open is compulsory */
202  const char *o = mutt_find_hook(MUTT_OPEN_HOOK, mailbox_path(m));
203  if (!o)
204  return NULL;
205 
206  const char *c = mutt_find_hook(MUTT_CLOSE_HOOK, mailbox_path(m));
207  const char *a = mutt_find_hook(MUTT_APPEND_HOOK, mailbox_path(m));
208 
209  struct CompressInfo *ci = mutt_mem_calloc(1, sizeof(struct CompressInfo));
210  m->compress_info = ci;
211 
212  ci->cmd_open = mutt_str_dup(o);
213  ci->cmd_close = mutt_str_dup(c);
214  ci->cmd_append = mutt_str_dup(a);
215 
216  return ci;
217 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
const char * cmd_append
append-hook command
Definition: lib.h:50
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
const char * cmd_close
close-hook command
Definition: lib.h:51
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:59
char * mutt_find_hook(HookFlags type, const char *pat)
Find a matching hook.
Definition: hook.c:552
#define MUTT_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:60
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:58
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const char * cmd_open
open-hook command
Definition: lib.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compress_info_free()

static void compress_info_free ( struct Mailbox m)
static

Frees the compress info members and structure.

Parameters
mMailbox to free compress_info for

Definition at line 223 of file compress.c.

224 {
225  if (!m || !m->compress_info)
226  return;
227 
228  struct CompressInfo *ci = m->compress_info;
229  FREE(&ci->cmd_open);
230  FREE(&ci->cmd_close);
231  FREE(&ci->cmd_append);
232 
233  unlock_realpath(m);
234 
235  FREE(&m->compress_info);
236 }
const char * cmd_append
append-hook command
Definition: lib.h:50
const char * cmd_close
close-hook command
Definition: lib.h:51
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:121
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
#define FREE(x)
Definition: memory.h:40
const char * cmd_open
open-hook command
Definition: lib.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compress_format_str()

static const char* compress_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
intptr_t  data,
MuttFormatFlags  flags 
)
static

Expand the filenames in a command string - Implements format_t.

Expando Description
%f Compressed file
%t Plaintext, temporary file

Definition at line 246 of file compress.c.

250 {
251  if (!buf || (data == 0))
252  return src;
253 
254  struct Mailbox *m = (struct Mailbox *) data;
255 
256  /* NOTE the compressed file config vars expect %f and %t to be
257  * surrounded by '' (unlike other NeoMutt config vars, which add the
258  * outer quotes for the user). This is why we use the
259  * mutt_buffer_quote_filename() form with add_outer of false. */
260  struct Buffer *quoted = mutt_buffer_pool_get();
261  switch (op)
262  {
263  case 'f':
264  /* Compressed file */
265  mutt_buffer_quote_filename(quoted, m->realpath, false);
266  snprintf(buf, buflen, "%s", mutt_b2s(quoted));
267  break;
268  case 't':
269  /* Plaintext, temporary file */
270  mutt_buffer_quote_filename(quoted, mailbox_path(m), false);
271  snprintf(buf, buflen, "%s", mutt_b2s(quoted));
272  break;
273  }
274 
275  mutt_buffer_pool_release(&quoted);
276  return src;
277 }
void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename, bool add_outer)
Quote a filename to survive the shell&#39;s quoting rules.
Definition: file.c:836
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
#define mutt_b2s(buf)
Definition: buffer.h:41
A mailbox.
Definition: mailbox.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expand_command_str()

static void expand_command_str ( const struct Mailbox m,
const char *  cmd,
char *  buf,
int  buflen 
)
static

Expand placeholders in command string.

Parameters
mMailbox for paths
cmdTemplate command to be expanded
bufBuffer to store the command
buflenSize of the buffer

This function takes a hook command and expands the filename placeholders within it. The function calls mutt_expando_format() to do the replacement which calls our callback function compress_format_str(). e.g.

Template command: gzip -cd 'f' > 't'

Result: gzip -dc '~/mail/abc.gz' > '/tmp/xyz'

Definition at line 296 of file compress.c.

297 {
298  if (!m || !cmd || !buf)
299  return;
300 
301  mutt_expando_format(buf, buflen, 0, buflen, cmd, compress_format_str,
302  (intptr_t) m, MUTT_FORMAT_NO_FLAGS);
303 }
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
static const char * compress_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Expand the filenames in a command string - Implements format_t.
Definition: compress.c:246
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:772
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ execute_command()

static int execute_command ( struct Mailbox m,
const char *  command,
const char *  progress 
)
static

Run a system command.

Parameters
mMailbox to work with
commandCommand string to execute
progressMessage to show the user
Return values
1Success
0Failure

Run the supplied command, taking care of all the NeoMutt requirements, such as locking files and blocking signals.

Definition at line 316 of file compress.c.

317 {
318  if (!m || !command || !progress)
319  return 0;
320 
321  if (m->verbose)
322  mutt_message(progress, m->realpath);
323 
324  int rc = 1;
325  char sys_cmd[STR_COMMAND];
326 
327  mutt_sig_block();
328  endwin();
329  fflush(stdout);
330 
331  expand_command_str(m, command, sys_cmd, sizeof(sys_cmd));
332 
333  if (mutt_system(sys_cmd) != 0)
334  {
335  rc = 0;
337  mutt_error(_("Error running \"%s\""), sys_cmd);
338  }
339 
341 
342  return rc;
343 }
void mutt_sig_unblock(void)
Restore previously blocked signals.
Definition: signal.c:168
#define mutt_message(...)
Definition: logging.h:83
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define _(a)
Definition: message.h:28
bool verbose
Display status messages?
Definition: mailbox.h:118
#define STR_COMMAND
Enough space for a long command line.
Definition: string2.h:35
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:604
#define mutt_error(...)
Definition: logging.h:84
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:150
static void expand_command_str(const struct Mailbox *m, const char *cmd, char *buf, int buflen)
Expand placeholders in command string.
Definition: compress.c:296
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_comp_can_append()

bool mutt_comp_can_append ( struct Mailbox m)

Can we append to this path?

Parameters
mMailbox
Return values
trueYes, we can append to the file
falseNo, appending isn't possible

To append to a file we can either use an 'append-hook' or a combination of 'open-hook' and 'close-hook'.

A match means it's our responsibility to append to the file.

Definition at line 356 of file compress.c.

357 {
358  if (!m)
359  return false;
360 
361  /* If this succeeds, we know there's an open-hook */
362  struct CompressInfo *ci = set_compress_info(m);
363  if (!ci)
364  return false;
365 
366  /* We have an open-hook, so to append we need an append-hook,
367  * or a close-hook. */
368  if (ci->cmd_append || ci->cmd_close)
369  return true;
370 
371  mutt_error(_("Can't append without an append-hook or close-hook : %s"), mailbox_path(m));
372  return false;
373 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
const char * cmd_append
append-hook command
Definition: lib.h:50
#define _(a)
Definition: message.h:28
const char * cmd_close
close-hook command
Definition: lib.h:51
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:193
Private data for compress.
Definition: lib.h:48
#define mutt_error(...)
Definition: logging.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_comp_can_read()

bool mutt_comp_can_read ( const char *  path)

Can we read from this file?

Parameters
pathPathname of file to be tested
Return values
trueYes, we can read the file
falseNo, we can't read the file

Search for an 'open-hook' with a regex that matches the path.

A match means it's our responsibility to open the file.

Definition at line 385 of file compress.c.

386 {
387  if (!path)
388  return false;
389 
390  if (mutt_find_hook(MUTT_OPEN_HOOK, path))
391  return true;
392 
393  return false;
394 }
char * mutt_find_hook(HookFlags type, const char *pat)
Find a matching hook.
Definition: hook.c:552
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_comp_valid_command()

int mutt_comp_valid_command ( const char *  cmd)

Is this command string allowed?

Parameters
cmdCommand string
Return values
1Valid command
0"%f" and/or "%t" is missing

A valid command string must have both "%f" (from file) and "%t" (to file). We don't check if we can actually run the command.

Definition at line 405 of file compress.c.

406 {
407  if (!cmd)
408  return 0;
409 
410  return strstr(cmd, "%f") && strstr(cmd, "%t");
411 }
+ Here is the caller graph for this function:

◆ comp_ac_find()

static struct Account* comp_ac_find ( struct Account a,
const char *  path 
)
static

Find an Account that matches a Mailbox path - Implements MxOps::ac_find()

Definition at line 416 of file compress.c.

417 {
418  return NULL;
419 }

◆ comp_ac_add()

static int comp_ac_add ( struct Account a,
struct Mailbox m 
)
static

Add a Mailbox to an Account - Implements MxOps::ac_add()

Definition at line 424 of file compress.c.

425 {
426  return 0;
427 }

◆ comp_mbox_open()

static int comp_mbox_open ( struct Mailbox m)
static

Open a Mailbox - Implements MxOps::mbox_open()

Set up a compressed mailbox to be read. Decompress the mailbox and set up the paths and hooks needed. Then determine the type of the mailbox so we can delegate the handling of messages.

Definition at line 437 of file compress.c.

438 {
439  struct CompressInfo *ci = set_compress_info(m);
440  if (!ci)
441  return -1;
442 
443  int rc;
444 
445  /* If there's no close-hook, or the file isn't writable */
446  if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
447  m->readonly = true;
448 
449  if (setup_paths(m) != 0)
450  goto cmo_fail;
451  store_size(m);
452 
453  if (!lock_realpath(m, false))
454  {
455  mutt_error(_("Unable to lock mailbox"));
456  goto cmo_fail;
457  }
458 
459  rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
460  if (rc == 0)
461  goto cmo_fail;
462 
463  unlock_realpath(m);
464 
466  if (m->type == MUTT_UNKNOWN)
467  {
468  mutt_error(_("Can't identify the contents of the compressed file"));
469  goto cmo_fail;
470  }
471 
472  ci->child_ops = mx_get_ops(m->type);
473  if (!ci->child_ops)
474  {
475  mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
476  goto cmo_fail;
477  }
478 
479  m->account->type = m->type;
480  return ci->child_ops->mbox_open(m);
481 
482 cmo_fail:
483  /* remove the partial uncompressed file */
484  remove(mailbox_path(m));
486  return -1;
487 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:223
#define _(a)
Definition: message.h:28
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
int(* mbox_open)(struct Mailbox *m)
Open a Mailbox.
Definition: mx.h:146
const char * cmd_close
close-hook command
Definition: lib.h:51
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:175
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:119
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:193
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:121
Private data for compress.
Definition: lib.h:48
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:316
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1335
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
#define mutt_error(...)
Definition: logging.h:84
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:82
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
const char * cmd_open
open-hook command
Definition: lib.h:52
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:147
+ Here is the call graph for this function:

◆ comp_mbox_open_append()

static int comp_mbox_open_append ( struct Mailbox m,
OpenMailboxFlags  flags 
)
static

Open a Mailbox for appending - Implements MxOps::mbox_open_append()

flags may also contain MUTT_NEWFOLDER

To append to a compressed mailbox we need an append-hook (or both open- and close-hooks).

Definition at line 497 of file compress.c.

498 {
499  /* If this succeeds, we know there's an open-hook */
500  struct CompressInfo *ci = set_compress_info(m);
501  if (!ci)
502  return -1;
503 
504  /* To append we need an append-hook or a close-hook */
505  if (!ci->cmd_append && !ci->cmd_close)
506  {
507  mutt_error(_("Can't append without an append-hook or close-hook : %s"),
508  mailbox_path(m));
509  goto cmoa_fail1;
510  }
511 
512  if (setup_paths(m) != 0)
513  goto cmoa_fail2;
514 
515  /* Lock the realpath for the duration of the append.
516  * It will be unlocked in the close */
517  if (!lock_realpath(m, true))
518  {
519  mutt_error(_("Unable to lock mailbox"));
520  goto cmoa_fail2;
521  }
522 
523  /* Open the existing mailbox, unless we are appending */
524  if (!ci->cmd_append && (mutt_file_get_size(m->realpath) > 0))
525  {
526  int rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
527  if (rc == 0)
528  {
529  mutt_error(_("Compress command failed: %s"), ci->cmd_open);
530  goto cmoa_fail2;
531  }
533  }
534  else
535  m->type = C_MboxType;
536 
537  /* We can only deal with mbox and mmdf mailboxes */
538  if ((m->type != MUTT_MBOX) && (m->type != MUTT_MMDF))
539  {
540  mutt_error(_("Unsupported mailbox type for appending"));
541  goto cmoa_fail2;
542  }
543 
544  ci->child_ops = mx_get_ops(m->type);
545  if (!ci->child_ops)
546  {
547  mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->type);
548  goto cmoa_fail2;
549  }
550 
551  if (ci->child_ops->mbox_open_append(m, flags) != 0)
552  goto cmoa_fail2;
553 
554  return 0;
555 
556 cmoa_fail2:
557  /* remove the partial uncompressed file */
558  remove(mailbox_path(m));
559 cmoa_fail1:
560  /* Free the compress_info to prevent close from trying to recompress */
562 
563  return -1;
564 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
const char * cmd_append
append-hook command
Definition: lib.h:50
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:223
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1495
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define _(a)
Definition: message.h:28
int(* mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending.
Definition: mx.h:158
const char * cmd_close
close-hook command
Definition: lib.h:51
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:193
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
unsigned char C_MboxType
Config: Default type for creating new mailboxes.
Definition: mx.c:84
Private data for compress.
Definition: lib.h:48
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:316
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1335
#define mutt_error(...)
Definition: logging.h:84
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:82
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
const char * cmd_open
open-hook command
Definition: lib.h:52
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:147
+ Here is the call graph for this function:

◆ comp_mbox_check()

static int comp_mbox_check ( struct Mailbox m)
static

Check for new mail - Implements MxOps::mbox_check()

Parameters
mMailbox
Return values
0Mailbox OK
MUTT_REOPENEDThe mailbox was closed and reopened
-1Mailbox bad

If the compressed file changes in size but the mailbox hasn't been changed in NeoMutt, then we can close and reopen the mailbox.

If the mailbox has been changed in NeoMutt, warn the user.

The return codes are picked to match mx_mbox_check().

Definition at line 580 of file compress.c.

581 {
582  if (!m->compress_info)
583  return -1;
584 
585  struct CompressInfo *ci = m->compress_info;
586 
587  const struct MxOps *ops = ci->child_ops;
588  if (!ops)
589  return -1;
590 
591  int size = mutt_file_get_size(m->realpath);
592  if (size == ci->size)
593  return 0;
594 
595  if (!lock_realpath(m, false))
596  {
597  mutt_error(_("Unable to lock mailbox"));
598  return -1;
599  }
600 
601  int rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
602  store_size(m);
603  unlock_realpath(m);
604  if (rc == 0)
605  return -1;
606 
607  return ops->mbox_check(m);
608 }
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1495
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define _(a)
Definition: message.h:28
long size
size of the compressed file
Definition: lib.h:53
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:175
int(* mbox_check)(struct Mailbox *m)
Check for new mail.
Definition: mx.h:169
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:121
Private data for compress.
Definition: lib.h:48
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:316
#define mutt_error(...)
Definition: logging.h:84
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:82
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
const char * cmd_open
open-hook command
Definition: lib.h:52
The Mailbox API.
Definition: mx.h:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ comp_mbox_sync()

static int comp_mbox_sync ( struct Mailbox m)
static

Save changes to the Mailbox - Implements MxOps::mbox_sync()

Changes in NeoMutt only affect the tmp file. Calling comp_mbox_sync() will commit them to the compressed file.

Definition at line 616 of file compress.c.

617 {
618  if (!m->compress_info)
619  return -1;
620 
621  struct CompressInfo *ci = m->compress_info;
622 
623  if (!ci->cmd_close)
624  {
625  mutt_error(_("Can't sync a compressed file without a close-hook"));
626  return -1;
627  }
628 
629  const struct MxOps *ops = ci->child_ops;
630  if (!ops)
631  return -1;
632 
633  if (!lock_realpath(m, true))
634  {
635  mutt_error(_("Unable to lock mailbox"));
636  return -1;
637  }
638 
639  int rc = comp_mbox_check(m);
640  if (rc != 0)
641  goto sync_cleanup;
642 
643  rc = ops->mbox_sync(m);
644  if (rc != 0)
645  goto sync_cleanup;
646 
647  rc = execute_command(m, ci->cmd_close, _("Compressing %s"));
648  if (rc == 0)
649  {
650  rc = -1;
651  goto sync_cleanup;
652  }
653 
654  rc = 0;
655 
656 sync_cleanup:
657  store_size(m);
658  unlock_realpath(m);
659  return rc;
660 }
#define _(a)
Definition: message.h:28
const char * cmd_close
close-hook command
Definition: lib.h:51
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:175
int(* mbox_sync)(struct Mailbox *m)
Save changes to the Mailbox.
Definition: mx.h:193
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:121
Private data for compress.
Definition: lib.h:48
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:316
static int comp_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check()
Definition: compress.c:580
#define mutt_error(...)
Definition: logging.h:84
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:82
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104
+ Here is the call graph for this function:

◆ comp_mbox_close()

static int 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 668 of file compress.c.

669 {
670  if (!m->compress_info)
671  return -1;
672 
673  struct CompressInfo *ci = m->compress_info;
674 
675  const struct MxOps *ops = ci->child_ops;
676  if (!ops)
677  {
679  return -1;
680  }
681 
682  ops->mbox_close(m);
683 
684  /* sync has already been called, so we only need to delete some files */
685  if (m->append)
686  {
687  const char *append = NULL;
688  const char *msg = NULL;
689 
690  /* The file exists and we can append */
691  if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
692  {
693  append = ci->cmd_append;
694  msg = _("Compressed-appending to %s...");
695  }
696  else
697  {
698  append = ci->cmd_close;
699  msg = _("Compressing %s");
700  }
701 
702  int rc = execute_command(m, append, msg);
703  if (rc == 0)
704  {
706  mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
707  }
708  else
709  remove(mailbox_path(m));
710 
711  unlock_realpath(m);
712  }
713  else
714  {
715  /* If the file was removed, remove the compressed folder too */
716  if ((access(mailbox_path(m), F_OK) != 0) && !C_SaveEmpty)
717  {
718  remove(m->realpath);
719  }
720  else
721  {
722  remove(mailbox_path(m));
723  }
724  }
725 
727 
728  return 0;
729 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:203
const char * cmd_append
append-hook command
Definition: lib.h:50
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:223
WHERE bool C_SaveEmpty
Config: (mbox,mmdf) Preserve empty mailboxes.
Definition: mutt_globals.h:158
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
#define _(a)
Definition: message.h:28
const char * cmd_close
close-hook command
Definition: lib.h:51
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:121
Private data for compress.
Definition: lib.h:48
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:316
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:604
int(* mbox_close)(struct Mailbox *m)
Close a Mailbox.
Definition: mx.h:204
#define mutt_error(...)
Definition: logging.h:84
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104
+ Here is the call graph for this function:

◆ comp_msg_open()

static int comp_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open()

Definition at line 734 of file compress.c.

735 {
736  if (!m->compress_info)
737  return -1;
738 
739  struct CompressInfo *ci = m->compress_info;
740 
741  const struct MxOps *ops = ci->child_ops;
742  if (!ops)
743  return -1;
744 
745  /* Delegate */
746  return ops->msg_open(m, msg, msgno);
747 }
int(* msg_open)(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox.
Definition: mx.h:219
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_msg_open_new()

static int comp_msg_open_new ( struct Mailbox m,
struct Message msg,
const struct Email e 
)
static

Open a new message in a Mailbox - Implements MxOps::msg_open_new()

Definition at line 752 of file compress.c.

753 {
754  if (!m->compress_info)
755  return -1;
756 
757  struct CompressInfo *ci = m->compress_info;
758 
759  const struct MxOps *ops = ci->child_ops;
760  if (!ops)
761  return -1;
762 
763  /* Delegate */
764  return ops->msg_open_new(m, msg, e);
765 }
Private data for compress.
Definition: lib.h:48
int(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Open a new message in a Mailbox.
Definition: mx.h:233
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_msg_commit()

static int comp_msg_commit ( struct Mailbox m,
struct Message msg 
)
static

Save changes to an email - Implements MxOps::msg_commit()

Definition at line 770 of file compress.c.

771 {
772  if (!m->compress_info)
773  return -1;
774 
775  struct CompressInfo *ci = m->compress_info;
776 
777  const struct MxOps *ops = ci->child_ops;
778  if (!ops)
779  return -1;
780 
781  /* Delegate */
782  return ops->msg_commit(m, msg);
783 }
int(* msg_commit)(struct Mailbox *m, struct Message *msg)
Save changes to an email.
Definition: mx.h:246
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_msg_close()

static int comp_msg_close ( struct Mailbox m,
struct Message msg 
)
static

Close an email - Implements MxOps::msg_close()

Definition at line 788 of file compress.c.

789 {
790  if (!m->compress_info)
791  return -1;
792 
793  struct CompressInfo *ci = m->compress_info;
794 
795  const struct MxOps *ops = ci->child_ops;
796  if (!ops)
797  return -1;
798 
799  /* Delegate */
800  return ops->msg_close(m, msg);
801 }
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
int(* msg_close)(struct Mailbox *m, struct Message *msg)
Close an email.
Definition: mx.h:259
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_msg_padding_size()

static int comp_msg_padding_size ( struct Mailbox m)
static

Bytes of padding between messages - Implements MxOps::msg_padding_size()

Definition at line 806 of file compress.c.

807 {
808  if (!m->compress_info)
809  return 0;
810 
811  struct CompressInfo *ci = m->compress_info;
812 
813  const struct MxOps *ops = ci->child_ops;
814  if (!ops || !ops->msg_padding_size)
815  return 0;
816 
817  return ops->msg_padding_size(m);
818 }
int(* msg_padding_size)(struct Mailbox *m)
Bytes of padding between messages.
Definition: mx.h:269
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_msg_save_hcache()

static int comp_msg_save_hcache ( struct Mailbox m,
struct Email e 
)
static

Save message to the header cache - Implements MxOps::msg_save_hcache()

Definition at line 823 of file compress.c.

824 {
825  if (!m->compress_info)
826  return 0;
827 
828  struct CompressInfo *ci = m->compress_info;
829 
830  const struct MxOps *ops = ci->child_ops;
831  if (!ops || !ops->msg_save_hcache)
832  return 0;
833 
834  return ops->msg_save_hcache(m, e);
835 }
int(* msg_save_hcache)(struct Mailbox *m, struct Email *e)
Save message to the header cache.
Definition: mx.h:282
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_tags_edit()

static int comp_tags_edit ( struct Mailbox m,
const char *  tags,
char *  buf,
size_t  buflen 
)
static

Prompt and validate new messages tags - Implements MxOps::tags_edit()

Definition at line 840 of file compress.c.

841 {
842  if (!m->compress_info)
843  return 0;
844 
845  struct CompressInfo *ci = m->compress_info;
846 
847  const struct MxOps *ops = ci->child_ops;
848  if (!ops || !ops->tags_edit)
849  return 0;
850 
851  return ops->tags_edit(m, tags, buf, buflen);
852 }
int(* tags_edit)(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Prompt and validate new messages tags.
Definition: mx.h:298
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104

◆ comp_tags_commit()

static int comp_tags_commit ( struct Mailbox m,
struct Email e,
char *  buf 
)
static

Save the tags to a message - Implements MxOps::tags_commit()

Definition at line 857 of file compress.c.

858 {
859  if (!m->compress_info)
860  return 0;
861 
862  struct CompressInfo *ci = m->compress_info;
863 
864  const struct MxOps *ops = ci->child_ops;
865  if (!ops || !ops->tags_commit)
866  return 0;
867 
868  return ops->tags_commit(m, e, buf);
869 }
Private data for compress.
Definition: lib.h:48
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:124
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: lib.h:54
The Mailbox API.
Definition: mx.h:104
int(* tags_commit)(struct Mailbox *m, struct Email *e, char *buf)
Save the tags to a message.
Definition: mx.h:313

◆ comp_path_probe()

static enum MailboxType comp_path_probe ( const char *  path,
const struct stat *  st 
)
static

Is this a compressed Mailbox? - Implements MxOps::path_probe()

Definition at line 874 of file compress.c.

875 {
876  if (!st || !S_ISREG(st->st_mode))
877  return MUTT_UNKNOWN;
878 
879  if (mutt_comp_can_read(path))
880  return MUTT_COMPRESSED;
881 
882  return MUTT_UNKNOWN;
883 }
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
Compressed file Mailbox type.
Definition: mailbox.h:56
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:385
+ Here is the call graph for this function:

◆ comp_path_canon()

static int comp_path_canon ( char *  buf,
size_t  buflen 
)
static

Canonicalise a Mailbox path - Implements MxOps::path_canon()

Definition at line 888 of file compress.c.

889 {
890  mutt_path_canon(buf, buflen, HomeDir, false);
891  return 0;
892 }
char * HomeDir
User&#39;s home directory.
Definition: mutt_globals.h:49
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:285
+ Here is the call graph for this function:

◆ comp_path_pretty()

static int comp_path_pretty ( char *  buf,
size_t  buflen,
const char *  folder 
)
static

Abbreviate a Mailbox path - Implements MxOps::path_pretty()

Definition at line 897 of file compress.c.

898 {
899  if (mutt_path_abbr_folder(buf, buflen, folder))
900  return 0;
901 
902  if (mutt_path_pretty(buf, buflen, HomeDir, false))
903  return 0;
904 
905  return -1;
906 }
bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir, bool is_dir)
Tidy a filesystem path.
Definition: path.c:186
char * HomeDir
User&#39;s home directory.
Definition: mutt_globals.h:49
bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder)
Create a folder abbreviation.
Definition: path.c:492
+ Here is the call graph for this function:

◆ comp_path_parent()

static int comp_path_parent ( char *  buf,
size_t  buflen 
)
static

Find the parent of a Mailbox path - Implements MxOps::path_parent()

Definition at line 911 of file compress.c.

912 {
913  if (mutt_path_parent(buf, buflen))
914  return 0;
915 
916  if (buf[0] == '~')
917  mutt_path_canon(buf, buflen, HomeDir, false);
918 
919  if (mutt_path_parent(buf, buflen))
920  return 0;
921 
922  return -1;
923 }
bool mutt_path_parent(char *buf, size_t buflen)
Find the parent of a path.
Definition: path.c:459
char * HomeDir
User&#39;s home directory.
Definition: mutt_globals.h:49
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:285
+ Here is the call graph for this function:

Variable Documentation

◆ comp_commands

const struct Command comp_commands[]
static
Initial value:
= {
{ "append-hook", mutt_parse_hook, MUTT_APPEND_HOOK },
{ "close-hook", mutt_parse_hook, MUTT_CLOSE_HOOK },
{ "open-hook", mutt_parse_hook, MUTT_OPEN_HOOK },
}
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the &#39;hook&#39; family of commands - Implements Command::parse()
Definition: hook.c:85
#define MUTT_APPEND_HOOK
append-hook: append to a compressed mailbox
Definition: hook.h:59
#define MUTT_CLOSE_HOOK
close-hook: write to a compressed mailbox
Definition: hook.h:60
#define MUTT_OPEN_HOOK
open-hook: to read a compressed mailbox
Definition: hook.h:58

Definition at line 55 of file compress.c.

◆ MxCompOps

struct MxOps MxCompOps
Initial value:
= {
.type = MUTT_COMPRESSED,
.name = "compressed",
.is_local = true,
.ac_find = comp_ac_find,
.ac_add = comp_ac_add,
.mbox_open = comp_mbox_open,
.mbox_open_append = comp_mbox_open_append,
.mbox_check = comp_mbox_check,
.mbox_check_stats = NULL,
.mbox_sync = comp_mbox_sync,
.mbox_close = comp_mbox_close,
.msg_open = comp_msg_open,
.msg_open_new = comp_msg_open_new,
.msg_commit = comp_msg_commit,
.msg_close = comp_msg_close,
.msg_padding_size = comp_msg_padding_size,
.msg_save_hcache = comp_msg_save_hcache,
.tags_edit = comp_tags_edit,
.tags_commit = comp_tags_commit,
.path_probe = comp_path_probe,
.path_canon = comp_path_canon,
.path_pretty = comp_path_pretty,
.path_parent = comp_path_parent,
.path_is_empty = NULL,
}
static int comp_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open()
Definition: compress.c:437
static int comp_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add()
Definition: compress.c:424
static int comp_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync()
Definition: compress.c:616
static int comp_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache()
Definition: compress.c:823
static int comp_path_parent(char *buf, size_t buflen)
Find the parent of a Mailbox path - Implements MxOps::path_parent()
Definition: compress.c:911
static int comp_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path - Implements MxOps::path_pretty()
Definition: compress.c:897
static struct Account * comp_ac_find(struct Account *a, const char *path)
Find an Account that matches a Mailbox path - Implements MxOps::ac_find()
Definition: compress.c:416
static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append()
Definition: compress.c:497
static int comp_tags_edit(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Prompt and validate new messages tags - Implements MxOps::tags_edit()
Definition: compress.c:840
static enum MailboxType comp_path_probe(const char *path, const struct stat *st)
Is this a compressed Mailbox? - Implements MxOps::path_probe()
Definition: compress.c:874
static int comp_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Implements MxOps::msg_padding_size()
Definition: compress.c:806
static int comp_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon()
Definition: compress.c:888
static int comp_tags_commit(struct Mailbox *m, struct Email *e, char *buf)
Save the tags to a message - Implements MxOps::tags_commit()
Definition: compress.c:857
static int comp_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
Open a new message in a Mailbox - Implements MxOps::msg_open_new()
Definition: compress.c:752
Compressed file Mailbox type.
Definition: mailbox.h:56
static int comp_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check()
Definition: compress.c:580
static int comp_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox - Implements MxOps::msg_open()
Definition: compress.c:734
static int comp_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit()
Definition: compress.c:770
static int comp_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close()
Definition: compress.c:788
static int comp_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close()
Definition: compress.c:668

Compressed Mailbox - Implements MxOps.

Compress only uses open, close and check. The message functions are delegated to mbox.

Definition at line 932 of file compress.c.