imap_max_line_length);
client->last_input = ioloop_time;
- client->mailbox_flags.pool =
- pool_alloconly_create("mailbox_custom_flags", 512);
+ client->keywords.pool = pool_alloconly_create("mailbox_keywords", 512);
client->namespaces = namespaces;
while (namespaces != NULL) {
i_stream_unref(client->input);
o_stream_unref(client->output);
- pool_unref(client->mailbox_flags.pool);
+ pool_unref(client->keywords.pool);
i_free(client);
/* quit the program */
typedef int command_func_t(struct client *client);
-struct mailbox_custom_flags {
+struct mailbox_keywords {
pool_t pool; /* will be p_clear()ed when changed */
- char **custom_flags;
- unsigned int custom_flags_count;
+ char **keywords;
+ unsigned int keywords_count;
};
struct client {
struct namespace *namespaces;
struct mailbox *mailbox;
- struct mailbox_custom_flags mailbox_flags;
+ struct mailbox_keywords keywords;
unsigned int select_counter; /* increased when mailbox is changed */
time_t last_input;
struct imap_parser *save_parser;
struct imap_arg *args;
struct imap_arg_list *flags_list;
- struct mailbox_custom_flags old_flags;
+ struct mailbox_keywords old_flags;
struct mail_full_flags flags;
struct istream *input;
time_t internal_date;
return TRUE;
}
- if (mailbox_get_status(box, STATUS_CUSTOM_FLAGS, &status) < 0) {
+ if (mailbox_get_status(box, STATUS_KEYWORDS, &status) < 0) {
client_send_storage_error(client, storage);
mailbox_close(box);
return TRUE;
}
memset(&old_flags, 0, sizeof(old_flags));
old_flags.pool = pool_datastack_create();
- client_save_custom_flags(&old_flags, status.custom_flags,
- status.custom_flags_count);
+ client_save_keywords(&old_flags, status.keywords,
+ status.keywords_count);
t = mailbox_transaction_begin(box, FALSE);
if (mailbox_get_status(box, STATUS_MESSAGES | STATUS_RECENT |
STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
- STATUS_UIDNEXT | STATUS_CUSTOM_FLAGS,
+ STATUS_UIDNEXT | STATUS_KEYWORDS,
&status) < 0) {
client_send_storage_error(client, storage);
mailbox_close(box);
return TRUE;
}
- client_save_custom_flags(&client->mailbox_flags, status.custom_flags,
- status.custom_flags_count);
+ client_save_keywords(&client->keywords,
+ status.keywords, status.keywords_count);
/* set client's mailbox only after getting status to make sure
we're not sending any expunge/exists replies too early to client */
client->mailbox = box;
client->select_counter++;
- client_send_mailbox_flags(client, box, status.custom_flags,
- status.custom_flags_count);
+ client_send_mailbox_flags(client, box, status.keywords,
+ status.keywords_count);
client_send_line(client,
t_strdup_printf("* %u EXISTS", status.messages));
if (args[2].type == IMAP_ARG_LIST) {
if (!client_parse_mail_flags(client,
IMAP_ARG_LIST(&args[2])->args,
- &client->mailbox_flags, &flags))
+ &client->keywords, &flags))
return TRUE;
} else {
if (!client_parse_mail_flags(client, args+2,
- &client->mailbox_flags, &flags))
+ &client->keywords, &flags))
return TRUE;
}
/* Copyright (C) 2002-2003 Timo Sirainen */
#include "common.h"
+#include "buffer.h"
#include "str.h"
#include "commands-util.h"
#include "imap-util.h"
t_strconcat(syntax ? "* BAD " : "* NO ", error, NULL));
}
-static int is_valid_custom_flag(struct client *client,
- const struct mailbox_custom_flags *old_flags,
- const char *flag)
+static int is_valid_keyword(struct client *client,
+ const struct mailbox_keywords *old_keywords,
+ const char *keyword)
{
size_t i;
/* if it already exists, skip validity checks */
- for (i = 0; i < old_flags->custom_flags_count; i++) {
- if (old_flags->custom_flags[i] != NULL &&
- strcasecmp(old_flags->custom_flags[i], flag) == 0)
+ for (i = 0; i < old_keywords->keywords_count; i++) {
+ if (old_keywords->keywords[i] != NULL &&
+ strcasecmp(old_keywords->keywords[i], keyword) == 0)
return TRUE;
}
- if (strlen(flag) > max_custom_flag_length) {
+ if (strlen(keyword) > max_keyword_length) {
client_send_tagline(client,
- t_strdup_printf("BAD Invalid flag name '%s': "
+ t_strdup_printf("BAD Invalid keyword name '%s': "
"Maximum length is %u characters",
- flag, max_custom_flag_length));
+ keyword, max_keyword_length));
return FALSE;
}
}
int client_parse_mail_flags(struct client *client, struct imap_arg *args,
- const struct mailbox_custom_flags *old_flags,
+ const struct mailbox_keywords *old_keywords,
struct mail_full_flags *flags)
{
- /* @UNSAFE */
+ const char *const *keywords;
char *atom;
- size_t max_flags, flag_pos, i;
-
- max_flags = MAIL_CUSTOM_FLAGS_COUNT;
+ buffer_t *buffer;
+ size_t size, i;
memset(flags, 0, sizeof(*flags));
- flags->custom_flags = t_new(const char *, max_flags);
+ buffer = buffer_create_dynamic(pool_datastack_create(),
+ 256, (size_t)-1);
- flag_pos = 0;
while (args->type != IMAP_ARG_EOL) {
if (args->type != IMAP_ARG_ATOM) {
client_send_command_error(client,
return FALSE;
}
} else {
- /* custom flag - first make sure it's not a duplicate */
- for (i = 0; i < flag_pos; i++) {
- if (strcasecmp(flags->custom_flags[i],
- atom) == 0)
+ /* keyword - first make sure it's not a duplicate */
+ keywords = buffer_get_data(buffer, &size);
+ size /= sizeof(const char *);
+ for (i = 0; i < size; i++) {
+ if (strcasecmp(keywords[i], atom) == 0)
break;
}
- if (i == max_flags) {
- client_send_tagline(client,
- "Maximum number of different custom "
- "flags exceeded");
- return FALSE;
- }
-
- if (i == flag_pos) {
- if (!is_valid_custom_flag(client, old_flags,
- atom))
+ if (i == size) {
+ if (!is_valid_keyword(client, old_keywords,
+ atom))
return FALSE;
- flags->flags |= 1 << (flag_pos +
- MAIL_CUSTOM_FLAG_1_BIT);
- flags->custom_flags[flag_pos++] = atom;
+ buffer_append(buffer, &atom, sizeof(atom));
}
}
args++;
}
- flags->custom_flags_count = flag_pos;
+ flags->keywords = buffer_get_modifyable_data(buffer, &size);
+ flags->keywords_count = size / sizeof(const char *);
return TRUE;
}
-static const char *get_custom_flags_string(const char *custom_flags[],
- unsigned int custom_flags_count)
+static const char *
+get_keywords_string(const char *keywords[], unsigned int keywords_count)
{
string_t *str;
unsigned int i;
- /* first see if there even is custom flags */
- for (i = 0; i < custom_flags_count; i++) {
- if (custom_flags[i] != NULL)
+ /* first see if there even is keywords */
+ for (i = 0; i < keywords_count; i++) {
+ if (keywords[i] != NULL)
break;
}
- if (i == custom_flags_count)
+ if (i == keywords_count)
return "";
str = t_str_new(256);
- for (; i < custom_flags_count; i++) {
- if (custom_flags[i] != NULL) {
+ for (; i < keywords_count; i++) {
+ if (keywords[i] != NULL) {
str_append_c(str, ' ');
- str_append(str, custom_flags[i]);
+ str_append(str, keywords[i]);
}
}
return str_c(str);
#define SYSTEM_FLAGS "\\Answered \\Flagged \\Deleted \\Seen \\Draft"
void client_send_mailbox_flags(struct client *client, struct mailbox *box,
- const char *custom_flags[],
- unsigned int custom_flags_count)
+ const char *keywords[],
+ unsigned int keywords_count)
{
const char *str;
- str = get_custom_flags_string(custom_flags, custom_flags_count);
+ str = get_keywords_string(keywords, keywords_count);
client_send_line(client,
t_strconcat("* FLAGS ("SYSTEM_FLAGS, str, ")", NULL));
} else {
client_send_line(client,
t_strconcat("* OK [PERMANENTFLAGS ("SYSTEM_FLAGS, str,
- mailbox_allow_new_custom_flags(box) ?
+ mailbox_allow_new_keywords(box) ?
" \\*" : "", ")] Flags permitted.", NULL));
}
}
-void client_save_custom_flags(struct mailbox_custom_flags *dest,
- const char *custom_flags[],
- unsigned int custom_flags_count)
+void client_save_keywords(struct mailbox_keywords *dest,
+ const char *keywords[], unsigned int keywords_count)
{
unsigned int i;
p_clear(dest->pool);
- if (custom_flags_count == 0) {
- dest->custom_flags = NULL;
- dest->custom_flags_count = 0;
+ if (keywords_count == 0) {
+ dest->keywords = NULL;
+ dest->keywords_count = 0;
return;
}
- dest->custom_flags =
- p_new(dest->pool, char *, custom_flags_count);
- dest->custom_flags_count = custom_flags_count;
+ dest->keywords = p_new(dest->pool, char *, keywords_count);
+ dest->keywords_count = keywords_count;
- for (i = 0; i < custom_flags_count; i++)
- dest->custom_flags[i] = p_strdup(dest->pool, custom_flags[i]);
+ for (i = 0; i < keywords_count; i++)
+ dest->keywords[i] = p_strdup(dest->pool, keywords[i]);
}
/* Parse flags. Returns TRUE if successful, if not sends an error message to
client. */
int client_parse_mail_flags(struct client *client, struct imap_arg *args,
- const struct mailbox_custom_flags *old_flags,
+ const struct mailbox_keywords *old_keywords,
struct mail_full_flags *flags);
/* Send FLAGS + PERMANENTFLAGS to client. */
void client_send_mailbox_flags(struct client *client, struct mailbox *box,
- const char *custom_flags[],
- unsigned int custom_flags_count);
+ const char *keywords[],
+ unsigned int keywords_count);
-/* Copy custom flags into dest. dest must have been initialized. */
-void client_save_custom_flags(struct mailbox_custom_flags *dest,
- const char *custom_flags[],
- unsigned int custom_flags_count);
+/* Copy keywords into dest. dest must have been initialized. */
+void client_save_keywords(struct mailbox_keywords *dest,
+ const char *keywords[], unsigned int keywords_count);
#endif
by default. */
#define DEFAULT_IMAP_MAX_LINE_LENGTH 65536
-#define DEFAULT_MAX_CUSTOM_FLAG_LENGTH 50
+#define DEFAULT_MAX_KEYWORD_LENGTH 50
extern struct ioloop *ioloop;
-extern unsigned int max_custom_flag_length, mailbox_check_interval;
+extern unsigned int max_keyword_length, mailbox_check_interval;
extern unsigned int imap_max_line_length;
extern string_t *capability_string;
client_send_line(client, str);
}
-static void new_custom_flags(struct mailbox *mailbox,
- const char *custom_flags[],
- unsigned int custom_flags_count, void *context)
+static void new_keywords(struct mailbox *mailbox, const char *keywords[],
+ unsigned int keywords_count, void *context)
{
struct client *client = context;
if (client->mailbox != mailbox)
return;
- client_save_custom_flags(&client->mailbox_flags, custom_flags,
- custom_flags_count);
-
- client_send_mailbox_flags(client, mailbox, custom_flags,
- custom_flags_count);
+ client_save_keywords(&client->keywords, keywords, keywords_count);
+ client_send_mailbox_flags(client, mailbox, keywords, keywords_count);
}
struct mail_storage_callbacks mail_storage_callbacks = {
expunge,
update_flags,
new_messages,
- new_custom_flags
+ new_keywords
};
(getenv("LOGGED_IN") == NULL && getenv("IMAPLOGINTAG") == NULL)
struct ioloop *ioloop;
-unsigned int max_custom_flag_length, mailbox_check_interval;
+unsigned int max_keyword_length, mailbox_check_interval;
unsigned int imap_max_line_length;
static struct module *modules;
DEFAULT_IMAP_MAX_LINE_LENGTH;
str = getenv("MAIL_MAX_FLAG_LENGTH");
- max_custom_flag_length = str != NULL ?
+ max_keyword_length = str != NULL ?
(unsigned int)strtoul(str, NULL, 10) :
- DEFAULT_MAX_CUSTOM_FLAG_LENGTH;
+ DEFAULT_MAX_KEYWORD_LENGTH;
str = getenv("MAILBOX_CHECK_INTERVAL");
mailbox_check_interval = str == NULL ? 0 :
const char *sysflags;
unsigned int i;
- i_assert(flags->custom_flags_count <= MAIL_CUSTOM_FLAGS_COUNT);
-
if (flags == 0)
return "";
if (*sysflags != '\0')
sysflags++;
- if (flags->custom_flags_count == 0)
+ if (flags->keywords_count == 0)
return sysflags;
- /* we have custom flags too */
+ /* we have keywords too */
str = t_str_new(256);
str_append(str, sysflags);
-#if 1
- for (i = 0; i < flags->custom_flags_count; i++) {
+ for (i = 0; i < flags->keywords_count; i++) {
if (str_len(str) > 0)
str_append_c(str, ' ');
- str_append(str, flags->custom_flags[i]);
- }
-#else // FIXME
- if ((flags->flags & MAIL_CUSTOM_FLAGS_MASK) == 0)
- return sysflags;
-
- for (i = 0; i < flags->custom_flags_count; i++) {
- if (flags->flags & (1 << (i + MAIL_CUSTOM_FLAG_1_BIT))) {
- name = flags->custom_flags[i];
- if (name != NULL && *name != '\0') {
- if (str_len(str) > 0)
- str_append_c(str, ' ');
- str_append(str, name);
- }
- }
+ str_append(str, flags->keywords[i]);
}
-#endif
return str_c(str);
}
struct mail_full_flags;
-/* growing number of flags isn't very easy. biggest problem is that they're
- stored into unsigned int, which is 32bit almost everywhere. another thing
- to remember is that with maildir format, the custom flags are stored into
- file name using 'a'..'z' letters which gets us exactly the needed 26
- flags. if more is added, the current code breaks. */
-enum {
- MAIL_CUSTOM_FLAG_1_BIT = 6,
- MAIL_CUSTOM_FLAGS_COUNT = 26,
-
- MAIL_FLAGS_COUNT = 32
-};
-
-/* Return flags as a space separated string. If custom flags don't have entry
- in flags->custom_flags[], or if it's NULL or "" the flag s ignored. */
+/* Return flags as a space separated string. */
const char *imap_write_flags(const struct mail_full_flags *flags);
#endif
{
struct mail_index_record *rec, *end;
uint8_t flag_mask, old_flags;
- custom_flags_mask_t custom_mask;
- int i, update_custom;
-
- update_custom = FALSE;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- if (syncrec->add_custom_flags[i] != 0)
- update_custom = TRUE;
- if (syncrec->remove_custom_flags[i] != 0)
- update_custom = TRUE;
- custom_mask[i] = ~syncrec->remove_custom_flags[i];
+ keywords_mask_t keyword_mask;
+ int i, update_keywords;
+
+ update_keywords = FALSE;
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ if (syncrec->add_keywords[i] != 0)
+ update_keywords = TRUE;
+ if (syncrec->remove_keywords[i] != 0)
+ update_keywords = TRUE;
+ keyword_mask[i] = ~syncrec->remove_keywords[i];
}
flag_mask = ~syncrec->remove_flags;
for (; rec != end; rec++) {
old_flags = rec->flags;
rec->flags = (rec->flags & flag_mask) | syncrec->add_flags;
- if (update_custom) {
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- rec->custom_flags[i] =
- (rec->custom_flags[i]&custom_mask[i]) |
- syncrec->add_custom_flags[i];
+ if (update_keywords) {
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ rec->keywords[i] =
+ (rec->keywords[i] & keyword_mask[i]) |
+ syncrec->add_keywords[i];
}
}
rec->seq2 = update->seq2;
rec->add_flags = update->add_flags;
- memcpy(rec->add_custom_flags, update->add_custom_flags,
- sizeof(rec->add_custom_flags));
+ memcpy(rec->add_keywords, update->add_keywords,
+ sizeof(rec->add_keywords));
rec->remove_flags = update->remove_flags;
- memcpy(rec->remove_custom_flags, update->remove_custom_flags,
- sizeof(rec->remove_custom_flags));
+ memcpy(rec->remove_keywords, update->remove_keywords,
+ sizeof(rec->remove_keywords));
}
static int mail_index_sync_rec_check(struct mail_index_view *view,
}
void mail_index_sync_flags_apply(const struct mail_index_sync_rec *sync_rec,
- uint8_t *flags,
- custom_flags_mask_t custom_flags)
+ uint8_t *flags, keywords_mask_t keywords)
{
int i;
i_assert(sync_rec->type == MAIL_INDEX_SYNC_TYPE_FLAGS);
*flags = (*flags & ~sync_rec->remove_flags) | sync_rec->add_flags;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- custom_flags[i] =
- (custom_flags[i] & ~sync_rec->remove_custom_flags[i]) |
- sync_rec->add_custom_flags[i];
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ keywords[i] = (keywords[i] & ~sync_rec->remove_keywords[i]) |
+ sync_rec->add_keywords[i];
}
}
static void mail_index_record_modify_flags(struct mail_index_record *rec,
enum modify_type modify_type,
enum mail_flags flags,
- custom_flags_mask_t custom_flags)
+ keywords_mask_t keywords)
{
int i;
switch (modify_type) {
case MODIFY_REPLACE:
rec->flags = flags;
- memcpy(rec->custom_flags, custom_flags,
- INDEX_CUSTOM_FLAGS_BYTE_COUNT);
+ memcpy(rec->keywords, keywords, INDEX_KEYWORDS_BYTE_COUNT);
break;
case MODIFY_ADD:
rec->flags |= flags;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++)
- rec->custom_flags[i] |= custom_flags[i];
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
+ rec->keywords[i] |= keywords[i];
break;
case MODIFY_REMOVE:
rec->flags &= ~flags;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++)
- rec->custom_flags[i] &= ~custom_flags[i];
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
+ rec->keywords[i] &= ~keywords[i];
break;
}
}
-#define IS_COMPATIBLE_UPDATE(t, modify_type, flags, custom_flags) \
+#define IS_COMPATIBLE_UPDATE(t, modify_type, flags, keywords) \
((t)->last_update_modify_type == (modify_type) && \
(t)->last_update.add_flags == (flags) && \
- memcmp((t)->last_update.add_custom_flags, custom_flags, \
- INDEX_CUSTOM_FLAGS_BYTE_COUNT) == 0)
+ memcmp((t)->last_update.add_keywords, keywords, \
+ INDEX_KEYWORDS_BYTE_COUNT) == 0)
void mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
enum modify_type modify_type,
- enum mail_flags flags,
- custom_flags_mask_t custom_flags)
+ enum mail_flags flags, keywords_mask_t keywords)
{
struct mail_index_record *rec;
size_t pos;
pos = (seq - t->first_new_seq) * sizeof(*rec);
rec = buffer_get_space_unsafe(t->appends, pos, sizeof(*rec));
mail_index_record_modify_flags(rec, modify_type,
- flags, custom_flags);
+ flags, keywords);
return;
}
transaction (eg. 1:10 +seen, 1:10 +deleted) */
if (t->last_update.seq2 == seq-1) {
if (t->last_update.seq1 != 0 &&
- IS_COMPATIBLE_UPDATE(t, modify_type, flags, custom_flags)) {
+ IS_COMPATIBLE_UPDATE(t, modify_type, flags, keywords)) {
t->last_update.seq2 = seq;
return;
}
} else if (t->last_update.seq1 == seq+1) {
if (t->last_update.seq1 != 0 &&
- IS_COMPATIBLE_UPDATE(t, modify_type, flags, custom_flags)) {
+ IS_COMPATIBLE_UPDATE(t, modify_type, flags, keywords)) {
t->last_update.seq1 = seq;
return;
}
t->last_update_modify_type = modify_type;
t->last_update.seq1 = t->last_update.seq2 = seq;
t->last_update.add_flags = flags;
- memcpy(t->last_update.add_custom_flags, custom_flags,
- INDEX_CUSTOM_FLAGS_BYTE_COUNT);
+ memcpy(t->last_update.add_keywords, keywords,
+ INDEX_KEYWORDS_BYTE_COUNT);
}
static void
/* remove_flags = ~add_flags */
update->remove_flags =
~update->add_flags & MAIL_INDEX_FLAGS_MASK;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- update->remove_custom_flags[i] =
- ~update->add_custom_flags[i];
- }
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
+ update->remove_keywords[i] = ~update->add_keywords[i];
break;
case MODIFY_ADD:
/* already in add_flags */
case MODIFY_REMOVE:
/* add_flags -> remove_flags */
update->remove_flags = update->add_flags;
- memcpy(&update->remove_custom_flags, &update->add_custom_flags,
- INDEX_CUSTOM_FLAGS_BYTE_COUNT);
+ memcpy(&update->remove_keywords, &update->add_keywords,
+ INDEX_KEYWORDS_BYTE_COUNT);
update->add_flags = 0;
- memset(&update->add_custom_flags, 0,
- INDEX_CUSTOM_FLAGS_BYTE_COUNT);
+ memset(&update->add_keywords, 0, INDEX_KEYWORDS_BYTE_COUNT);
break;
}
}
old_flags = rec->flags;
rec->flags = (rec->flags & ~u->remove_flags) | u->add_flags;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- rec->custom_flags[i] =
- (rec->custom_flags[i] &
- ~u->remove_custom_flags[i]) |
- u->add_custom_flags[i];
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ rec->keywords[i] = u->add_keywords[i] |
+ (rec->keywords[i] & ~u->remove_keywords[i]);
}
mail_index_header_update_counts(&map->hdr_copy, old_flags,
#define MAIL_INDEX_HEADER_MIN_SIZE 68
-/* Number of custom flags in mail_index_record. */
-#define INDEX_CUSTOM_FLAGS_COUNT (3*8)
-#define INDEX_CUSTOM_FLAGS_BYTE_COUNT ((INDEX_CUSTOM_FLAGS_COUNT*7)/8)
+/* Number of keywords in mail_index_record. */
+#define INDEX_KEYWORDS_COUNT (3*8)
+#define INDEX_KEYWORDS_BYTE_COUNT ((INDEX_KEYWORDS_COUNT*7)/8)
enum mail_index_open_flags {
/* Create index if it doesn't exist */
#define MAIL_INDEX_FLAGS_MASK \
(MAIL_ANSWERED | MAIL_FLAGGED | MAIL_DELETED | MAIL_SEEN | MAIL_DRAFT)
-typedef unsigned char custom_flags_mask_t[INDEX_CUSTOM_FLAGS_BYTE_COUNT];
+typedef unsigned char keywords_mask_t[INDEX_KEYWORDS_BYTE_COUNT];
struct mail_index_header {
/* major version is increased only when you can't have backwards
struct mail_index_record {
uint32_t uid;
uint8_t flags; /* mail_flags | mail_index_mail_flags */
- custom_flags_mask_t custom_flags;
+ keywords_mask_t keywords;
uint32_t cache_offset;
};
/* MAIL_INDEX_SYNC_TYPE_FLAGS: */
uint8_t add_flags;
- custom_flags_mask_t add_custom_flags;
+ keywords_mask_t add_keywords;
uint8_t remove_flags;
- custom_flags_mask_t remove_custom_flags;
+ keywords_mask_t remove_keywords;
/* MAIL_INDEX_SYNC_TYPE_APPEND: */
const struct mail_index_record *appends;
/* Update flags in index. */
void mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
enum modify_type modify_type,
- enum mail_flags flags,
- custom_flags_mask_t custom_flags);
+ enum mail_flags flags, keywords_mask_t keywords);
/* Returns the last error code. */
enum mail_index_error mail_index_get_last_error(struct mail_index *index);
/* Apply changes in MAIL_INDEX_SYNC_TYPE_FLAGS typed sync records to given
flags variables. */
void mail_index_sync_flags_apply(const struct mail_index_sync_rec *sync_rec,
- uint8_t *flags,
- custom_flags_mask_t custom_flags);
+ uint8_t *flags, keywords_mask_t keywords);
#endif
struct mail_transaction_flag_update {
uint32_t seq1, seq2;
uint8_t add_flags;
- custom_flags_mask_t add_custom_flags;
+ keywords_mask_t add_keywords;
uint8_t remove_flags;
- custom_flags_mask_t remove_custom_flags;
+ keywords_mask_t remove_keywords;
};
struct mail_transaction_log *
struct mail_full_flags {
enum mail_flags flags;
- const char **custom_flags;
- unsigned int custom_flags_count;
+ const char **keywords;
+ unsigned int keywords_count;
};
enum modify_type {
struct imap_message_cache *cache;
struct mail_index *index;
- const char **custom_flags;
- unsigned int custom_flags_count;
+ const char **keywords;
+ unsigned int keywords_count;
//struct mail_fetch_data *fetch_data;
struct ostream *output;
struct index_mail_data *data = &mail->data;
data->flags.flags = data->rec->flags;
- /*FIXME:data->flags.custom_flags =
- mail_custom_flags_list_get(mail->ibox->index->custom_flags);
- data->flags.custom_flags_count = MAIL_CUSTOM_FLAGS_COUNT;*/
+ /*FIXME:data->flags.keywords =
+ mail_keywords_list_get(mail->ibox->index->keywords);
+ data->flags.keywords_count = MAIL_KEYWORDS_COUNT;*/
return &data->flags;
}
{
struct index_mail *imail = (struct index_mail *)mail;
enum mail_flags modify_flags;
- custom_flags_mask_t custom_flags;
+ keywords_mask_t keywords;
/* \Recent can't be changed */
modify_flags = flags->flags & ~MAIL_RECENT;
- /*if (!index_mailbox_fix_custom_flags(ibox, &modify_flags,
- flags->custom_flags,
- flags->custom_flags_count))
+ /*if (!index_mailbox_fix_keywords(ibox, &modify_flags,
+ flags->keywords,
+ flags->keywords_count))
return FALSE;*/
- memset(custom_flags, 0, sizeof(custom_flags));
+ memset(keywords, 0, sizeof(keywords));
mail_index_update_flags(imail->trans->trans, mail->seq, modify_type,
- flags->flags, custom_flags);
+ flags->flags, keywords);
- /*if (mail_custom_flags_has_changes(ibox->index->custom_flags)) {
- storage->callbacks->new_custom_flags(&ibox->box,
- mail_custom_flags_list_get(ibox->index->custom_flags),
- MAIL_CUSTOM_FLAGS_COUNT, storage->callback_context);
+ /*if (mail_keywords_has_changes(ibox->index->keywords)) {
+ storage->callbacks->new_keywords(&ibox->box,
+ mail_keywords_list_get(ibox->index->keywords),
+ MAIL_KEYWORDS_COUNT, storage->callback_context);
}*/
return 0;
const struct mail_index_record *rec,
const char *value)
{
- const char **custom_flags;
+ const char **keywords;
int i;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- if (rec->custom_flags[i] != 0)
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ if (rec->keywords[i] != 0)
break;
}
- if (i == INDEX_CUSTOM_FLAGS_BYTE_COUNT)
- return FALSE; /* no custom flags set */
+ if (i == INDEX_KEYWORDS_BYTE_COUNT)
+ return FALSE; /* no keywords set */
- /*FIXME:custom_flags = mail_custom_flags_list_get(index->custom_flags);
- for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
- if (custom_flags[i] != NULL &&
- strcasecmp(custom_flags[i], value) == 0) {
+ /*FIXME:keywords = mail_keywords_list_get(index->keywords);
+ for (i = 0; i < MAIL_KEYWORDS_COUNT; i++) {
+ if (keywords[i] != NULL &&
+ strcasecmp(keywords[i], value) == 0) {
return rec->msg_flags &
- (1 << (MAIL_CUSTOM_FLAG_1_BIT+i));
+ (1 << (MAIL_KEYWORD_1_BIT+i));
}
}*/
STATUS_UIDVALIDITY | STATUS_UNSEEN | STATUS_FIRST_UNSEEN_SEQ)
/*static void
-get_custom_flags(struct mail_custom_flags *mcf, struct mailbox_status *status)
+get_keywords(struct mail_keywords *mcf, struct mailbox_status *status)
{
const char **flags;
unsigned int i;
- status->custom_flags_count = MAIL_CUSTOM_FLAGS_COUNT;
- status->custom_flags = t_new(const char *, MAIL_CUSTOM_FLAGS_COUNT);
+ status->keywords_count = MAIL_KEYWORDS_COUNT;
+ status->keywords = t_new(const char *, MAIL_KEYWORDS_COUNT);
- flags = mail_custom_flags_list_get(mcf);
- for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++)
- status->custom_flags[i] = t_strdup(flags[i]);
+ flags = mail_keywords_list_get(mcf);
+ for (i = 0; i < MAIL_KEYWORDS_COUNT; i++)
+ status->keywords[i] = t_strdup(flags[i]);
}*/
int index_storage_get_status(struct mailbox *box,
if ((items & STATUS_RECENT) != 0)
status->recent = ibox->get_recent_count(ibox);
- /*FIXME:if (items & STATUS_CUSTOM_FLAGS)
- get_custom_flags(ibox, status);*/
+ /*FIXME:if (items & STATUS_KEYWORDS)
+ get_keywords(ibox, status);*/
mail_index_view_unlock(ibox->view);
return 0;
return ibox->readonly;
}
-int index_storage_allow_new_custom_flags(struct mailbox *box)
+int index_storage_allow_new_keywords(struct mailbox *box)
{
struct index_mailbox *ibox = (struct index_mailbox *) box;
return FALSE;
}
-int index_mailbox_fix_custom_flags(struct index_mailbox *ibox,
- enum mail_flags *flags,
- const char *custom_flags[],
- unsigned int custom_flags_count)
+int index_mailbox_fix_keywords(struct index_mailbox *ibox,
+ enum mail_flags *flags,
+ const char *keywords[],
+ unsigned int keywords_count)
{
/*FIXME:int ret;
- ret = mail_custom_flags_fix_list(ibox->index,
- flags, custom_flags,
- custom_flags_count);
+ ret = mail_keywords_fix_list(ibox->index, flags, keywords,
+ keywords_count);
switch (ret) {
case 1:
return TRUE;
case 0:
mail_storage_set_error(ibox->box.storage,
- "Maximum number of different custom flags exceeded");
+ "Maximum number of different keywords exceeded");
return FALSE;
default:
return mail_storage_set_index_error(ibox);
void index_storage_mailbox_free(struct mailbox *box);
int index_storage_is_readonly(struct mailbox *box);
-int index_storage_allow_new_custom_flags(struct mailbox *box);
+int index_storage_allow_new_keywords(struct mailbox *box);
int index_storage_is_inconsistent(struct mailbox *box);
-int index_mailbox_fix_custom_flags(struct index_mailbox *ibox,
- enum mail_flags *flags,
- const char *custom_flags[],
- unsigned int custom_flags_count);
+int index_mailbox_fix_keywords(struct index_mailbox *ibox,
+ enum mail_flags *flags,
+ const char *keywords[],
+ unsigned int keywords_count);
unsigned int index_storage_get_recent_count(struct mail_index_view *view);
ctx = t->save_ctx;
mail_flags = flags->flags;
- /*FIXME:if (!index_mailbox_fix_custom_flags(ibox, &mail_flags,
- flags->custom_flags,
- flags->custom_flags_count))
+ /*FIXME:if (!index_mailbox_fix_keywords(ibox, &mail_flags,
+ flags->keywords,
+ flags->keywords_count))
return FALSE;*/
t_push();
NULL, /* storage */
index_storage_is_readonly,
- index_storage_allow_new_custom_flags,
+ index_storage_allow_new_keywords,
maildir_storage_close,
index_storage_get_status,
maildir_storage_sync,
int maildir_sync_last_commit(struct index_mailbox *ibox);
int maildir_filename_get_flags(const char *fname, enum mail_flags *flags_r,
- custom_flags_mask_t custom_flags_r);
+ keywords_mask_t keywords_r);
const char *maildir_filename_set_flags(const char *fname, enum mail_flags flags,
- custom_flags_mask_t custom_flags);
+ keywords_mask_t keywords);
unsigned int maildir_hash(const void *p);
int maildir_cmp(const void *p1, const void *p2);
const char *newpath;
enum mail_flags flags;
uint8_t flags8;
- custom_flags_mask_t custom_flags;
+ keywords_mask_t keywords;
- (void)maildir_filename_get_flags(path, &flags, custom_flags);
+ (void)maildir_filename_get_flags(path, &flags, keywords);
flags8 = flags;
- mail_index_sync_flags_apply(&ctx->sync_rec, &flags8, custom_flags);
+ mail_index_sync_flags_apply(&ctx->sync_rec, &flags8, keywords);
- newpath = maildir_filename_set_flags(path, flags8, custom_flags);
+ newpath = maildir_filename_set_flags(path, flags8, keywords);
if (rename(path, newpath) == 0) {
ibox->dirty_cur_time = ioloop_time;
return 1;
enum maildir_uidlist_rec_flag uflags;
const char *filename;
enum mail_flags flags;
- custom_flags_mask_t custom_flags;
+ keywords_mask_t keywords;
uint32_t sync_stamp;
int ret;
seq = 0;
iter = maildir_uidlist_iter_init(ibox->uidlist);
while (maildir_uidlist_iter_next(iter, &uid, &uflags, &filename)) {
- maildir_filename_get_flags(filename, &flags, custom_flags);
+ maildir_filename_get_flags(filename, &flags, keywords);
__again:
seq++;
if (seq > hdr->messages_count) {
mail_index_append(trans, uid, &seq);
mail_index_update_flags(trans, seq, MODIFY_REPLACE,
- flags, custom_flags);
+ flags, keywords);
continue;
}
continue;
}
- maildir_filename_get_flags(filename, &flags, custom_flags);
+ maildir_filename_get_flags(filename, &flags, keywords);
if ((uint8_t)flags != (rec->flags & MAIL_FLAGS_MASK) ||
- memcmp(custom_flags, rec->custom_flags,
- INDEX_CUSTOM_FLAGS_BYTE_COUNT) != 0) {
+ memcmp(keywords, rec->keywords,
+ INDEX_KEYWORDS_BYTE_COUNT) != 0) {
mail_index_update_flags(trans, seq, MODIFY_REPLACE,
- flags, custom_flags);
+ flags, keywords);
}
}
maildir_uidlist_iter_deinit(iter);
}
int maildir_filename_get_flags(const char *fname, enum mail_flags *flags_r,
- custom_flags_mask_t custom_flags_r)
+ keywords_mask_t keywords_r)
{
const char *info;
unsigned int num;
*flags_r = 0;
- memset(custom_flags_r, 0, INDEX_CUSTOM_FLAGS_BYTE_COUNT);
+ memset(keywords_r, 0, INDEX_KEYWORDS_BYTE_COUNT);
info = strchr(fname, ':');
if (info == NULL || info[1] != '2' || info[2] != ',')
break;
default:
if (*info >= 'a' && *info <= 'z') {
- /* custom flag */
+ /* keyword */
num = (*info - 'a');
- custom_flags_r[num / CHAR_BIT] |=
- num % CHAR_BIT;
+ keywords_r[num / CHAR_BIT] |= num % CHAR_BIT;
break;
}
}
const char *maildir_filename_set_flags(const char *fname, enum mail_flags flags,
- custom_flags_mask_t custom_flags)
+ keywords_mask_t keywords)
{
string_t *flags_str;
const char *info, *oldflags;
int i, nextflag;
- if (custom_flags != NULL) {
- /* see if any custom flags are given */
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- if (custom_flags[i] != 0)
+ if (keywords != NULL) {
+ /* see if any keywords are given */
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ if (keywords[i] != 0)
break;
}
- if (i == INDEX_CUSTOM_FLAGS_BYTE_COUNT)
- custom_flags = NULL;
+ if (i == INDEX_KEYWORDS_BYTE_COUNT)
+ keywords = NULL;
}
/* remove the old :info from file name, and get the old flags */
flags &= ~MAIL_DELETED;
}
- if (custom_flags != NULL && nextflag > 'a') {
- for (i = 0; i < INDEX_CUSTOM_FLAGS_COUNT; i++) {
- if ((custom_flags[i / CHAR_BIT] &
+ if (keywords != NULL && nextflag > 'a') {
+ for (i = 0; i < INDEX_KEYWORDS_COUNT; i++) {
+ if ((keywords[i / CHAR_BIT] &
(1 << (i % CHAR_BIT))) != 0)
str_append_c(flags_str, 'a' + i);
}
- custom_flags = NULL;
+ keywords = NULL;
}
if (*oldflags == '\0' || *oldflags == ',')
return str_c(str);
}
-static const char *get_custom_flags(const struct mail_full_flags *flags)
+static const char *get_keywords(const struct mail_full_flags *flags)
{
string_t *str;
unsigned int field;
unsigned int i;
- if ((flags->flags & MAIL_CUSTOM_FLAGS_MASK) == 0)
+ if ((flags->flags & MAIL_KEYWORDS_MASK) == 0)
return "";
str = t_str_new(256);
- field = 1 << MAIL_CUSTOM_FLAG_1_BIT;
- for (i = 0; i < flags->custom_flags_count; i++) {
- const char *custom_flag = flags->custom_flags[i];
+ field = 1 << MAIL_KEYWORD_1_BIT;
+ for (i = 0; i < flags->keywords_count; i++) {
+ const char *keyword = flags->keywords[i];
- if ((flags->flags & field) && custom_flag != NULL) {
+ if ((flags->flags & field) && keyword != NULL) {
str_append_c(str, ' ');
- str_append(str, custom_flag);
+ str_append(str, keyword);
}
field <<= 1;
}
ctx->content_length_offset = ctx->output->offset;
- /* calculate how much space custom flags and content-length
+ /* calculate how much space keywords and content-length
value needs, then write that amount of spaces. */
- space = strlen(get_custom_flags(ctx->flags));
+ space = strlen(get_keywords(ctx->flags));
space += sizeof("X-Keywords: ");
space += MBOX_HEADER_EXTRA_SPACE + MAX_INT_STRLEN + 1;
if (o_stream_send_str(ctx->output, str) < 0)
return write_error(ctx);
- /* write custom flags into X-Keywords */
- str = get_custom_flags(ctx->flags);
+ /* write keywords into X-Keywords */
+ str = get_keywords(ctx->flags);
if (o_stream_send_str(ctx->output, str) < 0)
return write_error(ctx);
they need to be checked/added though. */
ctx->flags = flags;
real_flags = flags->flags;
- if (!index_mailbox_fix_custom_flags(ctx->ibox, &real_flags,
- flags->custom_flags,
- flags->custom_flags_count))
+ if (!index_mailbox_fix_keywords(ctx->ibox, &real_flags,
+ flags->keywords,
+ flags->keywords_count))
return FALSE;
t_push();
#include "mkdir-parents.h"
#include "unlink-directory.h"
#include "subscription-file/subscription-file.h"
-#include "mail-custom-flags.h"
+#include "mail-keywords.h"
#include "mbox-index.h"
#include "mbox-lock.h"
#include "mbox-storage.h"
NULL, /* storage */
index_storage_is_readonly,
- index_storage_allow_new_custom_flags,
+ index_storage_allow_new_keywords,
mbox_storage_close,
mbox_storage_lock,
index_storage_get_status,
struct mbox_mail {
uint32_t uid;
uint8_t flags;
- custom_flags_mask_t custom_flags;
+ keywords_mask_t keywords;
uoff_t space_offset; /* if space is negative, points to beginning */
off_t space;
}
}
static void keywords_append(struct mbox_sync_mail_context *ctx,
- custom_flags_mask_t custom_flags)
+ keywords_mask_t keywords)
{
// FIXME
}
str_printfa(ctx->header, "X-IMAPbase: %u %u",
ctx->sync_ctx->hdr->uid_validity,
ctx->sync_ctx->next_uid);
- //FIXME:keywords_append(ctx, all_custom_flags);
+ //FIXME:keywords_append(ctx, all_keywords);
str_append_c(ctx->header, '\n');
}
}
have_keywords = FALSE;
- for (i = 0; i < INDEX_CUSTOM_FLAGS_BYTE_COUNT; i++) {
- if (ctx->mail->custom_flags[i] != 0) {
+ for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
+ if (ctx->mail->keywords[i] != 0) {
have_keywords = TRUE;
break;
}
if (ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] == (size_t)-1 && have_keywords) {
ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] = str_len(ctx->header);
str_append(ctx->header, "X-Keywords: ");
- keywords_append(ctx, ctx->mail->custom_flags);
+ keywords_append(ctx, ctx->mail->keywords);
str_append_c(ctx->header, '\n');
}
struct mail_index_sync_rec *update)
{
uint8_t old_flags;
- custom_flags_mask_t old_custom_flags;
+ keywords_mask_t old_keywords;
if (update != NULL) {
old_flags = ctx->mail->flags;
- memcpy(old_custom_flags, ctx->mail->custom_flags,
- sizeof(old_custom_flags));
+ memcpy(old_keywords, ctx->mail->keywords, sizeof(old_keywords));
mail_index_sync_flags_apply(update, &ctx->mail->flags,
- ctx->mail->custom_flags);
+ ctx->mail->keywords);
if ((old_flags & STATUS_FLAGS_MASK) !=
(ctx->mail->flags & STATUS_FLAGS_MASK))
if ((old_flags & XSTATUS_FLAGS_MASK) !=
(ctx->mail->flags & XSTATUS_FLAGS_MASK))
mbox_sync_update_xstatus(ctx);
- if (memcmp(old_custom_flags, ctx->mail->custom_flags,
- sizeof(old_custom_flags)) != 0)
+ if (memcmp(old_keywords, ctx->mail->keywords,
+ sizeof(old_keywords)) != 0)
mbox_sync_update_xkeywords(ctx);
}
struct mail_storage *storage;
int (*is_readonly)(struct mailbox *box);
- int (*allow_new_custom_flags)(struct mailbox *box);
+ int (*allow_new_keywords)(struct mailbox *box);
int (*close)(struct mailbox *box);
return box->is_readonly(box);
}
-int mailbox_allow_new_custom_flags(struct mailbox *box)
+int mailbox_allow_new_keywords(struct mailbox *box)
{
- return box->allow_new_custom_flags(box);
+ return box->allow_new_keywords(box);
}
int mailbox_get_status(struct mailbox *box,
STATUS_UIDVALIDITY = 0x08,
STATUS_UNSEEN = 0x10,
STATUS_FIRST_UNSEEN_SEQ = 0x20,
- STATUS_CUSTOM_FLAGS = 0x40
+ STATUS_KEYWORDS = 0x40
};
enum mailbox_name_status {
unsigned int diskspace_full:1;
/* may be allocated from data stack */
- unsigned int custom_flags_count;
- const char **custom_flags;
+ unsigned int keywords_count;
+ const char **keywords;
};
struct mail_storage_callbacks {
unsigned int messages_count,
unsigned int recent_count, void *context);
/* FLAGS, PERMANENTFLAGS */
- void (*new_custom_flags)(struct mailbox *mailbox,
- const char *custom_flags[],
- unsigned int custom_flags_count,
- void *context);
+ void (*new_keywords)(struct mailbox *mailbox,
+ const char *keywords[],
+ unsigned int keywords_count,
+ void *context);
};
/* Returns TRUE if mailbox is read-only. */
int mailbox_is_readonly(struct mailbox *box);
-/* Returns TRUE if mailbox currently supports adding custom flags. */
-int mailbox_allow_new_custom_flags(struct mailbox *box);
+/* Returns TRUE if mailbox currently supports adding keywords. */
+int mailbox_allow_new_keywords(struct mailbox *box);
/* Gets the mailbox status information. */
int mailbox_get_status(struct mailbox *box,
return p->box->is_readonly(p->box);
}
-static int _allow_new_custom_flags(struct mailbox *box)
+static int _allow_new_keywords(struct mailbox *box)
{
struct proxy_mailbox *p = (struct proxy_mailbox *) box;
- return p->box->allow_new_custom_flags(p->box);
+ return p->box->allow_new_keywords(p->box);
}
static int _close(struct mailbox *box)
pb->storage = box->storage;
pb->is_readonly = _is_readonly;
- pb->allow_new_custom_flags = _allow_new_custom_flags;
+ pb->allow_new_keywords = _allow_new_keywords;
pb->close = _close;
pb->get_status = _get_status;
pb->sync = _sync;
{
}
-static void new_custom_flags(struct mailbox *mailbox __attr_unused__,
- const char *custom_flags[] __attr_unused__,
- unsigned int custom_flags_count __attr_unused__,
- void *context __attr_unused__)
+static void new_keywords(struct mailbox *mailbox __attr_unused__,
+ const char *keywords[] __attr_unused__,
+ unsigned int keywords_count __attr_unused__,
+ void *context __attr_unused__)
{
}
expunge,
update_flags,
new_messages,
- new_custom_flags
+ new_keywords
};