1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
3
#include "imap-common.h"
4
#include "imap-metadata.h"
6
bool imap_metadata_verify_entry_name(struct client_command_context *cmd,
13
client_send_command_error(cmd,
14
"Entry name must begin with '/'");
17
for (i = 0; name[i] != '\0'; i++) {
20
if (i > 0 && name[i-1] == '/') {
21
client_send_command_error(cmd,
22
"Entry name can't contain consecutive '/'");
25
if (name[i+1] == '\0') {
26
client_send_command_error(cmd,
27
"Entry name can't end with '/'");
32
client_send_command_error(cmd,
33
"Entry name can't contain '*'");
36
client_send_command_error(cmd,
37
"Entry name can't contain '%'");
40
if (name[i] <= 0x19) {
41
client_send_command_error(cmd,
42
"Entry name can't contain control chars");
49
const char *prefix, *p = strchr(name+1, '/');
51
prefix = p == NULL ? name : t_strdup_until(name, p);
52
ok = strcasecmp(prefix, IMAP_METADATA_PRIVATE_PREFIX) == 0 ||
53
strcasecmp(prefix, IMAP_METADATA_SHARED_PREFIX) == 0;
56
client_send_command_error(cmd,
57
"Entry name must begin with /private or /shared");
63
void imap_metadata_entry2key(const char *entry, const char *key_prefix,
64
enum mail_attribute_type *type_r,
67
if (strncmp(entry, IMAP_METADATA_PRIVATE_PREFIX,
68
strlen(IMAP_METADATA_PRIVATE_PREFIX)) == 0) {
69
*key_r = entry + strlen(IMAP_METADATA_PRIVATE_PREFIX);
70
*type_r = MAIL_ATTRIBUTE_TYPE_PRIVATE;
72
i_assert(strncmp(entry, IMAP_METADATA_SHARED_PREFIX,
73
strlen(IMAP_METADATA_SHARED_PREFIX)) == 0);
74
*key_r = entry + strlen(IMAP_METADATA_SHARED_PREFIX);
75
*type_r = MAIL_ATTRIBUTE_TYPE_SHARED;
77
if ((*key_r)[0] == '\0') {
78
/* /private or /shared prefix has no value itself */
80
i_assert((*key_r)[0] == '/');
83
if (key_prefix != NULL)
84
*key_r = t_strconcat(key_prefix, *key_r, NULL);