File indexing completed on 2024-05-12 05:17:25
0001 /* 0002 Copyright (c) 2009 Andras Mantia <amantia@kde.org> 0003 0004 This library is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to the 0016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA. 0018 */ 0019 0020 #ifndef KIMAP2_SETMETADATAJOB_H 0021 #define KIMAP2_SETMETADATAJOB_H 0022 0023 #include "kimap2_export.h" 0024 0025 #include "metadatajobbase.h" 0026 0027 namespace KIMAP2 0028 { 0029 0030 class Session; 0031 struct Message; 0032 class SetMetaDataJobPrivate; 0033 0034 /** 0035 * Sets mailbox metadata. 0036 * 0037 * Provides support for the IMAP METADATA extension; both the 0038 * final RFC version 0039 * (<a href="http://tools.ietf.org/html/rfc5464">RFC 5464</a>) 0040 * and the older, incompatible draft version (known as ANNOTATEMORE) 0041 * (<a 0042 * href="http://tools.ietf.org/html/draft-daboo-imap-annotatemore-07" 0043 * >draft-daboo-imap-annotatemore-07</a>). See setServerCompatibility(). 0044 * 0045 * Note that in Annotatemore mode, this job can only operate on 0046 * one metadata entry at once. 0047 * 0048 * This job can only be run when the session is in the 0049 * authenticated (or selected) state. 0050 * 0051 * If the server supports ACLs, the user will need the 0052 * Acl::Lookup right on the mailbox, as well as one of 0053 * - Acl::Read 0054 * - Acl::KeepSeen 0055 * - Acl::Write 0056 * - Acl::Insert 0057 * - Acl::Post 0058 * Otherwise, the user must be able to list the mailbox 0059 * and either read or write the message content. 0060 * 0061 * Note that even if the user has these permissions, the 0062 * server may refuse to allow the user to write metadata 0063 * based on some other criteria. 0064 * 0065 * Note also that on servers that implement the Annotatemore 0066 * version of the extension, only Acl::Lookup rights are 0067 * required (ie: the user must be able to list the mailbox). 0068 */ 0069 class KIMAP2_EXPORT SetMetaDataJob : public MetaDataJobBase 0070 { 0071 Q_OBJECT 0072 Q_DECLARE_PRIVATE(SetMetaDataJob) 0073 0074 friend class SessionPrivate; 0075 0076 public: 0077 explicit SetMetaDataJob(Session *session); 0078 virtual ~SetMetaDataJob(); 0079 0080 /** 0081 * Adds a metadata entry or attribute to the list of modifications to make 0082 * 0083 * When in Metadata mode, this method adds a metadata 0084 * entry to the list of metadata additions and updates that 0085 * will be performed when the job is run. 0086 * 0087 * @p name must be a valid ASCII string and may not contain two 0088 * consecutive forward slashes ('/'), must not end with '/' and 0089 * must not contain '*', '%', non-ASCII characters or characters 0090 * in the ASCII range 0x00 to 0x19 (in practice, all control 0091 * characters should be avoided). The name is case-insensitive. 0092 * 0093 * The first part of the entry name should be "/private" or 0094 * "/shared", indicating the scope of the entry. Note that 0095 * private metadata may not be supported by all servers. 0096 * 0097 * Server metadata entry names include: 0098 * - /shared/comment 0099 * - /shared/admin - a URI for contacting the server administrator 0100 * (eg: a mailto: or tel: URI) 0101 * - /shared/vendor/<vendor-token>/something 0102 * - /private/vendor/<vendor-token>/something 0103 * 0104 * Mailbox metadata entry names include: 0105 * - /shared/comment 0106 * - /private/comment 0107 * - /shared/vendor/<vendor-token>/something 0108 * - /private/vendor/<vendor-token>/something 0109 * 0110 * @p value can be any data, although if it is a multi-line string 0111 * value, CRLF line-endings must be used. 0112 * 0113 * In Annotatemore mode it is possible to prefix the entry name with a /shared or /private prefix, that is automatically translated 0114 * to an appropriate value.shared|priv attribute. 0115 * 0116 * Annotatemore legacy mode: 0117 * When in Annotatemore mode, this method adds an attribute 0118 * entry to the list of additions and updates that will be 0119 * performed on the metadata entry when the job is run. 0120 * 0121 * @p name must be a valid UTF-8 string, and may not contain the 0122 * '%' or '*' characters, or NUL. Use of non-visible UTF-8 characters 0123 * is strongly discouraged. 0124 * 0125 * Possible attribute name prefixes are: 0126 * - value - the data value of the attribute 0127 * - content-type - a MIME content type and subtype 0128 * - content-language - a RFC 3282 language code 0129 * - vendor.<vendor-token> - a vendor-specific attribute 0130 * 0131 * Attribute names an attribute name prefix followed by ".priv" for 0132 * private attributes or ".shared" for shared attributes. Note that 0133 * the attributes "size.priv" and "size.shared" are read-only 0134 * attributes set by the server, and so cannot be used with 0135 * SetMetaDataJob. 0136 * 0137 * @param name the metadata entry name (Metadata or Annotatemore mode) in ASCII or 0138 * attribute name (Annotatemore mode, if used without /shared or /private prefix) in UTF-8 0139 * @param value the value of the entry or attribute 0140 */ 0141 // KDE5: drop ANNOTATEMORE support 0142 void addMetaData(const QByteArray &name, const QByteArray &value); 0143 0144 /** 0145 * Sets the metadata entry name to operate on (in Annotatemore mode) 0146 * 0147 * In Annotatemore mode, this specifies the metadata entry name to 0148 * operate on. For server metadata, this is one of: 0149 * - /comment 0150 * - /motd 0151 * - /admin 0152 * - /vendor/<vendor-token>/something 0153 * 0154 * For mailbox metadata, this is one of: 0155 * - /comment 0156 * - /sort 0157 * - /thread 0158 * - /check 0159 * - /checkperiod 0160 * - /vendor/<vendor-token>/something 0161 * 0162 * Entry names must be valid UTF-8 strings that do not contain the 0163 * '%' or '*' characters, or NUL. Use of non-visible UTF-8 0164 * characters is strongly discouraged. 0165 * 0166 * In Metadata mode, this has no effect. Metadata entry names 0167 * should instead be specified as the first argument to addMetaData(). 0168 * 0169 * @see setServerCapability() 0170 * 0171 * @param entry the metadata entry name in UTF-8 0172 * 0173 * @deprecated Use a /shared or /private prefix with addMetaData instead. 0174 */ 0175 // KDE5: remove 0176 KIMAP2_DEPRECATED void setEntry(const QByteArray &entry); 0177 0178 /** 0179 * Possible error codes that may be returned by the server. 0180 */ 0181 enum MetaDataError { 0182 NoError = 0, /**< Used to indicate that no errors have been received */ 0183 TooMany = 1, /**< Cannot add a new metadata item, because the limit has already been reached */ 0184 TooBig = 2, /**< A metadata value was too big (see maxAcceptedSize()) */ 0185 NoPrivate = 4 /**< The server does not support private metadata entries */ 0186 }; 0187 0188 // Q_DECLARE_WHATEVER_THAT_WAS missing 0189 Q_DECLARE_FLAGS(MetaDataErrors, MetaDataError) 0190 0191 /** 0192 * The metadata errors received from the server. 0193 * 0194 * @return a set of error codes 0195 */ 0196 MetaDataErrors metaDataErrors() const; 0197 /** 0198 * The maximum accepted metadata size. 0199 * 0200 * If the server replied that one of the metadata values was too 0201 * large (see metaDataErrors), this should indicate what the 0202 * maximum size accepted by the server is. 0203 * 0204 * @return the maximum value size in octets, or -1 if the limit is unknown 0205 */ 0206 qint64 maxAcceptedSize(); 0207 0208 protected: 0209 void doStart() Q_DECL_OVERRIDE; 0210 void handleResponse(const Message &response) Q_DECL_OVERRIDE; 0211 0212 }; 0213 0214 } 0215 0216 Q_DECLARE_OPERATORS_FOR_FLAGS(KIMAP2::SetMetaDataJob::MetaDataErrors) 0217 0218 #endif