zlib-plugin.c revision 0c991793912b5bf230b7f6a25492510fccef8230
/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "istream.h"
#include "istream-seekable.h"
#include "ostream.h"
#include "str.h"
#include "mail-user.h"
#include "dbox-single/sdbox-storage.h"
#include "dbox-multi/mdbox-storage.h"
#include "maildir/maildir-storage.h"
#include "index-storage.h"
#include "index-mail.h"
#include "compression.h"
#include "zlib-plugin.h"
#include <stdlib.h>
#include <fcntl.h>
#define ZLIB_PLUGIN_DEFAULT_LEVEL 6
#define ZLIB_CONTEXT(obj) \
#define ZLIB_MAIL_CONTEXT(obj) \
#define ZLIB_USER_CONTEXT(obj) \
struct zlib_transaction_context {
};
struct zlib_mail_cache {
};
struct zlib_user {
struct zlib_mail_cache cache;
const struct compression_handler *save_handler;
unsigned int save_level;
};
const char *zlib_plugin_version = DOVECOT_ABI_VERSION;
{
}
static struct istream *
{
/* zlib istream is seekable, but very slow. create a seekable istream
which we can use to quickly seek around in the stream that's been
read so far. usually the partial IMAP FETCHes continue from where
the previous left off, so this isn't strictly necessary, but with
the way lib-imap-storage's CRLF-cache works it has to seek backwards
somewhat, which causes a zlib stream reset. And the CRLF-cache isn't
easy to fix.. */
str_c(temp_prefix));
i_stream_unref(&inputs[0]);
/* index-mail wants the stream to be destroyed at close, so create
a new stream instead of just increasing reference. */
}
{
const struct compression_handler *handler;
/* don't uncompress input when we are reading a mail that we're just
in the middle of saving, and we didn't do the compression ourself.
in such situation we're probably checking if the user-given input
looks compressed */
/* use the cached stream. when doing partial reads it should
already be seeked into the wanted offset. */
}
"zlib plugin: Detected %s compression "
return -1;
}
}
}
{
union mail_module_context *zmail;
return;
}
static struct mailbox_transaction_context *
{
struct mailbox_transaction_context *t;
struct zlib_transaction_context *zt;
return t;
}
static void
{
}
static int
struct mail_transaction_commit_changes *changes_r)
{
int ret;
return ret;
}
static int
{
NULL);
}
}
}
{
return -1;
return -1;
"Saving mails compressed by client isn't supported");
return -1;
}
return 0;
}
static int
{
return -1;
zuser->save_level);
return 0;
}
static void
{
} else {
}
}
{
const struct compression_handler *handler;
int fd;
return 0;
/* looks like a compressed single file mailbox. we should be
able to handle this. */
if (fd == -1) {
/* let the standard handler figure out what to do
with the failure */
return 0;
}
i_close_fd(&fd);
return 0;
}
}
return 0;
}
{
MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) != 0) {
if (zlib_mailbox_open_input(box) < 0)
return -1;
}
}
{
}
{
union mailbox_module_context *zbox;
v->open = zlib_mailbox_open;
v->close = zlib_mailbox_close;
}
{
}
{
const char *name;
v->deinit = zlib_mail_user_deinit;
}
}
i_error("zlib_save_level: Level must be between 1..9");
zuser->save_level = 0;
}
}
if (zuser->save_level == 0)
}
static struct mail_storage_hooks zlib_mail_storage_hooks = {
};
{
}
void zlib_plugin_deinit(void)
{
}