summaryrefslogtreecommitdiff
path: root/src/mail.cpp
diff options
context:
space:
mode:
authorNaram Qashat <cyberbotx@cyberbotx.com>2010-07-25 21:58:20 -0400
committerNaram Qashat <cyberbotx@cyberbotx.com>2010-07-25 21:58:20 -0400
commitae38212c1ce829c783edf971081c90137abb49a0 (patch)
tree5c652d9cdc38103dec6fa112d57fca882b4e3e44 /src/mail.cpp
parent15d7f0f6fe8bb903275f603f734c13f65f3aa906 (diff)
Epic commit to replace most of the strings in Anope with a single Anope::string class, plus some other little fixes here and there. If you follow 1.9.x development and are testing things, THIS is one of those things that NEEDS testing.
Diffstat (limited to 'src/mail.cpp')
-rw-r--r--src/mail.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/mail.cpp b/src/mail.cpp
index c7c8ebda7..b5e2149f9 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -11,12 +11,12 @@ MailThread::~MailThread()
void MailThread::Run()
{
- FILE *pipe = popen(Config.SendMailPath, "w");
+ FILE *pipe = popen(Config.SendMailPath.c_str(), "w");
if (!pipe)
return;
- fprintf(pipe, "From: %s\n", Config.SendFrom);
+ fprintf(pipe, "From: %s\n", Config.SendFrom.c_str());
if (Config.DontQuoteAddresses)
fprintf(pipe, "To: %s <%s>\n", MailTo.c_str(), Addr.c_str());
else
@@ -30,7 +30,7 @@ void MailThread::Run()
Success = true;
}
-bool Mail(User *u, NickRequest *nr, const std::string &service, const std::string &subject, const std::string &message)
+bool Mail(User *u, NickRequest *nr, const Anope::string &service, const Anope::string &subject, const Anope::string &message)
{
if (!u || !nr || subject.empty() || service.empty() || message.empty())
return false;
@@ -38,11 +38,11 @@ bool Mail(User *u, NickRequest *nr, const std::string &service, const std::strin
time_t t = time(NULL);
if (!Config.UseMail)
- notice_lang(service.c_str(), u, MAIL_DISABLED);
+ notice_lang(service, u, MAIL_DISABLED);
else if (t - u->lastmail < Config.MailDelay)
- notice_lang(service.c_str(), u, MAIL_DELAYED, t - u->lastmail);
- else if (!nr->email)
- notice_lang(service.c_str(), u, MAIL_INVALID, nr->nick);
+ notice_lang(service, u, MAIL_DELAYED, t - u->lastmail);
+ else if (nr->email.empty())
+ notice_lang(service, u, MAIL_INVALID, nr->nick.c_str());
else
{
u->lastmail = nr->lastmail = t;
@@ -53,7 +53,7 @@ bool Mail(User *u, NickRequest *nr, const std::string &service, const std::strin
return false;
}
-bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &subject, const std::string &message)
+bool Mail(User *u, NickCore *nc, const Anope::string &service, const Anope::string &subject, const Anope::string &message)
{
if (!u || !nc || subject.empty() || service.empty() || message.empty())
return false;
@@ -61,11 +61,11 @@ bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &
time_t t = time(NULL);
if (!Config.UseMail)
- notice_lang(service.c_str(), u, MAIL_DISABLED);
+ notice_lang(service, u, MAIL_DISABLED);
else if (t - u->lastmail < Config.MailDelay)
- notice_lang(service.c_str(), u, MAIL_DELAYED, t - u->lastmail);
- else if (!nc->email)
- notice_lang(service.c_str(), u, MAIL_INVALID, nc->display);
+ notice_lang(service, u, MAIL_DELAYED, t - u->lastmail);
+ else if (nc->email.empty())
+ notice_lang(service, u, MAIL_INVALID, nc->display.c_str());
else
{
u->lastmail = nc->lastmail = t;
@@ -76,9 +76,9 @@ bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &
return false;
}
-bool Mail(NickCore *nc, const std::string &subject, const std::string &message)
+bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message)
{
- if (!Config.UseMail || !nc || !nc->email || subject.empty() || message.empty())
+ if (!Config.UseMail || !nc || nc->email.empty() || subject.empty() || message.empty())
return false;
nc->lastmail = time(NULL);
@@ -96,28 +96,28 @@ bool Mail(NickCore *nc, const std::string &subject, const std::string &message)
* @param email Email to Validate
* @return bool
*/
-bool MailValidate(const std::string &email)
+bool MailValidate(const Anope::string &email)
{
bool has_period = false;
- char copy[BUFSIZE];
static char specials[] = {'(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']', ' '};
if (email.empty())
return false;
- strlcpy(copy, email.c_str(), sizeof(copy));
+ Anope::string copy = email;
- char *domain = strchr(copy, '@');
- if (!domain)
+ size_t at = copy.find('@');
+ if (at == Anope::string::npos)
return false;
- *domain++ = '\0';
+ Anope::string domain = copy.substr(at + 1);
+ copy = copy.substr(0, at);
- /* Don't accept NULL copy or domain. */
- if (!*copy || !*domain)
+ /* Don't accept empty copy or domain. */
+ if (copy.empty() || domain.empty())
return false;
/* Check for forbidden characters in the name */
- for (unsigned int i = 0; i < strlen(copy); ++i)
+ for (unsigned i = 0, end = copy.length(); i < end; ++i)
{
if (copy[i] <= 31 || copy[i] >= 127)
return false;
@@ -127,7 +127,7 @@ bool MailValidate(const std::string &email)
}
/* Check for forbidden characters in the domain */
- for (unsigned int i = 0; i < strlen(domain); ++i)
+ for (unsigned i = 0, end = domain.length(); i < end; ++i)
{
if (domain[i] <= 31 || domain[i] >= 127)
return false;
@@ -136,7 +136,7 @@ bool MailValidate(const std::string &email)
return false;
if (domain[i] == '.')
{
- if (!i || i == strlen(domain) - 1)
+ if (!i || i == end - 1)
return false;
has_period = true;
}