Skip to content

Commit

Permalink
pop3c: Add no pipelining pop3c feature
Browse files Browse the repository at this point in the history
This should help with certain broken pop3c
servers that advertise that they support pipelining
but they really don't.
  • Loading branch information
cmouse authored and GitLab committed Feb 20, 2017
1 parent 74bc7e6 commit ec3eb53
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/lib-storage/index/pop3c/pop3c-client.c
Expand Up @@ -490,7 +490,8 @@ pop3c_client_prelogin_input_line(struct pop3c_client *client, const char *line)
pop3c_client_login_finished(client);
break;
}
if (strcasecmp(line, "PIPELINING") == 0)
if ((client->set.parsed_features & POP3C_FEATURE_NO_PIPELINING) == 0 &&
strcasecmp(line, "PIPELINING") == 0)
client->capabilities |= POP3C_CAPABILITY_PIPELINING;
else if (strcasecmp(line, "TOP") == 0)
client->capabilities |= POP3C_CAPABILITY_TOP;
Expand Down
2 changes: 2 additions & 0 deletions src/lib-storage/index/pop3c/pop3c-client.h
Expand Up @@ -2,6 +2,7 @@
#define POP3C_CLIENT_H

#include "net.h"
#include "pop3c-settings.h"

enum pop3c_capability {
POP3C_CAPABILITY_PIPELINING = 0x01,
Expand Down Expand Up @@ -33,6 +34,7 @@ struct pop3c_client_settings {
const char *temp_path_prefix;

enum pop3c_client_ssl_mode ssl_mode;
enum pop3c_features parsed_features;
const char *ssl_ca_dir, *ssl_ca_file;
bool ssl_verify;

Expand Down
1 change: 0 additions & 1 deletion src/lib-storage/index/pop3c/pop3c-mail.c
Expand Up @@ -4,7 +4,6 @@
#include "ioloop.h"
#include "istream.h"
#include "index-mail.h"
#include "pop3c-settings.h"
#include "pop3c-client.h"
#include "pop3c-sync.h"
#include "pop3c-storage.h"
Expand Down
57 changes: 56 additions & 1 deletion src/lib-storage/index/pop3c/pop3c-settings.c
Expand Up @@ -25,6 +25,8 @@ static const struct setting_define pop3c_setting_defines[] = {
DEF(SET_STR, pop3c_rawlog_dir),
DEF(SET_BOOL, pop3c_quick_received_date),

DEF(SET_STR, pop3c_features),

SETTING_DEFINE_LIST_END
};

Expand All @@ -40,9 +42,60 @@ static const struct pop3c_settings pop3c_default_settings = {
.pop3c_ssl_verify = TRUE,

.pop3c_rawlog_dir = "",
.pop3c_quick_received_date = FALSE
.pop3c_quick_received_date = FALSE,

.pop3c_features = ""
};

/* <settings checks> */
struct pop3c_feature_list {
const char *name;
enum pop3c_features num;
};

static const struct pop3c_feature_list pop3c_feature_list[] = {
{ "no-pipelining", POP3C_FEATURE_NO_PIPELINING },
{ NULL, 0 }
};

static int
pop3c_settings_parse_features(struct pop3c_settings *set,
const char **error_r)
{
enum pop3c_features features = 0;
const struct pop3c_feature_list *list;
const char *const *str;

str = t_strsplit_spaces(set->pop3c_features, " ,");
for (; *str != NULL; str++) {
list = pop3c_feature_list;
for (; list->name != NULL; list++) {
if (strcasecmp(*str, list->name) == 0) {
features |= list->num;
break;
}
}
if (list->name == NULL) {
*error_r = t_strdup_printf("pop3c_features: "
"Unknown feature: %s", *str);
return -1;
}
}
set->parsed_features = features;
return 0;
}

static bool pop3c_settings_check(void *_set, pool_t pool ATTR_UNUSED,
const char **error_r)
{
struct pop3c_settings *set = _set;

if (pop3c_settings_parse_features(set, error_r) < 0)
return FALSE;
return TRUE;
}
/* </settings checks> */

static const struct setting_parser_info pop3c_setting_parser_info = {
.module_name = "pop3c",
.defines = pop3c_setting_defines,
Expand All @@ -53,6 +106,8 @@ static const struct setting_parser_info pop3c_setting_parser_info = {

.parent_offset = (size_t)-1,
.parent = &mail_user_setting_parser_info,

.check_func = pop3c_settings_check
};

const struct setting_parser_info *pop3c_get_setting_parser_info(void)
Expand Down
10 changes: 10 additions & 0 deletions src/lib-storage/index/pop3c/pop3c-settings.h
Expand Up @@ -3,6 +3,13 @@

#include "net.h"

/* <settings checks> */
enum pop3c_features {
POP3C_FEATURE_NO_PIPELINING = 0x1,
};
/* </settings checks> */


struct pop3c_settings {
const char *pop3c_host;
in_port_t pop3c_port;
Expand All @@ -16,6 +23,9 @@ struct pop3c_settings {

const char *pop3c_rawlog_dir;
bool pop3c_quick_received_date;

const char *pop3c_features;
enum pop3c_features parsed_features;
};

const struct setting_parser_info *pop3c_get_setting_parser_info(void);
Expand Down
1 change: 0 additions & 1 deletion src/lib-storage/index/pop3c/pop3c-storage.c
Expand Up @@ -8,7 +8,6 @@
#include "mailbox-list-private.h"
#include "index-mail.h"
#include "pop3c-client.h"
#include "pop3c-settings.h"
#include "pop3c-sync.h"
#include "pop3c-storage.h"

Expand Down

0 comments on commit ec3eb53

Please sign in to comment.