From cc22837a17eee5679a10babe3f7fc91b6db99a75 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 6 Oct 2016 15:06:45 -0400 Subject: ns_maxemail: optionally remove gmail aliases --- modules/nickserv/maxemail.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/nickserv/maxemail.cpp b/modules/nickserv/maxemail.cpp index a75fffaf0..0660e7b92 100644 --- a/modules/nickserv/maxemail.cpp +++ b/modules/nickserv/maxemail.cpp @@ -22,6 +22,27 @@ class NSMaxEmail : public Module , public EventHook { + bool clean = false; + + /* strip dots from username, and remove anything after the first + */ + Anope::string CleanMail(const Anope::string &email) + { + size_t host = email.find('@'); + if (host == Anope::string::npos) + return email; + + Anope::string username = email.substr(0, host); + username = username.replace_all_cs(".", ""); + + size_t sz = username.find('+'); + if (sz != Anope::string::npos) + username = username.substr(0, sz); + + Anope::string cleaned = username + email.substr(host); + Log(LOG_DEBUG) << "cleaned " << email << " to " << cleaned; + return cleaned; + } + bool CheckLimitReached(CommandSource &source, const Anope::string &email) { int NSEmailMax = Config->GetModule(this)->Get("maxemails"); @@ -47,9 +68,15 @@ class NSMaxEmail : public Module if (email.empty()) return 0; + Anope::string cleanemail = clean ? CleanMail(email) : email; + for (NickServ::Account *nc : NickServ::service->GetAccountList()) - if (unc != nc && !nc->GetEmail().empty() && nc->GetEmail().equals_ci(email)) + { + Anope::string cleannc = clean ? CleanMail(nc->GetEmail()) : nc->GetEmail(); + + if (unc != nc && cleanemail.equals_ci(cleannc)) ++count; + } return count; } @@ -60,6 +87,11 @@ class NSMaxEmail : public Module { } + void OnReload(Configuration::Conf *conf) override + { + clean = conf->GetModule(this)->Get("remove_aliases", "true"); + } + EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector ¶ms) override { if (source.IsOper()) -- cgit