# include <sys/utsname.h>
#endif
+/* Limit the allowed characters that an IMAP ID parameter might have. */
+#define IMAP_ID_KEY_ACCEPT_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_-"
+
static struct utsname utsname_result;
static bool utsname_set = FALSE;
}
return str_len(reply) == 0 ? NULL : str_c(reply);
}
+
+void
+imap_id_add_log_entry(struct imap_id_log_entry *log_entry, const char *key,
+ const char *value)
+{
+ if (str_len(log_entry->reply) > 0)
+ str_append(log_entry->reply, ", ");
+ str_append(log_entry->reply, key);
+ str_append_c(log_entry->reply, '=');
+ str_append(log_entry->reply, value == NULL ? "NIL" : value);
+
+ const char *l_key = t_str_lcase(key);
+ const char *prefixed_key;
+ const char *val_str = value == NULL ? "NIL" : value;
+ if (strspn(l_key, IMAP_ID_KEY_ACCEPT_CHARS) == strlen(l_key)) {
+ prefixed_key = t_strconcat("id_param_", l_key, NULL);
+ event_add_str(log_entry->event, prefixed_key, val_str);
+ } else {
+ prefixed_key = t_strdup_printf("id_invalid%u",
+ ++log_entry->invalid_key_id_counter);
+ const char *key_val = t_strconcat(key, " ", val_str, NULL);
+ event_add_str(log_entry->event, prefixed_key, key_val);
+ }
+}
struct imap_arg;
+struct imap_id_log_entry {
+ struct event *event;
+ string_t *reply;
+ /* Enumerator variable that increments per ID parameter with invalid
+ characters. For convenience reasons the value is pre-incremented,
+ under the assumption that the value is initialized to 0, it will
+ start enumerating the value with 1. */
+ unsigned int invalid_key_id_counter;
+};
+
/* RFC 2971 says keys are max. 30 octets */
#define IMAP_ID_KEY_MAX_LEN 30
/* Append [, ]key=value to the reply sanitized. */
void imap_id_log_reply_append(string_t *reply, const char *key,
const char *value);
+/* Format the IMAP ID parameters into string-fields of the given event, and
+ into a printable log message. */
+void imap_id_add_log_entry(struct imap_id_log_entry *log_entry,
+ const char *key, const char *value);
#endif