43 #include "calendarinterface.h"
46 #include "pop3settings.h"
50 #include "mailimporter/filterbalsa.h"
51 #include "mailimporter/filter_evolution.h"
52 #include "mailimporter/filter_evolution_v2.h"
53 #include "mailimporter/filter_evolution_v3.h"
54 #include "mailimporter/filter_clawsmail.h"
55 #include "mailimporter/filter_sylpheed.h"
56 #include "mailimporter/filter_thunderbird.h"
57 #include "mailimporter/filter_opera.h"
58 #include "mailimporter/othermailerutil.h"
60 #include <incidenceeditor-ng/globalsettings.h>
61 #include <incidenceeditor-ng/incidencedialogfactory.h>
63 #include <messagecore/utils/stringutil.h>
64 #include <messagecore/helpers/messagehelpers.h>
66 #include <messagecomposer/helper/messagehelper.h>
68 #include <Akonadi/AgentManager>
69 #include <Akonadi/EntityMimeTypeFilterModel>
70 #include <Akonadi/EntityTreeModel>
71 #include <Akonadi/ItemFetchJob>
72 #include <Akonadi/ItemFetchScope>
73 #include <Akonadi/KMime/MessageParts>
75 #include <KMime/KMimeMessage>
77 #include <KPIMUtils/Email>
79 #include <KColorScheme>
80 #include <KDBusServiceStarter>
83 #include <KMessageBox>
84 #include <KTemporaryFile>
85 #include <KIO/JobUiDelegate>
89 const QString &ident )
92 new OrgKdeAkonadiPOP3SettingsInterface(
93 QLatin1String(
"org.freedesktop.Akonadi.Resource.") + ident, QLatin1String(
"/Settings"), QDBusConnection::sessionBus() );
105 resource == QLatin1String(
"akonadi_nepomuktag_resource" ) ||
106 resource == QLatin1String(
"akonadi_search_resource" ) );
111 return resource.contains(QLatin1String(
"akonadi_mbox_resource")) ||
112 resource.contains(QLatin1String(
"akonadi_maildir_resource")) ||
113 resource.contains(QLatin1String(
"akonadi_mixedmaildir_resource"));
122 Akonadi::EntityTreeModel::modelIndexForCollection(
KernelIf->collectionModel(), collection );
123 if ( !idx.isValid() ) {
127 fullPath = idx.data().toString();
129 while ( idx != QModelIndex() ) {
130 fullPath = idx.data().toString() + QLatin1Char(
'/') + fullPath;
138 if ( job->error() ) {
139 if ( static_cast<KIO::Job*>( job )->ui() ) {
140 static_cast<KIO::Job*
>(job)->ui()->showErrorMessage();
142 kDebug() <<
" job->errorString() :"<<job->errorString();
151 Akonadi::AgentInstance::List relevantInstances;
152 foreach (
const Akonadi::AgentInstance &instance, Akonadi::AgentManager::self()->instances() ) {
153 const QStringList capabilities( instance.type().capabilities() );
154 if ( instance.type().mimeTypes().contains( KMime::Message::mimeType() ) ) {
155 if ( capabilities.contains( QLatin1String(
"Resource") ) &&
156 !capabilities.contains( QLatin1String(
"Virtual") ) &&
157 !capabilities.contains( QLatin1String(
"MailTransport") ) )
159 relevantInstances << instance;
160 }
else if ( !excludeMailDispacher &&
161 instance.identifier() == QLatin1String(
"akonadi_maildispatcher_agent" ) ) {
162 relevantInstances << instance;
166 return relevantInstances;
179 #if defined (Q_OS_WINCE) || defined(Q_OS_WIN32)
181 QDBusInterface *
interface = new QDBusInterface( QLatin1String("org.kde.korganizer"), QLatin1String("/MainApplication") );
182 if ( !interface->isValid() ) {
183 kDebug() <<
"Starting korganizer...";
185 QDBusServiceWatcher *watcher =
186 new QDBusServiceWatcher( QLatin1String(
"org.kde.korganizer"), QDBusConnection::sessionBus(),
187 QDBusServiceWatcher::WatchForRegistration );
189 watcher->connect( watcher, SIGNAL(serviceRegistered(QString)), &loop, SLOT(quit()) );
190 result = QProcess::startDetached( QLatin1String(
"korganizer-mobile") );
192 kDebug() <<
"Starting loop";
194 kDebug() <<
"Korganizer finished starting";
196 kWarning() <<
"Failed to start korganizer with QProcess";
205 #ifdef KDEPIM_MOBILE_UI
207 constraint = QLatin1String(
"'mobile' in Keywords");
210 result = KDBusServiceStarter::self()->findServiceFor( QLatin1String(
"DBUS/Organizer"),
212 &error, &dbusService ) == 0;
216 QDBusInterface iface( QLatin1String(
"org.kde.korganizer"), QLatin1String(
"/MainApplication"),
217 QLatin1String(
"org.kde.KUniqueApplication") );
218 if ( iface.isValid() ) {
220 iface.call( QLatin1String(
"newInstance") );
223 QDBusInterface pimIface(
"org.kde.korganizer",
"/korganizer_PimApplication",
224 "org.kde.KUniqueApplication" );
225 QDBusReply<bool> r = pimIface.call(
"load" );
226 if ( !r.isValid() || !r.value() ) {
227 kWarning() <<
"Loading korganizer failed: " << pimIface.lastError().message();
231 kWarning() <<
"Couldn't obtain korganizer D-Bus interface" << iface.lastError().message();
237 kWarning() <<
"Couldn't start DBUS/Organizer:" << dbusService << error;
243 const Akonadi::Item &mailItem )
245 Akonadi::Item item( mailItem );
248 if ( !item.loadedPayloadParts().contains( Akonadi::MessagePart::Body ) ) {
249 Akonadi::ItemFetchJob *job =
new Akonadi::ItemFetchJob( item );
250 job->fetchScope().fetchFullPayload();
252 if ( job->items().count() == 1 ) {
253 item = job->items().first();
258 KMime::Message::Ptr msg = MessageCore::Util::message( item );
264 bool isInlineAttachment =
false;
265 QStringList attachmentUris;
268 tf.setAutoRemove(
false );
271 kWarning() <<
"CreateIncidenceFromMail: Unable to open temp file.";
275 const QString incidenceDescription =
276 i18n(
"From: %1\nTo: %2\nSubject: %3",
277 msg->from()->asUnicodeString(),
278 msg->to()->asUnicodeString(),
279 msg->subject()->asUnicodeString() );
281 QStringList attachmentLabels;
282 attachmentLabels << msg->subject()->asUnicodeString();
284 QStringList attachmentMimeTypes;
285 attachmentMimeTypes << QLatin1String(
"message/rfc822" );
287 int action = IncidenceEditorNG::GlobalSettings::self()->defaultEmailAttachMethod();
288 if ( IncidenceEditorNG::GlobalSettings::self()->defaultEmailAttachMethod() ==
289 IncidenceEditorNG::GlobalSettings::Ask ) {
292 if ( !dialog.exec() ) {
298 action = IncidenceEditorNG::GlobalSettings::Link;
301 action = IncidenceEditorNG::GlobalSettings::InlineFull;
304 action = IncidenceEditorNG::GlobalSettings::InlineBody;
310 case IncidenceEditorNG::GlobalSettings::Link:
311 attachmentUris << mailItem.url( Akonadi::Item::UrlWithMimeType ).url();
312 isInlineAttachment =
false;
314 case IncidenceEditorNG::GlobalSettings::InlineFull:
315 tf.write( msg->encodedContent() );
318 attachmentUris << tf.fileName();
319 isInlineAttachment =
true;
321 case IncidenceEditorNG::GlobalSettings::InlineBody:
323 if ( msg.get() == msg->textContent() || msg->textContent() == 0 ) {
324 tf.write( msg->encodedContent() );
327 attachmentUris << tf.fileName();
328 isInlineAttachment =
true;
330 if ( KMessageBox::warningContinueCancel(
332 i18n(
"Removing attachments from an email might invalidate its signature." ),
333 i18n(
"Remove Attachments" ),
334 KStandardGuiItem::cont(),
335 KStandardGuiItem::cancel(),
336 QLatin1String(
"BodyOnlyInlineAttachment") ) != KMessageBox::Continue ) {
340 KMime::Message::Ptr newMsg(
new KMime::Message() );
341 newMsg->setHead( msg->head() );
342 newMsg->setBody( msg->textContent()->body() );
344 newMsg->contentTransferEncoding()->from7BitString(
345 msg->textContent()->contentTransferEncoding()->as7BitString() );
346 newMsg->contentType()->from7BitString( msg->textContent()->contentType()->as7BitString() );
348 tf.write( newMsg->encodedContent() );
351 attachmentUris << tf.fileName();
352 isInlineAttachment =
true;
359 kDebug() <<
"AttachmentUris = " << attachmentUris
360 <<
"; isInlineAttachment = " << isInlineAttachment
361 <<
"; mimeTypes = " << attachmentMimeTypes;
363 #ifndef KDEPIM_MOBILE_UI
364 kDebug() <<
"desktop";
366 case KCalCore::IncidenceBase::TypeEvent:
367 IncidenceEditorNG::IncidenceDialogFactory::createEventEditor(
368 i18n(
"Mail: %1", msg->subject()->asUnicodeString() ),
369 incidenceDescription,
375 Akonadi::Collection(),
379 case KCalCore::IncidenceBase::TypeTodo:
380 IncidenceEditorNG::IncidenceDialogFactory::createTodoEditor(
381 i18n(
"Mail: %1", msg->subject()->asUnicodeString() ),
382 incidenceDescription,
388 Akonadi::Collection(),
397 kDebug() <<
"mobile";
399 kDebug() <<
"opening editor";
400 OrgKdeKorganizerCalendarInterface *iface =
401 new OrgKdeKorganizerCalendarInterface( QLatin1String(
"org.kde.korganizer"), QLatin1String(
"/Calendar"),
402 QDBusConnection::sessionBus() );
404 case KCalCore::IncidenceBase::TypeEvent:
405 iface->openEventEditor(
406 i18n(
"Mail: %1", msg->subject()->asUnicodeString() ),
407 incidenceDescription,
411 isInlineAttachment );
414 case KCalCore::IncidenceBase::TypeTodo:
415 iface->openTodoEditor(
416 i18n(
"Mail: %1", msg->subject()->asUnicodeString() ),
417 incidenceDescription,
421 isInlineAttachment );
449 if ( item.isValid() && item.parentCollection().isValid() ) {
450 Akonadi::Collection col = item.parentCollection();
451 if ( col.resource().isEmpty()) {
455 FolderCollection::forCollection( col,
false );
465 if ( model->rowCount( current ) > 0 ) {
466 return model->index( 0, 0, current );
470 const QModelIndex parent = model->parent( current );
471 const QModelIndex sibling = model->index( current.row() + 1, 0, parent );
473 if ( sibling.isValid() ) {
477 if ( !parent.isValid() ) {
478 return QModelIndex();
482 const QModelIndex parentsSibling = parent.sibling( parent.row() + 1, 0 );
483 if ( parentsSibling.isValid() ) {
484 return parentsSibling;
488 QModelIndex currentParent = parent;
489 QModelIndex grandParent = model->parent( currentParent );
490 while ( currentParent.isValid() ) {
492 if ( model->rowCount( grandParent ) > currentParent.row() + 1 ) {
493 const QModelIndex index =
494 indexBelow( model, model->index( currentParent.row() + 1, 0, grandParent ) );
495 if ( index.isValid() ) {
500 currentParent = grandParent;
501 grandParent = model->parent( currentParent );
504 return QModelIndex();
509 if ( model->rowCount( current ) == 0 ) {
513 return lastChildOfModel( model, model->index( model->rowCount( current ) - 1, 0, current ) );
518 const QModelIndex parent = model->parent( current );
520 if ( current.row() == 0 ) {
526 const QModelIndex previousSibling = model->index( current.row() - 1, 0, parent );
534 const QModelIndex ¤t,
536 bool (*ignoreCollectionCallback)(
const Akonadi::Collection &collection ) )
538 QModelIndex index = current;
546 if ( !index.isValid() ) {
547 return QModelIndex();
551 const Akonadi::Collection collection =
552 index.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
554 if ( collection.isValid() ) {
557 if ( collection.statistics().unreadCount() > 0 ) {
558 if ( ignoreCollectionCallback && ignoreCollectionCallback( collection ) ) {
568 return QModelIndex();
588 QString realPath( path );
589 realPath.remove( QLatin1String(
".directory") );
590 realPath.replace( QLatin1String(
"/."), QLatin1String(
"/") );
591 if ( !realPath.isEmpty() && ( realPath.at( 0 ) == QLatin1Char(
'.') ) ) {
592 realPath.remove( 0, 1 );
599 KColorScheme scheme( QPalette::Active, KColorScheme::View );
600 return scheme.foreground( KColorScheme::NegativeText ).color();
606 KernelIf->jobScheduler()->registerTask( task );
611 const QModelIndex idx = Akonadi::EntityTreeModel::modelIndexForCollection(
KernelIf->collectionModel(), col );
612 const Akonadi::Collection collection = idx.data( Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>();
618 Akonadi::Collection::Id newFolderId=-1;
619 bool exactPath =
false;
621 if ( lst.count() == 1 && exactPath )
622 newFolderId = lst.at( 0 ).id();
626 newFolderId = dlg->selectedCollection().id();
636 if (newFolderId == -1 )
638 return QString::number(newFolderId);
644 lst << MailImporter::FilterEvolution::defaultSettingsPath();
645 lst << MailImporter::FilterEvolution_v2::defaultSettingsPath();
646 lst << MailImporter::FilterEvolution_v3::defaultSettingsPath();
647 lst << MailImporter::FilterBalsa::defaultSettingsPath();
648 lst << MailImporter::FilterClawsMail::defaultSettingsPath();
649 lst << MailImporter::FilterOpera::defaultSettingsPath();
650 lst << MailImporter::FilterSylpheed::defaultSettingsPath();
651 lst << MailImporter::FilterThunderbird::defaultSettingsPath();
652 lst << MailImporter::OtherMailerUtil::trojitaDefaultPath();
654 Q_FOREACH(
const QString& path, lst) {
655 QDir directory( path );
656 if ( directory.exists() ) {
MAILCOMMON_EXPORT bool ignoreNewMailInFolder(const Akonadi::Collection &collection)
MAILCOMMON_EXPORT QColor defaultQuotaColor()
MAILCOMMON_EXPORT Akonadi::AgentInstance::List agentInstances(bool excludeMailTransport=true)
MAILCOMMON_EXPORT bool createEventFromMail(const Akonadi::Item &mailItem)
static QModelIndex indexAbove(QAbstractItemModel *model, const QModelIndex ¤t)
MAILCOMMON_EXPORT bool isLocalCollection(const QString &resource)
MAILCOMMON_EXPORT bool isVirtualCollection(const Akonadi::Collection &col)
Type attachmentType() const
A scheduled "expire mails in this folder" task.
SearchDirection
Describes the direction for searching next unread collection.
MAILCOMMON_EXPORT Akonadi::Collection updatedCollection(const Akonadi::Collection &col)
MAILCOMMON_EXPORT Akonadi::Collection parentCollectionFromItem(const Akonadi::Item &item)
MAILCOMMON_EXPORT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &folder)
static QModelIndex indexBelow(QAbstractItemModel *model, const QModelIndex ¤t)
MAILCOMMON_EXPORT bool createTodoFromMail(const Akonadi::Item &mailItem)
static QModelIndex lastChildOfModel(QAbstractItemModel *model, const QModelIndex ¤t)
MAILCOMMON_EXPORT uint folderIdentity(const Akonadi::Item &item)
Returns the identity of the folder that contains the given Akonadi::Item.
MAILCOMMON_EXPORT bool showJobErrorMessage(KJob *job)
MAILCOMMON_EXPORT QString fullCollectionPath(const Akonadi::Collection &collection)
MAILCOMMON_EXPORT QString convertFolderPathToCollectionStr(const QString &folder)
MAILCOMMON_EXPORT QModelIndex nextUnreadCollection(QAbstractItemModel *model, const QModelIndex ¤t, SearchDirection direction, bool(*ignoreCollectionCallback)(const Akonadi::Collection &collection)=0)
Returns the index of the next unread collection following a given index.
bool ignoreNewMail() const
MAILCOMMON_EXPORT void expireOldMessages(const Akonadi::Collection &collection, bool immediate)
MAILCOMMON_EXPORT bool foundMailer()
MAILCOMMON_EXPORT QString realFolderPath(const QString &path)
MAILCOMMON_EXPORT bool ensureKorganizerRunning(bool switchTo)
static Akonadi::Collection::List potentialCorrectFolders(const QString &path, bool &exactPath)
MAILCOMMON_EXPORT OrgKdeAkonadiPOP3SettingsInterface * createPop3SettingsInterface(const QString &ident)
static bool createIncidenceFromMail(KCalCore::IncidenceBase::IncidenceType type, const Akonadi::Item &mailItem)