diff --git a/README.md b/README.md
index a6fabb2..f403b54 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,7 @@ Command-line Options:
prompt for cache encryption during oauth2 setup
-d, --confdir
- use a different directory than ~/.nmail
+ use a different directory than ~/.config/nmail
-e, --verbose
enable verbose logging
@@ -82,18 +82,15 @@ Command-line Options:
Configuration files:
- ~/.nmail/auth.conf
+ ~/.config/nmail/auth.conf
configures custom oauth2 client id and secret
- ~/.nmail/main.conf
+ ~/.config/nmail/main.conf
configures mail account and general settings
- ~/.nmail/ui.conf
+ ~/.config/nmail/ui.conf
customizes UI settings
- ~/.nmail/secret.conf
- stores saved passwords
-
Examples:
nmail -s gmail
@@ -236,8 +233,8 @@ file:
$ nmail
-Then open the config file `~/.nmail/main.conf` in your favourite text editor
-and fill out the required fields:
+Then open the config file `~/.config/nmail/main.conf` in your favourite text
+editor and fill out the required fields:
address=example@example.com
drafts=Drafts
@@ -251,7 +248,7 @@ and fill out the required fields:
trash=Trash
user=example@example.com
-Full example of a config file `~/.nmail/main.conf`:
+Full example of a config file `~/.config/nmail/main.conf`:
address=example@example.com
addressbook_encrypt=0
@@ -571,8 +568,8 @@ different config directories (and thus different email accounts), but it will
be just that - multiple instances - each in its own terminal. To facilitate
such usage one can set up aliases for accessing different accounts, e.g.:
- alias gm='nmail -d ${HOME}/.nmail-gm' # gmail
- alias hm='nmail -d ${HOME}/.nmail-hm' # hotmail
+ alias gm='nmail -d ${HOME}/.config/nmail-gm' # gmail
+ alias hm='nmail -d ${HOME}/.config/nmail-hm' # hotmail
Email Viewer
@@ -699,7 +696,7 @@ encrypted).
Storing the account password (`save_pass=1` in main.conf) is *not* secure.
While nmail encrypts the password, the key is trivial to determine from
the source code. Only store the password if measurements are taken to ensure
-`~/.nmail/secret.conf` cannot by accessed by a third-party.
+`~/.config/nmail/secret.conf` cannot by accessed by a third-party.
Configuration
@@ -708,8 +705,8 @@ Configuration
Aside from `main.conf` covered above, the following files can be used to
configure nmail.
-~/.nmail/ui.conf
-----------------
+~/.config/nmail/ui.conf
+-----------------------
This configuration file controls the UI aspects of nmail. Default configuration
file (platform-dependent defaults are left empty below):
@@ -1002,10 +999,11 @@ an email (default disabled).
### signature
Determines whether to suffix emails with a signature (default disabled). When
-enabled, nmail will use `~/.nmail/signature.txt` if present, or otherwise use
-`~/.signature` for signature plain text content. When composing markdown
-formatted emails, nmail will use `~/.nmail/signature.html` if present, for the
-html part, and otherwise simply convert the plain text signature to html.
+enabled, nmail will use `~/.config/nmail/signature.txt` if present, or
+otherwise use `~/.signature` for signature plain text content. When composing
+markdown formatted emails, nmail will use `~/.config/nmail/signature.html` if
+present, for the html part, and otherwise simply convert the plain text
+signature to html.
Note: For **custom html** signature to work properly, the plain text signature
should not be present more than once in the composed message, thus a very short
@@ -1029,14 +1027,14 @@ Controls which character to indicate that an email is unread (default: `N`).
For a more graphical interface, an emoji such as `✉` can be used.
-~/.nmail/colors.conf
---------------------
+~/.config/nmail/colors.conf
+---------------------------
This configuration file controls the configurable colors of nmail. For this
configuration to take effect, `colors_enabled=1` must be set in
-`~/.nmail/ui.conf`.
+`~/.config/nmail/ui.conf`.
Example color config files are provided in `/usr/local/share/nmail/themes`
-and can be used by overwriting `~/.nmail/colors.conf`.
+and can be used by overwriting `~/.config/nmail/colors.conf`.
### Htop style theme
@@ -1047,7 +1045,7 @@ nmail and htop.
To use this config:
- cp /usr/local/share/nmail/themes/htop-style.conf ~/.nmail/colors.conf
+ cp /usr/local/share/nmail/themes/htop-style.conf ~/.config/nmail/colors.conf
### Manual configuration
@@ -1119,8 +1117,8 @@ Selected messages in message list view.
Top / title bar.
-~/.nmail/auth.conf
-------------------
+~/.config/nmail/auth.conf
+-------------------------
This configuration file allows users to set up custom OAuth 2.0 client id and
client secret. If not specified, nmail uses its own application id and secret.
Default configuration file:
@@ -1164,7 +1162,7 @@ to `d99kris at gmail dot com` with subject `nmail google oauth2 invite` from
the google account address you would like to be invited.
Alternatively a user may set up their own OAuth 2.0 application with Google
-and configure `~/.nmail/auth.conf` accordingly.
+and configure `~/.config/nmail/auth.conf` accordingly.
Accessing Email Cache using Other Email Clients
diff --git a/doc/DEBUGGING.md b/doc/DEBUGGING.md
index 06ce4c2..7030fa1 100644
--- a/doc/DEBUGGING.md
+++ b/doc/DEBUGGING.md
@@ -4,7 +4,7 @@ If any issues are observed, try running nmail with verbose logging
nmail --verbose
-and provide a copy of `~/.nmail/log.txt` when reporting a bug.
+and provide a copy of `~/.config/nmail/log.txt` when reporting a bug.
If nmail **crashes** it's very useful to obtain a core dump and extract
information from it (such as the callstacks). See details below.
@@ -25,8 +25,8 @@ writable for all users by running:
sudo chmod og+w /cores
-Then enable core dumps only for nmail by editing `~/.nmail/main.conf` and
-setting:
+Then enable core dumps only for nmail by editing `~/.config/nmail/main.conf`
+and setting:
coredump_enabled=1
@@ -59,7 +59,8 @@ substantial amount of disk space:
Core Dumps - Linux
==================
-Enable core dumps only for nmail by editing `~/.nmail/main.conf` and setting:
+Enable core dumps only for nmail by editing `~/.config/nmail/main.conf` and
+setting:
coredump_enabled=1
diff --git a/src/main.cpp b/src/main.cpp
index a9630da..f0ddeee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
{
// Defaults
umask(S_IRWXG | S_IRWXO);
- Util::SetApplicationDir(std::string(getenv("HOME")) + std::string("/.nmail"));
+ Util::SetApplicationDir(Util::GetDefaultApplicationDir());
Log::SetVerboseLevel(Log::INFO_LEVEL);
bool online = true;
bool changePass = false;
@@ -462,47 +462,46 @@ static void ShowHelp()
"Usage: nmail [OPTION]\n"
"\n"
"Options:\n"
- " -c, --cache-encrypt prompt for cache encryption during oauth2 setup\n"
- " -d, --confdir use a different directory than ~/.nmail\n"
- " -e, --verbose enable verbose logging\n"
- " -ee, --extra-verbose enable extra verbose logging\n"
- " -h, --help display this help and exit\n"
- " -k, --keydump key code dump mode\n"
- " -o, --offline run in offline mode\n"
- " -p, --pass change password\n"
- " -s, --setup setup wizard for specified service, supported\n"
- " services: gmail, gmail-oauth2, icloud, outlook,\n"
- " outlook-oauth2\n"
- " -v, --version output version information and exit\n"
- " -x, --export export cache to specified dir in Maildir format\n"
+ " -c, --cache-encrypt prompt for cache encryption during oauth2 setup\n"
+ " -d, --confdir use a different directory than ~/.config/nmail\n"
+ " -e, --verbose enable verbose logging\n"
+ " -ee, --extra-verbose enable extra verbose logging\n"
+ " -h, --help display this help and exit\n"
+ " -k, --keydump key code dump mode\n"
+ " -o, --offline run in offline mode\n"
+ " -p, --pass change password\n"
+ " -s, --setup setup wizard for specified service, supported\n"
+ " services: gmail, gmail-oauth2, icloud, outlook,\n"
+ " outlook-oauth2\n"
+ " -v, --version output version information and exit\n"
+ " -x, --export export cache to specified dir in Maildir format\n"
"\n"
"Examples:\n"
- " nmail -s gmail setup nmail for a gmail account\n"
- " nmail running nmail without setup wizard will generate\n"
- " default configuration files in ~/.nmail dir if\n"
- " not present already, these can be manually edited\n"
- " to configure nmail for email service providers not\n"
- " supported by the built-in setup wizard (refer to\n"
- " FILES section on ~/.nmail/main.conf for details)\n"
+ " nmail -s gmail setup nmail for a gmail account\n"
+ " nmail running nmail without setup wizard will generate\n"
+ " default configuration files in the nmail dir if\n"
+ " not present already, these can be edited to\n"
+ " configure nmail for email service providers not\n"
+ " supported by the built-in setup wizard (refer to\n"
+ " FILES section for details)\n"
"\n"
"Files:\n"
- " ~/.nmail/auth.conf configures custom oauth2 client id and secret\n"
- " ~/.nmail/main.conf configures mail account and general settings, for\n"
- " full nmail functionality the following fields\n"
- " shall be configured:\n"
- " address (ex: example@example.com),\n"
- " drafts (folder name, ex: Drafts),\n"
- " imap_host (ex: imap.example.com),\n"
- " imap_port (ex: 993),\n"
- " inbox (folder name, ex: Inbox),\n"
- " name (ex: Firstname Lastname),\n"
- " sent (folder name, ex: Sent),\n"
- " smtp_host (ex: smtp.example.com),\n"
- " smtp_port (ex: 465 or 587),\n"
- " trash (folder name, ex: Trash),\n"
- " user (ex: example@example.com or example).\n"
- " ~/.nmail/ui.conf customizes UI settings\n"
- " ~/.nmail/secret.conf stores saved passwords\n"
+ " ~/.config/nmail/auth.conf configures custom oauth2 client id and secret\n"
+ " ~/.config/nmail/main.conf configures mail account and general settings,\n"
+ " for full functionality the following fields\n"
+ " shall be configured:\n"
+ " address (ex: example@example.com),\n"
+ " drafts (folder name, ex: Drafts),\n"
+ " imap_host (ex: imap.example.com),\n"
+ " imap_port (ex: 993),\n"
+ " inbox (folder name, ex: Inbox),\n"
+ " name (ex: Firstname Lastname),\n"
+ " sent (folder name, ex: Sent),\n"
+ " smtp_host (ex: smtp.example.com),\n"
+ " smtp_port (ex: 465 or 587),\n"
+ " trash (folder name, ex: Trash),\n"
+ " user (ex: example@example.com or example).\n"
+ " ~/.config/nmail/ui.conf customizes UI settings\n"
"\n"
"Report bugs at https://github.com/d99kris/nmail\n"
"\n";
diff --git a/src/nmail.1 b/src/nmail.1
index ca085bf..94c556a 100644
--- a/src/nmail.1
+++ b/src/nmail.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
-.TH NMAIL "1" "July 2024" "nmail 5.1.3" "User Commands"
+.TH NMAIL "1" "July 2024" "nmail 5.1.4" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
@@ -14,7 +14,7 @@ alpine / pine, supporting IMAP and SMTP.
prompt for cache encryption during oauth2 setup
.TP
\fB\-d\fR, \fB\-\-confdir\fR
-use a different directory than ~/.nmail
+use a different directory than ~/.config/nmail
.TP
\fB\-e\fR, \fB\-\-verbose\fR
enable verbose logging
@@ -46,12 +46,12 @@ output version information and exit
export cache to specified dir in Maildir format
.SH FILES
.TP
-~/.nmail/auth.conf
+~/.config/nmail/auth.conf
configures custom oauth2 client id and secret
.TP
-~/.nmail/main.conf
-configures mail account and general settings, for
-full nmail functionality the following fields
+~/.config/nmail/main.conf
+configures mail account and general settings,
+for full functionality the following fields
shall be configured:
address (ex: example@example.com),
drafts (folder name, ex: Drafts),
@@ -65,11 +65,8 @@ smtp_port (ex: 465 or 587),
trash (folder name, ex: Trash),
user (ex: example@example.com or example).
.TP
-~/.nmail/ui.conf
+~/.config/nmail/ui.conf
customizes UI settings
-.TP
-~/.nmail/secret.conf
-stores saved passwords
.SH EXAMPLES
.TP
nmail \-s gmail
@@ -77,11 +74,11 @@ setup nmail for a gmail account
.TP
nmail
running nmail without setup wizard will generate
-default configuration files in ~/.nmail dir if
-not present already, these can be manually edited
-to configure nmail for email service providers not
+default configuration files in the nmail dir if
+not present already, these can be edited to
+configure nmail for email service providers not
supported by the built\-in setup wizard (refer to
-FILES section on ~/.nmail/main.conf for details)
+FILES section for details)
.SH AUTHOR
Written by Kristofer Berggren.
.SH "REPORTING BUGS"
diff --git a/src/oauth2nmail b/src/oauth2nmail
index 0e223f9..6351353 100755
--- a/src/oauth2nmail
+++ b/src/oauth2nmail
@@ -71,10 +71,10 @@ def show_help():
print("")
print("Examples:")
print(" OAUTH2_TYPE=\"gmail-oauth2\" OAUTH2_CLIENT_ID=\"9\" OAUTH2_CLIENT_SECRET=\"j\" \\")
- print(" OAUTH2_TOKEN_STORE=\"${HOME}/.nmail/oauth2.tokens\" oauth2nmail -g")
+ print(" OAUTH2_TOKEN_STORE=\"${HOME}/.config/nmail/oauth2.tokens\" oauth2nmail -g")
print("")
print(" OAUTH2_TYPE=\"gmail-oauth2\" OAUTH2_CLIENT_ID=\"9\" OAUTH2_CLIENT_SECRET=\"j\" \\")
- print(" OAUTH2_TOKEN_STORE=\"${HOME}/.nmail/oauth2.tokens\" oauth2nmail -r")
+ print(" OAUTH2_TOKEN_STORE=\"${HOME}/.config/nmail/oauth2.tokens\" oauth2nmail -r")
print("")
print("Report bugs at https://github.com/d99kris/nmail")
print("")
diff --git a/src/util.cpp b/src/util.cpp
index bd7f4d8..cc80d0c 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -2295,3 +2295,25 @@ bool Util::IsIpAddress(const std::string& p_Str)
return rv;
}
+
+std::string Util::GetDefaultApplicationDir()
+{
+ char* homeEnv = getenv("HOME");
+ static const std::string homeDir = std::string((homeEnv != nullptr) ? homeEnv : "");
+
+ // Use old ~/.nmail if present, for backward compatibility
+ static const std::string legacyApplicationDir = homeDir + "/.nmail";
+ if (IsDir(legacyApplicationDir))
+ {
+ return legacyApplicationDir;
+ }
+
+ // Common value: export XDG_CONFIG_HOME="$HOME/.config"
+ char* xdgConfigHomeEnv = getenv("XDG_CONFIG_HOME");
+ static const std::string xdgConfigHomeDir = std::string((xdgConfigHomeEnv != nullptr) ? xdgConfigHomeEnv : "");
+ static const std::string configHomeDir = (!xdgConfigHomeDir.empty() ? xdgConfigHomeDir : (homeDir + "/.config"));
+
+ // Typically: ~/.config/nmail
+ static const std::string applicationDir = configHomeDir + "/nmail";
+ return applicationDir;
+}
diff --git a/src/util.h b/src/util.h
index 88856ab..08bfdfa 100644
--- a/src/util.h
+++ b/src/util.h
@@ -295,6 +295,7 @@ class Util
static std::string GetOsArch();
static std::string ExtractString(const std::string& p_Str, const std::string& p_Prefix, const std::string& p_Suffix);
static bool IsIpAddress(const std::string& p_Str);
+ static std::string GetDefaultApplicationDir();
template
static inline void Unused(const T& p_Arg)
diff --git a/src/version.cpp b/src/version.cpp
index 629ccd3..c37ea1f 100644
--- a/src/version.cpp
+++ b/src/version.cpp
@@ -7,7 +7,7 @@
#include "version.h"
-#define NMAIL_VERSION "5.1.3"
+#define NMAIL_VERSION "5.1.4"
std::string Version::GetBuildOs()
{