summaryrefslogtreecommitdiff
path: root/src/mail.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mail.cpp')
-rw-r--r--src/mail.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/mail.cpp b/src/mail.cpp
index 03b1be318..172b7a5fe 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -15,31 +15,31 @@
Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &a, const Anope::string &s, const Anope::string &m)
: Thread()
- , sendmail_path(Config->GetBlock("mail")->Get<const Anope::string>("sendmailpath"))
- , send_from(sf), mail_to(mailto)
+ , sendmail_path(Config->GetBlock("mail")->Get<const Anope::string>("sendmailpath", "/usr/sbin/sendmail -it"))
+ , send_from(sf)
+ , mail_to(mailto)
, addr(a)
, subject(s)
, message(m)
, content_type(Config->GetBlock("mail")->Get<const Anope::string>("content_type", "text/plain; charset=UTF-8"))
, dont_quote_addresses(Config->GetBlock("mail")->Get<bool>("dontquoteaddresses"))
- , success(false)
{
}
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();
}
@@ -86,9 +90,9 @@ bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &su
if (!b->Get<bool>("usemail") || b->Get<const Anope::string>("sendfrom").empty())
u->SendMessage(service, _("Services have been configured to not send mail."));
else if (Anope::CurTime - u->lastmail < b->Get<time_t>("delay"))
- u->SendMessage(service, _("Please wait \002%d\002 seconds and retry."), b->Get<time_t>("delay") - (Anope::CurTime - u->lastmail));
+ u->SendMessage(service, _("Please wait \002%lu\002 seconds and retry."), (unsigned long)b->Get<time_t>("delay") - (Anope::CurTime - u->lastmail));
else if (nc->email.empty())
- u->SendMessage(service, _("E-mail for \002%s\002 is invalid."), nc->display.c_str());
+ u->SendMessage(service, _("Email for \002%s\002 is invalid."), nc->display.c_str());
else
{
u->lastmail = nc->lastmail = Anope::CurTime;
@@ -115,9 +119,9 @@ bool Mail::Send(NickCore *nc, const Anope::string &subject, const Anope::string
}
/**
- * Checks whether we have a valid, common e-mail address.
+ * Checks whether we have a valid, common email address.
* This is NOT entirely RFC compliant, and won't be so, because I said
- * *common* cases. ;) It is very unlikely that e-mail addresses that
+ * *common* cases. ;) It is very unlikely that email addresses that
* are really being used will fail the check.
*
* @param email Email to Validate
@@ -144,13 +148,15 @@ bool Mail::Validate(const Anope::string &email)
return false;
/* Check for forbidden characters in the name */
- for (unsigned i = 0, end = copy.length(); i < end; ++i)
+ for (auto chr : copy)
{
- if (copy[i] <= 31 || copy[i] >= 127)
+ if (chr <= 31 || chr >= 127)
return false;
- for (unsigned int j = 0; j < 13; ++j)
- if (copy[i] == specials[j])
+ for (auto special : specials)
+ {
+ if (chr == special)
return false;
+ }
}
/* Check for forbidden characters in the domain */
@@ -158,9 +164,11 @@ bool Mail::Validate(const Anope::string &email)
{
if (domain[i] <= 31 || domain[i] >= 127)
return false;
- for (unsigned int j = 0; j < 13; ++j)
- if (domain[i] == specials[j])
+ for (auto special : specials)
+ {
+ if (domain[i] == special)
return false;
+ }
if (domain[i] == '.')
{
if (!i || i == end - 1)