summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-05-09 19:02:50 -0400
committerAdam <Adam@anope.org>2010-06-18 21:01:09 -0400
commit4e1286ca109d079f32d32f07c344a1ab93899032 (patch)
treeef55488a4cc068f8954a8862ab2e67f2d1872281 /src/core
parent4149afd45d2c0b9f464d1b4434f7bdaa61873d44 (diff)
Rewrote the mail system to use threading
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ns_register.c40
-rw-r--r--src/core/ns_resetpass.c80
-rw-r--r--src/core/ns_sendpass.c43
3 files changed, 70 insertions, 93 deletions
diff --git a/src/core/ns_register.c b/src/core/ns_register.c
index 9074f109f..89495eb57 100644
--- a/src/core/ns_register.c
+++ b/src/core/ns_register.c
@@ -14,7 +14,7 @@
#include "module.h"
-int do_sendregmail(User *u, NickRequest *nr);
+static bool SendRegmail(User *u, NickRequest *nr);
class CommandNSConfirm : public Command
{
@@ -279,7 +279,7 @@ class CommandNSRegister : public CommandNSConfirm
FOREACH_MOD(I_OnMakeNickRequest, OnMakeNickRequest(nr));
if (Config.NSEmailReg)
{
- if (!do_sendregmail(u, nr))
+ if (SendRegmail(u, nr))
{
notice_lang(Config.s_NickServ, u, NICK_ENTER_REG_CODE, email, Config.s_NickServ);
Alog() << Config.s_NickServ << ": sent registration verification code to " << nr->email;
@@ -337,7 +337,7 @@ class CommandNSResend : public Command
notice_lang(Config.s_NickServ, u, MAIL_LATER);
return MOD_CONT;
}
- if (!do_sendregmail(u, nr))
+ if (!SendRegmail(u, nr))
{
nr->lastmail = time(NULL);
notice_lang(Config.s_NickServ, u, NICK_REG_RESENT, nr->email);
@@ -375,6 +375,7 @@ class NSRegister : public Module
ModuleManager::Attach(I_OnNickServHelp, this);
}
+
void OnNickServHelp(User *u)
{
notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_REGISTER);
@@ -386,33 +387,14 @@ class NSRegister : public Module
}
};
-/*************************************************************************/
-
-int do_sendregmail(User *u, NickRequest *nr)
+static bool SendRegmail(User *u, NickRequest *nr)
{
- MailInfo *mail = NULL;
- char buf[BUFSIZE];
-
- if (!nr && !u)
- return -1;
- snprintf(buf, sizeof(buf), getstring(NICK_REG_MAIL_SUBJECT), nr->nick);
- mail = MailRegBegin(u, nr, buf, Config.s_NickServ);
- if (!mail)
- return -1;
- fprintf(mail->pipe, "%s", getstring(NICK_REG_MAIL_HEAD));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring(NICK_REG_MAIL_LINE_1), nr->nick);
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring(NICK_REG_MAIL_LINE_2), Config.s_NickServ, nr->passcode.c_str());
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, "%s", getstring(NICK_REG_MAIL_LINE_3));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, "%s", getstring(NICK_REG_MAIL_LINE_4));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring(NICK_REG_MAIL_LINE_5), Config.NetworkName);
- fprintf(mail->pipe, "\n.\n");
- MailEnd(mail);
- return 0;
+ char subject[BUFSIZE], message[BUFSIZE];
+
+ snprintf(subject, sizeof(subject), getstring(NICK_REG_MAIL_SUBJECT), nr->nick);
+ snprintf(message, sizeof(message), getstring(NICK_REG_MAIL), nr->nick, Config.NetworkName, Config.s_NickServ, nr->passcode.c_str(), Config.NetworkName);
+
+ return Mail(u, nr, Config.s_NickServ, subject, message);
}
MODULE_INIT(NSRegister)
diff --git a/src/core/ns_resetpass.c b/src/core/ns_resetpass.c
index c47fa0308..fc904d66c 100644
--- a/src/core/ns_resetpass.c
+++ b/src/core/ns_resetpass.c
@@ -14,6 +14,8 @@
#include "module.h"
+static bool SendResetEmail(User *u, NickAlias *na);
+
class CommandNSResetPass : public Command
{
public:
@@ -33,41 +35,11 @@ class CommandNSResetPass : public Command
notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
else
{
- char buf[BUFSIZE], message[BUFSIZE];
- snprintf(buf, sizeof(buf), getstring(na, NICK_RESETPASS_SUBJECT), na->nick);
-
- MailInfo *mail = MailBegin(u, na->nc, buf, Config.s_NickServ);
- if (!mail)
- return MOD_CONT;
-
- char passcode[20];
- int min = 1, max = 62;
- int chars[] = {
- ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
- 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
- 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
- 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
- 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
- };
-
- int idx;
- for (idx = 0; idx < 20; ++idx)
- passcode[idx] = chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min];
- passcode[idx] = '\0';
-
- snprintf(message, sizeof(message), getstring(na, NICK_RESETPASS_MESSAGE), na->nick, Config.s_NickServ, passcode, Config.NetworkName);
- fprintf(mail->pipe, "%s", message);
- fprintf(mail->pipe, "\n.\n");
- MailEnd(mail);
-
- na->nc->Shrink("ns_resetpass_code");
- na->nc->Shrink("ns_resetpass_time");
-
- na->nc->Extend("ns_resetpass_code", new ExtensibleItemPointerArray<char>(sstrdup(passcode)));
- na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(time(NULL)));
-
- Alog() << Config.s_NickServ << ": " << u->GetMask() << " used RESETPASS on " << na->nick << " (" << na->nc->display << ")";
- notice_lang(Config.s_NickServ, u, NICK_RESETPASS_COMPLETE, na->nick);
+ if (SendResetEmail(u, na))
+ {
+ Alog() << Config.s_NickServ << ": " << u->GetMask() << " used RESETPASS on " << na->nick << " (" << na->nc->display << ")";
+ notice_lang(Config.s_NickServ, u, NICK_RESETPASS_COMPLETE, na->nick);
+ }
}
return MOD_CONT;
@@ -110,14 +82,13 @@ class NSResetPass : public Module
EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
{
- time_t t;
- char *c;
-
if (service == Config.s_NickServ && command == "CONFIRM" && !params.empty())
{
NickAlias *na = findnick(u->nick);
- if (na && na->nc->GetExtArray("ns_resetpass_code", c) && na->nc->GetExtRegular<time_t>("ns_resetpass_time", t))
+ time_t t;
+ std::string c;
+ if (na && na->nc->GetExtRegular("ns_resetpass_code", c) && na->nc->GetExtRegular("ns_resetpass_time", t))
{
if (t < time(NULL) - 3600)
{
@@ -167,4 +138,35 @@ class NSResetPass : public Module
}
};
+static bool SendResetEmail(User *u, NickAlias *na)
+{
+ char subject[BUFSIZE], message[BUFSIZE], passcode[20];
+
+ snprintf(subject, sizeof(subject), getstring(na, NICK_RESETPASS_SUBJECT), na->nick);
+
+ int min = 1, max = 62;
+ int chars[] = {
+ ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
+ 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
+ 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
+ };
+
+ int idx;
+ for (idx = 0; idx < 20; ++idx)
+ passcode[idx] = chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min];
+ passcode[idx] = '\0';
+
+ snprintf(message, sizeof(message), getstring(na, NICK_RESETPASS_MESSAGE), na->nick, Config.s_NickServ, passcode, Config.NetworkName);
+
+ na->nc->Shrink("ns_resetpass_code");
+ na->nc->Shrink("ns_resetpass_time");
+
+ na->nc->Extend("ns_resetpass_code", new ExtensibleItemRegular<std::string>(passcode));
+ na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(time(NULL)));
+
+ return Mail(u, na->nc, Config.s_NickServ, subject, message);
+}
+
MODULE_INIT(NSResetPass)
diff --git a/src/core/ns_sendpass.c b/src/core/ns_sendpass.c
index 0ce8f6c5c..ffa4b6ece 100644
--- a/src/core/ns_sendpass.c
+++ b/src/core/ns_sendpass.c
@@ -14,6 +14,8 @@
#include "module.h"
+static bool SendPassMail(User *u, NickAlias *na, const std::string &pass);
+
class CommandNSSendPass : public Command
{
public:
@@ -34,34 +36,14 @@ class CommandNSSendPass : public Command
notice_lang(Config.s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
else
{
- char buf[BUFSIZE];
std::string tmp_pass;
if (enc_decrypt(na->nc->pass,tmp_pass) == 1)
{
- MailInfo *mail;
-
- snprintf(buf, sizeof(buf), getstring(na, NICK_SENDPASS_SUBJECT), na->nick);
- mail = MailBegin(u, na->nc, buf, Config.s_NickServ);
- if (!mail)
- return MOD_CONT;
-
- fprintf(mail->pipe, "%s", getstring(na, NICK_SENDPASS_HEAD));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring(na, NICK_SENDPASS_LINE_1), na->nick);
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring(na, NICK_SENDPASS_LINE_2), tmp_pass.c_str());
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, "%s", getstring(na, NICK_SENDPASS_LINE_3));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, "%s", getstring(na, NICK_SENDPASS_LINE_4));
- fprintf(mail->pipe, "\n\n");
- fprintf(mail->pipe, getstring(na, NICK_SENDPASS_LINE_5), Config.NetworkName);
- fprintf(mail->pipe, "\n.\n");
-
- MailEnd(mail);
-
- Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SENDPASS on " << nick;
- notice_lang(Config.s_NickServ, u, NICK_SENDPASS_OK, nick);
+ if (SendPassMail(u, na, tmp_pass))
+ {
+ Alog() << Config.s_NickServ << ": " << u->GetMask() << " used SENDPASS on " << nick;
+ notice_lang(Config.s_NickServ, u, NICK_SENDPASS_OK, nick);
+ }
}
else
notice_lang(Config.s_NickServ, u, NICK_SENDPASS_UNAVAILABLE);
@@ -102,10 +84,21 @@ class NSSendPass : public Module
ModuleManager::Attach(I_OnNickServHelp, this);
}
+
void OnNickServHelp(User *u)
{
notice_lang(Config.s_NickServ, u, NICK_HELP_CMD_SENDPASS);
}
};
+static bool SendPassMail(User *u, NickAlias *na, const std::string &pass)
+{
+ char subject[BUFSIZE], message[BUFSIZE];
+
+ snprintf(subject, sizeof(subject), getstring(na, NICK_SENDPASS_SUBJECT), na->nick);
+ snprintf(message, sizeof(message), getstring(na, NICK_SENDPASS), na->nick, pass.c_str(), Config.NetworkName);
+
+ return Mail(u, na->nc, Config.s_NickServ, subject, message);
+}
+
MODULE_INIT(NSSendPass)