mailbox-attribute.h revision 69e0311cb068f20b0f285a30263068f87bc78ce3
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen#ifndef MAILBOX_ATTRIBUTE_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#define MAILBOX_ATTRIBUTE_H
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenstruct mailbox;
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainenstruct mailbox_transaction_context;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen
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#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT \
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen MAILBOX_ATTRIBUTE_PREFIX_DOVECOT"pvt/"
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
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen If INBOX is deleted, attributes under this prefix are preserved. */
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen#define MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER \
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT"server/"
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen
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))
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainenenum mail_attribute_type {
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen MAIL_ATTRIBUTE_TYPE_PRIVATE,
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen MAIL_ATTRIBUTE_TYPE_SHARED
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen};
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainenenum mail_attribute_value_flags {
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen MAIL_ATTRIBUTE_VALUE_FLAG_READONLY = 0x01,
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen MAIL_ATTRIBUTE_VALUE_FLAG_INT_STREAMS = 0x02
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen};
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainenstruct mail_attribute_value {
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. */
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen const char *value;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen struct istream *value_stream;
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen /* Last time the attribute was changed (0 = unknown). This may be
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen returned even for values that don't exist anymore. */
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen time_t last_change;
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen enum mail_attribute_value_flags flags;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen};
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen/*
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen * Attribute API
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen */
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen
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 const struct mail_attribute_value *value);
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 struct mail_attribute_value *value_r);
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,
df831edaa3b3aa22e03bc5fd416a0553c5600a69Phil Carmody struct mail_attribute_value *value_r);
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen/* Iterate through mailbox attributes of the given type. The prefix can be used
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen to restrict what attributes are returned. */
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainenstruct mailbox_attribute_iter *
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);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenint mailbox_attribute_iter_deinit(struct mailbox_attribute_iter **iter);
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#endif
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen