23 #include "sievedebugdialog.h"
28 #include <tqdatetime.h>
31 #include <tdelocale.h>
32 #include <tdemessagebox.h>
34 #include <kmime_header_parsing.h>
35 #include <ksieve/error.h>
36 #include <ksieve/parser.h>
37 #include <ksieve/scriptbuilder.h>
38 #include <libkpimidentities/identity.h>
39 #include <libkpimidentities/identitymanager.h>
41 #include "kmacctimap.h"
42 #include "accountmanager.h"
46 #include <tqtextedit.h>
48 using KMail::SieveJob;
49 using KMime::Types::AddrSpecList;
54 class SieveDebugDataExtractor :
public KSieve::ScriptBuilder
68 SieveDebugDataExtractor()
69 : KSieve::ScriptBuilder()
71 kdDebug( 5006 ) << k_funcinfo << endl;
74 virtual ~SieveDebugDataExtractor()
76 kdDebug( 5006 ) << k_funcinfo << endl;
80 void commandStart(
const TQString & identifier )
82 kdDebug( 5006 ) << k_funcinfo <<
"Identifier: '" << identifier <<
"'" << endl;
88 kdDebug( 5006 ) << k_funcinfo << endl;
91 void testStart(
const TQString & )
93 kdDebug( 5006 ) << k_funcinfo << endl;
98 kdDebug( 5006 ) << k_funcinfo << endl;
103 kdDebug( 5006 ) << k_funcinfo << endl;
108 kdDebug( 5006 ) << k_funcinfo << endl;
113 kdDebug( 5006 ) << k_funcinfo << endl;
118 kdDebug( 5006 ) << k_funcinfo << endl;
121 void hashComment(
const TQString & )
123 kdDebug( 5006 ) << k_funcinfo << endl;
126 void bracketComment(
const TQString & )
128 kdDebug( 5006 ) << k_funcinfo << endl;
133 kdDebug( 5006 ) << k_funcinfo << endl;
136 void error(
const KSieve::Error & e )
138 kdDebug( 5006 ) <<
"### " << k_funcinfo <<
"Error: " <<
139 e.asString() <<
" @ " << e.line() <<
"," << e.column() << endl;
144 kdDebug( 5006 ) << k_funcinfo << endl;
147 void taggedArgument(
const TQString & tag )
149 kdDebug( 5006 ) << k_funcinfo <<
"Tag: '" << tag <<
"'" << endl;
152 void stringArgument(
const TQString &
string,
bool,
const TQString & )
154 kdDebug( 5006 ) << k_funcinfo <<
"String: '" <<
string <<
"'" << endl;
157 void numberArgument(
unsigned long number,
char )
159 kdDebug( 5006 ) << k_funcinfo <<
"Number: " << number << endl;
162 void stringListArgumentStart()
164 kdDebug( 5006 ) << k_funcinfo << endl;
167 void stringListEntry(
const TQString &
string,
bool,
const TQString & )
169 kdDebug( 5006 ) << k_funcinfo <<
"String: '" <<
string <<
"'" << endl;
172 void stringListArgumentEnd()
174 kdDebug( 5006 ) << k_funcinfo << endl;
180 kdDebug( 5006 ) << k_funcinfo << endl;
189 SieveDebugDialog::SieveDebugDialog( TQWidget *parent,
const char *name )
190 : KDialogBase( parent, name, true, i18n(
"Sieve Diagnostics" ), KDialogBase::
Ok,
191 KDialogBase::
Ok, true ),
197 for ( KMAccount *a = am->
first(); a; a = am->
next() )
198 mAccountList.append( a );
200 mEdit =
new TQTextEdit(
this );
201 mEdit->setReadOnly(
true);
202 setMainWidget( mEdit );
204 mEdit->setText( i18n(
"Collecting diagnostic information about Sieve support...\n\n" ) );
206 setInitialSize( TQSize( 640, 480 ) );
208 if ( !mAccountList.isEmpty() )
209 TQTimer::singleShot( 0,
this, TQ_SLOT( slotDiagNextAccount() ) );
212 SieveDebugDialog::~SieveDebugDialog()
219 kdDebug( 5006 ) << k_funcinfo << endl;
222 static KURL urlFromAccount(
const KMail::ImapAccountBase * a ) {
223 const SieveConfig sieve = a->sieveConfig();
224 if ( !sieve.managesieveSupported() )
228 if ( sieve.reuseConfig() ) {
230 u.setProtocol(
"sieve" );
231 u.setHost( a->host() );
232 u.setUser( a->login() );
233 u.setPass( a->passwd() );
234 u.setPort( sieve.port() );
237 u.addQueryItem(
"x-mech", a->auth() ==
"*" ?
"PLAIN" : a->auth() );
238 if ( !a->useSSL() && !a->useTLS() )
239 u.addQueryItem(
"x-allow-unencrypted",
"true" );
241 u = sieve.alternateURL();
242 if ( u.protocol().lower() ==
"sieve" && !a->useSSL() && !a->useTLS() && u.queryItem(
"x-allow-unencrypted").isEmpty() )
243 u.addQueryItem(
"x-allow-unencrypted",
"true" );
248 void SieveDebugDialog::slotDiagNextAccount()
250 if ( mAccountList.isEmpty() )
253 KMAccount *acc = mAccountList.first();
254 mAccountList.pop_front();
256 mEdit->append( i18n(
"Collecting data for account '%1'...\n" ).arg( acc->name() ) );
257 mEdit->append( i18n(
"------------------------------------------------------------\n" ) );
258 mAccountBase =
dynamic_cast<KMail::ImapAccountBase *
>( acc );
262 const KURL url = urlFromAccount( mAccountBase );
263 if ( !url.isValid() )
265 mEdit->append( i18n(
"(Account does not support Sieve)\n\n" ) );
269 mSieveJob = SieveJob::list( mUrl );
271 connect( mSieveJob, TQ_SIGNAL( gotList( KMail::SieveJob *,
bool,
const TQStringList &,
const TQString & ) ),
272 TQ_SLOT( slotGetScriptList( KMail::SieveJob *,
bool,
const TQStringList &,
const TQString & ) ) );
278 mEdit->append( i18n(
"(Account is not an IMAP account)\n\n" ) );
282 TQTimer::singleShot( 0,
this, TQ_SLOT( slotDiagNextAccount() ) );
285 void SieveDebugDialog::slotDiagNextScript()
287 if ( mScriptList.isEmpty() )
291 TQTimer::singleShot( 0,
this, TQ_SLOT( slotDiagNextAccount() ) );
295 TQString scriptFile = mScriptList.first();
296 mScriptList.pop_front();
298 mEdit->append( i18n(
"Contents of script '%1':\n" ).arg( scriptFile ) );
300 mUrl = urlFromAccount( mAccountBase );
301 mUrl.setFileName( scriptFile );
303 mSieveJob = SieveJob::get( mUrl );
305 connect( mSieveJob, TQ_SIGNAL( gotScript( KMail::SieveJob *,
bool,
const TQString &,
bool ) ),
306 TQ_SLOT( slotGetScript( KMail::SieveJob *,
bool,
const TQString &,
bool ) ) );
309 void SieveDebugDialog::slotGetScript( SieveJob * ,
bool success,
310 const TQString &script,
bool active )
312 kdDebug( 5006 ) <<
"SieveDebugDialog::slotGetScript( ??, " << success
313 <<
", ?, " << active <<
" )" << endl
318 if ( script.isEmpty() )
320 mEdit->append( i18n(
"(This script is empty.)\n\n" ) );
325 "------------------------------------------------------------\n"
327 "------------------------------------------------------------\n\n" ).arg( script ) );
331 TQTimer::singleShot( 0,
this, TQ_SLOT( slotDiagNextScript() ) );
334 void SieveDebugDialog::slotGetScriptList( SieveJob *job,
bool success,
335 const TQStringList &scriptList,
const TQString &activeScript )
337 kdDebug( 5006 ) << k_funcinfo <<
"Success: " << success <<
", List: " << scriptList.join(
", " ) <<
338 ", active: " << activeScript << endl;
341 mEdit->append( i18n(
"Sieve capabilities:\n" ) );
342 TQStringList caps = job->sieveCapabilities();
343 if ( caps.isEmpty() )
345 mEdit->append( i18n(
"(No special capabilities available)" ) );
349 for ( TQStringList::const_iterator it = caps.begin(); it != caps.end(); ++it )
350 mEdit->append(
"* " + *it +
"\n" );
351 mEdit->append(
"\n" );
354 mEdit->append( i18n(
"Available Sieve scripts:\n" ) );
356 if ( scriptList.isEmpty() )
358 mEdit->append( i18n(
"(No Sieve scripts available on this server)\n\n" ) );
362 mScriptList = scriptList;
363 for ( TQStringList::const_iterator it = scriptList.begin(); it != scriptList.end(); ++it )
364 mEdit->append(
"* " + *it +
"\n" );
365 mEdit->append(
"\n" );
366 mEdit->append( i18n(
"Active script: %1\n\n" ).arg( activeScript ) );
370 TQTimer::singleShot( 0,
this, TQ_SLOT( slotDiagNextScript() ) );
373 void SieveDebugDialog::slotDialogOk()
375 kdDebug(5006) <<
"SieveDebugDialog::slotDialogOk()" << endl;
378 void SieveDebugDialog::slotPutActiveResult( SieveJob * job,
bool success )
380 handlePutResult( job, success,
true );
383 void SieveDebugDialog::slotPutInactiveResult( SieveJob * job,
bool success )
385 handlePutResult( job, success,
false );
388 void SieveDebugDialog::handlePutResult( SieveJob *,
bool success,
bool activated )
392 KMessageBox::information( 0, activated ? i18n(
393 "Sieve script installed successfully on the server.\n"
394 "Out of Office reply is now active." )
395 : i18n(
"Sieve script installed successfully on the server.\n"
396 "Out of Office reply has been deactivated." ) );
399 kdDebug( 5006 ) <<
"SieveDebugDialog::handlePutResult( ???, " << success <<
", ? )" << endl;
406 #include "sievedebugdialog.moc"
The account manager is responsible for creating accounts of various types via the factory method crea...
const KMAccount * first() const
First account of the list.
const KMAccount * next() const
Next account of the list.
@ Ok
The user rights/ACL have been fetched from the server sucessfully.