summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-03-18 11:57:08 +0000
committerSadie Powell <sadie@witchery.services>2024-03-18 12:34:34 +0000
commit60083834f802456382ffc63f0c908db3e2676feb (patch)
treef07b0cdf282812731c35cbaf45278d318ef6a70e /src
parent9ac4da0489ee70b2d18daca8c359b468ad28ed49 (diff)
Improve sending email.
- Use consistent line endings as expected by the email spec. - Don't require admins to escape . at the start of lines. - Log the reason why sending email fails.
Diffstat (limited to 'src')
-rw-r--r--src/mail.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/mail.cpp b/src/mail.cpp
index 87a030668..762c889a5 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -28,18 +28,18 @@ Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, con
Mail::Message::~Message()
{
- if (success)
+ if (error.empty())
Log(LOG_NORMAL, "mail") << "Successfully delivered mail for " << mail_to << " (" << addr << ")";
else
- Log(LOG_NORMAL, "mail") << "Error delivering mail for " << mail_to << " (" << addr << ")";
+ Log(LOG_NORMAL, "mail") << "Error delivering mail for " << mail_to << " (" << addr << "): " << error;
}
void Mail::Message::Run()
{
- FILE *pipe = popen(sendmail_path.c_str(), "w");
-
+ auto *pipe = popen(sendmail_path.c_str(), "w");
if (!pipe)
{
+ error = strerror(errno);
SetExitState();
return;
}
@@ -53,12 +53,16 @@ void Mail::Message::Run()
fprintf(pipe, "Content-Type: %s\r\n", content_type.c_str());
fprintf(pipe, "Content-Transfer-Encoding: 8bit\r\n");
fprintf(pipe, "\r\n");
- fprintf(pipe, "%s", message.c_str());
- fprintf(pipe, "\r\n.\r\n");
- pclose(pipe);
+ std::stringstream stream(message.str());
+ for (Anope::string line; std::getline(stream, line.str()); )
+ fprintf(pipe, "%s\r\n", line.c_str());
+ fprintf(pipe, "\r\n");
+
+ auto result = pclose(pipe);
+ if (result > 0)
+ error = "Sendmail exited with code " + Anope::ToString(result);
- success = true;
SetExitState();
}