Mercurial > pidgin
comparison src/util.c @ 9045:38d022e5eb19
[gaim-migrate @ 9821]
nosnilmot wrote:
" This patch prevents turning strings with '@' in them
into mailto: links if they are not valid email addresses.
An example would be copying from a shell something like:
[user@host dir]$ thing
would create a mailto link to "[user@host"
It adds a gaim_email_is_valid function to util.c which
could also be used elsewhere :)
Thanks to Alver on #gaim for reporting this buglet."
And also said:
"Updated patch attached, tested against 86,171 valid email
addresses and as many invalid addresses as I could make up"
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Sun, 23 May 2004 22:17:38 +0000 |
| parents | 6f21aa413b18 |
| children | 96415a3aa93c |
comparison
equal
deleted
inserted
replaced
| 9044:23bcfdcd530d | 9045:38d022e5eb19 |
|---|---|
| 1516 | 1516 |
| 1517 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--) | 1517 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--) |
| 1518 *d = '\0'; | 1518 *d = '\0'; |
| 1519 | 1519 |
| 1520 tmpurlbuf = gaim_unescape_html(url_buf); | 1520 tmpurlbuf = gaim_unescape_html(url_buf); |
| 1521 g_string_append_printf(ret, "<A HREF=\"mailto:%s\">%s</A>", | 1521 if (gaim_email_is_valid(tmpurlbuf)) { |
| 1522 tmpurlbuf, url_buf); | 1522 g_string_append_printf(ret, "<A HREF=\"mailto:%s\">%s</A>", |
| 1523 tmpurlbuf, url_buf); | |
| 1524 } else { | |
| 1525 g_string_append(ret, url_buf); | |
| 1526 } | |
| 1523 g_free(tmpurlbuf); | 1527 g_free(tmpurlbuf); |
| 1524 c = t; | 1528 c = t; |
| 1525 | 1529 |
| 1526 break; | 1530 break; |
| 1527 } else { | 1531 } else { |
| 2581 buf[j] = '\0'; | 2585 buf[j] = '\0'; |
| 2582 | 2586 |
| 2583 return buf; | 2587 return buf; |
| 2584 } | 2588 } |
| 2585 | 2589 |
| 2590 /* lifted from http://www.oreillynet.com/pub/a/network/excerpt/spcookbook_chap03/index3.html */ | |
| 2591 gboolean | |
| 2592 gaim_email_is_valid(const char *address) | |
| 2593 { | |
| 2594 int count = 0; | |
| 2595 const char *c, *domain; | |
| 2596 static char *rfc822_specials = "()<>@,;:\\\"[]"; | |
| 2597 | |
| 2598 /* first we validate the name portion (name@domain) */ | |
| 2599 for (c = address; *c; c++) { | |
| 2600 if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) == '\"')) { | |
| 2601 while (*++c) { | |
| 2602 if (*c == '\"') break; | |
| 2603 if (*c == '\\' && (*++c == ' ')) continue; | |
| 2604 if (*c <= ' ' || *c >= 127) return FALSE; | |
| 2605 } | |
| 2606 if (!*c++) return FALSE; | |
| 2607 if (*c == '@') break; | |
| 2608 if (*c != '.') return FALSE; | |
| 2609 continue; | |
| 2610 } | |
| 2611 if (*c == '@') break; | |
| 2612 if (*c <= ' ' || *c >= 127) return FALSE; | |
| 2613 if (strchr(rfc822_specials, *c)) return FALSE; | |
| 2614 } | |
| 2615 if (c == address || *(c - 1) == '.') return FALSE; | |
| 2616 | |
| 2617 /* next we validate the domain portion (name@domain) */ | |
| 2618 if (!*(domain = ++c)) return FALSE; | |
| 2619 do { | |
| 2620 if (*c == '.') { | |
| 2621 if (c == domain || *(c - 1) == '.') return FALSE; | |
| 2622 count++; | |
| 2623 } | |
| 2624 if (*c <= ' ' || *c >= 127) return FALSE; | |
| 2625 if (strchr(rfc822_specials, *c)) return FALSE; | |
| 2626 } while (*++c); | |
| 2627 | |
| 2628 return (count >= 1 ? TRUE : FALSE); | |
| 2629 } | |
| 2630 | |
| 2586 /************************************************************************** | 2631 /************************************************************************** |
| 2587 * UTF8 String Functions | 2632 * UTF8 String Functions |
| 2588 **************************************************************************/ | 2633 **************************************************************************/ |
| 2589 char * | 2634 char * |
| 2590 gaim_utf8_try_convert(const char *str) | 2635 gaim_utf8_try_convert(const char *str) |
