1 /*******************************************************************************
4 ** Created on : 03 April, 2005
5 ** Copyright : (c) 2005 Till Adam
6 ** Email : <adam@kde.org>
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
37 *******************************************************************************/
41 #include "imapsettings.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>
61 #include <kio/jobuidelegate.h>
66 #include "foldercollection.h"
68 using namespace MailCommon
;
71 KMime::Types::Mailbox::List
KMail::Util::mailingListsFromMessage( const Akonadi::Item
& item
)
73 KMime::Types::Mailbox::List 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
<< MessageCore::StringUtil::mailboxFromUnicodeString( fd
->mailingListPostAddress() );
87 Akonadi::Item::Id
KMail::Util::putRepliesInSameFolder( const Akonadi::Item
& item
)
89 Akonadi::Collection parentCollection
= item
.parentCollection();
90 QSharedPointer
<FolderCollection
> fd
;
91 if ( parentCollection
.isValid() ) {
92 fd
= FolderCollection::forCollection( parentCollection
);
93 if( fd
->putRepliesInSameFolder() ) {
94 return parentCollection
.id();
100 void KMail::Util::launchAccountWizard( QWidget
*w
)
103 lst
.append( "--type" );
104 lst
.append( "message/rfc822" );
106 const QString path
= KStandardDirs::findExe( QLatin1String("accountwizard" ) );
107 if( !QProcess::startDetached( path
, lst
) )
108 KMessageBox::error( w
, i18n( "Could not start the account wizard. "
109 "Please check your installation." ),
110 i18n( "Unable to start account wizard" ) );
114 void KMail::Util::handleClickedURL( const KUrl
&url
, uint identity
)
116 if ( url
.protocol() == "mailto" )
118 KMime::Message::Ptr
msg ( new KMime::Message
);
119 MessageHelper::initHeader( msg
, KMKernel::self()->identityManager(), identity
);
120 msg
->contentType()->setCharset("utf-8");
122 QMap
<QString
, QString
> fields
= MessageCore::StringUtil::parseMailtoUrl( url
);
124 msg
->to()->fromUnicodeString( fields
.value( "to" ),"utf-8" );
125 if ( !fields
.value( "subject" ).isEmpty() )
126 msg
->subject()->fromUnicodeString( fields
.value( "subject" ),"utf-8" );
127 if ( !fields
.value( "body" ).isEmpty() )
128 msg
->setBody( fields
.value( "body" ).toUtf8() );
129 if ( !fields
.value( "cc" ).isEmpty() )
130 msg
->cc()->fromUnicodeString( fields
.value( "cc" ),"utf-8" );
132 KMail::Composer
* win
= KMail::makeComposer( msg
, KMail::Composer::New
, identity
);
133 win
->setFocusToSubject();
136 kWarning() << "Can't handle URL:" << url
;