2 * This file is part of KMail.
4 * Copyright (c) 2010 KDAB
6 * Authors: Tobias Koenig <tokoe@kde.org>
7 * Leo Franchi <lfranchi@kde.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "emailaddressresolvejob.h"
26 #include "aliasesexpandjob.h"
27 #include "messagecomposersettings.h"
29 #include "messagecomposer/composer.h"
30 #include "messagecomposer/infopart.h"
32 #include <KPIMUtils/Email>
34 using namespace MessageComposer
;
36 EmailAddressResolveJob::EmailAddressResolveJob( QObject
*parent
)
37 : KJob( parent
), mJobCount( 0 )
41 EmailAddressResolveJob::~EmailAddressResolveJob()
45 static inline bool containsAliases( const QString
&address
)
47 return !address
.contains( QLatin1Char( '@' ) );
50 static bool containsAliases( const QStringList
&addresses
)
52 foreach ( const QString
&address
, addresses
) {
53 if ( containsAliases( address
) )
60 void EmailAddressResolveJob::start()
62 QVector
<AliasesExpandJob
*> jobs
;
64 if ( containsAliases( mFrom
) ) {
65 AliasesExpandJob
*job
= new AliasesExpandJob( mFrom
, MessageComposerSettings::defaultDomain(), this );
66 job
->setProperty( "id", QLatin1String( "infoPartFrom" ) );
67 connect( job
, SIGNAL(result(KJob
*)), SLOT(slotAliasExpansionDone(KJob
*)) );
71 if ( containsAliases( mTo
) ) {
72 AliasesExpandJob
*job
= new AliasesExpandJob( mTo
.join( QLatin1String( ", " ) ), MessageComposerSettings::defaultDomain(), this );
73 job
->setProperty( "id", QLatin1String( "infoPartTo" ) );
74 connect( job
, SIGNAL(result(KJob
*)), SLOT(slotAliasExpansionDone(KJob
*)) );
78 if ( containsAliases( mCc
) ) {
79 AliasesExpandJob
*job
= new AliasesExpandJob( mCc
.join( QLatin1String( ", " ) ), MessageComposerSettings::defaultDomain(), this );
80 job
->setProperty( "id", QLatin1String( "infoPartCc" ) );
81 connect( job
, SIGNAL(result(KJob
*)), SLOT(slotAliasExpansionDone(KJob
*)) );
85 if ( containsAliases( mBcc
) ) {
86 AliasesExpandJob
*job
= new AliasesExpandJob( mBcc
.join( QLatin1String( ", " ) ), MessageComposerSettings::defaultDomain(), this );
87 job
->setProperty( "id", QLatin1String( "infoPartBcc" ) );
88 connect( job
, SIGNAL(result(KJob
*)), SLOT(slotAliasExpansionDone(KJob
*)) );
92 mJobCount
= jobs
.count();
94 if ( mJobCount
== 0 ) {
97 foreach ( AliasesExpandJob
*job
, jobs
)
102 void EmailAddressResolveJob::slotAliasExpansionDone( KJob
*job
)
104 if ( job
->error() ) {
105 setError( job
->error() );
106 setErrorText( job
->errorText() );
111 const AliasesExpandJob
*expandJob
= qobject_cast
<AliasesExpandJob
*>( job
);
112 mResultMap
.insert( expandJob
->property( "id" ).toString(), expandJob
->addresses() );
115 if ( mJobCount
== 0 ) {
120 void EmailAddressResolveJob::setFrom( const QString
&from
)
123 mResultMap
.insert( QLatin1String( "infoPartFrom" ), from
);
126 void EmailAddressResolveJob::setTo( const QStringList
&to
)
129 mResultMap
.insert( QLatin1String( "infoPartTo" ), to
.join( QLatin1String( ", " ) ) );
132 void EmailAddressResolveJob::setCc( const QStringList
&cc
)
135 mResultMap
.insert( QLatin1String( "infoPartCc" ), cc
.join( QLatin1String( ", " ) ) );
138 void EmailAddressResolveJob::setBcc( const QStringList
&bcc
)
141 mResultMap
.insert( QLatin1String( "infoPartBcc" ), bcc
.join( QLatin1String( ", " ) ) );
145 QString
EmailAddressResolveJob::expandedFrom() const
147 return mResultMap
.value( QLatin1String( "infoPartFrom" ) ).toString();
150 QStringList
EmailAddressResolveJob::expandedTo() const
152 return KPIMUtils::splitAddressList( mResultMap
.value( QLatin1String( "infoPartTo" ) ).toString() );
155 QStringList
EmailAddressResolveJob::expandedCc() const
157 return KPIMUtils::splitAddressList( mResultMap
.value( QLatin1String( "infoPartCc" ) ).toString() );
161 QStringList
EmailAddressResolveJob::expandedBcc() const
163 return KPIMUtils::splitAddressList( mResultMap
.value( QLatin1String( "infoPartBcc" ) ).toString() );
166 #include "emailaddressresolvejob.moc"