Skip to content

Commit

Permalink
automatic: Mail server credentials from .netrc
Browse files Browse the repository at this point in the history
Do not store email server credentials in automatic.conf config file,
take them from .netrc.
  • Loading branch information
m-blaha committed Dec 4, 2023
1 parent 5910487 commit 57ac549
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
6 changes: 2 additions & 4 deletions dnf5-plugins/automatic_plugin/config/etc/dnf/automatic.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ email_host = localhost
# Port number to connect to at the email host.
email_port = 25

# Use TLS or STARTTLS to connect to the email host.
# Use "tls" or "starttls" for secure connection, "no" for plain text
email_tls = no

# Credentials to use for SMTP server authentication
#email_username = username
#email_password = password
# Credentials to use for SMTP server authentication are taken from .netrc file


[command]
Expand Down
2 changes: 0 additions & 2 deletions dnf5-plugins/automatic_plugin/config_automatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ ConfigAutomaticEmail::ConfigAutomaticEmail() {
opt_binds().add("email_host", email_host);
opt_binds().add("email_port", email_port);
opt_binds().add("email_tls", email_tls);
opt_binds().add("email_username", email_username);
opt_binds().add("email_password", email_password);
}


Expand Down
2 changes: 0 additions & 2 deletions dnf5-plugins/automatic_plugin/config_automatic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class ConfigAutomaticEmail : public libdnf5::Config {
libdnf5::OptionString email_host{"localhost"};
libdnf5::OptionNumber<std::int32_t> email_port{25};
libdnf5::OptionEnum<std::string> email_tls{"no", {"no", "yes", "starttls"}};
libdnf5::OptionString email_username{""};
libdnf5::OptionString email_password{""};
};


Expand Down
12 changes: 5 additions & 7 deletions dnf5-plugins/automatic_plugin/emitters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,18 @@ void EmitterEmail::notify() {
{
// use curl to send the message
std::string payload = message.str();
std::string tls = config_automatic.config_email.email_tls.get_value().c_str();
std::string tls = config_automatic.config_email.email_tls.get_value();

CURL * curl;
CURLcode res = CURLE_OK;
struct curl_slist * recipients = NULL;

curl = curl_easy_init();
if (curl) {
std::string username = config_automatic.config_email.email_username.get_value();
std::string password = config_automatic.config_email.email_password.get_value();
if (!username.empty()) {
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str());
}
// TODO(mblaha): option for switching the debugging messages on?
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);

const char * protocol = "smtp";
if (tls == "starttls") {
Expand Down

0 comments on commit 57ac549

Please sign in to comment.