]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
zlib: If gz/bz2 support isn't compiled in but we detect a mail with gz/bz2
authorTimo Sirainen <tss@iki.fi>
Thu, 10 Jul 2008 17:08:31 +0000 (22:38 +0530)
committerTimo Sirainen <tss@iki.fi>
Thu, 10 Jul 2008 17:08:31 +0000 (22:38 +0530)
compression, log an error and fail to read the mail.

--HG--
branch : HEAD

src/plugins/zlib/zlib-plugin.c

index 28b6a83c3dde81431d75affb904e70073f7d3caf..d3553d15a01783a44b8c86c87caa47cdbef399ae 100644 (file)
 #define ZLIB_MAIL_CONTEXT(obj) \
        MODULE_CONTEXT(obj, zlib_mail_module)
 
+#ifndef HAVE_ZLIB
+#  define i_stream_create_zlib NULL
+#endif
+#ifndef HAVE_BZLIB
+#  define i_stream_create_bzlib NULL
+#endif
+
 struct zlib_handler {
+       const char *name;
        bool (*is_compressed)(struct istream *input);
        struct istream *(*create_istream)(int fd);
 };
@@ -31,7 +39,6 @@ static MODULE_CONTEXT_DEFINE_INIT(zlib_storage_module,
                                  &mail_storage_module_register);
 static MODULE_CONTEXT_DEFINE_INIT(zlib_mail_module, &mail_module_register);
 
-#ifdef HAVE_ZLIB
 static bool is_compressed_zlib(struct istream *input)
 {
        const unsigned char *data;
@@ -47,9 +54,7 @@ static bool is_compressed_zlib(struct istream *input)
 
        return data[0] == 31 && data[1] == 139;
 }
-#endif
 
-#ifdef HAVE_ZLIB
 static bool is_compressed_bzlib(struct istream *input)
 {
        const unsigned char *data;
@@ -65,23 +70,17 @@ static bool is_compressed_bzlib(struct istream *input)
                return FALSE;
        return memcmp(data + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0;
 }
-#endif
 
 static struct zlib_handler zlib_handlers[] = {
-#ifdef HAVE_ZLIB
-       { is_compressed_zlib, i_stream_create_zlib },
-#endif
-#ifdef HAVE_BZLIB
-       { is_compressed_bzlib, i_stream_create_bzlib },
-#endif
-       { NULL, NULL }
+       { "zlib", is_compressed_zlib, i_stream_create_zlib },
+       { "bzlib", is_compressed_bzlib, i_stream_create_bzlib }
 };
 
 static struct zlib_handler *zlib_get_zlib_handler(struct istream *input)
 {
        unsigned int i;
 
-       for (i = 0; i < N_ELEMENTS(zlib_handlers)-1; i++) {
+       for (i = 0; i < N_ELEMENTS(zlib_handlers); i++) {
                if (zlib_handlers[i].is_compressed(input))
                        return &zlib_handlers[i];
        }
@@ -111,9 +110,18 @@ static int zlib_maildir_get_stream(struct mail *_mail,
 
        handler = zlib_get_zlib_handler(imail->data.stream);
        if (handler != NULL) {
-               fd = dup(i_stream_get_fd(imail->data.stream));
-               if (fd == -1)
-                       i_error("zlib plugin: dup() failed: %m");
+               if (handler->create_istream == NULL) {
+                       mail_storage_set_critical(_mail->box->storage,
+                               "zlib plugin: Detected %s "
+                               "but support not compiled in", handler->name);
+                       fd = -1;
+               } else {
+                       fd = dup(i_stream_get_fd(imail->data.stream));
+                       if (fd == -1) {
+                               mail_storage_set_critical(_mail->box->storage,
+                                       "zlib plugin: dup() failed: %m");
+                       }
+               }
 
                imail->data.destroying_stream = TRUE;
                i_stream_unref(&imail->data.stream);