--- php-4.3.3/ext/standard/mail.c	2003-05-07 22:32:28.000000000 +0200
+++ php-4.3.3+mail_limit/ext/standard/mail.c	2005-07-16 02:23:34.000000000 +0200
@@ -46,6 +46,14 @@
 #include "netware/sysexits.h"   /* For exit status codes like EX_OK */
 #endif
 
+/* drg include for mail() limit */
+#define MAIL_LIMITS_DIR	"/usr/local/php/maillimits"
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+/* --- */
+
 #define SKIP_LONG_HEADER_SEP(str, pos)										\
 	if (str[pos] == '\r' && str[pos + 1] == '\n' && (str[pos + 2] == ' ' || str[pos + 2] == '\t')) {	\
 		pos += 3;											\
@@ -87,6 +95,42 @@
 	int to_len, message_len, headers_len;
 	int subject_len, extra_cmd_len, i;
 
+/* drg mail limit feature */
+	long phpuid;
+
+	phpuid = php_getuid();
+	if (phpuid >= 0) {
+		struct passwd *pw;
+		char path[1024];
+
+		if ((pw = getpwuid(phpuid)) != NULL) {
+			int fd = -1;
+
+			snprintf(path, 1024, "%s/%s", MAIL_LIMITS_DIR, pw->pw_name);
+			if ((fd = open(path, O_RDWR)) >= 0) {
+				long mails = 0;
+				
+				read(fd, &mails, sizeof(mails));
+				if (mails != 0) {
+					if (mails > -2147483640)
+						mails--;
+					if (mails == 0)
+						mails--;
+					lseek(fd, 0, SEEK_SET);
+					write(fd, &mails, sizeof(mails));
+				}
+				close(fd);
+				
+				if (mails < 0) {
+					php_error_docref(NULL TSRMLS_CC, E_WARNING, "mail() limit reached");
+					RETURN_FALSE;
+				}
+			}
+		}
+	}
+/* end of drg mail limit feature */
+		
+
 	if (PG(safe_mode) && (ZEND_NUM_ARGS() == 5)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE Restriction in effect.  The fifth parameter is disabled in SAFE MODE.");
 		RETURN_FALSE;

