Skip to content

profile: Add configuration to allow for independent configuration of imap/pop3/lmtp hosts - #127

Open
slusarz wants to merge 8 commits into
dovecot:mainfrom
slusarz:profile_multi_host
Open

slusarz wants to merge 8 commits into
dovecot:mainfrom
slusarz:profile_multi_host

Conversation

@slusarz

@slusarz slusarz commented May 22, 2026

Copy link
Copy Markdown
Contributor

Closes #126

Comment thread src/profile-parse.c
Comment thread src/profile.c
@slusarz
slusarz force-pushed the profile_multi_host branch from 8dd4720 to 23d080c Compare May 22, 2026 20:45
Comment thread src/profile-parse.c

const struct profile_hostport profile_hostport_default_settings = {
.host = NULL,
.port = (unsigned int)-1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UINT_MAX is what we nowadays use, since this gives some complaints somewhere. Also, end with a comma.

Comment thread src/profile-parse.c
}

static void parser_close_hostport(struct profile_parser *parser,
const struct profile_hostport *hp)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent isn't right

Comment thread src/profile-parse.c
{
unsigned int port = hp->port;

if (port == (unsigned int)-1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UINT_MAX

Comment thread src/profile.h Outdated
unsigned int pop3_port;
/* Deprecated: use lmtp {} { port = ... } instead. Kept for backward
* compatibility with existing profile configs that still use the
* global lmtp_port setting. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this deprecation warning is correct here? There is imap_port, pop3_port so there must be lmtp_port as well in here. There is already a deprecation comment earlier in lmtp_port setting parsing.

Comment thread src/profile.h
ARRAY_TYPE(ip_addr_array) imap_ips;
ARRAY_TYPE(ip_addr_array) pop3_ips;
ARRAY_TYPE(ip_addr_array) lmtp_ips;
unsigned int lmtp_ip_idx;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These IP things belong to the next commit.

Comment thread src/test-profile-parser.c
size_t len;

snprintf(path, sizeof(path), "/tmp/imaptest-profile-XXXXXX");
fd = mkstemp(path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's a unit test, but still .. lets use Dovecot's safe functions. Like here safe_mkstemp()

Comment thread src/test-profile-parser.c
snprintf(path, sizeof(path), "/tmp/imaptest-profile-XXXXXX");
fd = mkstemp(path);
if (fd < 0) {
fprintf(stderr, "mkstemp failed: %s\n", strerror(errno));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Dovecot logging functions, like i_error()

Comment thread src/test-profile-parser.c
if (write(fd, data, len) != (ssize_t)len) {
fprintf(stderr, "write failed: %s\n", strerror(errno));
close(fd);
unlink(path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i_close_fd, i_unlink (or i_unlink_if_exists). Here and elsewhere.

Comment thread src/test-profile-parser.c
return NULL;
}
close(fd);
return i_strdup(path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With safe_mkstemp() return the path string from data stack, and avoid i_free()s in callers.

Comment thread src/pop3-client.c Outdated
port = conf.port;
else
port = POP3_DEFAULT_PORT;
client->client.port = port;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying amount of code duplication for imap/pop3/lmtp related to all this. Not sure if it's worth the trouble to deduplicate.

slusarz added 8 commits June 10, 2026 10:27
- Refactor IP rotation in profile mode to ensure IMAP, POP3, and LMTP
  each maintain their own independent IP pool and rotation index.
- Update client_init() to accept an explicit IP address, moving the
  selection logic to protocol-specific constructors.
- Perform upfront host resolution for all protocols in profile mode.
- Completely bypass global connection state (conf.ips/ip_idx) when
  running in profile mode.
@slusarz
slusarz force-pushed the profile_multi_host branch from 23d080c to 58a300d Compare June 10, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature - different endpoints

3 participants