NeoMutt  2019-12-07-60-g0cfa53
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/mutt.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "compress.h"
#include "format_flags.h"
#include "globals.h"
#include "hook.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

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, unsigned long 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, int *index_hint)
 Check for new mail - Implements MxOps::mbox_check() More...
 
static int comp_mbox_sync (struct Mailbox *m, int *index_hint)
 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, 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

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

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

66 {
67  if (!m || !m->compress_info)
68  return false;
69 
70  struct CompressInfo *ci = m->compress_info;
71 
72  if (ci->locked)
73  return true;
74 
75  if (excl)
76  ci->fp_lock = fopen(m->realpath, "a");
77  else
78  ci->fp_lock = fopen(m->realpath, "r");
79  if (!ci->fp_lock)
80  {
82  return false;
83  }
84 
85  int r = mutt_file_lock(fileno(ci->fp_lock), excl, true);
86  if (r == 0)
87  ci->locked = true;
88  else if (excl)
89  {
91  m->readonly = true;
92  return true;
93  }
94 
95  return r == 0;
96 }
#define mutt_perror(...)
Definition: logging.h:85
FILE * fp_lock
fp used for locking
Definition: compress.h:46
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
bool locked
if realpath is locked
Definition: compress.h:45
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:118
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
int mutt_file_lock(int fd, bool excl, bool timeout)
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
+ 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 104 of file compress.c.

105 {
106  if (!m || !m->compress_info)
107  return;
108 
109  struct CompressInfo *ci = m->compress_info;
110 
111  if (!ci->locked)
112  return;
113 
114  mutt_file_unlock(fileno(ci->fp_lock));
115 
116  ci->locked = false;
118 }
FILE * fp_lock
fp used for locking
Definition: compress.h:46
bool locked
if realpath is locked
Definition: compress.h:45
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
int mutt_file_unlock(int fd)
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
+ 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 130 of file compress.c.

131 {
132  if (!m)
133  return -1;
134 
135  /* Setup the right paths */
137 
138  /* We will uncompress to /tmp */
139  struct Buffer *buf = mutt_buffer_pool_get();
140  mutt_buffer_mktemp(buf);
141  mutt_buffer_copy(&m->pathbuf, buf);
143 
144  FILE *fp = mutt_file_fopen(mailbox_path(m), "w");
145  if (!fp)
146  return -1;
147 
148  mutt_file_fclose(&fp);
149  return 0;
150 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:78
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:83
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:152
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:453
struct Buffer pathbuf
Definition: mailbox.h:82
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:585
+ 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 158 of file compress.c.

159 {
160  if (!m || !m->compress_info)
161  return;
162 
163  struct CompressInfo *ci = m->compress_info;
164 
165  ci->size = mutt_file_get_size(m->realpath);
166 }
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1486
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
long size
size of the compressed file
Definition: compress.h:43
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
+ 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 176 of file compress.c.

177 {
178  if (!m)
179  return NULL;
180 
181  if (m->compress_info)
182  return m->compress_info;
183 
184  /* Open is compulsory */
185  const char *o = mutt_find_hook(MUTT_OPEN_HOOK, mailbox_path(m));
186  if (!o)
187  return NULL;
188 
189  const char *c = mutt_find_hook(MUTT_CLOSE_HOOK, mailbox_path(m));
190  const char *a = mutt_find_hook(MUTT_APPEND_HOOK, mailbox_path(m));
191 
192  struct CompressInfo *ci = mutt_mem_calloc(1, sizeof(struct CompressInfo));
193  m->compress_info = ci;
194 
195  ci->cmd_open = mutt_str_strdup(o);
196  ci->cmd_close = mutt_str_strdup(c);
197  ci->cmd_append = mutt_str_strdup(a);
198 
199  return ci;
200 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
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: compress.h:40
const char * cmd_close
close-hook command
Definition: compress.h:41
#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: compress.h:38
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const char * cmd_open
open-hook command
Definition: compress.h:42
+ 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 206 of file compress.c.

207 {
208  if (!m || !m->compress_info)
209  return;
210 
211  struct CompressInfo *ci = m->compress_info;
212  FREE(&ci->cmd_open);
213  FREE(&ci->cmd_close);
214  FREE(&ci->cmd_append);
215 
216  unlock_realpath(m);
217 
218  FREE(&m->compress_info);
219 }
const char * cmd_append
append-hook command
Definition: compress.h:40
const char * cmd_close
close-hook command
Definition: compress.h:41
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:104
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
#define FREE(x)
Definition: memory.h:40
const char * cmd_open
open-hook command
Definition: compress.h:42
+ 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,
unsigned long  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 229 of file compress.c.

233 {
234  if (!buf || (data == 0))
235  return src;
236 
237  struct Mailbox *m = (struct Mailbox *) data;
238 
239  /* NOTE the compressed file config vars expect %f and %t to be
240  * surrounded by '' (unlike other NeoMutt config vars, which add the
241  * outer quotes for the user). This is why we use the
242  * mutt_buffer_quote_filename() form with add_outer of false. */
243  struct Buffer *quoted = mutt_buffer_pool_get();
244  switch (op)
245  {
246  case 'f':
247  /* Compressed file */
248  mutt_buffer_quote_filename(quoted, m->realpath, false);
249  snprintf(buf, buflen, "%s", mutt_b2s(quoted));
250  break;
251  case 't':
252  /* Plaintext, temporary file */
253  mutt_buffer_quote_filename(quoted, mailbox_path(m), false);
254  snprintf(buf, buflen, "%s", mutt_b2s(quoted));
255  break;
256  }
257 
258  mutt_buffer_pool_release(&quoted);
259  return src;
260 }
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:834
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
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:83
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:80
+ 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 279 of file compress.c.

280 {
281  if (!m || !cmd || !buf)
282  return;
283 
284  mutt_expando_format(buf, buflen, 0, buflen, cmd, compress_format_str,
285  (unsigned long) m, MUTT_FORMAT_NO_FLAGS);
286 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:877
#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, unsigned long data, MuttFormatFlags flags)
Expand the filenames in a command string - Implements format_t.
Definition: compress.c:229
+ 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 299 of file compress.c.

300 {
301  if (!m || !command || !progress)
302  return 0;
303 
304  if (!m->quiet)
305  mutt_message(progress, m->realpath);
306 
307  int rc = 1;
308  char sys_cmd[STR_COMMAND];
309 
310  mutt_sig_block();
311  endwin();
312  fflush(stdout);
313 
314  expand_command_str(m, command, sys_cmd, sizeof(sys_cmd));
315 
316  if (mutt_system(sys_cmd) != 0)
317  {
318  rc = 0;
320  mutt_error(_("Error running \"%s\""), sys_cmd);
321  }
322 
324 
325  return rc;
326 }
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:83
#define _(a)
Definition: message.h:28
bool quiet
Inhibit status messages?
Definition: mailbox.h:117
#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:578
#define mutt_error(...)
Definition: logging.h:84
static void expand_command_str(const struct Mailbox *m, const char *cmd, char *buf, int buflen)
Expand placeholders in command string.
Definition: compress.c:279
void mutt_sig_block(void)
Block signals during critical operations.
Definition: signal.c:150
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:52
+ 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 339 of file compress.c.

340 {
341  if (!m)
342  return false;
343 
344  /* If this succeeds, we know there's an open-hook */
345  struct CompressInfo *ci = set_compress_info(m);
346  if (!ci)
347  return false;
348 
349  /* We have an open-hook, so to append we need an append-hook,
350  * or a close-hook. */
351  if (ci->cmd_append || ci->cmd_close)
352  return true;
353 
354  mutt_error(_("Can't append without an append-hook or close-hook : %s"), mailbox_path(m));
355  return false;
356 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
const char * cmd_append
append-hook command
Definition: compress.h:40
#define _(a)
Definition: message.h:28
const char * cmd_close
close-hook command
Definition: compress.h:41
Private data for compress.
Definition: compress.h:38
#define mutt_error(...)
Definition: logging.h:84
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:176
+ 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 368 of file compress.c.

369 {
370  if (!path)
371  return false;
372 
373  if (mutt_find_hook(MUTT_OPEN_HOOK, path))
374  return true;
375 
376  return false;
377 }
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 388 of file compress.c.

389 {
390  if (!cmd)
391  return 0;
392 
393  return strstr(cmd, "%f") && strstr(cmd, "%t");
394 }
+ 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 399 of file compress.c.

400 {
401  return NULL;
402 }

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

408 {
409  if (!a || !m || (m->magic != MUTT_COMPRESSED))
410  return -1;
411  return 0;
412 }
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:104
Compressed file Mailbox type.
Definition: mailbox.h:55

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

423 {
424  if (!m || (m->magic != MUTT_COMPRESSED))
425  return -1;
426 
427  struct CompressInfo *ci = set_compress_info(m);
428  if (!ci)
429  return -1;
430 
431  int rc;
432 
433  /* If there's no close-hook, or the file isn't writable */
434  if (!ci->cmd_close || (access(mailbox_path(m), W_OK) != 0))
435  m->readonly = true;
436 
437  if (setup_paths(m) != 0)
438  goto cmo_fail;
439  store_size(m);
440 
441  if (!lock_realpath(m, false))
442  {
443  mutt_error(_("Unable to lock mailbox"));
444  goto cmo_fail;
445  }
446 
447  rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
448  if (rc == 0)
449  goto cmo_fail;
450 
451  unlock_realpath(m);
452 
453  m->magic = mx_path_probe(mailbox_path(m), NULL);
454  if (m->magic == MUTT_UNKNOWN)
455  {
456  mutt_error(_("Can't identify the contents of the compressed file"));
457  goto cmo_fail;
458  }
459 
460  ci->child_ops = mx_get_ops(m->magic);
461  if (!ci->child_ops)
462  {
463  mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->magic);
464  goto cmo_fail;
465  }
466 
467  m->account->magic = m->magic;
468  return ci->child_ops->mbox_open(m);
469 
470 cmo_fail:
471  /* remove the partial uncompressed file */
472  remove(mailbox_path(m));
474  return -1;
475 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:158
#define _(a)
Definition: message.h:28
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:46
int(* mbox_open)(struct Mailbox *m)
Open a Mailbox.
Definition: mx.h:131
const char * cmd_close
close-hook command
Definition: compress.h:41
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:104
bool readonly
Don&#39;t allow changes to the mailbox.
Definition: mailbox.h:118
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:206
enum MailboxType magic
Type of Mailboxes this Account contains.
Definition: account.h:38
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:65
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:104
Compressed file Mailbox type.
Definition: mailbox.h:55
Private data for compress.
Definition: compress.h:38
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:130
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:130
const struct MxOps * mx_get_ops(enum MailboxType magic)
Get mailbox operations.
Definition: mx.c:140
#define mutt_error(...)
Definition: logging.h:84
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:299
enum MailboxType mx_path_probe(const char *path, struct stat *st)
Find a mailbox that understands a path.
Definition: mx.c:1288
const char * cmd_open
open-hook command
Definition: compress.h:42
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:176
+ 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 485 of file compress.c.

486 {
487  if (!m)
488  return -1;
489 
490  /* If this succeeds, we know there's an open-hook */
491  struct CompressInfo *ci = set_compress_info(m);
492  if (!ci)
493  return -1;
494 
495  /* To append we need an append-hook or a close-hook */
496  if (!ci->cmd_append && !ci->cmd_close)
497  {
498  mutt_error(_("Can't append without an append-hook or close-hook : %s"),
499  mailbox_path(m));
500  goto cmoa_fail1;
501  }
502 
503  if (setup_paths(m) != 0)
504  goto cmoa_fail2;
505 
506  /* Lock the realpath for the duration of the append.
507  * It will be unlocked in the close */
508  if (!lock_realpath(m, true))
509  {
510  mutt_error(_("Unable to lock mailbox"));
511  goto cmoa_fail2;
512  }
513 
514  /* Open the existing mailbox, unless we are appending */
515  if (!ci->cmd_append && (mutt_file_get_size(m->realpath) > 0))
516  {
517  int rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
518  if (rc == 0)
519  {
520  mutt_error(_("Compress command failed: %s"), ci->cmd_open);
521  goto cmoa_fail2;
522  }
523  m->magic = mx_path_probe(mailbox_path(m), NULL);
524  }
525  else
526  m->magic = C_MboxType;
527 
528  /* We can only deal with mbox and mmdf mailboxes */
529  if ((m->magic != MUTT_MBOX) && (m->magic != MUTT_MMDF))
530  {
531  mutt_error(_("Unsupported mailbox type for appending"));
532  goto cmoa_fail2;
533  }
534 
535  ci->child_ops = mx_get_ops(m->magic);
536  if (!ci->child_ops)
537  {
538  mutt_error(_("Can't find mailbox ops for mailbox type %d"), m->magic);
539  goto cmoa_fail2;
540  }
541 
542  if (ci->child_ops->mbox_open_append(m, flags) != 0)
543  goto cmoa_fail2;
544 
545  return 0;
546 
547 cmoa_fail2:
548  /* remove the partial uncompressed file */
549  remove(mailbox_path(m));
550 cmoa_fail1:
551  /* Free the compress_info to prevent close from trying to recompress */
553 
554  return -1;
555 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
const char * cmd_append
append-hook command
Definition: compress.h:40
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1486
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
#define _(a)
Definition: message.h:28
int(* mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending.
Definition: mx.h:139
const char * cmd_close
close-hook command
Definition: compress.h:41
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:104
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:206
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:65
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:48
unsigned char C_MboxType
Config: Default type for creating new mailboxes.
Definition: mx.c:83
Private data for compress.
Definition: compress.h:38
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:47
static int setup_paths(struct Mailbox *m)
Set the mailbox paths.
Definition: compress.c:130
const struct MxOps * mx_get_ops(enum MailboxType magic)
Get mailbox operations.
Definition: mx.c:140
#define mutt_error(...)
Definition: logging.h:84
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:299
enum MailboxType mx_path_probe(const char *path, struct stat *st)
Find a mailbox that understands a path.
Definition: mx.c:1288
const char * cmd_open
open-hook command
Definition: compress.h:42
static struct CompressInfo * set_compress_info(struct Mailbox *m)
Find the compress hooks for a mailbox.
Definition: compress.c:176
+ Here is the call graph for this function:

◆ comp_mbox_check()

static int comp_mbox_check ( struct Mailbox m,
int *  index_hint 
)
static

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

Parameters
mMailbox
index_hintCurrently selected mailbox
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 572 of file compress.c.

573 {
574  if (!m || !m->compress_info)
575  return -1;
576 
577  struct CompressInfo *ci = m->compress_info;
578 
579  const struct MxOps *ops = ci->child_ops;
580  if (!ops)
581  return -1;
582 
583  int size = mutt_file_get_size(m->realpath);
584  if (size == ci->size)
585  return 0;
586 
587  if (!lock_realpath(m, false))
588  {
589  mutt_error(_("Unable to lock mailbox"));
590  return -1;
591  }
592 
593  int rc = execute_command(m, ci->cmd_open, _("Decompressing %s"));
594  store_size(m);
595  unlock_realpath(m);
596  if (rc == 0)
597  return -1;
598 
599  return ops->mbox_check(m, index_hint);
600 }
long mutt_file_get_size(const char *path)
Get the size of a file.
Definition: file.c:1486
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:158
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
#define _(a)
Definition: message.h:28
long size
size of the compressed file
Definition: compress.h:43
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:65
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:104
int(* mbox_check)(struct Mailbox *m, int *index_hint)
Check for new mail.
Definition: mx.h:147
Private data for compress.
Definition: compress.h:38
#define mutt_error(...)
Definition: logging.h:84
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:299
const char * cmd_open
open-hook command
Definition: compress.h:42
The Mailbox API.
Definition: mx.h:103
+ 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,
int *  index_hint 
)
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 608 of file compress.c.

609 {
610  if (!m || !m->compress_info)
611  return -1;
612 
613  struct CompressInfo *ci = m->compress_info;
614 
615  if (!ci->cmd_close)
616  {
617  mutt_error(_("Can't sync a compressed file without a close-hook"));
618  return -1;
619  }
620 
621  const struct MxOps *ops = ci->child_ops;
622  if (!ops)
623  return -1;
624 
625  if (!lock_realpath(m, true))
626  {
627  mutt_error(_("Unable to lock mailbox"));
628  return -1;
629  }
630 
631  int rc = comp_mbox_check(m, index_hint);
632  if (rc != 0)
633  goto sync_cleanup;
634 
635  rc = ops->mbox_sync(m, index_hint);
636  if (rc != 0)
637  goto sync_cleanup;
638 
639  rc = execute_command(m, ci->cmd_close, _("Compressing %s"));
640  if (rc == 0)
641  {
642  rc = -1;
643  goto sync_cleanup;
644  }
645 
646  rc = 0;
647 
648 sync_cleanup:
649  store_size(m);
650  unlock_realpath(m);
651  return rc;
652 }
int(* mbox_sync)(struct Mailbox *m, int *index_hint)
Save changes to the Mailbox.
Definition: mx.h:164
static void store_size(const struct Mailbox *m)
Save the size of the compressed file.
Definition: compress.c:158
#define _(a)
Definition: message.h:28
const char * cmd_close
close-hook command
Definition: compress.h:41
static bool lock_realpath(struct Mailbox *m, bool excl)
Try to lock the ctx->realpath.
Definition: compress.c:65
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:104
static int comp_mbox_check(struct Mailbox *m, int *index_hint)
Check for new mail - Implements MxOps::mbox_check()
Definition: compress.c:572
Private data for compress.
Definition: compress.h:38
#define mutt_error(...)
Definition: logging.h:84
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:299
The Mailbox API.
Definition: mx.h:103
+ 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 660 of file compress.c.

661 {
662  if (!m || !m->compress_info)
663  return -1;
664 
665  struct CompressInfo *ci = m->compress_info;
666 
667  const struct MxOps *ops = ci->child_ops;
668  if (!ops)
669  {
671  return -1;
672  }
673 
674  ops->mbox_close(m);
675 
676  /* sync has already been called, so we only need to delete some files */
677  if (m->append)
678  {
679  const char *append = NULL;
680  const char *msg = NULL;
681 
682  /* The file exists and we can append */
683  if ((access(m->realpath, F_OK) == 0) && ci->cmd_append)
684  {
685  append = ci->cmd_append;
686  msg = _("Compressed-appending to %s...");
687  }
688  else
689  {
690  append = ci->cmd_close;
691  msg = _("Compressing %s");
692  }
693 
694  int rc = execute_command(m, append, msg);
695  if (rc == 0)
696  {
698  mutt_error(_("Error. Preserving temporary file: %s"), mailbox_path(m));
699  }
700  else
701  remove(mailbox_path(m));
702 
703  unlock_realpath(m);
704  }
705  else
706  {
707  /* If the file was removed, remove the compressed folder too */
708  if ((access(mailbox_path(m), F_OK) != 0) && !C_SaveEmpty)
709  {
710  remove(m->realpath);
711  }
712  else
713  {
714  remove(mailbox_path(m));
715  }
716  }
717 
719 
720  return 0;
721 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:191
const char * cmd_append
append-hook command
Definition: compress.h:40
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:83
WHERE bool C_SaveEmpty
Config: (mbox,mmdf) Preserve empty mailboxes.
Definition: globals.h:249
#define _(a)
Definition: message.h:28
const char * cmd_close
close-hook command
Definition: compress.h:41
static void compress_info_free(struct Mailbox *m)
Frees the compress info members and structure.
Definition: compress.c:206
static void unlock_realpath(struct Mailbox *m)
Unlock the mailbox->realpath.
Definition: compress.c:104
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:112
Private data for compress.
Definition: compress.h:38
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:578
int(* mbox_close)(struct Mailbox *m)
Close a Mailbox.
Definition: mx.h:171
#define mutt_error(...)
Definition: logging.h:84
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
static int execute_command(struct Mailbox *m, const char *command, const char *progress)
Run a system command.
Definition: compress.c:299
The Mailbox API.
Definition: mx.h:103
+ 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 726 of file compress.c.

727 {
728  if (!m || !m->compress_info)
729  return -1;
730 
731  struct CompressInfo *ci = m->compress_info;
732 
733  const struct MxOps *ops = ci->child_ops;
734  if (!ops)
735  return -1;
736 
737  /* Delegate */
738  return ops->msg_open(m, msg, msgno);
739 }
int(* msg_open)(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox.
Definition: mx.h:180
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

◆ comp_msg_open_new()

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

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

Definition at line 744 of file compress.c.

745 {
746  if (!m || !m->compress_info)
747  return -1;
748 
749  struct CompressInfo *ci = m->compress_info;
750 
751  const struct MxOps *ops = ci->child_ops;
752  if (!ops)
753  return -1;
754 
755  /* Delegate */
756  return ops->msg_open_new(m, msg, e);
757 }
int(* msg_open_new)(struct Mailbox *m, struct Message *msg, struct Email *e)
Open a new message in a Mailbox.
Definition: mx.h:189
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

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

763 {
764  if (!m || !m->compress_info)
765  return -1;
766 
767  struct CompressInfo *ci = m->compress_info;
768 
769  const struct MxOps *ops = ci->child_ops;
770  if (!ops)
771  return -1;
772 
773  /* Delegate */
774  return ops->msg_commit(m, msg);
775 }
int(* msg_commit)(struct Mailbox *m, struct Message *msg)
Save changes to an email.
Definition: mx.h:197
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

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

781 {
782  if (!m || !m->compress_info)
783  return -1;
784 
785  struct CompressInfo *ci = m->compress_info;
786 
787  const struct MxOps *ops = ci->child_ops;
788  if (!ops)
789  return -1;
790 
791  /* Delegate */
792  return ops->msg_close(m, msg);
793 }
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
int(* msg_close)(struct Mailbox *m, struct Message *msg)
Close an email.
Definition: mx.h:205
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

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

799 {
800  if (!m || !m->compress_info)
801  return 0;
802 
803  struct CompressInfo *ci = m->compress_info;
804 
805  const struct MxOps *ops = ci->child_ops;
806  if (!ops || !ops->msg_padding_size)
807  return 0;
808 
809  return ops->msg_padding_size(m);
810 }
int(* msg_padding_size)(struct Mailbox *m)
Bytes of padding between messages.
Definition: mx.h:211
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

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

816 {
817  if (!m || !m->compress_info)
818  return 0;
819 
820  struct CompressInfo *ci = m->compress_info;
821 
822  const struct MxOps *ops = ci->child_ops;
823  if (!ops || !ops->msg_save_hcache)
824  return 0;
825 
826  return ops->msg_save_hcache(m, e);
827 }
int(* msg_save_hcache)(struct Mailbox *m, struct Email *e)
Save message to the header cache.
Definition: mx.h:219
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

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

833 {
834  if (!m || !m->compress_info)
835  return 0;
836 
837  struct CompressInfo *ci = m->compress_info;
838 
839  const struct MxOps *ops = ci->child_ops;
840  if (!ops || !ops->tags_edit)
841  return 0;
842 
843  return ops->tags_edit(m, tags, buf, buflen);
844 }
int(* tags_edit)(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Prompt and validate new messages tags.
Definition: mx.h:230
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103

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

850 {
851  if (!m || !m->compress_info)
852  return 0;
853 
854  struct CompressInfo *ci = m->compress_info;
855 
856  const struct MxOps *ops = ci->child_ops;
857  if (!ops || !ops->tags_commit)
858  return 0;
859 
860  return ops->tags_commit(m, e, buf);
861 }
Private data for compress.
Definition: compress.h:38
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:123
const struct MxOps * child_ops
callbacks of de-compressed file
Definition: compress.h:44
The Mailbox API.
Definition: mx.h:103
int(* tags_commit)(struct Mailbox *m, struct Email *e, char *buf)
Save the tags to a message.
Definition: mx.h:239

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

867 {
868  if (!path)
869  return MUTT_UNKNOWN;
870 
871  if (!st || !S_ISREG(st->st_mode))
872  return MUTT_UNKNOWN;
873 
874  if (mutt_comp_can_read(path))
875  return MUTT_COMPRESSED;
876 
877  return MUTT_UNKNOWN;
878 }
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:368
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:46
Compressed file Mailbox type.
Definition: mailbox.h:55
+ 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 883 of file compress.c.

884 {
885  if (!buf)
886  return -1;
887 
888  mutt_path_canon(buf, buflen, HomeDir);
889  return 0;
890 }
WHERE char * HomeDir
User&#39;s home directory.
Definition: globals.h:49
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir)
Create the canonical version of a path.
Definition: path.c:221
+ 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 895 of file compress.c.

896 {
897  if (!buf)
898  return -1;
899 
900  if (mutt_path_abbr_folder(buf, buflen, folder))
901  return 0;
902 
903  if (mutt_path_pretty(buf, buflen, HomeDir))
904  return 0;
905 
906  return -1;
907 }
WHERE char * HomeDir
User&#39;s home directory.
Definition: globals.h:49
bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder)
Create a folder abbreviation.
Definition: path.c:470
bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir)
Tidy a filesystem path.
Definition: path.c:183
+ 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 912 of file compress.c.

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

Variable Documentation

◆ MxCompOps

struct MxOps MxCompOps
Initial value:
= {
.magic = MUTT_COMPRESSED,
.name = "compressed",
.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_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,
}
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:726
static int comp_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open()
Definition: compress.c:422
static int comp_msg_open_new(struct Mailbox *m, struct Message *msg, struct Email *e)
Open a new message in a Mailbox - Implements MxOps::msg_open_new()
Definition: compress.c:744
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:866
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:399
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:849
static int comp_path_parent(char *buf, size_t buflen)
Find the parent of a Mailbox path - Implements MxOps::path_parent()
Definition: compress.c:912
static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append()
Definition: compress.c:485
static int comp_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close()
Definition: compress.c:660
static int comp_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Implements MxOps::msg_padding_size()
Definition: compress.c:798
static int comp_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close()
Definition: compress.c:780
Compressed file Mailbox type.
Definition: mailbox.h:55
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:815
static int comp_mbox_check(struct Mailbox *m, int *index_hint)
Check for new mail - Implements MxOps::mbox_check()
Definition: compress.c:572
static int comp_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon()
Definition: compress.c:883
static int comp_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path - Implements MxOps::path_pretty()
Definition: compress.c:895
static int comp_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add()
Definition: compress.c:407
static int comp_mbox_sync(struct Mailbox *m, int *index_hint)
Save changes to the Mailbox - Implements MxOps::mbox_sync()
Definition: compress.c:608
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:832
static int comp_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit()
Definition: compress.c:762

Compressed Mailbox - Implements MxOps.

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

Definition at line 936 of file compress.c.