avoid ugly casts.
Signed-off-by: Pierre Habouzit <madcoder@madism.org>
#include "mbox.h"
#include "compress.h"
#include "mbox.h"
#include "compress.h"
const char *close; /* close-hook command */
const char *open; /* open-hook command */
const char *append; /* append-hook command */
off_t size; /* size of real folder */
const char *close; /* close-hook command */
const char *open; /* open-hook command */
const char *append; /* append-hook command */
off_t size; /* size of real folder */
char echo_cmd[HUGE_STRING];
char echo_cmd[HUGE_STRING];
*/
static const char *get_append_command (const char *path, const CONTEXT * ctx)
{
*/
static const char *get_append_command (const char *path, const CONTEXT * ctx)
{
- COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
-
- return (is_new (path)) ? ci->close : ci->append;
+ return is_new(path) ? ctx->cinfo->close : ctx->cinfo->append;
}
int mutt_can_append_compressed (const char *path)
}
int mutt_can_append_compressed (const char *path)
}
/* open a compressed mailbox */
}
/* open a compressed mailbox */
-static COMPRESS_INFO *set_compress_info (CONTEXT * ctx)
+static compress_info *set_compress_info (CONTEXT * ctx)
+ compress_info *ci = p_new(compress_info, 1);
/* Now lets uncompress this thing */
/* Now lets uncompress this thing */
- ci = p_new(COMPRESS_INFO, 1);
- ctx->compressinfo = (void *) ci;
ci->append = find_compress_hook (M_APPENDHOOK, ctx->path);
ci->open = find_compress_hook (M_OPENHOOK, ctx->path);
ci->close = find_compress_hook (M_CLOSEHOOK, ctx->path);
ci->append = find_compress_hook (M_APPENDHOOK, ctx->path);
ci->open = find_compress_hook (M_OPENHOOK, ctx->path);
ci->close = find_compress_hook (M_CLOSEHOOK, ctx->path);
+
+ return (ctx->cinfo = ci);
}
static void set_path (CONTEXT * ctx)
}
static void set_path (CONTEXT * ctx)
-static void store_size (CONTEXT * ctx)
-{
- COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
-
- ci->size = get_size (ctx->realpath);
-}
-
static const char *compresshook_format_str (char *dest, ssize_t destlen,
char op, const char *src,
const char *fmt,
static const char *compresshook_format_str (char *dest, ssize_t destlen,
char op, const char *src,
const char *fmt,
int mutt_check_mailbox_compressed (CONTEXT * ctx)
{
int mutt_check_mailbox_compressed (CONTEXT * ctx)
{
- COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
-
- if (ci->size != get_size (ctx->realpath)) {
- p_delete(&ctx->compressinfo);
+ if (ctx->cinfo->size != get_size (ctx->realpath)) {
+ p_delete(&ctx->cinfo);
p_delete(&ctx->realpath);
mutt_error _("Mailbox was corrupted!");
p_delete(&ctx->realpath);
mutt_error _("Mailbox was corrupted!");
- COMPRESS_INFO *ci = set_compress_info (ctx);
+ compress_info *ci = set_compress_info (ctx);
if (!ci->open) {
ctx->magic = 0;
if (!ci->open) {
ctx->magic = 0;
- p_delete(&ctx->compressinfo);
return (-1);
}
if (!ci->close || access (ctx->path, W_OK) != 0)
ctx->readonly = 1;
set_path (ctx);
return (-1);
}
if (!ci->close || access (ctx->path, W_OK) != 0)
ctx->readonly = 1;
set_path (ctx);
+ ctx->cinfo->size = get_size(ctx->realpath);
if (!ctx->quiet)
mutt_message (_("Decompressing %s..."), ctx->realpath);
if (!ctx->quiet)
mutt_message (_("Decompressing %s..."), ctx->realpath);
if (rc) {
mutt_any_key_to_continue (NULL);
ctx->magic = 0;
if (rc) {
mutt_any_key_to_continue (NULL);
ctx->magic = 0;
- p_delete(&ctx->compressinfo);
- mutt_error (_("Error executing: %s : unable to open the mailbox!\n"),
- cmd);
+ p_delete(&ctx->cinfo);
+ mutt_error(_("Error executing: %s : unable to open the mailbox!\n"), cmd);
}
p_delete(&cmd);
if (rc)
}
p_delete(&cmd);
if (rc)
int mutt_open_append_compressed (CONTEXT * ctx)
{
FILE *fh;
int mutt_open_append_compressed (CONTEXT * ctx)
{
FILE *fh;
- COMPRESS_INFO *ci = set_compress_info (ctx);
+ compress_info *ci = set_compress_info (ctx);
if (!get_append_command (ctx->path, ctx)) {
if (ci->open && ci->close)
return (mutt_open_read_compressed (ctx));
ctx->magic = 0;
if (!get_append_command (ctx->path, ctx)) {
if (ci->open && ci->close)
return (mutt_open_read_compressed (ctx));
ctx->magic = 0;
- p_delete(&ctx->compressinfo);
/* close a compressed mailbox */
void mutt_fast_close_compressed (CONTEXT * ctx)
{
/* close a compressed mailbox */
void mutt_fast_close_compressed (CONTEXT * ctx)
{
- if (ctx->compressinfo) {
if (ctx->fp)
fclose (ctx->fp);
ctx->fp = NULL;
if (ctx->fp)
fclose (ctx->fp);
ctx->fp = NULL;
remove_file (ctx);
restore_path (ctx);
remove_file (ctx);
restore_path (ctx);
- p_delete(&ctx->compressinfo);
char *cmd;
int rc = 0;
FILE *fp;
char *cmd;
int rc = 0;
FILE *fp;
- COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
if (!ctx->quiet)
mutt_message (_("Compressing %s..."), ctx->realpath);
if (!ctx->quiet)
mutt_message (_("Compressing %s..."), ctx->realpath);
- cmd = get_compression_cmd (ci->close, ctx);
+ cmd = get_compression_cmd (ctx->cinfo->close, ctx);
if (cmd == NULL)
return (-1);
if (cmd == NULL)
return (-1);
mutt_unblock_signals ();
mutt_error _("Unable to lock mailbox!");
mutt_unblock_signals ();
mutt_error _("Unable to lock mailbox!");
+ ctx->cinfo->size = get_size(ctx->realpath);
p_delete(&cmd);
return (-1);
p_delete(&cmd);
return (-1);
+ ctx->cinfo->size = get_size(ctx->realpath);
FILE *fp;
const char *append;
char *cmd;
FILE *fp;
const char *append;
char *cmd;
- COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo;
+ compress_info *ci = ctx->cinfo;
if (!(ctx->append && ((append = get_append_command (ctx->realpath, ctx))
if (!(ctx->append && ((append = get_append_command (ctx->realpath, ctx))
- || (append = ci->close)))) { /* if we can not or should not append,
- * we only have to remove the compressed info, because sync was already
- * called
- */
+ || (append = ci->close)))) {
+ /* if we can not or should not append, we only have to remove the
+ compressed info, because sync was already called */
mutt_fast_close_compressed (ctx);
return (0);
}
mutt_fast_close_compressed (ctx);
return (0);
}
if (mutt_system (cmd)) {
mutt_any_key_to_continue (NULL);
if (mutt_system (cmd)) {
mutt_any_key_to_continue (NULL);
- mutt_error (_
- (" %s: Error compressing mailbox! Uncompressed one kept!\n"),
+ mutt_error (_(" %s: Error compressing mailbox! Uncompressed one kept!\n"),
ctx->path);
p_delete(&cmd);
mbox_unlock_compressed (ctx, fp);
ctx->path);
p_delete(&cmd);
mbox_unlock_compressed (ctx, fp);
remove_file (ctx);
restore_path (ctx);
p_delete(&cmd);
remove_file (ctx);
restore_path (ctx);
p_delete(&cmd);
- p_delete(&ctx->compressinfo);
if (Context) {
int check;
if (Context) {
int check;
- if (Context->compressinfo && Context->realpath)
+ if (Context->cinfo && Context->realpath)
m_strreplace(&LastFolder, Context->realpath);
else
m_strreplace(&LastFolder, Context->path);
m_strreplace(&LastFolder, Context->realpath);
else
m_strreplace(&LastFolder, Context->path);
case 'B':
snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
case 'B':
snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- if (Context && Context->compressinfo && Context->realpath) {
+ if (Context && Context->cinfo && Context->realpath) {
if ((p = strrchr (Context->realpath, '/')))
m_strcpy(tmp, sizeof(tmp), p + 1);
else
if ((p = strrchr (Context->realpath, '/')))
m_strcpy(tmp, sizeof(tmp), p + 1);
else
case 'f':
snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
case 'f':
snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
- if (Context && Context->compressinfo && Context->realpath) {
+ if (Context && Context->cinfo && Context->realpath) {
m_strcpy(tmp, sizeof(tmp), Context->realpath);
mutt_pretty_mailbox (tmp);
m_strcpy(tmp, sizeof(tmp), Context->realpath);
mutt_pretty_mailbox (tmp);
if (Context && Context->path) {
m_strcpy(tmp, sizeof(tmp), Context->path);
mutt_pretty_mailbox (tmp);
if (Context && Context->path) {
m_strcpy(tmp, sizeof(tmp), Context->path);
mutt_pretty_mailbox (tmp);
m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
snprintf (buf, buflen, fmt, tmp);
break;
snprintf (buf, buflen, fmt, tmp);
break;
{
mx_unlock_file (ctx->path, fileno (ctx->fp), 1);
{
mx_unlock_file (ctx->path, fileno (ctx->fp), 1);
mutt_slow_close_compressed (ctx);
mutt_unblock_signals ();
mutt_slow_close_compressed (ctx);
mutt_unblock_signals ();
regex_t *rx;
} pattern_t;
regex_t *rx;
} pattern_t;
+typedef struct compress_info compress_info;
+
typedef struct {
char *path;
FILE *fp;
typedef struct {
char *path;
FILE *fp;
short magic; /* mailbox type */
short magic; /* mailbox type */
- void *compressinfo; /* compressed mbox module private data */
+ compress_info *cinfo; /* compressed mbox module private data */
char *realpath; /* path to compressed mailbox */
unsigned int locked:1; /* is the mailbox locked? */
char *realpath; /* path to compressed mailbox */
unsigned int locked:1; /* is the mailbox locked? */
p_delete(&ctx->hdrs);
p_delete(&ctx->v2r);
p_delete(&ctx->hdrs);
p_delete(&ctx->v2r);
mutt_fast_close_compressed (ctx);
p_delete(&ctx->path);
mutt_fast_close_compressed (ctx);
p_delete(&ctx->path);
/* the 1 is only of interest for IMAP and means EXPUNGE */
rc = mxfmts[ctx->magic-1]->mx_sync_mailbox(ctx,1,index_hint);
/* the 1 is only of interest for IMAP and means EXPUNGE */
rc = mxfmts[ctx->magic-1]->mx_sync_mailbox(ctx,1,index_hint);
- if (rc == 0 && ctx->compressinfo)
+ if (rc == 0 && ctx->cinfo)
return mutt_sync_compressed (ctx);
return rc;
return mutt_sync_compressed (ctx);
return rc;
!mutt_is_spool (ctx->path) && !option (OPTSAVEEMPTY))
mx_unlink_empty (ctx->path);
!mutt_is_spool (ctx->path) && !option (OPTSAVEEMPTY))
mx_unlink_empty (ctx->path);
- if (ctx->compressinfo && mutt_slow_close_compressed (ctx))
+ if (ctx->cinfo && mutt_slow_close_compressed (ctx))
return (-1);
mx_fastclose_mailbox (ctx);
return (-1);
mx_fastclose_mailbox (ctx);
/* check for new mail */
int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) {
/* check for new mail */
int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) {
return mutt_check_mailbox_compressed (ctx);
if (ctx) {
return mutt_check_mailbox_compressed (ctx);
if (ctx) {