share: fix case where no default mail client

Change-Id: I534382c60c5efbf9d6669e4adddc39e4d6f079d9
Tuleap: #411
diff --git a/utils.cpp b/utils.cpp
index 556f012..49bbd7b 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -19,6 +19,7 @@
 #include "utils.h"
 
 #ifdef Q_OS_WIN
+#include <windows.h>
 #include <lmcons.h>
 #include <shobjidl.h>
 #include <shlguid.h>
@@ -26,6 +27,11 @@
 #include <shlwapi.h>
 #endif
 
+
+//Qt
+#include <QObject>
+#include <QErrorMessage>
+
 bool
 Utils::CreateStartupLink()
 {
@@ -165,8 +171,17 @@
 Utils::InvokeMailto(const QString& subject,
                     const QString& body,
                     const QString& attachement) {
-    auto addr = QString("mailto:?subject=%1&body=%2").arg(subject).arg(body);
-    if (not attachement.isEmpty())
-        addr += QString("&attachement=%1").arg(attachement);
-    ShellExecute(nullptr, L"open", addr.toStdWString().c_str(), NULL, NULL, SW_SHOWNORMAL);
+#ifdef Q_OS_WIN
+    HKEY hKey;
+    LONG lRes = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"mailto", 0, KEY_READ, &hKey);
+    if (lRes != ERROR_FILE_NOT_FOUND) {
+        auto addr = QString("mailto:?subject=%1&body=%2").arg(subject).arg(body);
+        if (not attachement.isEmpty())
+            addr += QString("&attachement=%1").arg(attachement);
+        ShellExecute(nullptr, L"open", addr.toStdWString().c_str(), NULL, NULL, SW_SHOWNORMAL);
+    } else {
+        QErrorMessage errorMessage;
+        errorMessage.showMessage(QObject::tr("No default mail client found"));
+    }
+#endif
 }