zlib-plugin.c revision efe78d3ba24fc866af1c79b9223dc0809ba26cad
/* Copyright (c) 2005-2016 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 "index-storage.h"
#include "index-mail.h"
#include "compression.h"
#include "zlib-plugin.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_mail {
union mail_module_context module_ctx;
bool verifying_save;
};
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 *
{
if (do_cache)
/* 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_get_name(inputs[0])));
i_stream_unref(&inputs[0]);
if (do_cache) {
/* index-mail wants the stream to be destroyed at close, so create
a new stream instead of just increasing reference. */
} else {
return input;
}
}
{
const struct compression_handler *handler;
if (zmail->verifying_save) {
/* zlib_mail_save_finish() is verifying that the user-given
input doesn't look 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;
}
/* dont cache the stream if _mail->uid is 0 */
}
}
{
/* make sure we have read the entire email into the seekable
stream (which causes the original input stream to be
unrefed). we can't safely keep the original input stream
open after the mail is closed. */
}
}
{
return;
v->close = zlib_mail_close;
}
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);
}
}
}
{
int ret;
return -1;
if (ret < 0)
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;
if ((class_flags & MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) == 0 &&
}
{
}
{
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)
{
}