mailbox-attribute.h revision 69e0311cb068f20b0f285a30263068f87bc78ce3
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen/* RFC 5464 specifies that this is vendor/<vendor-token>/. The registered
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen vendor-tokens always begin with "vendor." so there's some redundancy.. */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT "vendor/vendor.dovecot/"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen/* Prefix used for attributes reserved for Dovecot's internal use. Normal
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen users cannot access these in any way. */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen/* Server attributes are currently stored in INBOX under this private prefix.
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen They're under the pvt/ prefix so they won't be listed as regular INBOX
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen attributes, but unlike other pvt/ attributes it's actually possible to
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen access these attributes as regular users.
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen If INBOX is deleted, attributes under this prefix are preserved. */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER \
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen/* User can get/set all non-pvt/ attributes and also pvt/server/
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen (but not pvt/server/pvt/) attributes. */
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen#define MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key) \
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen (strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT, \
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) != 0 || \
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen (strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER, \
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER)) == 0 && \
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT, \
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) != 0))
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* mailbox_attribute_set() can set either value or value_stream.
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mailbox_attribute_get() returns only values, but
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen mailbox_attribute_get_stream() may return either value or
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen value_stream. The caller must unreference the returned streams. */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* Last time the attribute was changed (0 = unknown). This may be
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen returned even for values that don't exist anymore. */
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen * Attribute API
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen/* Set mailbox attribute key to value. The key should be compatible with
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen IMAP METADATA, so for Dovecot-specific keys use
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen MAILBOX_ATTRIBUTE_PREFIX_DOVECOT. */
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainenint mailbox_attribute_set(struct mailbox_transaction_context *t,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen enum mail_attribute_type type, const char *key,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen/* Delete mailbox attribute key. This is just a wrapper to
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen mailbox_attribute_set() with value->value=NULL. */
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainenint mailbox_attribute_unset(struct mailbox_transaction_context *t,
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen enum mail_attribute_type type, const char *key);
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen/* Returns value for mailbox attribute key. Returns 1 if value was returned,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen 0 if value wasn't found (set to NULL), -1 if error */
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainenint mailbox_attribute_get(struct mailbox_transaction_context *t,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen enum mail_attribute_type type, const char *key,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen/* Same as mailbox_attribute_get(), but the returned value may be either an
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen input stream or a string. */
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainenint mailbox_attribute_get_stream(struct mailbox_transaction_context *t,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen enum mail_attribute_type type, const char *key,
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen/* Iterate through mailbox attributes of the given type. The prefix can be used
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen to restrict what attributes are returned. */
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainenmailbox_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type,
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen const char *prefix);
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen/* Returns the attribute key or NULL if there are no more attributes. */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenconst char *mailbox_attribute_iter_next(struct mailbox_attribute_iter *iter);