bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#include "imap-common.h"
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#include "str.h"
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen#include "imap-list.h"
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainenbool imap_mailbox_flags2str(string_t *str, enum mailbox_info_flags flags)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen{
2ac5f36aa7c2e7a07ba8815d43a6d7483f62e74cTimo Sirainen size_t orig_len = str_len(str);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((flags & MAILBOX_SUBSCRIBED) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\Subscribed ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((flags & MAILBOX_NOSELECT) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\Noselect ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((flags & MAILBOX_NONEXISTENT) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\NonExistent ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((flags & MAILBOX_CHILDREN) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\HasChildren ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen else if ((flags & MAILBOX_NOINFERIORS) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\NoInferiors ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen else if ((flags & MAILBOX_NOCHILDREN) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\HasNoChildren ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((flags & MAILBOX_MARKED) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\Marked ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((flags & MAILBOX_UNMARKED) != 0)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_append(str, "\\UnMarked ");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if (str_len(str) == orig_len)
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen return FALSE;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen str_truncate(str, str_len(str)-1);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen return TRUE;
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen}