From 1f3b9bb1ebb5377543842e50cd9098aeb3bf02ba Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Wed, 2 Jan 2013 22:04:51 +0100 Subject: [PATCH] Allow to attach folder. But ask if it's not an error. so we know what we will attach. For example it will avoid to attach $HOME :) --- CMakeLists.txt | 2 +- kmail_addattachmentfolderservicemenu.desktop | 10 ++++++++++ kmkernel.cpp | 12 +++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 kmail_addattachmentfolderservicemenu.desktop diff --git a/CMakeLists.txt b/CMakeLists.txt index dc8d403b9..3f85ef9ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,7 +302,7 @@ if (NOT WINCE AND KDEPIM_BUILD_DESKTOP) DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} ) - install( FILES kmail_addattachmentservicemenu.desktop DESTINATION + install( FILES kmail_addattachmentservicemenu.desktop kmail_addattachmentfolderservicemenu.desktop DESTINATION ${SERVICES_INSTALL_DIR}/ServiceMenus) endif (NOT WINCE AND KDEPIM_BUILD_DESKTOP) diff --git a/kmail_addattachmentfolderservicemenu.desktop b/kmail_addattachmentfolderservicemenu.desktop new file mode 100644 index 000000000..9ca76cc8b --- /dev/null +++ b/kmail_addattachmentfolderservicemenu.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Service +ServiceTypes=KonqPopupMenu/Plugin +MimeType=inode/directory; +Actions=attachfolder; + +[Desktop Action attachfolder] +Icon=kmail +Name=Send Directory as Email Attachment +Exec=kmail --attach %F diff --git a/kmkernel.cpp b/kmkernel.cpp index 5a15f7476..369190ae9 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -646,8 +646,8 @@ int KMKernel::openComposer( const QString &to, const QString &cc, const int pos = (*it).indexOf( ':' ); if ( pos > 0 ) { - QString header = (*it).left( pos ).trimmed(); - QString value = (*it).mid( pos+1 ).trimmed(); + const QString header = (*it).left( pos ).trimmed(); + const QString value = (*it).mid( pos+1 ).trimmed(); if ( !header.isEmpty() && !value.isEmpty() ) { KMime::Headers::Generic *h = new KMime::Headers::Generic( header.toUtf8(), msg.get(), value.toUtf8() ); msg->setHeader( h ); @@ -660,8 +660,14 @@ int KMKernel::openComposer( const QString &to, const QString &cc, if (!to.isEmpty()) cWin->setFocusToSubject(); KUrl::List attachURLs = KUrl::List( attachmentPaths ); - for ( KUrl::List::ConstIterator it = attachURLs.constBegin() ; it != attachURLs.constEnd() ; ++it ) + for ( KUrl::List::ConstIterator it = attachURLs.constBegin() ; it != attachURLs.constEnd() ; ++it ) { + if( KMimeType::findByUrl( *it )->name() == QLatin1String( "inode/directory" ) ) { + if(KMessageBox::questionYesNo(0, i18n("Do you want to attach this folder \"%1\"?",(*it).prettyUrl()), i18n("Attach Folder")) == KMessageBox::No ) { + continue; + } + } cWin->addAttachment( (*it), "" ); + } if ( !hidden ) { cWin->show(); // Activate window - doing this instead of KWindowSystem::activateWindow(cWin->winId());