This avoids accidents with the array numbering being wrong.
static const struct var_expand_table *
imap_client_get_var_expand_table(struct imap_client *client)
{
- static struct var_expand_table static_tab[] = {
- { 'u', NULL, "user" },
- { 'n', NULL, "username" },
- { 'd', NULL, "domain" },
- { 's', NULL, "service" },
- { 'h', NULL, "home" },
- { 'l', NULL, "lip" },
- { 'r', NULL, "rip" },
- { 'p', NULL, "pid" },
- { 'i', NULL, "uid" },
- { '\0', NULL, "gid" },
- { '\0', NULL, "session" },
- { '\0', NULL, "auth_user" },
- { '\0', NULL, "auth_username" },
- { '\0', NULL, "auth_domain" },
- /* NOTE: keep this synced with lib-storage's
- mail_user_var_expand_table() */
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
- const char *auth_user;
-
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = client->state.username;
- tab[1].value = t_strcut(client->state.username, '@');
- tab[2].value = i_strchr_to_next(client->state.username, '@');
- tab[3].value = "imap-hibernate";
- tab[4].value = NULL; /* we shouldn't need this */
- tab[5].value = client->state.local_ip.family == 0 ? NULL :
+ const char *username = t_strcut(client->state.username, '@');
+ const char *domain = i_strchr_to_next(client->state.username, '@');
+ const char *local_ip = client->state.local_ip.family == 0 ? NULL :
net_ip2addr(&client->state.local_ip);
- tab[6].value = client->state.remote_ip.family == 0 ? NULL :
+ const char *remote_ip = client->state.remote_ip.family == 0 ? NULL :
net_ip2addr(&client->state.remote_ip);
- tab[7].value = my_pid;
- tab[8].value = dec2str(client->state.uid);
- tab[9].value = dec2str(client->state.gid);
- tab[10].value = client->state.session_id;
+ const char *auth_user, *auth_username, *auth_domain;
imap_client_parse_userdb_fields(client, &auth_user);
if (auth_user == NULL) {
- tab[11].value = tab[0].value;
- tab[12].value = tab[1].value;
- tab[13].value = tab[2].value;
+ auth_user = client->state.username;
+ auth_username = username;
+ auth_domain = domain;
} else {
- tab[11].value = auth_user;
- tab[12].value = t_strcut(auth_user, '@');
- tab[13].value = i_strchr_to_next(auth_user, '@');
- }
+ auth_username = t_strcut(auth_user, '@');
+ auth_domain = i_strchr_to_next(auth_user, '@');
+ }
+
+ const struct var_expand_table stack_tab[] = {
+ { 'u', client->state.username, "user" },
+ { 'n', username, "username" },
+ { 'd', domain, "domain" },
+ { 's', "imap-hibernate", "service" },
+ { 'h', NULL /* we shouldn't need this */, "home" },
+ { 'l', local_ip, "lip" },
+ { 'r', remote_ip, "rip" },
+ { 'p', my_pid, "pid" },
+ { 'i', dec2str(client->state.uid), "uid" },
+ { '\0', dec2str(client->state.gid), "gid" },
+ { '\0', client->state.session_id, "session" },
+ { '\0', auth_user, "auth_user" },
+ { '\0', auth_username, "auth_username" },
+ { '\0', auth_domain, "auth_domain" },
+ /* NOTE: keep this synced with lib-storage's
+ mail_user_var_expand_table() */
+ { '\0', NULL, NULL }
+ };
+ struct var_expand_table *tab;
+
+ tab = t_malloc_no0(sizeof(stack_tab));
+ memcpy(tab, stack_tab, sizeof(stack_tab));
return tab;
}
const char *client_stats(struct client *client)
{
- static struct var_expand_table static_tab[] = {
- { 'i', NULL, "input" },
- { 'o', NULL, "output" },
- { '\0', NULL, "session" },
- { '\0', NULL, "fetch_hdr_count" },
- { '\0', NULL, "fetch_hdr_bytes" },
- { '\0', NULL, "fetch_body_count" },
- { '\0', NULL, "fetch_body_bytes" },
- { '\0', NULL, "deleted" },
- { '\0', NULL, "expunged" },
- { '\0', NULL, "trashed" },
+ const struct var_expand_table tab[] = {
+ { 'i', dec2str(i_stream_get_absolute_offset(client->input)), "input" },
+ { 'o', dec2str(client->output->offset), "output" },
+ { '\0', client->session_id, "session" },
+ { '\0', dec2str(client->fetch_hdr_count), "fetch_hdr_count" },
+ { '\0', dec2str(client->fetch_hdr_bytes), "fetch_hdr_bytes" },
+ { '\0', dec2str(client->fetch_body_count), "fetch_body_count" },
+ { '\0', dec2str(client->fetch_body_bytes), "fetch_body_bytes" },
+ { '\0', dec2str(client->deleted_count), "deleted" },
+ { '\0', dec2str(client->expunged_count), "expunged" },
+ { '\0', dec2str(client->trashed_count), "trashed" },
{ '\0', NULL, NULL }
};
- struct var_expand_table *tab;
string_t *str;
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = dec2str(i_stream_get_absolute_offset(client->input));
- tab[1].value = dec2str(client->output->offset);
- tab[2].value = client->session_id;
- tab[3].value = dec2str(client->fetch_hdr_count);
- tab[4].value = dec2str(client->fetch_hdr_bytes);
- tab[5].value = dec2str(client->fetch_body_count);
- tab[6].value = dec2str(client->fetch_body_bytes);
- tab[7].value = dec2str(client->deleted_count);
- tab[8].value = dec2str(client->expunged_count);
- tab[9].value = dec2str(client->trashed_count);
-
str = t_str_new(128);
var_expand(str, client->set->imap_logout_format, tab);
return str_c(str);
mail_deliver_log_var_expand_table_update_times(struct mail_deliver_context *ctx,
struct var_expand_table *tab)
{
-#define VAR_EXPAND_SESSION_TIME_IDX 7
+#define VAR_EXPAND_DELIVERY_TIME_IDX 7
int delivery_time_msecs;
io_loop_time_refresh();
delivery_time_msecs = timeval_diff_msecs(&ioloop_timeval,
&ctx->delivery_time_started);
- tab[VAR_EXPAND_SESSION_TIME_IDX].value = dec2str(delivery_time_msecs);
+ tab[VAR_EXPAND_DELIVERY_TIME_IDX].value = dec2str(delivery_time_msecs);
}
static const struct var_expand_table *
struct mail *mail,
const char *message)
{
- static struct var_expand_table static_tab[] = {
- { '$', NULL, NULL },
- { 'm', NULL, "msgid" },
- { 's', NULL, "subject" },
- { 'f', NULL, "from" },
- { 'e', NULL, "from_envelope" },
- { 'p', NULL, "size" },
- { 'w', NULL, "vsize" },
- { '\0', NULL, "delivery_time" },
- { '\0', NULL, "session_time" },
- { '\0', NULL, "to_envelope" },
- { '\0', NULL, "storage_id" },
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
- const char *str;
+ const char *message_id, *subject = NULL, *from_envelope = NULL;
+ const char *from, *psize = NULL, *vsize = NULL, *storage_id = NULL;
+ const char *session_time = NULL, *to_envelope = NULL;
uoff_t size;
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = message;
- (void)mail_get_first_header(mail, "Message-ID", &tab[1].value);
- tab[1].value = tab[1].value == NULL ? "unspecified" :
- str_sanitize(tab[1].value, 200);
+ if (mail_get_first_header(mail, "Message-ID", &message_id) <= 0)
+ message_id = "unspecified";
+ else
+ message_id = str_sanitize(message_id, 200);
- (void)mail_get_first_header_utf8(mail, "Subject", &tab[2].value);
- tab[2].value = str_sanitize(tab[2].value, 80);
- tab[3].value = str_sanitize(mail_deliver_get_address(mail, "From"), 80);
+ if (mail_get_first_header_utf8(mail, "Subject", &subject) > 0)
+ subject = str_sanitize(subject, 80);
+ from = str_sanitize(mail_deliver_get_address(mail, "From"), 80);
- if (mail_get_special(mail, MAIL_FETCH_FROM_ENVELOPE, &str) < 0)
- str = "";
- tab[4].value = str_sanitize(str, 80);
+ if (mail_get_special(mail, MAIL_FETCH_FROM_ENVELOPE, &from_envelope) > 0)
+ from_envelope = str_sanitize(from_envelope, 80);
if (mail_get_physical_size(mail, &size) == 0)
- tab[5].value = dec2str(size);
+ psize = dec2str(size);
if (mail_get_virtual_size(mail, &size) == 0)
- tab[6].value = dec2str(size);
+ vsize = dec2str(size);
if (ctx != NULL) {
- mail_deliver_log_var_expand_table_update_times(ctx, tab);
- tab[8].value = dec2str(ctx->session_time_msecs);
- tab[9].value = ctx->dest_addr;
+ session_time = dec2str(ctx->session_time_msecs);
+ to_envelope = ctx->dest_addr;
}
- (void)mail_get_special(mail, MAIL_FETCH_STORAGE_ID, &tab[10].value);
+ (void)mail_get_special(mail, MAIL_FETCH_STORAGE_ID, &storage_id);
+
+ const struct var_expand_table stack_tab[] = {
+ { '$', message, NULL },
+ { 'm', message_id, "msgid" },
+ { 's', subject, "subject" },
+ { 'f', from, "from" },
+ { 'e', from_envelope, "from_envelope" },
+ { 'p', psize, "size" },
+ { 'w', vsize, "vsize" },
+ /* must be VAR_EXPAND_DELIVERY_TIME_IDX */
+ { '\0', NULL, "delivery_time" },
+ { '\0', session_time, "session_time" },
+ { '\0', to_envelope, "to_envelope" },
+ { '\0', storage_id, "storage_id" },
+ { '\0', NULL, NULL }
+ };
+ struct var_expand_table *tab;
+
+ tab = t_malloc_no0(sizeof(stack_tab));
+ memcpy(tab, stack_tab, sizeof(stack_tab));
+ if (ctx != NULL)
+ mail_deliver_log_var_expand_table_update_times(ctx, tab);
return tab;
}
mail_deliver_log_var_expand_table_update_times(ctx, ctx->var_expand_table);
var_expand(str, ctx->set->deliver_log_format, ctx->var_expand_table);
ctx->var_expand_table[0].value = "";
- ctx->var_expand_table[VAR_EXPAND_SESSION_TIME_IDX].value = "";
+ ctx->var_expand_table[VAR_EXPAND_DELIVERY_TIME_IDX].value = "";
i_info("%s", str_c(str));
va_end(args);
get_var_expand_table(struct mail *mail, const char *reason,
const char *recipient)
{
- static struct var_expand_table static_tab[] = {
- { 'n', NULL, "crlf" },
- { 'r', NULL, "reason" },
- { 's', NULL, "subject" },
- { 't', NULL, "to" },
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
const char *subject;
-
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = "\r\n";
- tab[1].value = reason;
if (mail_get_first_header(mail, "Subject", &subject) <= 0)
subject = "";
- tab[2].value = str_sanitize(subject, 80);
- tab[3].value = recipient;
+ const struct var_expand_table stack_tab[] = {
+ { 'n', "\r\n", "crlf" },
+ { 'r', reason, "reason" },
+ { 's', subject, "subject" },
+ { 't', recipient, "to" },
+ { '\0', NULL, NULL }
+ };
+ struct var_expand_table *tab;
+
+ tab = t_malloc_no0(sizeof(stack_tab));
+ memcpy(tab, stack_tab, sizeof(stack_tab));
return tab;
}
unsigned int mail_user_hash(const char *username, const char *format)
{
- static struct var_expand_table static_tab[] = {
- { 'u', NULL, "user" },
- { 'n', NULL, "username" },
- { 'd', NULL, "domain" },
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
unsigned char md5[MD5_RESULTLEN];
unsigned int i, hash = 0;
strlen(username), md5);
} T_END;
} else T_BEGIN {
+ const struct var_expand_table tab[] = {
+ { 'u', username, "user" },
+ { 'n', t_strcut(username, '@'), "username" },
+ { 'd', i_strchr_to_next(username, '@'), "domain" },
+ { '\0', NULL, NULL }
+ };
string_t *str = t_str_new(128);
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
- tab[0].value = username;
- tab[1].value = t_strcut(username, '@');
- tab[2].value = i_strchr_to_next(username, '@');
-
var_expand(str, format, tab);
md5_get_digest(str_data(str), str_len(str), md5);
} T_END;
struct mailbox_list *list = (*_ns)->list;
struct shared_storage *storage = (struct shared_storage *)_storage;
struct mail_user *user = _storage->user;
- static struct var_expand_table static_tab[] = {
- { 'u', NULL, "user" },
- { 'n', NULL, "username" },
- { 'd', NULL, "domain" },
- { 'h', NULL, "home" },
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
struct mail_namespace *new_ns, *ns = *_ns;
struct mail_namespace_settings *ns_set, *unexpanded_ns_set;
struct mail_user *owner;
/* expand the namespace prefix and see if it already exists.
this should normally happen only when the mailbox is being opened */
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
- tab[0].value = userdomain;
- tab[1].value = username;
- tab[2].value = domain;
+ struct var_expand_table tab[] = {
+ { 'u', userdomain, "user" },
+ { 'n', username, "username" },
+ { 'd', domain, "domain" },
+ { 'h', NULL, "home" },
+ { '\0', NULL, NULL }
+ };
prefix = t_str_new(128);
str_append(prefix, ns->prefix);
const struct mail_storage_service_input *input,
const struct mail_storage_service_privileges *priv)
{
- static struct var_expand_table static_tab[] = {
- { 'u', NULL, "user" },
- { 'n', NULL, "username" },
- { 'd', NULL, "domain" },
- { 's', NULL, "service" },
- { 'l', NULL, "lip" },
- { 'r', NULL, "rip" },
- { 'p', NULL, "pid" },
- { 'i', NULL, "uid" },
- { '\0', NULL, "gid" },
- { '\0', NULL, "session" },
- { '\0', NULL, "auth_user" },
- { '\0', NULL, "auth_username" },
- { '\0', NULL, "auth_domain" },
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
-
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = input->username;
- tab[1].value = t_strcut(input->username, '@');
- tab[2].value = i_strchr_to_next(input->username, '@');
- tab[3].value = service->name;
- tab[4].value = net_ip2addr(&input->local_ip);
- tab[5].value = net_ip2addr(&input->remote_ip);
- tab[6].value = my_pid;
- tab[7].value = priv == NULL ? NULL :
+ const char *username = t_strcut(input->username, '@');
+ const char *domain = i_strchr_to_next(input->username, '@');
+ const char *uid = priv == NULL ? NULL :
dec2str(priv->uid == (uid_t)-1 ? geteuid() : priv->uid);
- tab[8].value = priv == NULL ? NULL :
+ const char *gid = priv == NULL ? NULL :
dec2str(priv->gid == (gid_t)-1 ? getegid() : priv->gid);
- tab[9].value = input->session_id;
+
+ const char *auth_user, *auth_username, *auth_domain;
if (user == NULL || user->auth_user == NULL) {
- tab[10].value = tab[0].value;
- tab[11].value = tab[1].value;
- tab[12].value = tab[2].value;
+ auth_user = input->username;
+ auth_username = username;
+ auth_domain = domain;
} else {
- tab[10].value = user->auth_user;
- tab[11].value = t_strcut(user->auth_user, '@');
- tab[12].value = i_strchr_to_next(user->auth_user, '@');
- }
+ auth_user = user->auth_user;
+ auth_username = t_strcut(user->auth_user, '@');
+ auth_domain = i_strchr_to_next(user->auth_user, '@');
+ }
+
+ const struct var_expand_table stack_tab[] = {
+ { 'u', input->username, "user" },
+ { 'n', username, "username" },
+ { 'd', domain, "domain" },
+ { 's', service->name, "service" },
+ { 'l', net_ip2addr(&input->local_ip), "lip" },
+ { 'r', net_ip2addr(&input->remote_ip), "rip" },
+ { 'p', my_pid, "pid" },
+ { 'i', uid, "uid" },
+ { '\0', gid, "gid" },
+ { '\0', input->session_id, "session" },
+ { '\0', auth_user, "auth_user" },
+ { '\0', auth_username, "auth_username" },
+ { '\0', auth_domain, "auth_domain" },
+ { '\0', NULL, NULL }
+ };
+ struct var_expand_table *tab;
+
+ tab = t_malloc_no0(sizeof(stack_tab));
+ memcpy(tab, stack_tab, sizeof(stack_tab));
return tab;
}
const struct var_expand_table *
mail_user_var_expand_table(struct mail_user *user)
{
- static struct var_expand_table static_tab[] = {
- { 'u', NULL, "user" },
- { 'n', NULL, "username" },
- { 'd', NULL, "domain" },
- { 's', NULL, "service" },
- { 'h', NULL, "home" },
- { 'l', NULL, "lip" },
- { 'r', NULL, "rip" },
- { 'p', NULL, "pid" },
- { 'i', NULL, "uid" },
- { '\0', NULL, "gid" },
- { '\0', NULL, "session" },
- { '\0', NULL, "auth_user" },
- { '\0', NULL, "auth_username" },
- { '\0', NULL, "auth_domain" },
- /* NOTE: keep this synced with imap-hibernate's
- imap_client_var_expand_table() */
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
-
/* use a cached table, unless home directory has been set afterwards */
if (user->var_expand_table != NULL &&
user->var_expand_table[4].value == user->_home)
return user->var_expand_table;
- tab = p_malloc(user->pool, sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = user->username;
- tab[1].value = p_strdup(user->pool, t_strcut(user->username, '@'));
- tab[2].value = i_strchr_to_next(user->username, '@');
- tab[3].value = user->service;
- tab[4].value = user->_home; /* don't look it up unless we need it */
- tab[5].value = user->local_ip == NULL ? NULL :
+ const char *username =
+ p_strdup(user->pool, t_strcut(user->username, '@'));
+ const char *domain = i_strchr_to_next(user->username, '@');
+ const char *local_ip = user->local_ip == NULL ? NULL :
p_strdup(user->pool, net_ip2addr(user->local_ip));
- tab[6].value = user->remote_ip == NULL ? NULL :
+ const char *remote_ip = user->remote_ip == NULL ? NULL :
p_strdup(user->pool, net_ip2addr(user->remote_ip));
- tab[7].value = my_pid;
- tab[8].value = p_strdup(user->pool, dec2str(user->uid));
- tab[9].value = p_strdup(user->pool, dec2str(user->gid));
- tab[10].value = user->session_id;
+
+ const char *auth_user, *auth_username, *auth_domain;
if (user->auth_user == NULL) {
- tab[11].value = tab[0].value;
- tab[12].value = tab[1].value;
- tab[13].value = tab[2].value;
+ auth_user = user->username;
+ auth_username = username;
+ auth_domain = domain;
} else {
- tab[11].value = user->auth_user;
- tab[12].value = p_strdup(user->pool, t_strcut(user->auth_user, '@'));
- tab[13].value = i_strchr_to_next(user->auth_user, '@');
+ auth_user = user->auth_user;
+ auth_username =
+ p_strdup(user->pool, t_strcut(user->auth_user, '@'));
+ auth_domain = i_strchr_to_next(user->auth_user, '@');
}
+ const struct var_expand_table stack_tab[] = {
+ { 'u', user->username, "user" },
+ { 'n', username, "username" },
+ { 'd', domain, "domain" },
+ { 's', user->service, "service" },
+ { 'h', user->_home /* don't look it up unless we need it */, "home" },
+ { 'l', local_ip, "lip" },
+ { 'r', remote_ip, "rip" },
+ { 'p', my_pid, "pid" },
+ { 'i', p_strdup(user->pool, dec2str(user->uid)), "uid" },
+ { '\0', p_strdup(user->pool, dec2str(user->gid)), "gid" },
+ { '\0', user->session_id, "session" },
+ { '\0', auth_user, "auth_user" },
+ { '\0', auth_username, "auth_username" },
+ { '\0', auth_domain, "auth_domain" },
+ /* NOTE: keep this synced with imap-hibernate's
+ imap_client_var_expand_table() */
+ { '\0', NULL, NULL }
+ };
+ struct var_expand_table *tab;
+
+ tab = p_malloc(user->pool, sizeof(stack_tab));
+ memcpy(tab, stack_tab, sizeof(stack_tab));
+
user->var_expand_table = tab;
return user->var_expand_table;
}
static const char *
client_get_log_str(struct client *client, const char *msg)
{
- static const struct var_expand_table static_tab[3] = {
- { 's', NULL, NULL },
- { '$', NULL, NULL },
- { '\0', NULL, NULL }
- };
static const struct var_expand_func_table func_table[] = {
{ "passdb", client_var_expand_func_passdb },
{ NULL, NULL }
};
const struct var_expand_table *var_expand_table;
- struct var_expand_table *tab;
char *const *e;
string_t *str, *str2;
unsigned int pos;
var_expand_table = get_var_expand_table(client);
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
str = t_str_new(256);
str2 = t_str_new(128);
for (e = client->set->log_format_elements_split; *e != NULL; e++) {
if (str_len(str) > 0)
str_truncate(str, str_len(str)-2);
- tab[0].value = t_strdup(str_c(str));
- tab[1].value = msg;
- str_truncate(str, 0);
+ const struct var_expand_table tab[3] = {
+ { 's', t_strdup(str_c(str)), NULL },
+ { '$', msg, NULL },
+ { '\0', NULL, NULL }
+ };
+ str_truncate(str, 0);
var_expand(str, client->set->login_log_format, tab);
return str_c(str);
}
static const struct var_expand_table *
login_set_var_expand_table(const struct master_service_settings_input *input)
{
- static struct var_expand_table static_tab[] = {
- { 'l', NULL, "lip" },
- { 'r', NULL, "rip" },
- { 'p', NULL, "pid" },
- { 's', NULL, "service" },
- { '\0', NULL, "local_name" },
+ const struct var_expand_table stack_tab[] = {
+ { 'l', net_ip2addr(&input->local_ip), "lip" },
+ { 'r', net_ip2addr(&input->remote_ip), "rip" },
+ { 'p', my_pid, "pid" },
+ { 's', input->service, "service" },
+ { '\0', input->local_name, "local_name" },
{ '\0', NULL, NULL }
};
struct var_expand_table *tab;
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = net_ip2addr(&input->local_ip);
- tab[1].value = net_ip2addr(&input->remote_ip);
- tab[2].value = my_pid;
- tab[3].value = input->service;
- tab[4].value = input->local_name;
+ tab = t_malloc_no0(sizeof(stack_tab));
+ memcpy(tab, stack_tab, sizeof(stack_tab));
return tab;
}
acl_shared_namespace_add(struct mail_namespace *ns,
struct mail_storage *storage, const char *userdomain)
{
- static struct var_expand_table static_tab[] = {
- { 'u', NULL, "user" },
- { 'n', NULL, "username" },
- { 'd', NULL, "domain" },
- { '\0', NULL, NULL }
- };
struct shared_storage *sstorage = (struct shared_storage *)storage;
struct mail_namespace *new_ns = ns;
- struct var_expand_table *tab;
struct mailbox_list_iterate_context *iter;
const struct mailbox_info *info;
- const char *p, *mailbox;
+ const char *mailbox;
string_t *str;
if (strcmp(ns->user->username, userdomain) == 0) {
return;
}
- p = strchr(userdomain, '@');
-
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
- tab[0].value = userdomain;
- tab[1].value = p == NULL ? userdomain : t_strdup_until(userdomain, p);
- tab[2].value = p == NULL ? "" : p + 1;
+ const struct var_expand_table tab[] = {
+ { 'u', userdomain, "user" },
+ { 'n', t_strcut(userdomain, '@'), "username" },
+ { 'd', i_strchr_to_next(userdomain, '@'), "domain" },
+ { '\0', NULL, NULL }
+ };
str = t_str_new(128);
var_expand(str, sstorage->ns_prefix_pattern, tab);
static const char *client_stats(struct client *client)
{
- static struct var_expand_table static_tab[] = {
- { 'p', NULL, "top_bytes" },
- { 't', NULL, "top_count" },
- { 'b', NULL, "retr_bytes" },
- { 'r', NULL, "retr_count" },
- { 'd', NULL, "deleted_count" },
- { 'm', NULL, "message_count" },
- { 's', NULL, "message_bytes" },
- { 'i', NULL, "input" },
- { 'o', NULL, "output" },
- { 'u', NULL, "uidl_change" },
- { '\0', NULL, "session" },
- { 'd', NULL, "deleted_bytes" },
+ const char *uidl_change = "";
+ if (var_has_key(client->set->pop3_logout_format,
+ 'o', "uidl_change"))
+ uidl_change = client_build_uidl_change_string(client);
+
+ const struct var_expand_table tab[] = {
+ { 'p', dec2str(client->top_bytes), "top_bytes" },
+ { 't', dec2str(client->top_count), "top_count" },
+ { 'b', dec2str(client->retr_bytes), "retr_bytes" },
+ { 'r', dec2str(client->retr_count), "retr_count" },
+ { 'd', !client->delete_success ? "0" :
+ dec2str(client->deleted_count), "deleted_count" },
+ { 'm', dec2str(client->messages_count), "message_count" },
+ { 's', dec2str(client->total_size), "message_bytes" },
+ { 'i', dec2str(client->input->v_offset), "input" },
+ { 'o', dec2str(client->output->offset), "output" },
+ { 'u', uidl_change, "uidl_change" },
+ { '\0', client->session_id, "session" },
+ { 'd', !client->delete_success ? "0" :
+ dec2str(client->deleted_size), "deleted_bytes" },
{ '\0', NULL, NULL }
};
- struct var_expand_table *tab;
string_t *str;
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
-
- tab[0].value = dec2str(client->top_bytes);
- tab[1].value = dec2str(client->top_count);
- tab[2].value = dec2str(client->retr_bytes);
- tab[3].value = dec2str(client->retr_count);
- tab[4].value = client->delete_success ?
- dec2str(client->deleted_count) : "0";
- tab[5].value = dec2str(client->messages_count);
- tab[6].value = dec2str(client->total_size);
- tab[7].value = dec2str(client->input->v_offset);
- tab[8].value = dec2str(client->output->offset);
- if (var_has_key(client->set->pop3_logout_format,
- tab[9].key, tab[9].long_key))
- tab[9].value = client_build_uidl_change_string(client);
- else
- tab[9].value = "";
- tab[10].value = client->session_id;
- tab[11].value = client->delete_success ?
- dec2str(client->deleted_size) : "0";
-
str = t_str_new(128);
var_expand(str, client->set->pop3_logout_format, tab);
return str_c(str);
pop3_get_uid(struct client *client, struct mail *mail, string_t *str,
bool *permanent_uidl_r)
{
- static struct var_expand_table static_tab[] = {
- { 'v', NULL, "uidvalidity" },
- { 'u', NULL, "uid" },
- { 'm', NULL, "md5" },
- { 'f', NULL, "filename" },
- { 'g', NULL, "guid" },
- { '\0', NULL, NULL }
- };
- struct var_expand_table *tab;
- char uid_str[MAX_INT_STRLEN];
+ char uid_str[MAX_INT_STRLEN] = { 0 };
const char *uidl;
+ const char *hdr_md5 = NULL, *filename = NULL, *guid = NULL;
if (mail_get_special(mail, MAIL_FETCH_UIDL_BACKEND, &uidl) == 0 &&
*uidl != '\0') {
return 0;
}
- tab = t_malloc_no0(sizeof(static_tab));
- memcpy(tab, static_tab, sizeof(static_tab));
- tab[0].value = t_strdup_printf("%u", client->uid_validity);
-
if ((client->uidl_keymask & UIDL_UID) != 0) {
if (i_snprintf(uid_str, sizeof(uid_str), "%u", mail->uid) < 0)
i_unreached();
- tab[1].value = uid_str;
}
if ((client->uidl_keymask & UIDL_MD5) != 0) {
if (mail_get_special(mail, MAIL_FETCH_HEADER_MD5,
- &tab[2].value) < 0) {
+ &hdr_md5) < 0) {
i_error("UIDL: Header MD5 lookup failed: %s",
mailbox_get_last_error(mail->box, NULL));
return -1;
- } else if (*tab[2].value == '\0') {
+ } else if (hdr_md5[0] == '\0') {
i_error("UIDL: Header MD5 not found "
"(pop3_uidl_format=%%m not supported by storage?)");
return -1;
}
if ((client->uidl_keymask & UIDL_FILE_NAME) != 0) {
if (mail_get_special(mail, MAIL_FETCH_STORAGE_ID,
- &tab[3].value) < 0) {
+ &filename) < 0) {
i_error("UIDL: File name lookup failed: %s",
mailbox_get_last_error(mail->box, NULL));
return -1;
- } else if (*tab[3].value == '\0') {
+ } else if (filename[0] == '\0') {
i_error("UIDL: File name not found "
"(pop3_uidl_format=%%f not supported by storage?)");
return -1;
}
if ((client->uidl_keymask & UIDL_GUID) != 0) {
if (mail_get_special(mail, MAIL_FETCH_GUID,
- &tab[4].value) < 0) {
+ &guid) < 0) {
i_error("UIDL: Message GUID lookup failed: %s",
mailbox_get_last_error(mail->box, NULL));
return -1;
- } else if (*tab[4].value == '\0') {
+ } else if (guid[0] == '\0') {
i_error("UIDL: Message GUID not found "
"(pop3_uidl_format=%%g not supported by storage?)");
return -1;
}
}
+
+ const struct var_expand_table tab[] = {
+ { 'v', dec2str(client->uid_validity), "uidvalidity" },
+ { 'u', uid_str, "uid" },
+ { 'm', hdr_md5, "md5" },
+ { 'f', filename, "filename" },
+ { 'g', guid, "guid" },
+ { '\0', NULL, NULL }
+ };
var_expand(str, client->mail_set->pop3_uidl_format, tab);
return 0;
}