diff options
author | Adam <Adam@anope.org> | 2016-10-06 15:06:45 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-10-06 15:06:45 -0400 |
commit | cc22837a17eee5679a10babe3f7fc91b6db99a75 (patch) | |
tree | f846b32b5dbf5f7ddbfc9e5ca0ea8ddcf6e38804 | |
parent | d3ac74a575dfc31bcfb15af1ce1e4cc4c30bda3e (diff) |
ns_maxemail: optionally remove gmail aliases
-rw-r--r-- | modules/nickserv/maxemail.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
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<Event::PreCommand> { + 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<int>("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<bool>("remove_aliases", "true"); + } + EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) override { if (source.IsOper()) |