Commit cdea96b6 authored by Allen Winter's avatar Allen Winter
Browse files

lots of coding style fixes

SVN_SILENT:

svn path=/trunk/KDE/kdepimlibs/; revision=766024
parent 89495baa
......@@ -26,22 +26,21 @@
using namespace MailTransport;
QString Legacy::decryptKMail(const QString & data)
QString Legacy::decryptKMail( const QString &data )
{
return KStringHandler::obscure( data );
}
QString Legacy::decryptKNode(const QString & data)
QString Legacy::decryptKNode( const QString &data )
{
uint i, val, len = data.length();
QString result;
for ( i = 0; i < len; ++i )
{
for ( i = 0; i < len; ++i ) {
val = data[i].toLatin1();
val -= ' ';
val = (255-' ') - val;
result += QLatin1Char( (char)(val + ' ') );
val = ( 255 - ' ' ) - val;
result += QLatin1Char( (char)( val + ' ' ) );
}
return result;
......
......@@ -48,5 +48,4 @@
#define IMAP_PORT 143
#define IMAPS_PORT 993
#endif
......@@ -40,8 +40,8 @@ class PreCommandJobPrivate
QString precommand;
};
PrecommandJob::PrecommandJob(const QString & precommand, QObject * parent) :
KJob( parent ), d( new PreCommandJobPrivate )
PrecommandJob::PrecommandJob( const QString &precommand, QObject *parent )
: KJob( parent ), d( new PreCommandJobPrivate )
{
d->precommand = precommand;
d->process = new KProcess( this );
......@@ -65,14 +65,14 @@ void PrecommandJob::start()
void PrecommandJob::slotStarted()
{
emit infoMessage( this, i18n("Executing precommand"),
i18n("Executing precommand '%1'.", d->precommand ) );
emit infoMessage( this, i18n( "Executing precommand" ),
i18n( "Executing precommand '%1'.", d->precommand ) );
}
void PrecommandJob::slotError( QProcess::ProcessError error)
void PrecommandJob::slotError( QProcess::ProcessError error )
{
setError( UserDefinedError );
setErrorText( i18n("Could not execute precommand '%1'.", d->precommand ) );
setErrorText( i18n( "Could not execute precommand '%1'.", d->precommand ) );
kDebug(5324) << "Execution precommand has failed:" << error;
emitResult();
}
......@@ -84,16 +84,15 @@ bool PrecommandJob::doKill()
return true;
}
void PrecommandJob::slotFinished(int exitCode,
QProcess::ExitStatus exitStatus )
void PrecommandJob::slotFinished( int exitCode, QProcess::ExitStatus exitStatus )
{
if ( exitStatus == QProcess::CrashExit ) {
setError( UserDefinedError );
setErrorText( i18n("The precommand crashed." ));
setErrorText( i18n( "The precommand crashed." ) );
} else if ( exitCode != 0 ) {
setError( UserDefinedError );
setErrorText( i18n("The precommand exited with code %1.",
d->process->exitStatus()) );
setErrorText( i18n( "The precommand exited with code %1.",
d->process->exitStatus() ) );
}
emitResult();
}
......
......@@ -61,9 +61,9 @@ class PrecommandJob : public KJob
virtual bool doKill();
private slots:
void slotFinished(int, QProcess::ExitStatus);
void slotFinished( int, QProcess::ExitStatus );
void slotStarted();
void slotError( QProcess::ProcessError error);
void slotError( QProcess::ProcessError error );
private:
PreCommandJobPrivate *const d;
......
......@@ -38,12 +38,12 @@ using namespace MailTransport;
class SendMailJobPrivate
{
public:
QProcess* process;
QProcess *process;
QString lastError;
};
SendmailJob::SendmailJob(Transport * transport, QObject * parent) :
TransportJob( transport, parent ), d( new SendMailJobPrivate )
SendmailJob::SendmailJob( Transport *transport, QObject *parent )
: TransportJob( transport, parent ), d( new SendMailJobPrivate )
{
d->process = new QProcess( this );
connect( d->process,
......@@ -63,14 +63,13 @@ SendmailJob::~ SendmailJob()
void SendmailJob::doStart()
{
QStringList arguments;
arguments << QLatin1String("-i") << QLatin1String("-f")
<< sender() << to() << cc() << bcc();
d->process->start(transport()->host(), arguments);
arguments << QLatin1String( "-i" ) << QLatin1String( "-f" )
<< sender() << to() << cc() << bcc();
d->process->start( transport()->host(), arguments );
if ( !d->process->waitForStarted() ) {
setError( UserDefinedError );
setErrorText( i18n("Failed to execute mailer program %1",
transport()->host()) );
setErrorText( i18n( "Failed to execute mailer program %1", transport()->host() ) );
emitResult();
} else {
d->process->write( buffer()->readAll() );
......@@ -80,12 +79,13 @@ void SendmailJob::doStart()
void SendmailJob::sendmailExited( int exitCode, QProcess::ExitStatus exitStatus )
{
if ( exitStatus != 0 || exitCode != 0) {
if ( exitStatus != 0 || exitCode != 0 ) {
setError( UserDefinedError );
if (d->lastError.isEmpty())
setErrorText( i18n("Sendmail exited abnormally.") );
else
setErrorText( i18n("Sendmail exited abnormally: %1", d->lastError) );
if ( d->lastError.isEmpty() ) {
setErrorText( i18n( "Sendmail exited abnormally." ) );
} else {
setErrorText( i18n( "Sendmail exited abnormally: %1", d->lastError ) );
}
}
emitResult();
}
......
......@@ -43,7 +43,7 @@ class MAILTRANSPORT_EXPORT SendmailJob : public TransportJob
@param transport The transport settings.
@param parent The parent object.
*/
explicit SendmailJob( Transport* transport, QObject* parent = 0 );
explicit SendmailJob( Transport *transport, QObject *parent = 0 );
/**
Destroys this job.
......@@ -55,7 +55,7 @@ class MAILTRANSPORT_EXPORT SendmailJob : public TransportJob
virtual bool doKill();
private Q_SLOTS:
void sendmailExited(int, QProcess::ExitStatus);
void sendmailExited( int, QProcess::ExitStatus );
void receivedError();
void receivedStdErr();
......
......@@ -42,52 +42,53 @@ namespace MailTransport
class ServerTestPrivate
{
public:
ServerTestPrivate( ServerTest* test);
ServerTestPrivate( ServerTest *test );
ServerTest* const q;
ServerTest *const q;
QString server;
QString fakeHostname;
QString testProtocol;
MailTransport::Socket* normalSocket;
MailTransport::Socket* secureSocket;
MailTransport::Socket *normalSocket;
MailTransport::Socket *secureSocket;
QList< int > connectionResults;
QHash< int, QList<int> > authenticationResults;
QTimer* normalSocketTimer;
QTimer* secureSocketTimer;
QTimer* progressTimer;
QTimer *normalSocketTimer;
QTimer *secureSocketTimer;
QTimer *progressTimer;
QProgressBar* testProgress;
QProgressBar *testProgress;
bool secureSocketFinished;
bool normalSocketFinished;
void finalResult();
void read( int type, const QString& text );
void sendInitialCapabilityQuery( MailTransport::Socket* socket );
void read( int type, const QString &text );
void sendInitialCapabilityQuery( MailTransport::Socket *socket );
// slots
void slotNormalPossible();
void slotNormalNotPossible();
void slotSslPossible();
void slotSslNotPossible();
void slotReadNormal( const QString& text );
void slotReadSecure( const QString& text );
void slotReadNormal( const QString &text );
void slotReadSecure( const QString &text );
void slotUpdateProgress();
};
}
ServerTestPrivate::ServerTestPrivate( ServerTest* test)
ServerTestPrivate::ServerTestPrivate( ServerTest *test )
: q( test )
{
}
void ServerTestPrivate::finalResult()
{
if ( !secureSocketFinished || !normalSocketFinished )
if ( !secureSocketFinished || !normalSocketFinished ) {
return;
}
kDebug( 5324 ) << connectionResults;
......@@ -97,46 +98,49 @@ void ServerTestPrivate::finalResult()
emit q->finished( connectionResults );
}
void ServerTestPrivate::read( int type, const QString& text )
void ServerTestPrivate::read( int type, const QString &text )
{
kDebug( 5324 ) << text;
if ( !text.contains( QLatin1String( "AUTH" ), Qt::CaseInsensitive ) )
if ( !text.contains( QLatin1String( "AUTH" ), Qt::CaseInsensitive ) ) {
return;
}
QStringList protocols;
protocols << QLatin1String( "LOGIN" ) << QLatin1String( "PLAIN" )
<< QLatin1String( "CRAM-MD5" ) << QLatin1String("DIGEST-MD5")
<< QLatin1String( "NTLM" ) << QLatin1String( "GSSAPI" );
<< QLatin1String( "CRAM-MD5" ) << QLatin1String( "DIGEST-MD5" )
<< QLatin1String( "NTLM" ) << QLatin1String( "GSSAPI" );
QStringList results;
for ( int i = 0 ; i < protocols.count(); ++i ) {
if ( text.contains( protocols.at( i ), Qt::CaseInsensitive ) )
for ( int i = 0; i < protocols.count(); ++i ) {
if ( text.contains( protocols.at( i ), Qt::CaseInsensitive ) ) {
results.append( protocols.at( i ) );
}
}
QList<int> result;
for ( QStringList::ConstIterator it = results.begin() ;
it != results.end() ; ++it ) {
if ( *it == QLatin1String("LOGIN") )
for ( QStringList::ConstIterator it = results.begin(); it != results.end(); ++it ) {
if ( *it == QLatin1String( "LOGIN" ) ) {
result << Transport::EnumAuthenticationType::LOGIN;
else if ( *it == QLatin1String("PLAIN") )
} else if ( *it == QLatin1String( "PLAIN" ) ) {
result << Transport::EnumAuthenticationType::PLAIN;
else if ( *it == QLatin1String("CRAM-MD5") )
} else if ( *it == QLatin1String( "CRAM-MD5" ) ) {
result << Transport::EnumAuthenticationType::CRAM_MD5;
else if ( *it == QLatin1String("DIGEST-MD5") )
} else if ( *it == QLatin1String( "DIGEST-MD5" ) ) {
result << Transport::EnumAuthenticationType::DIGEST_MD5;
else if ( *it == QLatin1String("NTLM") )
} else if ( *it == QLatin1String( "NTLM" ) ) {
result << Transport::EnumAuthenticationType::NTLM;
else if ( *it == QLatin1String("GSSAPI") )
} else if ( *it == QLatin1String( "GSSAPI" ) ) {
result << Transport::EnumAuthenticationType::GSSAPI;
}
}
// LOGIN doesn't offer anything over PLAIN, requires more server
// roundtrips and is not an official SASL mechanism, but a MS-ism,
// so only enable it if PLAIN isn't available:
if ( result.contains( Transport::EnumAuthenticationType::PLAIN ) )
if ( result.contains( Transport::EnumAuthenticationType::PLAIN ) ) {
result.removeAll( Transport::EnumAuthenticationType::LOGIN );
}
authenticationResults[type] = result;
}
......@@ -147,10 +151,11 @@ void ServerTestPrivate::slotNormalPossible()
connectionResults << Transport::EnumEncryption::None;
}
void ServerTestPrivate::sendInitialCapabilityQuery( MailTransport::Socket* socket )
void ServerTestPrivate::sendInitialCapabilityQuery( MailTransport::Socket *socket )
{
if ( testProtocol == IMAP_PROTOCOL )
if ( testProtocol == IMAP_PROTOCOL ) {
socket->write( QLatin1String( "1 CAPABILITY" ) );
}
else if ( testProtocol == SMTP_PROTOCOL ) {
......@@ -161,13 +166,11 @@ void ServerTestPrivate::sendInitialCapabilityQuery( MailTransport::Socket* socke
QString hostname;
if ( !fakeHostname.isNull() ) {
hostname = fakeHostname;
}
else {
} else {
hostname = QHostInfo::localHostName();
if( hostname.isEmpty() ) {
hostname = QLatin1String( "localhost.invalid" );
}
else if ( !hostname.contains( QChar::fromAscii( '.' ) ) ) {
} else if ( !hostname.contains( QChar::fromAscii( '.' ) ) ) {
hostname += QLatin1String( ".localnet" );
}
}
......@@ -177,7 +180,7 @@ void ServerTestPrivate::sendInitialCapabilityQuery( MailTransport::Socket* socke
}
}
void ServerTestPrivate::slotReadNormal( const QString& text )
void ServerTestPrivate::slotReadNormal( const QString &text )
{
static bool first = true;
if ( first ) {
......@@ -186,8 +189,9 @@ void ServerTestPrivate::slotReadNormal( const QString& text )
return;
}
if ( text.contains( QLatin1String("STARTTLS" ), Qt::CaseInsensitive) )
if ( text.contains( QLatin1String( "STARTTLS" ), Qt::CaseInsensitive ) ) {
connectionResults << Transport::EnumEncryption::TLS;
}
read( Transport::EnumEncryption::None, text );
......@@ -196,7 +200,7 @@ void ServerTestPrivate::slotReadNormal( const QString& text )
finalResult();
}
void ServerTestPrivate::slotReadSecure( const QString& text )
void ServerTestPrivate::slotReadSecure( const QString &text )
{
static bool first = true;
if ( first ) {
......@@ -237,7 +241,7 @@ void ServerTestPrivate::slotUpdateProgress()
//---------------------- end private class -----------------------//
ServerTest::ServerTest( QWidget* parent )
ServerTest::ServerTest( QWidget *parent )
: QWidget( parent ), d( new ServerTestPrivate( this ) )
{
d->normalSocketTimer = new QTimer( this );
......@@ -274,14 +278,15 @@ void ServerTest::start()
d->normalSocket->setObjectName( QLatin1String( "normal" ) );
d->normalSocket->setServer( d->server );
d->normalSocket->setProtocol( d->testProtocol );
if ( d->testProtocol == IMAP_PROTOCOL )
if ( d->testProtocol == IMAP_PROTOCOL ) {
d->normalSocket->setPort( IMAP_PORT );
else
} else {
d->normalSocket->setPort( SMTP_PORT );
connect( d->normalSocket, SIGNAL( connected() ), SLOT( slotNormalPossible() ) );
connect( d->normalSocket, SIGNAL( failed() ), SLOT( slotNormalNotPossible() ) );
connect( d->normalSocket, SIGNAL( data( const QString& ) ),
SLOT( slotReadNormal( const QString& ) ) );
}
connect( d->normalSocket, SIGNAL(connected()), SLOT(slotNormalPossible()) );
connect( d->normalSocket, SIGNAL(failed()), SLOT(slotNormalNotPossible()) );
connect( d->normalSocket, SIGNAL(data(const QString&)),
SLOT(slotReadNormal(const QString&)) );
d->normalSocket->reconnect();
d->normalSocketTimer->start( 10000 );
......@@ -289,20 +294,21 @@ void ServerTest::start()
d->secureSocket->setObjectName( QLatin1String( "secure" ) );
d->secureSocket->setServer( d->server );
d->secureSocket->setProtocol( d->testProtocol + QLatin1Char( 's' ) );
if ( d->testProtocol == IMAP_PROTOCOL)
if ( d->testProtocol == IMAP_PROTOCOL ) {
d->secureSocket->setPort( IMAPS_PORT );
else
} else {
d->secureSocket->setPort( SMTPS_PORT );
}
d->secureSocket->setSecure( true );
connect( d->secureSocket, SIGNAL( connected() ), SLOT( slotSslPossible() ) );
connect( d->secureSocket, SIGNAL( failed() ), SLOT( slotSslNotPossible() ) );
connect( d->secureSocket, SIGNAL( data( const QString& ) ),
SLOT( slotReadSecure( const QString& ) ) );
connect( d->secureSocket, SIGNAL(connected()), SLOT(slotSslPossible()) );
connect( d->secureSocket, SIGNAL(failed()), SLOT(slotSslNotPossible()) );
connect( d->secureSocket, SIGNAL(data(const QString&) ),
SLOT(slotReadSecure(const QString&)) );
d->secureSocket->reconnect();
d->secureSocketTimer->start( 10000 );
}
void ServerTest::setFakeHostname( const QString& fakeHostname )
void ServerTest::setFakeHostname( const QString &fakeHostname )
{
d->fakeHostname = fakeHostname;
}
......@@ -312,17 +318,17 @@ QString ServerTest::fakeHostname()
return d->fakeHostname;
}
void ServerTest::setServer( const QString& server )
void ServerTest::setServer( const QString &server )
{
d->server = server;
}
void ServerTest::setProgressBar( QProgressBar* pb )
void ServerTest::setProgressBar( QProgressBar *pb )
{
d->testProgress = pb;
}
void ServerTest::setProtocol( const QString& protocol )
void ServerTest::setProtocol( const QString &protocol )
{
d->testProtocol = protocol;
}
......@@ -337,7 +343,7 @@ QString ServerTest::server()
return d->server;
}
QProgressBar* ServerTest::progressBar()
QProgressBar *ServerTest::progressBar()
{
return d->testProgress;
}
......@@ -352,5 +358,4 @@ QList< int > ServerTest::secureProtocols()
return d->authenticationResults[Transport::EnumEncryption::SSL];
}
#include "servertest.moc"
/*
/*
Copyright (C) 2007 KovoKs <info@kovoks.nl>
This library is free software; you can redistribute it and/or modify it
......@@ -27,8 +27,8 @@
#include <QtCore/QHash>
class QProgressBar;
namespace MailTransport
namespace MailTransport
{
class ServerTestPrivate;
......@@ -43,14 +43,14 @@ class MAILTRANSPORT_EXPORT ServerTest : public QWidget
Q_OBJECT
Q_PROPERTY( QString server READ server WRITE setServer )
Q_PROPERTY( QString protocol READ protocol WRITE setProtocol )
Q_PROPERTY( QProgressBar* progressBar READ progressBar WRITE setProgressBar )
Q_PROPERTY( QProgressBar *progressBar READ progressBar WRITE setProgressBar )
public:
/**
* Constructor
* @param parent Parent Widget
*/
ServerTest( QWidget* parent = 0 );
ServerTest( QWidget *parent = 0 );
/**
* Destructor
......@@ -60,7 +60,7 @@ class MAILTRANSPORT_EXPORT ServerTest : public QWidget
/**
* Set the server to test.
*/
void setServer( const QString& server );
void setServer( const QString &server );
/**
* Get the server to test.
......@@ -77,7 +77,7 @@ class MAILTRANSPORT_EXPORT ServerTest : public QWidget
*
* @param fakeHostname the fake hostname to send
*/
void setFakeHostname( const QString& fakeHostname );
void setFakeHostname( const QString &fakeHostname );
/**
* @return the fake hostname, as set before with @ref setFakeHostname
......@@ -89,18 +89,18 @@ class MAILTRANSPORT_EXPORT ServerTest : public QWidget
* and hide() and will count down. It does not take ownership of
* the progressbar.
*/
void setProgressBar( QProgressBar* pb );
void setProgressBar( QProgressBar *pb );
/**
* returns the used progressBar
*/
QProgressBar* progressBar();
QProgressBar *progressBar();
/**
* Set @p proto the protocol to test, currently supported are
* "smtp" and "imap". This will be an enum soon.
*/
void setProtocol( const QString& protocol );
void setProtocol( const QString &protocol );
/**
* returns the protocol
......@@ -134,16 +134,16 @@ class MAILTRANSPORT_EXPORT ServerTest : public QWidget
void finished( QList< int > );
private:
Q_DECLARE_PRIVATE(ServerTest)
Q_DECLARE_PRIVATE( ServerTest )
ServerTestPrivate *const d;
Q_PRIVATE_SLOT(d, void slotNormalPossible() )
Q_PRIVATE_SLOT(d, void slotSslPossible())
Q_PRIVATE_SLOT(d, void slotReadNormal( const QString& text ))
Q_PRIVATE_SLOT(d, void slotReadSecure( const QString& text ))
Q_PRIVATE_SLOT(d, void slotNormalNotPossible())
Q_PRIVATE_SLOT(d, void slotSslNotPossible())
Q_PRIVATE_SLOT(d, void slotUpdateProgress())
Q_PRIVATE_SLOT( d, void slotNormalPossible() )
Q_PRIVATE_SLOT( d, void slotSslPossible() )
Q_PRIVATE_SLOT( d, void slotReadNormal( const QString &text ) )
Q_PRIVATE_SLOT( d, void slotReadSecure( const QString &text ) )
Q_PRIVATE_SLOT( d, void slotNormalNotPossible() )
Q_PRIVATE_SLOT( d, void slotSslNotPossible() )
Q_PRIVATE_SLOT( d, void slotUpdateProgress() )
};
}
......
......@@ -42,11 +42,11 @@ static QHash<int,KIO::Slave*> slavePool;
static void removeSlaveFromPool( KIO::Slave *slave, bool disconnect = false )
{
const int slaveKey = slavePool.key( slave );
if (slaveKey > 0)
{
if ( slaveKey > 0 ) {
slavePool.remove( slaveKey );
if ( disconnect )
if ( disconnect ) {
KIO::Scheduler::disconnectSlave( slave );
}
}
}
......@@ -57,15 +57,15 @@ static void removeSlaveFromPool( KIO::Slave *slave, bool disconnect = false )
class SmtpJobPrivate
{
public:
KIO::Slave* slave;
KIO::Slave *slave;
enum State {
Idle, Precommand, Smtp
} currentState;
bool finished;
};
SmtpJob::SmtpJob(Transport * transport, QObject * parent) :
TransportJob( transport, parent ), d( new SmtpJobPrivate )
SmtpJob::SmtpJob( Transport *transport, QObject *parent )
: TransportJob( transport, parent ), d( new SmtpJobPrivate )
{
d->currentState = SmtpJobPrivate::Idle;
d->slave = 0;
......@@ -80,8 +80,9 @@ SmtpJob::~SmtpJob()
slavePoolRef--;
if ( slavePoolRef == 0 ) {
kDebug(5324) << "clearing SMTP slave pool" << slavePool.count();
foreach ( KIO::Slave *slave, slavePool.values() )
foreach ( KIO::Slave *slave, slavePool.values() ) {
KIO::Scheduler::disconnectSlave( slave );
}
slavePool.clear();
}
delete d;
......@@ -104,24 +105,27 @@ void SmtpJob::doStart()
void SmtpJob::startSmtpJob()
{
KUrl destination;
destination.setProtocol( (transport()->encryption() ==
Transport::EnumEncryption::SSL) ? SMTPS_PROTOCOL : SMTP_PROTOCOL );
destination.setProtocol( ( transport()->encryption() == Transport::EnumEncryption::SSL ) ?
SMTPS_PROTOCOL : SMTP_PROTOCOL );
destination.setHost( transport()->host() );
destination.setPort( transport()->port() );
destination.addQueryItem( QLatin1String("headers"), QLatin1String("0") );
destination.addQueryItem( QLatin1String("from"), sender() );
destination.addQueryItem( QLatin1String( "headers" ), QLatin1String( "0" ) );
destination.addQueryItem( QLatin1String( "from" ), sender() );
foreach ( QString str, to() )
destination.addQueryItem( QLatin1String("to"), str );
foreach ( QString str, cc() )
destination.addQueryItem( QLatin1String("cc"), str );