2 * This file is part of KMail.
4 * Copyright (c) 2010 KDAB
6 * Author: Tobias Koenig <tokoe@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "addressvalidationjob.h"
24 #include <messagecomposer/aliasesexpandjob.h>
25 using MessageComposer::AliasesExpandJob
;
27 #include "messagecomposersettings.h"
30 #include <kmessagebox.h>
32 #include <KPIMUtils/Email>
34 #include <messagecore/stringutil.h>
36 class AddressValidationJob::Private
39 Private( AddressValidationJob
*qq
, const QString
&emailAddresses
, QWidget
*parentWidget
)
40 : q( qq
), mEmailAddresses( emailAddresses
), mIsValid( false ), mParentWidget( parentWidget
)
44 void slotAliasExpansionDone( KJob
* );
46 AddressValidationJob
*q
;
47 QString mEmailAddresses
;
49 QWidget
*mParentWidget
;
52 void AddressValidationJob::Private::slotAliasExpansionDone( KJob
*job
)
55 q
->setError( job
->error() );
56 q
->setErrorText( job
->errorText() );
62 const AliasesExpandJob
*expandJob
= qobject_cast
<AliasesExpandJob
*>( job
);
63 const QStringList emptyDistributionLists
= expandJob
->emptyDistributionLists();
65 QString brokenAddress
;
67 const KPIMUtils::EmailParseResult errorCode
= KPIMUtils::isValidAddressList( expandJob
->addresses(), brokenAddress
);
68 if ( !emptyDistributionLists
.isEmpty() ) {
69 const QString errorMsg
= i18n( "Distribution list \"%1\" is empty, it cannot be used.",
70 emptyDistributionLists
.join( ", " ) );
71 KMessageBox::sorry( mParentWidget
, errorMsg
, i18n( "Invalid Email Address" ) );
74 if ( !( errorCode
== KPIMUtils::AddressOk
||
75 errorCode
== KPIMUtils::AddressEmpty
) ) {
76 const QString
errorMsg( "<qt><p><b>" + brokenAddress
+
78 KPIMUtils::emailParseResultToString( errorCode
) +
80 KMessageBox::sorry( mParentWidget
, errorMsg
, i18n( "Invalid Email Address" ) );
90 AddressValidationJob::AddressValidationJob( const QString
&emailAddresses
, QWidget
*parentWidget
, QObject
*parent
)
91 : KJob( parent
), d( new Private( this, emailAddresses
, parentWidget
) )
95 AddressValidationJob::~AddressValidationJob()
100 void AddressValidationJob::start()
102 AliasesExpandJob
*job
= new AliasesExpandJob( d
->mEmailAddresses
, MessageComposer::MessageComposerSettings::defaultDomain(), this );
103 connect( job
, SIGNAL( result( KJob
* ) ), SLOT( slotAliasExpansionDone( KJob
* ) ) );
108 bool AddressValidationJob::isValid() const
113 #include "addressvalidationjob.moc"