]> jfr.im git - irc/atheme/atheme.git/commitdiff
libathemecore/function.c: sendemail(): allow for urlencoding account
authorAaron Jones <redacted>
Sat, 10 Jul 2021 18:07:47 +0000 (18:07 +0000)
committerAaron Jones <redacted>
Sat, 10 Jul 2021 18:07:47 +0000 (18:07 +0000)
If one wishes to replace their register email template to prefix the account
name and registration verification token with a URL (to implement a webserver
to verify registrations, so people don't have to copy and paste commands to
execute on IRC), we should allow for the possibility that people will have
non-alphanumeric characters in their account name, and provide a URL-encoded
version of it.

This will ensure that such links are always clickable in various MUAs.

libathemecore/function.c

index 51644c4f1097f4a6e44767780bf86aacfa2f062d..0401f7c994bafe651b4a4fda23782a997c523cc4 100644 (file)
@@ -673,6 +673,35 @@ has_ctrl_chars(const char *text)
        return false;
 }
 
+static const char *
+sendemail_urlencode(const char *const restrict src)
+{
+       static char result[BUFSIZE];
+
+       const size_t srclen = strlen(src);
+       size_t offset = 0;
+
+       for (size_t i = 0; i < srclen; i++)
+       {
+               if (! isalnum(src[i]))
+               {
+                       char tmpbuf[8];
+
+                       (void) snprintf(tmpbuf, sizeof tmpbuf, "%02X", (unsigned int) src[i]);
+
+                       result[offset++] = '%';
+                       result[offset++] = tmpbuf[0];
+                       result[offset++] = tmpbuf[1];
+               }
+               else
+                       result[offset++] = src[i];
+       }
+
+       result[offset] = 0x00;
+
+       return result;
+}
+
 #ifndef MOWGLI_OS_WIN
 static void
 sendemail_waited(pid_t pid, int status, void *data)
@@ -812,6 +841,7 @@ sendemail(struct user *u, struct myuser *mu, const char *type, const char *email
                replace(buf, sizeof buf, "&replyto&", me.adminemail);
                replace(buf, sizeof buf, "&date&", date);
                replace(buf, sizeof buf, "&accountname&", entity(mu)->name);
+               replace(buf, sizeof buf, "&urlaccountname&", sendemail_urlencode(entity(mu)->name));
                replace(buf, sizeof buf, "&entityname&", u->myuser ? entity(u->myuser)->name : u->nick);
                replace(buf, sizeof buf, "&netname&", me.netname);
                replace(buf, sizeof buf, "&param&", param);