Skip to content

Commit 02cad90

Browse files
author
Kristian Köhntopp
committed
ezmlm_hash() function also available for php4.
1 parent 85422c3 commit 02cad90

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

ext/standard/basic_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ function_entry basic_functions[] = {
455455

456456
/* functions from mail.c */
457457
PHP_FE(mail, NULL)
458+
PHP_FE(ezmlm_hash, NULL)
458459

459460
/* functions from syslog.c */
460461
PHP_FE(openlog, NULL)

ext/standard/mail.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,37 @@
3838
ZEND_GET_MODULE(odbc)
3939
#endif
4040

41+
/* {{{ proto int ezmlm_hash(string addr)
42+
Calculate EZMLM list hash value. */
43+
PHP_FUNCTION(ezmlm_hash)
44+
{
45+
pval **pstr = NULL;
46+
char *str=NULL;
47+
unsigned long h = 5381L;
48+
int j, l;
49+
50+
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pstr) == FAILURE) {
51+
WRONG_PARAM_COUNT;
52+
}
53+
54+
convert_to_string_ex(pstr);
55+
if ((*pstr)->value.str.val) {
56+
str = (*pstr)->value.str.val;
57+
} else {
58+
php_error(E_WARNING, "Must give string parameter to ezmlm_hash()");
59+
RETURN_FALSE;
60+
}
61+
62+
l = strlen(str);
63+
for (j=0; j<l; j++) {
64+
h = (h + (h<<5)) ^ (unsigned long) (unsigned char) tolower(str[j]);
65+
}
66+
67+
h = (h%53);
68+
69+
RETURN_LONG((int) h);
70+
}
71+
4172
/* {{{ proto int mail(string to, string subject, string message [, string additional_headers])
4273
Send an email message */
4374
PHP_FUNCTION(mail)

ext/standard/php_mail.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#if HAVE_SENDMAIL
3737

3838
PHP_FUNCTION(mail);
39+
PHP_FUNCTION(ezmlm_hash);
3940
PHP_MINFO_FUNCTION(mail);
4041
extern int php_mail(char *to, char *subject, char *message, char *headers);
4142

0 commit comments

Comments
 (0)