diff --git a/kimap/Mainpage.dox b/kimap/Mainpage.dox index f9e3d9108..98ea05e86 100644 --- a/kimap/Mainpage.dox +++ b/kimap/Mainpage.dox @@ -1,37 +1,32 @@ /*! * @mainpage KIMAP - a job-based API for interacting with IMAP servers * * @section purpose Purpose * * This library provides a job-based API for interacting with an IMAP4rev1 server. * It manages connections, encryption and parameter quoting and encoding, but * otherwise provides quite a low-level interface to the protocol. This library * does not implement an IMAP client; it merely makes it easier to do so. * * Users should be familiar with * RFC 3501, - * as well as other related RFCs such as - * RFC 4315, - * RFC 2822, - * RFC 4314 - * and - * RFC 5257, + * as well as other related RFCs, * although the library hides some of the nastier details like the encoding and quoting of * strings. * * @section desc Description * * @authors * The major authors of this library are:\n * Sven Carstens \ * * @maintainers * Tom Albers \, * Volker Krause \, * Allen Winter \ * * @licenses * @lgpl */ // DOXYGEN_PROJECTNAME=KIMAP Library diff --git a/kimap/acljobbase.h b/kimap/acljobbase.h index 0c6502598..39616a28a 100644 --- a/kimap/acljobbase.h +++ b/kimap/acljobbase.h @@ -1,78 +1,81 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIMAP_ACLJOBBASE_H #define KIMAP_ACLJOBBASE_H #include "kimap_export.h" #include "acl.h" #include "job.h" namespace KIMAP { class Session; struct Message; class AclJobBasePrivate; /** * Base class for jobs that operate on mailbox ACLs * + * Provides support for the IMAP ACL extension, as defined by + * RFC 4314. + * * This class cannot be used directly, you must subclass it and reimplement * at least the doStart() method. */ class KIMAP_EXPORT AclJobBase : public Job { Q_OBJECT Q_DECLARE_PRIVATE(AclJobBase) friend class SessionPrivate; public: AclJobBase( Session *session ); virtual ~AclJobBase(); /** * Used when subclassing to specify how the ACL will be modified. */ enum AclModifier { Add = 0, Remove, Change }; /** * Set the mailbox to act on * * @param mailBox the name of an existing mailbox */ void setMailBox( const QString &mailBox ); /** * The mailbox that will be acted upon. */ QString mailBox() const; protected: explicit AclJobBase( JobPrivate &dd ); }; } #endif diff --git a/kimap/getquotajob.cpp b/kimap/getquotajob.cpp index 3ba6f64b0..a74ce98cc 100644 --- a/kimap/getquotajob.cpp +++ b/kimap/getquotajob.cpp @@ -1,83 +1,84 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "getquotajob.h" #include #include #include "quotajobbase_p.h" #include "message_p.h" #include "session_p.h" namespace KIMAP { class GetQuotaJobPrivate : public QuotaJobBasePrivate { public: GetQuotaJobPrivate( Session *session, const QString& name ) : QuotaJobBasePrivate(session, name) { } ~GetQuotaJobPrivate() { } QByteArray root; }; } using namespace KIMAP; GetQuotaJob::GetQuotaJob( Session *session ) : QuotaJobBase( *new GetQuotaJobPrivate(session, i18n("GetQuota")) ) { } GetQuotaJob::~GetQuotaJob() { } void GetQuotaJob::doStart() { Q_D(GetQuotaJob); + //XXX: [alexmerry, 2010-07-24]: should d->root be quoted properly? d->tags << d->sessionInternal()->sendCommand( "GETQUOTA", '\"' + d->root + '\"'); } void GetQuotaJob::handleResponse(const Message &response) { Q_D(GetQuotaJob); if (handleErrorReplies(response) == NotHandled) { if ( response.content.size() >= 4 && response.content[1].toString() == "QUOTA" ) { d->quota = d->readQuota(response.content[3]); } } } void GetQuotaJob::setRoot(const QByteArray& root) { Q_D(GetQuotaJob); d->root = root; } QByteArray GetQuotaJob::root() const { Q_D(const GetQuotaJob); return d->root; } #include "getquotajob.moc" diff --git a/kimap/getquotajob.h b/kimap/getquotajob.h index adb1cc294..01231eade 100644 --- a/kimap/getquotajob.h +++ b/kimap/getquotajob.h @@ -1,53 +1,80 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIMAP_GETQUOTAJOB_H #define KIMAP_GETQUOTAJOB_H #include "quotajobbase.h" namespace KIMAP { class Session; struct Message; class GetQuotaJobPrivate; +/** + * Gets resource limits for a quota root. + * + * Quotas are defined with respect to "resources" and "quota roots". + * A resource is a numerical property that can be limited, such + * as the octet size of all the messages in a mailbox, or the + * number of messages in a mailbox. Each mailbox has one or more + * quota roots, which are where the resource limits are defined. + * A quota root may or may not be a mailbox name, and an empty + * string is a valid quota root. All mailboxes with the same quota + * root share the resource limits of the quota root. + * + * This job can only be run when the session is in the + * authenticated (or selected) state. + * + * This job requires that the server supports the QUOTA + * capability, defined in + * RFC 2087. + */ class KIMAP_EXPORT GetQuotaJob : public QuotaJobBase { Q_OBJECT Q_DECLARE_PRIVATE(GetQuotaJob) friend class SessionPrivate; public: explicit GetQuotaJob( Session *session ); virtual ~GetQuotaJob(); + /** + * Set the quota root to get the resource limits for. + * + * @see GetQuotaRootJob + */ void setRoot(const QByteArray &root); + /** + * The quota root that resource limit information will be fetched for. + */ QByteArray root() const; protected: virtual void doStart(); virtual void handleResponse(const Message &response); }; } #endif diff --git a/kimap/getquotarootjob.h b/kimap/getquotarootjob.h index 7a9829255..b1fa49eec 100644 --- a/kimap/getquotarootjob.h +++ b/kimap/getquotarootjob.h @@ -1,59 +1,124 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIMAP_GETQUOTAROOTJOB_H #define KIMAP_GETQUOTAROOTJOB_H #include "quotajobbase.h" namespace KIMAP { class Session; struct Message; class GetQuotaRootJobPrivate; +/** + * Gets the quota root and resource limits for a mailbox. + * + * Quotas are defined with respect to "resources" and "quota roots". + * A resource is a numerical property that can be limited, such + * as the octet size of all the messages in a mailbox, or the + * number of messages in a mailbox. Each mailbox has one or more + * quota roots, which are where the resource limits are defined. + * A quota root may or may not be a mailbox name, and an empty + * string is a valid quota root. All mailboxes with the same quota + * root share the resource limits of the quota root. + * + * This job can only be run when the session is in the + * authenticated (or selected) state. + * + * This job requires that the server supports the QUOTA + * capability, defined in + * RFC 2087. + */ class KIMAP_EXPORT GetQuotaRootJob : public QuotaJobBase { Q_OBJECT Q_DECLARE_PRIVATE(GetQuotaRootJob) friend class SessionPrivate; public: explicit GetQuotaRootJob( Session *session ); virtual ~GetQuotaRootJob(); + /** + * Set the mailbox to get the quota roots for. + * + * @param mailBox the name of an existing mailbox + */ void setMailBox(const QString &mailBox); + /** + * The mailbox that the quota roots will be fetched for. + */ QString mailBox() const; + + /** + * The quota roots for the mailbox. + */ QList roots() const; + /** + * Get the current usage for a resource. + * + * Note that if there is no limit for a resource, the + * server will not provide information about resource + * usage. + * + * @param root the quota root to get the resource usage for + * @param resource the resource to get the usage for + * @return the resource usage in appropriate units, or -1 + * if the usage is unknown or there is no + * limit on the resource + */ qint64 usage(const QByteArray &root, const QByteArray &resource) const; + /** + * Get the current limit for a resource. + * + * @param root the quota root to get the resource limit for + * @param resource the resource to get the limit for + * @return the resource limit in appropriate units, or -1 + * if the limit is unknown or there is no + * limit on the resource + */ qint64 limit(const QByteArray &root, const QByteArray &resource) const; + /** + * Get a map containing all resource usage figures for a quota root. + * + * @param root the quota root to get resource usage figures for + * @return a map from resource names to usage figures + */ QMap allUsages(const QByteArray &root) const; + /** + * Get a map containing all resource limits for a quota root. + * + * @param root the quota root to get resource limits for + * @return a map from resource names to limits + */ QMap allLimits(const QByteArray &root) const; protected: virtual void doStart(); virtual void handleResponse(const Message &response); }; } #endif diff --git a/kimap/idlejob.h b/kimap/idlejob.h index c925141e1..34ed83a5e 100644 --- a/kimap/idlejob.h +++ b/kimap/idlejob.h @@ -1,65 +1,129 @@ /* Copyright (c) 2009 Kevin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIMAP_IDLEJOB_H #define KIMAP_IDLEJOB_H #include "kimap_export.h" #include "imapset.h" #include "job.h" #include "kmime/kmime_content.h" #include "kmime/kmime_message.h" #include namespace KIMAP { class Session; struct Message; class IdleJobPrivate; +/** + * Idles the connection to the IMAP server. + * + * This job can be run while the client has no other use + * for the connection, and the server will send updates + * about the selected mailbox. + * + * Note that although the server may send a variety of + * responses while the job is running (including EXPUNGE, + * for example), only RECENT and EXISTS responses are + * actually reported by this job. + * + * The job also processes updates in pairs - if the server + * sends an EXISTS update but not a RECENT one (because + * another client is changing the mailbox contents), this + * job will not report the update. + * + * It only makes sense to run this job when the session is + * in the selected state. + * + * This job requires that the server supports the IDLE + * capability, defined in + * RFC 2177. + */ class KIMAP_EXPORT IdleJob : public Job { Q_OBJECT Q_DECLARE_PRIVATE(IdleJob) public: explicit IdleJob( Session *session ); virtual ~IdleJob(); + /** + * The last mailbox status that was reported. + * + * This is just the session's selected mailbox. + */ QString lastMailBox() const; + /** + * The last message count that was reported. + * + * The server will send updates about the number of + * messages in the mailbox when that number changes. + * This is the last number it reported. + * + * @return the last message count the server reported, + * or -1 if it has not reported a message count + * since the job started. + */ int lastMessageCount() const; + /** + * The last recent message count that was reported. + * + * The server will send updates about the number of + * messages in the mailbox that are tagged with \Recent + * when that number changes. This is the last number it + * reported. + * + * @return the last recent message count the server reported, + * or -1 if it has not reported a recent message count + * since the job started. + */ int lastRecentCount() const; public Q_SLOTS: + /** + * Stops the idle job. + */ void stop(); Q_SIGNALS: + /** + * Signals that the server has notified that the total and + * recent message counts have changed. + * + * @param job this object + * @param mailBox the selected mailbox + * @param messageCount the new total message count reported by the server + * @param recentCount the new "recent message" count reported by the server + */ void mailBoxStats(KIMAP::IdleJob *job, const QString &mailBox, int messageCount, int recentCount); protected: virtual void doStart(); virtual void handleResponse(const Message &response); }; } #endif diff --git a/kimap/quotajobbase.h b/kimap/quotajobbase.h index a263b6c76..640ca0dc7 100644 --- a/kimap/quotajobbase.h +++ b/kimap/quotajobbase.h @@ -1,57 +1,99 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIMAP_QUOTAJOBBASE_H #define KIMAP_QUOTAJOBBASE_H #include "kimap_export.h" #include "job.h" namespace KIMAP { class Session; struct Message; class QuotaJobBasePrivate; -/** @short Base class of Quota related jobs. It cannot be used directly, you must subclass it and reimplement at least the -doStart() method. +/** + * Base class for jobs that operate on mailbox quotas + * + * Provides support for the IMAP QUOTA extension, as defined by + * RFC 2087. + * + * This class cannot be used directly, you must subclass it and reimplement + * at least the doStart() method. */ class KIMAP_EXPORT QuotaJobBase : public Job { Q_OBJECT Q_DECLARE_PRIVATE(QuotaJobBase) friend class SessionPrivate; public: explicit QuotaJobBase( Session *session ); virtual ~QuotaJobBase(); + /** + * Get the current usage for a resource. + * + * All quota jobs will normally cause the server to return + * details of resource usage for all resources that were + * queried or modified by the job. + * + * Note that RFC 2087 is slightly ambiguous about whether + * SETQUOTA will cause this information to be sent by the + * server. + * + * Note that if there is no limit for a resource, the + * server will not provide information about resource + * usage. + * + * @param resource the resource to get the usage for + * @return the resource usage in appropriate units, or -1 + * if the usage is unknown or there is no + * limit on the resource + */ qint64 usage(const QByteArray& resource); + /** + * Get the current limit for a resource. + * + * All quota jobs will normally cause the server to return + * details of resource limits for all resources that were + * queried or modified by the job. + * + * Note that RFC 2087 is slightly ambiguous about whether + * SETQUOTA will cause this information to be sent by the + * server. + * + * @param resource the resource to get the limit for + * @return the resource limit in appropriate units, or -1 + * if the limit is unknown or there is no limit + * on the resource + */ qint64 limit(const QByteArray& resource); protected: QuotaJobBase( JobPrivate &dd ); }; } #endif diff --git a/kimap/setquotajob.cpp b/kimap/setquotajob.cpp index bded7640f..037a8444c 100644 --- a/kimap/setquotajob.cpp +++ b/kimap/setquotajob.cpp @@ -1,104 +1,106 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "setquotajob.h" #include #include #include "quotajobbase_p.h" #include "message_p.h" #include "session_p.h" namespace KIMAP { class SetQuotaJobPrivate : public QuotaJobBasePrivate { public: SetQuotaJobPrivate( Session *session, const QString& name ) : QuotaJobBasePrivate(session, name) { } ~SetQuotaJobPrivate() { } QMap setList; QByteArray root; }; } using namespace KIMAP; SetQuotaJob::SetQuotaJob( Session *session ) : QuotaJobBase( *new SetQuotaJobPrivate(session, i18n("SetQuota")) ) { } SetQuotaJob::~SetQuotaJob() { } void SetQuotaJob::doStart() { Q_D(SetQuotaJob); QByteArray s; s += '('; for (QMap::ConstIterator it = d->setList.constBegin(); it != d->setList.constEnd(); ++it ) { + //XXX: [alexmerry, 2010-07-24]: we're restricting the resource to being an atom, here s += it.key() + ' ' + QByteArray::number(it.value()) + ' '; } if (d->setList.isEmpty()) { s += ')'; } else { s[s.length() - 1] = ')'; } kDebug() << "SETQUOTA " << '\"' + d->root + "\" " + s; + //XXX: [alexmerry, 2010-07-24]: should d->root be quoted properly? d->tags << d->sessionInternal()->sendCommand( "SETQUOTA", '\"' + d->root + "\" " + s); } void SetQuotaJob::handleResponse(const Message &response) { Q_D(SetQuotaJob); if (handleErrorReplies(response) == NotHandled) { if ( response.content.size() >= 4 && response.content[1].toString() == "QUOTA" ) { d->quota = d->readQuota(response.content[3]); } } } void SetQuotaJob::setQuota(const QByteArray &resource, qint64 limit) { Q_D(SetQuotaJob); d->setList[resource.toUpper()] = limit; } void SetQuotaJob::setRoot(const QByteArray& root) { Q_D(SetQuotaJob); d->root = root; } QByteArray SetQuotaJob::root() const { Q_D(const SetQuotaJob); return d->root; } #include "setquotajob.moc" diff --git a/kimap/setquotajob.h b/kimap/setquotajob.h index db16acbc7..f3fac3779 100644 --- a/kimap/setquotajob.h +++ b/kimap/setquotajob.h @@ -1,61 +1,103 @@ /* Copyright (c) 2009 Andras Mantia This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIMAP_SETQUOTAJOB_H #define KIMAP_SETQUOTAJOB_H #include "quotajobbase.h" namespace KIMAP { class Session; struct Message; class SetQuotaJobPrivate; +/** + * Sets resource limits on a quota root. + * + * Quotas are defined with respect to "resources" and "quota roots". + * A resource is a numerical property that can be limited, such + * as the octet size of all the messages in a mailbox, or the + * number of messages in a mailbox. Each mailbox has one or more + * quota roots, which are where the resource limits are defined. + * A quota root may or may not be a mailbox name, and an empty + * string is a valid quota root. All mailboxes with the same quota + * root share the resource limits of the quota root. + * + * This job can only be run when the session is in the + * authenticated (or selected) state. + * + * This job requires that the server supports the QUOTA + * capability, defined in + * RFC 2087. + */ class KIMAP_EXPORT SetQuotaJob : public QuotaJobBase { Q_OBJECT - Q_DECLARE_PRIVATE(SetQuotaJob) + Q_DECLARE_PRIVATE( SetQuotaJob ) friend class SessionPrivate; public: explicit SetQuotaJob( Session *session ); virtual ~SetQuotaJob(); /** - * Set a limit for a quota resource - * @param resource quota resouce name - * @param limit limit for the resouce + * Set a limit for a quota resource. + * + * For example, you might set the limit for "STORAGE" to + * 512 to limit the sum of the messages' RFC822.SIZE to + * 512*1024 octets (ie: 512 kb), or the limit for "MESSAGE" + * to 100 to limit the number of messages to 100. + * + * Note that although RFC 2087 allows a resource name to + * be any string, this API actually limits resource names + * to upper-case atoms. In practice, resource names will + * almost certainly be composed entirely of upper-case latin + * letters (A-Z). + * + * @param resource the resource name + * @param limit the maximum value the resource may take */ - // use qint64 for all the quota stuff - void setQuota(const QByteArray& resource, qint64 limit); + void setQuota( const QByteArray &resource, qint64 limit ); - void setRoot(const QByteArray &root); + /** + * Set the quota root the resource limits should be set for. + * + * Note: if the quota root does not already exist, the server + * may create it and change the quota roots for any number of + * existing mailboxes in an implementation-defined manner. + * + * @see GetQuotaRootJob + */ + void setRoot( const QByteArray &root ); + /** + * The quota root that will be modified. + */ QByteArray root() const; protected: virtual void doStart(); - virtual void handleResponse(const Message &response); + virtual void handleResponse( const Message &response ); }; } #endif