Verified Commit c343a62e authored by Andre Heinecke's avatar Andre Heinecke
Browse files

Take name / email prefill also from EMAIL env var

This adds another fallback to prefill name and email from
the environment.

We depend on KCodecs anyway so we can use it for this task.

GnuPG-Bug-Id: T5181
parent 5639dc83
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include <KSharedConfig> #include <KSharedConfig>
#include <KEMailSettings> #include <KEMailSettings>
#include <KEmailAddress>
#include <QLocale> #include <QLocale>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
...@@ -288,7 +289,7 @@ static void parseAlgoString(const QString &algoString, int *size, Subkey::Pubkey ...@@ -288,7 +289,7 @@ static void parseAlgoString(const QString &algoString, int *size, Subkey::Pubkey
/* Use Windows API to query the user name and email. /* Use Windows API to query the user name and email.
EXTENDED_NAME_FORMAT is documented in MSDN */ EXTENDED_NAME_FORMAT is documented in MSDN */
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString win_get_user_name (EXTENDED_NAME_FORMAT what) static QString win_get_user_name (EXTENDED_NAME_FORMAT what)
{ {
QString ret; QString ret;
wchar_t tmp[1]; wchar_t tmp[1];
...@@ -321,6 +322,19 @@ QString win_get_user_name (EXTENDED_NAME_FORMAT what) ...@@ -321,6 +322,19 @@ QString win_get_user_name (EXTENDED_NAME_FORMAT what)
} }
#endif #endif
static QString env_get_user_name (bool mbox)
{
const auto var = qEnvironmentVariable("EMAIL");
if (!var.isEmpty()) {
QString name, addrspec, comment;
const auto result = KEmailAddress::splitAddress (var, name, addrspec, comment);
if (result == KEmailAddress::AddressOk) {
return (mbox ? addrspec : name);
}
}
return QString ();
}
Q_DECLARE_METATYPE(GpgME::Subkey::PubkeyAlgo) Q_DECLARE_METATYPE(GpgME::Subkey::PubkeyAlgo)
namespace Kleo namespace Kleo
{ {
...@@ -1535,6 +1549,9 @@ void EnterDetailsPage::updateForm() ...@@ -1535,6 +1549,9 @@ void EnterDetailsPage::updateForm()
name = win_get_user_name(NameUnknown); name = win_get_user_name(NameUnknown);
} }
#endif #endif
if (name.isEmpty()) {
name = env_get_user_name (false);
}
ui.nameLE->setText(name); ui.nameLE->setText(name);
} }
if (ui.emailLE->text().isEmpty()) { if (ui.emailLE->text().isEmpty()) {
...@@ -1544,6 +1561,9 @@ void EnterDetailsPage::updateForm() ...@@ -1544,6 +1561,9 @@ void EnterDetailsPage::updateForm()
mbox = win_get_user_name(NameUserPrincipal); mbox = win_get_user_name(NameUserPrincipal);
} }
#endif #endif
if (mbox.isEmpty()) {
mbox = env_get_user_name (true);
}
ui.emailLE->setText(mbox); ui.emailLE->setText(mbox);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment