]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap, pop3: Moved imap/pop3_client_workarounds setting parsing to config checking.
authorTimo Sirainen <tss@iki.fi>
Fri, 16 Oct 2009 21:46:31 +0000 (17:46 -0400)
committerTimo Sirainen <tss@iki.fi>
Fri, 16 Oct 2009 21:46:31 +0000 (17:46 -0400)
--HG--
branch : HEAD

15 files changed:
src/imap/cmd-subscribe.c
src/imap/imap-client.h
src/imap/imap-commands-util.c
src/imap/imap-common.h
src/imap/imap-fetch-body.c
src/imap/imap-settings.c
src/imap/imap-settings.h
src/imap/imap-sync.c
src/imap/main.c
src/pop3/pop3-client.c
src/pop3/pop3-client.h
src/pop3/pop3-commands.c
src/pop3/pop3-common.h
src/pop3/pop3-settings.c
src/pop3/pop3-settings.h

index 53b75a67c6da70ef571d0ab92b5bbfbd32e951b4..f5ebaaa34e71289cd1924219638f59eb2defbe9b 100644 (file)
@@ -60,7 +60,8 @@ bool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe)
                mailbox += strlen(ns->prefix);
        }
 
-       if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
+       if ((cmd->client->set->parsed_workarounds &
+                       WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
            *mailbox != '\0' && mailbox[strlen(mailbox)-1] ==
            mailbox_list_get_hierarchy_sep(ns->list)) {
                /* verify the validity without the trailing '/' */
index e40d56f5e4cb3573ad018764bf22ec7a6b681b15..1c0c1002544ee332e4e2c63f9e28f2e33086fb37 100644 (file)
@@ -95,7 +95,6 @@ struct client {
        struct timeout *to_idle, *to_idle_output;
 
         const struct imap_settings *set;
-       enum client_workarounds workarounds;
        string_t *capability_string;
 
         struct mail_user *user;
index 3b890ddd6b5e9212d21485ffded86c2df49e0d81..6fdaffb7a6c4c6f030de3848f3e7e8eba4aa187a 100644 (file)
@@ -46,7 +46,8 @@ client_find_namespace(struct client_command_context *cmd, const char **mailboxp,
        }
 
        mailbox_len = strlen(mailbox);
-       if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
+       if ((cmd->client->set->parsed_workarounds &
+                       WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
            mailbox[mailbox_len-1] == mailbox_list_get_hierarchy_sep(ns->list)) {
                /* drop the extra trailing hierarchy separator */
                mailbox = t_strndup(mailbox, mailbox_len-1);
index c2c0e6b429a6af9879684fd175f4312f027b0cd7..7ce6da68640c306ce0ae4575821526d830a5f299 100644 (file)
 /* Disconnect client when it sends too many bad commands in a row */
 #define CLIENT_MAX_BAD_COMMANDS 20
 
-enum client_workarounds {
-       WORKAROUND_DELAY_NEWMAIL                = 0x01,
-       WORKAROUND_NETSCAPE_EOH                 = 0x04,
-       WORKAROUND_TB_EXTRA_MAILBOX_SEP         = 0x08
-};
-
 #include "lib.h"
 #include "imap-client.h"
 #include "imap-settings.h"
index b0a3900ab36455875c7cdff1a040d904c9282ad8..601da87f9f83cfdded6b9bf9377853f6ae3b3772 100644 (file)
@@ -433,7 +433,7 @@ static int fetch_header_partial_from(struct imap_fetch_context *ctx,
        i_stream_seek(ctx->cur_input, old_offset);
 
        if (!ctx->cur_have_eoh &&
-           (ctx->client->workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
+           (ctx->client->set->parsed_workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
                /* Netscape 4.x doesn't like if end of headers line is
                   missing. */
                msg_size.virtual_size += 2;
index a9c8142ba357de47f62a4180864dd3a24bf0113a..1ac111964384549526f948090ad2d365f3adf39c 100644 (file)
@@ -9,6 +9,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+static bool imap_settings_verify(void *_set, pool_t pool,
+                                const char **error_r);
+
 #undef DEF
 #undef DEFLIST
 #define DEF(type, name) \
@@ -62,6 +65,59 @@ struct setting_parser_info imap_setting_parser_info = {
        MEMBER(parent_offset) (size_t)-1,
        MEMBER(type_offset) (size_t)-1,
        MEMBER(struct_size) sizeof(struct imap_settings),
-       MEMBER(check_func) NULL,
+       MEMBER(check_func) imap_settings_verify,
        MEMBER(dependencies) imap_setting_dependencies
 };
+
+/* <settings checks> */
+struct imap_client_workaround_list {
+       const char *name;
+       enum imap_client_workarounds num;
+};
+
+static struct imap_client_workaround_list imap_client_workaround_list[] = {
+       { "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
+       { "outlook-idle", 0 }, /* only for backwards compatibility */
+       { "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
+       { "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
+       { NULL, 0 }
+};
+
+static int
+imap_settings_parse_workarounds(struct imap_settings *set,
+                               const char **error_r)
+{
+        enum imap_client_workarounds client_workarounds = 0;
+        struct imap_client_workaround_list *list;
+       const char *const *str;
+
+        str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
+       for (; *str != NULL; str++) {
+               list = imap_client_workaround_list;
+               for (; list->name != NULL; list++) {
+                       if (strcasecmp(*str, list->name) == 0) {
+                               client_workarounds |= list->num;
+                               break;
+                       }
+               }
+               if (list->name == NULL) {
+                       *error_r = t_strdup_printf("imap_client_workarounds: "
+                               "Unknown workaround: %s", *str);
+                       return -1;
+               }
+       }
+       set->parsed_workarounds = client_workarounds;
+       return 0;
+}
+
+
+static bool
+imap_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
+{
+       struct imap_settings *set = _set;
+
+       if (imap_settings_parse_workarounds(set, error_r) < 0)
+               return FALSE;
+       return TRUE;
+}
+/* </settings checks> */
index 7629b6d05743d2e5b11fabaf15c30bbb71e1f8a2..275a969880b99a92118fb8f5284d28fef7ab399f 100644 (file)
@@ -3,6 +3,14 @@
 
 struct mail_user_settings;
 
+/* <settings checks> */
+enum imap_client_workarounds {
+       WORKAROUND_DELAY_NEWMAIL                = 0x01,
+       WORKAROUND_NETSCAPE_EOH                 = 0x04,
+       WORKAROUND_TB_EXTRA_MAILBOX_SEP         = 0x08
+};
+/* </settings checks> */
+
 struct imap_settings {
        bool mail_debug;
        bool shutdown_clients;
@@ -15,6 +23,8 @@ struct imap_settings {
        const char *imap_logout_format;
        const char *imap_id_send;
        const char *imap_id_log;
+
+       enum imap_client_workarounds parsed_workarounds;
 };
 
 extern struct setting_parser_info imap_setting_parser_info;
index 77923490ff7055b385934fec800b6a466c99d495..e749a4fc1cf4c991de986453327a3beaeabccf84 100644 (file)
@@ -579,7 +579,7 @@ static bool cmd_sync_client(struct client_command_context *sync_cmd)
        get_common_sync_flags(client, &flags, &imap_flags);
        client->sync_counter++;
 
-       no_newmail = (client->workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
+       no_newmail = (client->set->parsed_workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
                (imap_flags & IMAP_SYNC_FLAG_SAFE) == 0;
        if (no_newmail) {
                /* expunges might break the client just as badly as new mail
index 2a6c1cb95e72f68d6e3f5ef222c3bd1599a1984b..cf70504fbca37bbfee9907301f899df6c09e086d 100644 (file)
 #define IS_STANDALONE() \
         (getenv("CLIENT_INPUT") == NULL)
 
-struct client_workaround_list {
-       const char *name;
-       enum client_workarounds num;
-};
-
-static struct client_workaround_list client_workaround_list[] = {
-       { "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
-       { "outlook-idle", 0 }, /* only for backwards compatibility */
-       { "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
-       { "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
-       { NULL, 0 }
-};
-
 void (*hook_client_created)(struct client **client) = NULL;
 
-static enum client_workarounds
-parse_workarounds(const struct imap_settings *set)
-{
-        enum client_workarounds client_workarounds = 0;
-        struct client_workaround_list *list;
-       const char *const *str;
-
-        str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
-       for (; *str != NULL; str++) {
-               list = client_workaround_list;
-               for (; list->name != NULL; list++) {
-                       if (strcasecmp(*str, list->name) == 0) {
-                               client_workarounds |= list->num;
-                               break;
-                       }
-               }
-               if (list->name == NULL)
-                       i_fatal("Unknown client workaround: %s", *str);
-       }
-
-       return client_workarounds;
-}
-
 static void client_add_input(struct client *client, const char *input)
 {
        buffer_t *buf;
@@ -122,7 +86,6 @@ static void main_init(const struct imap_settings *set, struct mail_user *user,
                master_service_set_die_with_master(master_service, TRUE);
 
        client = client_create(0, 1, user, set);
-        client->workarounds = parse_workarounds(set);
 
        if (dump_capability) {
                printf("%s\n", str_c(client->capability_string));
index 0d096ca33608b1a95abb4e262a72d78879dc1c28..f00293c73c68f283d08f6aea058875d90c1daa19 100644 (file)
    transaction. This allows the mailbox to become unlocked. */
 #define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000)
 
-struct client_workaround_list {
-       const char *name;
-       enum client_workarounds num;
-};
-
-static struct client_workaround_list client_workaround_list[] = {
-       { "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
-       { "oe-ns-eoh", WORKAROUND_OE_NS_EOH },
-       { NULL, 0 }
-};
-
 static struct client *pop3_clients;
 
 static void client_input(struct client *client);
@@ -167,28 +156,6 @@ static bool init_mailbox(struct client *client, const char **error_r)
        return FALSE;
 }
 
-static enum client_workarounds
-parse_workarounds(const struct pop3_settings *set)
-{
-        enum client_workarounds client_workarounds = 0;
-       struct client_workaround_list *list;
-       const char *const *str;
-
-        str = t_strsplit_spaces(set->pop3_client_workarounds, " ,");
-       for (; *str != NULL; str++) {
-               list = client_workaround_list;
-               for (; list->name != NULL; list++) {
-                       if (strcasecmp(*str, list->name) == 0) {
-                               client_workarounds |= list->num;
-                               break;
-                       }
-               }
-               if (list->name == NULL)
-                       i_fatal("Unknown client workaround: %s", *str);
-       }
-       return client_workarounds;
-}
-
 static enum uidl_keys parse_uidl_keymask(const char *format)
 {
        enum uidl_keys mask = 0;
@@ -281,7 +248,6 @@ struct client *client_create(int fd_in, int fd_out, struct mail_user *user,
                return NULL;
        }
 
-       client->workarounds = parse_workarounds(set);
        client->uidl_keymask =
                parse_uidl_keymask(client->mail_set->pop3_uidl_format);
        if (client->uidl_keymask == 0)
index 8bc503d99efd6273898d303d15e5d2a157da1534..a70b1bc278e9e272d8ff917cde5051cdaba95dca 100644 (file)
@@ -52,7 +52,6 @@ struct client {
        /* settings: */
        const struct pop3_settings *set;
        const struct mail_storage_settings *mail_set;
-       enum client_workarounds workarounds;
        enum uidl_keys uidl_keymask;
 
        unsigned int disconnected:1;
index 551fe0996223d595ace0626c85a795071b0315aa..9681ccef27b99f605a380f188ec11fedaf2c625c 100644 (file)
@@ -321,7 +321,7 @@ static void fetch_callback(struct client *client)
                                add = '.';
                                break;
                        } else if (data[i] == '\0' &&
-                                  (client->workarounds &
+                                  (client->set->parsed_workarounds &
                                    WORKAROUND_OUTLOOK_NO_NULS) != 0) {
                                add = 0x80;
                                break;
@@ -360,7 +360,7 @@ static void fetch_callback(struct client *client)
        }
 
        if (!ctx->in_body &&
-           (client->workarounds & WORKAROUND_OE_NS_EOH) != 0) {
+           (client->set->parsed_workarounds & WORKAROUND_OE_NS_EOH) != 0) {
                /* Add the missing end of headers line. */
                (void)o_stream_send(client->output, "\r\n", 2);
        }
index 8a31acd4047f1d1f827d1e441f6db246ba2f0b5b..e4b0fd496efa5ed195ed2889d111968fe6cdab98 100644 (file)
@@ -1,11 +1,6 @@
 #ifndef POP3_COMMON_H
 #define POP3_COMMON_H
 
-enum client_workarounds {
-       WORKAROUND_OUTLOOK_NO_NULS              = 0x01,
-       WORKAROUND_OE_NS_EOH                    = 0x02
-};
-
 enum uidl_keys {
        UIDL_UIDVALIDITY        = 0x01,
        UIDL_UID                = 0x02,
index 05b6fda83461e4956f4d42b7f0873de980f9b071..ba64c6400b148e379676d5729081309f7ad40b04 100644 (file)
@@ -9,6 +9,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+static bool pop3_settings_verify(void *_set, pool_t pool,
+                                const char **error_r);
+
 #undef DEF
 #undef DEFLIST
 #define DEF(type, name) \
@@ -59,6 +62,56 @@ struct setting_parser_info pop3_setting_parser_info = {
        MEMBER(parent_offset) (size_t)-1,
        MEMBER(type_offset) (size_t)-1,
        MEMBER(struct_size) sizeof(struct pop3_settings),
-       MEMBER(check_func) NULL,
+       MEMBER(check_func) pop3_settings_verify,
        MEMBER(dependencies) pop3_setting_dependencies
 };
+
+/* <settings checks> */
+struct pop3_client_workaround_list {
+       const char *name;
+       enum pop3_client_workarounds num;
+};
+
+static struct pop3_client_workaround_list pop3_client_workaround_list[] = {
+       { "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
+       { "oe-ns-eoh", WORKAROUND_OE_NS_EOH },
+       { NULL, 0 }
+};
+
+static int
+pop3_settings_parse_workarounds(struct pop3_settings *set,
+                               const char **error_r)
+{
+        enum pop3_client_workarounds client_workarounds = 0;
+       struct pop3_client_workaround_list *list;
+       const char *const *str;
+
+        str = t_strsplit_spaces(set->pop3_client_workarounds, " ,");
+       for (; *str != NULL; str++) {
+               list = pop3_client_workaround_list;
+               for (; list->name != NULL; list++) {
+                       if (strcasecmp(*str, list->name) == 0) {
+                               client_workarounds |= list->num;
+                               break;
+                       }
+               }
+               if (list->name == NULL) {
+                       *error_r = t_strdup_printf("pop3_client_workarounds: "
+                               "Unknown workaround: %s", *str);
+                       return -1;
+               }
+       }
+       set->parsed_workarounds = client_workarounds;
+       return 0;
+}
+
+static bool
+pop3_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
+{
+       struct pop3_settings *set = _set;
+
+       if (pop3_settings_parse_workarounds(set, error_r) < 0)
+               return FALSE;
+       return TRUE;
+}
+/* </settings checks> */
index 09faeb01a0416cdc143aeb141154973db738d53b..02515a5222ca86abbddc071afd3aa577c04ad1f9 100644 (file)
@@ -3,6 +3,13 @@
 
 struct mail_user_settings;
 
+/* <settings checks> */
+enum pop3_client_workarounds {
+       WORKAROUND_OUTLOOK_NO_NULS              = 0x01,
+       WORKAROUND_OE_NS_EOH                    = 0x02
+};
+/* </settings checks> */
+
 struct pop3_settings {
        bool mail_debug;
        bool shutdown_clients;
@@ -15,6 +22,8 @@ struct pop3_settings {
        bool pop3_lock_session;
        const char *pop3_client_workarounds;
        const char *pop3_logout_format;
+
+       enum pop3_client_workarounds parsed_workarounds;
 };
 
 extern struct setting_parser_info pop3_setting_parser_info;