Skip to content

Commit

Permalink
require option -c to prompt for cache encryption during oauth2 setup
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Mar 18, 2023
1 parent 9a2dcc4 commit 774668f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Usage:

Command-line Options:

-c, --cache-encrypt
prompt for cache encryption during oauth2 setup

-d, --confdir <DIR>
use a different directory than ~/.nmail

Expand Down
19 changes: 15 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static bool ObtainAuthPasswords(const bool p_IsSetup, const std::string& p_User,
std::string& p_Pass, std::string& p_SmtpUser, std::string& p_SmtpPass,
std::shared_ptr<Config> p_SecretConfig, std::shared_ptr<Config> p_MainConfig);
static bool ObtainCacheEncryptPassword(const bool p_IsSetup, const std::string& p_User,
bool p_SetupAllowCacheEncrypt,
std::string& p_Pass, std::string& p_SmtpUser, std::string& p_SmtpPass,
std::shared_ptr<Config> p_SecretConfig, std::shared_ptr<Config> p_MainConfig);
static bool ReportConfigError(const std::string& p_Param);
Expand Down Expand Up @@ -63,14 +64,19 @@ int main(int argc, char* argv[])
Log::SetVerboseLevel(Log::INFO_LEVEL);
bool online = true;
bool changePass = false;
bool setupAllowCacheEncrypt = false;
std::string setup;
std::string exportDir;

// Argument handling
std::vector<std::string> args(argv + 1, argv + argc);
for (auto it = args.begin(); it != args.end(); ++it)
{
if (((*it == "-d") || (*it == "--configdir")) && (std::distance(it + 1, args.end()) > 0))
if ((*it == "-c") || (*it == "--cache-encrypt"))
{
setupAllowCacheEncrypt = true;
}
else if (((*it == "-d") || (*it == "--configdir")) && (std::distance(it + 1, args.end()) > 0))
{
++it;
Util::SetApplicationDir(*it);
Expand Down Expand Up @@ -334,7 +340,7 @@ int main(int argc, char* argv[])
}
else
{
if (!ObtainCacheEncryptPassword(isSetup, user, pass, smtpUser, smtpPass, secretConfig, mainConfig))
if (!ObtainCacheEncryptPassword(isSetup, user, setupAllowCacheEncrypt, pass, smtpUser, smtpPass, secretConfig, mainConfig))
{
return 1;
}
Expand Down Expand Up @@ -432,6 +438,7 @@ static void ShowHelp()
"Usage: nmail [OPTION]\n"
"\n"
"Options:\n"
" -c, --cache-encrypt prompt for cache encryption during oauth2 setup\n"
" -d, --confdir <DIR> use a different directory than ~/.nmail\n"
" -e, --verbose enable verbose logging\n"
" -ee, --extra-verbose enable extra verbose logging\n"
Expand Down Expand Up @@ -658,13 +665,17 @@ static bool ObtainAuthPasswords(const bool p_IsSetup, const std::string& p_User,
}

static bool ObtainCacheEncryptPassword(const bool p_IsSetup, const std::string& p_User,
bool p_SetupAllowCacheEncrypt,
std::string& p_Pass, std::string& p_SmtpUser, std::string& p_SmtpPass,
std::shared_ptr<Config> p_SecretConfig, std::shared_ptr<Config> p_MainConfig)
{
if (p_IsSetup)
{
std::cout << "Cache Encryption Password (optional): ";
p_Pass = Util::GetPass();
if (p_SetupAllowCacheEncrypt)
{
std::cout << "Cache Encryption Password (optional): ";
p_Pass = Util::GetPass();
}

if (p_Pass.empty())
{
Expand Down
5 changes: 4 additions & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "March 2023" "nmail v4.19" "User Commands"
.TH NMAIL "1" "March 2023" "nmail v4.20" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand All @@ -10,6 +10,9 @@ nmail is a terminal\-based email client with a user interface similar to
alpine / pine, supporting IMAP and SMTP.
.SH OPTIONS
.TP
\fB\-c\fR, \fB\-\-cache\-encrypt\fR
prompt for cache encryption during oauth2 setup
.TP
\fB\-d\fR, \fB\-\-confdir\fR <DIR>
use a different directory than ~/.nmail
.TP
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "4.19"
#define NMAIL_VERSION "4.20"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit 774668f

Please sign in to comment.