Complete the SASL authentication code to also handle the complex
[kdepim.git] / kmail / util.cpp
blob4147cc0dd5592a3f85bfd4d16ce497890d7eb5c5
1 /*******************************************************************************
2 **
3 ** Filename : util
4 ** Created on : 03 April, 2005
5 ** Copyright : (c) 2005 Till Adam
6 ** Email : <adam@kde.org>
7 **
8 *******************************************************************************/
10 /*******************************************************************************
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
17 ** It is distributed in the hope that it will be useful, but
18 ** WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 ** In addition, as a special exception, the copyright holders give
27 ** permission to link the code of this program with any edition of
28 ** the Qt library by Trolltech AS, Norway (or with modified versions
29 ** of Qt that use the same license as Qt), and distribute linked
30 ** combinations including the two. You must obey the GNU General
31 ** Public License in all respects for all of the code used other than
32 ** Qt. If you modify this file, you may extend this exception to
33 ** your version of the file, but you are not obligated to do so. If
34 ** you do not wish to do so, delete this exception statement from
35 ** your version.
37 *******************************************************************************/
40 #include "util.h"
41 #include "imapsettings.h"
42 #include "kmkernel.h"
44 #include "messagecore/stringutil.h"
45 #include "messagecomposer/messagehelper.h"
49 #include <kmime/kmime_message.h>
50 #include <kpimutils/email.h>
51 #include <kimap/loginjob.h>
52 #include <mailtransport/transport.h>
53 #include <Akonadi/AgentManager>
54 #include <Akonadi/EntityTreeModel>
55 #include <akonadi/entitymimetypefiltermodel.h>
57 #include <KStandardDirs>
58 #include <kascii.h>
59 #include <KCharsets>
60 #include <KJob>
61 #include <kio/jobuidelegate.h>
64 #include <stdlib.h>
66 #include "foldercollection.h"
68 using namespace MailCommon;
71 QStringList KMail::Util::mailingListsFromMessage( const Akonadi::Item& item )
73 QStringList addresses;
74 // determine the mailing list posting address
75 Akonadi::Collection parentCollection = item.parentCollection();
76 QSharedPointer<FolderCollection> fd;
77 if ( parentCollection.isValid() ) {
78 fd = FolderCollection::forCollection( parentCollection );
79 if ( fd->isMailingListEnabled() && !fd->mailingListPostAddress().isEmpty() ) {
80 addresses << fd->mailingListPostAddress();
83 return addresses;
86 Akonadi::Item::Id KMail::Util::putRepliesInSameFolder( const Akonadi::Item& item )
88 Akonadi::Collection parentCollection = item.parentCollection();
89 QSharedPointer<FolderCollection> fd;
90 if ( parentCollection.isValid() ) {
91 fd = FolderCollection::forCollection( parentCollection );
92 if( fd->putRepliesInSameFolder() ) {
93 return parentCollection.id();
96 return -1;
99 void KMail::Util::launchAccountWizard( QWidget *w )
101 QStringList lst;
102 lst.append( "--type" );
103 lst.append( "message/rfc822" );
105 const QString path = KStandardDirs::findExe( QLatin1String("accountwizard" ) );
106 if( !QProcess::startDetached( path, lst ) )
107 KMessageBox::error( w, i18n( "Could not start the account wizard. "
108 "Please check your installation." ),
109 i18n( "Unable to start account wizard" ) );
113 void KMail::Util::handleClickedURL( const KUrl &url, uint identity )
115 if ( url.protocol() == "mailto" )
117 KMime::Message::Ptr msg ( new KMime::Message );
118 MessageHelper::initHeader( msg, KMKernel::self()->identityManager(), identity );
119 msg->contentType()->setCharset("utf-8");
121 QMap<QString, QString> fields = MessageCore::StringUtil::parseMailtoUrl( url );
123 msg->to()->fromUnicodeString( fields.value( "to" ),"utf-8" );
124 if ( !fields.value( "subject" ).isEmpty() )
125 msg->subject()->fromUnicodeString( fields.value( "subject" ),"utf-8" );
126 if ( !fields.value( "body" ).isEmpty() )
127 msg->setBody( fields.value( "body" ).toUtf8() );
128 if ( !fields.value( "cc" ).isEmpty() )
129 msg->cc()->fromUnicodeString( fields.value( "cc" ),"utf-8" );
131 KMail::Composer * win = KMail::makeComposer( msg, KMail::Composer::New, identity );
132 win->setFocusToSubject();
133 win->show();
134 } else {
135 kWarning() << "Can't handle URL:" << url;