32 #include <tdeio/scheduler.h>
35 using namespace KMail;
39 static unsigned int IMAPRightsToPermission(
const TQString& str,
const KURL& url,
const TQString& user ) {
40 unsigned int perm = 0;
41 uint len = str.length();
42 for (uint i = 0; i < len; ++i) {
44 switch ( ch.latin1() ) {
45 case 'l': perm |= ACLJobs::List;
break;
46 case 'r': perm |= ACLJobs::Read;
break;
47 case 's': perm |= ACLJobs::WriteSeenFlag;
break;
48 case 'w': perm |= ACLJobs::WriteFlags;
break;
49 case 'i': perm |= ACLJobs::Insert;
break;
50 case 'p': perm |= ACLJobs::Post;
break;
52 case 'c': perm |= ACLJobs::Create;
break;
54 case 'd': perm |= ACLJobs::Delete;
break;
55 case 'a': perm |= ACLJobs::Administer;
break;
59 if ( ( perm & ACLJobs::Read ) && !( perm & ACLJobs::WriteSeenFlag ) ) {
63 kdWarning(5006) <<
"IMAPRightsToPermission: found read (r) but not seen (s). Things will not work well for folder " << url <<
" and user " << ( user.isEmpty() ?
"myself" : user ) << endl;
64 if ( perm & ACLJobs::Administer )
65 kdWarning(5006) <<
"You can change this yourself in the ACL dialog" << endl;
67 kdWarning(5006) <<
"Ask your admin for 's' permissions." << endl;
74 static TQCString permissionsToIMAPRights(
unsigned int permissions ) {
76 if ( permissions & ACLJobs::List )
78 if ( permissions & ACLJobs::Read )
80 if ( permissions & ACLJobs::WriteSeenFlag )
82 if ( permissions & ACLJobs::WriteFlags )
84 if ( permissions & ACLJobs::Insert )
86 if ( permissions & ACLJobs::Post )
88 if ( permissions & ACLJobs::Create )
90 if ( permissions & ACLJobs::Delete )
92 if ( permissions & ACLJobs::Administer )
98 TQString ACLJobs::permissionsToString(
unsigned int permissions )
101 if ( permissions & ACLJobs::List )
103 if ( permissions & ACLJobs::Read )
105 if ( permissions & ACLJobs::WriteFlags )
107 if ( permissions & ACLJobs::Insert )
109 if ( permissions & ACLJobs::Post )
111 if ( permissions & ACLJobs::Create )
113 if ( permissions & ACLJobs::Delete )
115 if ( permissions & ACLJobs::Administer )
116 str +=
"Administer ";
117 if ( !str.isEmpty() )
118 str.truncate( str.length() - 1 );
123 TDEIO::SimpleJob*
ACLJobs::setACL( TDEIO::Slave* slave,
const KURL& url,
const TQString& user,
unsigned int permissions )
125 TQString perm = TQString::fromLatin1( permissionsToIMAPRights( permissions ) );
127 TQByteArray packedArgs;
128 TQDataStream stream( packedArgs, IO_WriteOnly );
129 stream << (int)
'A' << (
int)
'S' << url << user << perm;
131 TDEIO::SimpleJob* job = TDEIO::special( url, packedArgs,
false );
132 TDEIO::Scheduler::assignJobToSlave( slave, job );
138 TQByteArray packedArgs;
139 TQDataStream stream( packedArgs, IO_WriteOnly );
140 stream << (int)
'A' << (
int)
'D' << url << user;
143 TDEIO::Scheduler::assignJobToSlave( slave, job );
149 TQByteArray packedArgs;
150 TQDataStream stream( packedArgs, IO_WriteOnly );
151 stream << (int)
'A' << (
int)
'G' << url;
154 TDEIO::Scheduler::assignJobToSlave( slave, job );
160 TQByteArray packedArgs;
161 TQDataStream stream( packedArgs, IO_WriteOnly );
162 stream << (int)
'A' << (
int)
'M' << url;
165 TDEIO::Scheduler::assignJobToSlave( slave, job );
169 ACLJobs::GetACLJob::GetACLJob(
const KURL& url,
const TQByteArray &packedArgs,
170 bool showProgressInfo )
171 : TDEIO::SimpleJob( url, TDEIO::CMD_SPECIAL, packedArgs, showProgressInfo )
173 connect(
this, TQ_SIGNAL(infoMessage(TDEIO::Job*,
const TQString&)),
174 TQ_SLOT(slotInfoMessage(TDEIO::Job*,
const TQString&)) );
177 void ACLJobs::GetACLJob::slotInfoMessage( TDEIO::Job*,
const TQString& str )
180 TQStringList lst = TQStringList::split(
"\"", str,
true );
181 while ( lst.count() >= 2 )
183 TQString user = lst.front(); lst.pop_front();
184 TQString imapRights = lst.front(); lst.pop_front();
185 unsigned int perm = IMAPRightsToPermission( imapRights, url(), user );
186 m_entries.append(
ACLListEntry( user, imapRights, perm ) );
190 ACLJobs::GetUserRightsJob::GetUserRightsJob(
const KURL& url,
const TQByteArray &packedArgs,
191 bool showProgressInfo )
192 : TDEIO::SimpleJob( url, TDEIO::CMD_SPECIAL, packedArgs, showProgressInfo )
194 connect(
this, TQ_SIGNAL(infoMessage(TDEIO::Job*,
const TQString&)),
195 TQ_SLOT(slotInfoMessage(TDEIO::Job*,
const TQString&)) );
198 void ACLJobs::GetUserRightsJob::slotInfoMessage( TDEIO::Job*,
const TQString& str )
201 m_permissions = IMAPRightsToPermission( str, url(), TQString() );
204 ACLJobs::DeleteACLJob::DeleteACLJob(
const KURL& url,
const TQString& userId,
205 const TQByteArray &packedArgs,
206 bool showProgressInfo )
207 : TDEIO::SimpleJob( url, TDEIO::CMD_SPECIAL, packedArgs, showProgressInfo ),
214 ACLJobs::MultiSetACLJob::MultiSetACLJob( TDEIO::Slave* slave,
const KURL& url,
const ACLList& acl,
bool showProgressInfo )
215 : TDEIO::Job( showProgressInfo ),
217 mUrl( url ), mACLList( acl ), mACLListIterator( mACLList.begin() )
219 TQTimer::singleShot(0,
this, TQ_SLOT(slotStart()));
222 void ACLJobs::MultiSetACLJob::slotStart()
225 while ( mACLListIterator != mACLList.end() && !(*mACLListIterator).changed )
228 if ( mACLListIterator != mACLList.end() )
235 job =
deleteACL( mSlave, mUrl, entry.userId );
243 void ACLJobs::MultiSetACLJob::slotResult( TDEIO::Job *job )
245 if ( job->error() ) {
246 TDEIO::Job::slotResult( job );
251 emit aclChanged( entry.userId, entry.
permissions );
263 #include "acljobs.moc"
Delete the permissions for a given user on a given url This class only exists to store the userid in ...
List all ACLs for a given url.
Get the users' rights for a given url.
Set and delete a list of permissions for different users on a given url.
DeleteACLJob * deleteACL(TDEIO::Slave *slave, const KURL &url, const TQString &user)
Delete the permissions for a given user on a given url.
TDEIO::SimpleJob * setACL(TDEIO::Slave *slave, const KURL &url, const TQString &user, unsigned int permissions)
Set the permissions for a given user on a given url.
GetUserRightsJob * getUserRights(TDEIO::Slave *slave, const KURL &url)
Get the users' rights for a given url.
MultiSetACLJob * multiSetACL(TDEIO::Slave *slave, const KURL &url, const ACLList &acl)
Set and delete a list of permissions for different users on a given url.
GetACLJob * getACL(TDEIO::Slave *slave, const KURL &url)
List all ACLs for a given url.
One entry in the ACL list: user and permissions.
int permissions
based on the ACLPermissions enum