diff options
Diffstat (limited to 'src/mail.cpp')
-rw-r--r-- | src/mail.cpp | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/mail.cpp b/src/mail.cpp index fe8bb0b90..f3adab44c 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -15,8 +15,9 @@ 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) @@ -36,8 +37,7 @@ Mail::Message::~Message() void Mail::Message::Run() { errno = 0; - FILE *pipe = popen(sendmail_path.c_str(), "w"); - + auto *pipe = popen(sendmail_path.c_str(), "w"); if (!pipe) { error = strerror(errno); @@ -54,13 +54,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"); - int result = 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 " + stringify(result); + error = "Sendmail exited with code " + Anope::ToString(result); + SetExitState(); } @@ -88,9 +91,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; @@ -117,9 +120,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 @@ -146,13 +149,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 */ @@ -160,9 +165,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) |