1 | /* |
2 | Copyright (c) 2009 Andras Mantia <amantia@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "listrightsjob.h" |
21 | |
22 | #include <KDE/KLocalizedString> |
23 | #include <KDE/KDebug> |
24 | |
25 | #include "acljobbase_p.h" |
26 | #include "message_p.h" |
27 | #include "session_p.h" |
28 | #include "rfccodecs.h" |
29 | |
30 | namespace KIMAP |
31 | { |
32 | class ListRightsJobPrivate : public AclJobBasePrivate |
33 | { |
34 | public: |
35 | ListRightsJobPrivate( Session *session, const QString& name ) : AclJobBasePrivate( session, name ), defaultRights( Acl::None ) {} |
36 | ~ListRightsJobPrivate() { } |
37 | |
38 | Acl::Rights defaultRights; |
39 | QList<Acl::Rights> possibleRights; |
40 | |
41 | }; |
42 | } |
43 | |
44 | using namespace KIMAP; |
45 | |
46 | ListRightsJob::ListRightsJob( Session *session ) |
47 | : AclJobBase( *new ListRightsJobPrivate( session, i18n( "ListRights" ) ) ) |
48 | { |
49 | |
50 | } |
51 | |
52 | ListRightsJob::~ListRightsJob() |
53 | { |
54 | } |
55 | |
56 | void ListRightsJob::doStart() |
57 | { |
58 | Q_D( ListRightsJob ); |
59 | |
60 | d->tags << d->sessionInternal()->sendCommand( "LISTRIGHTS" , '\"' + KIMAP::encodeImapFolderName( d->mailBox.toUtf8() ) + "\" \"" + d->id + "\"" ); |
61 | } |
62 | |
63 | void ListRightsJob::handleResponse( const Message &response ) |
64 | { |
65 | Q_D( ListRightsJob ); |
66 | |
67 | if ( handleErrorReplies( response ) == NotHandled ) { |
68 | if ( response.content.size() >= 4 && |
69 | response.content[1].toString() == "LISTRIGHTS" ) { |
70 | QByteArray s = response.content[4].toString(); |
71 | d->defaultRights = Acl::rightsFromString( s ); |
72 | int i = 5; |
73 | while ( i < response.content.size() ) { |
74 | s = response.content[i].toString(); |
75 | d->possibleRights.append( Acl::rightsFromString( s ) ); |
76 | i++; |
77 | } |
78 | } |
79 | } |
80 | } |
81 | |
82 | void ListRightsJob::setIdentifier( const QByteArray &identifier ) |
83 | { |
84 | Q_D( ListRightsJob ); |
85 | d->setIdentifier( identifier ); |
86 | } |
87 | |
88 | QByteArray ListRightsJob::identifier() |
89 | { |
90 | Q_D( ListRightsJob ); |
91 | return d->identifier(); |
92 | } |
93 | |
94 | Acl::Rights ListRightsJob::defaultRights() |
95 | { |
96 | Q_D( ListRightsJob ); |
97 | return d->defaultRights; |
98 | } |
99 | |
100 | QList<Acl::Rights> ListRightsJob::possibleRights() |
101 | { |
102 | Q_D( ListRightsJob ); |
103 | return d->possibleRights; |
104 | } |
105 | |