| 1 |
/* |
| 2 |
* Copyright (c) 2012 Marien Zwart |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* Canonicalize gmail addresses: |
| 6 |
* - Remove dots from the address. |
| 7 |
* - Remove labels (+foo). |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "atheme.h" |
| 11 |
|
| 12 |
DECLARE_MODULE_V1 |
| 13 |
( |
| 14 |
"misc/canon_gmail", false, _modinit, _moddeinit, |
| 15 |
PACKAGE_STRING, |
| 16 |
VENDOR_STRING |
| 17 |
); |
| 18 |
|
| 19 |
static void canonicalize_gmail(char email[EMAILLEN + 1], void *user_data) |
| 20 |
{ |
| 21 |
static char buf[EMAILLEN + 1]; |
| 22 |
const char *p, *p_at; |
| 23 |
char *p_out; |
| 24 |
stringref result; |
| 25 |
|
| 26 |
p_at = strchr(email, '@'); |
| 27 |
if (!p_at || strcasecmp(p_at, "@gmail.com")) |
| 28 |
return; |
| 29 |
|
| 30 |
for (p = email, p_out = buf; p < p_at; p++) { |
| 31 |
if (*p == '.') |
| 32 |
continue; |
| 33 |
|
| 34 |
if (*p == '+') |
| 35 |
break; |
| 36 |
|
| 37 |
*p_out++ = *p; |
| 38 |
} |
| 39 |
|
| 40 |
/* Note the string handling here relies on the email address |
| 41 |
* passed in being at most EMAILLEN long, and the canonical |
| 42 |
* address being at most equally long. That is true for the |
| 43 |
* loop above, but if we start mapping equivalent domains here |
| 44 |
* be careful not to overflow the buffer. |
| 45 |
*/ |
| 46 |
|
| 47 |
strcpy(p_out, "@gmail.com"); |
| 48 |
|
| 49 |
strcpy(email, buf); |
| 50 |
} |
| 51 |
|
| 52 |
void _modinit(module_t *m) |
| 53 |
{ |
| 54 |
register_email_canonicalizer(canonicalize_gmail, NULL); |
| 55 |
} |
| 56 |
|
| 57 |
void _moddeinit(module_unload_intent_t intent) |
| 58 |
{ |
| 59 |
unregister_email_canonicalizer(canonicalize_gmail, NULL); |
| 60 |
} |