In case it helps anyone to have the entire code to look at, attached is
a patch against mail.c that contains all my changes.
> On Thu, 26 Dec 2002, Ari Pollak wrote:
>
> > Hi there, I'm trying to hack mail.c to automatically pass a -f argument
> > to qmail with a return address, so that the Return-path of the message
> > is not always root@blah. Anyway, I seem to have been successful in this
> > endeavor, but I have a slight problem - whenever my code gets executed,
> > I get two errors output:
> >
> > /home/ari/php-4.3.0RC4/ext/standard/mail.c(235) : Freeing 0x088F6524
> > (51 bytes), script=/home/ari/public_html/mail.php
> > /home/ari/php-4.3.0RC4/ext/standard/mail.c(229) : Freeing 0x088F647C
> > (23 bytes), script=/home/ari/public_html/mail.php
> >
> > Line 229 and 235 are the following, respectively:
> > qmail_from = emalloc(strlen(temp) + 3);
> > sendmail_cmd = emalloc(strlen(sendmail_path) + strlen(qmail_from) +
> > 2);
> >
> > I efree() both temp and qmail_from when they're done being used, but I
> > can't seem to find why exactly this message is popping up. Both temp and
> > qmail_from seem to be valid strings, and those are the only two strings
> > I create myself that are used.
> >
> > Any ideas? What else could cause the Freeing error message?
--- php-4.3.0RC4/ext/standard/mail.c~ Wed Dec 25 21:18:14 2002
+++ php-4.3.0RC4/ext/standard/mail.c Thu Dec 26 04:50:57 2002
@@ -137,6 +138,55 @@
}
/* }}} */
+/* {{{ qmail_email
+ Returns an e-mail address if found in a From: header
+*/
+char *qmail_email(char *headers)
+{
+ int len = 0;
+ char *temp = NULL, *loc1 = NULL, *loc2 = NULL;
+ char *qmail_from = NULL;
+
+ temp = strstr(headers, "From: ");
+ if(temp != NULL) { /* From: header found, do everything */
+ loc1 = strchr(temp, '<');
+ if(loc1 != NULL) { /* < found, get text between brackets */
+ loc1 += 1;
+ loc2 = strchr(loc1, '>');
+ if(loc2 != NULL) { /* > found, text should end one char before
+*/
+ loc2 -= 1;
+ len = loc2 - loc1 + 1;
+ } else { /* > not found, don't bother with any of this */
+ return NULL;
+ }
+ } else { /* no <, just get all the text afterwards */
+ loc1 = temp + 6;
+ loc2 = strchr(loc1, '\n');
+ if(loc2 != NULL) { /* newline found, we're almost set*/
+ loc2 -= 1;
+ len = loc2 - loc1 + 1;
+ }
+ }
+ if(loc2 == NULL) { /* Go until the end of the string */
+ qmail_from = estrdup(loc1);
+ } else { /* Only copy until loc2 */
+ qmail_from = emalloc(len + 1);
+ temp = qmail_from;
+ while(loc1 <= loc2) {
+ *temp = *loc1;
+ loc1++;
+ temp++;
+ }
+ *temp = '\0';
+ }
+ return qmail_from;
+ }
+ else {
+ return NULL;
+ }
+}
+/* }}} */
+
/* {{{ php_mail
*/
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
*extra_cmd TSRMLS_DC)
@@ -147,6 +197,7 @@
#endif
FILE *sendmail;
int ret;
+ char *temp = NULL, *qmail_from = NULL;
char *sendmail_path = INI_STR("sendmail_path");
char *sendmail_cmd = NULL;
@@ -172,6 +223,23 @@
strcpy (sendmail_cmd, sendmail_path);
strcat (sendmail_cmd, " ");
strcat (sendmail_cmd, extra_cmd);
+ } else if(INI_STR("qmail_compat") && headers != NULL) {
+ temp = qmail_email(headers);
+ if(temp != NULL) { /* return e-mail address found */
+ qmail_from = emalloc(strlen(temp) + 3);
+ strcpy(qmail_from, "-f");
+ strcat(qmail_from, temp);
+ qmail_from = php_escape_shell_cmd(qmail_from);
+ efree(temp);
+
+ sendmail_cmd = emalloc(strlen(sendmail_path) +
+strlen(qmail_from) + 2);
+ strcpy(sendmail_cmd, sendmail_path);
+ strcat(sendmail_cmd, " ");
+ strcat(sendmail_cmd, qmail_from);
+ efree(qmail_from);
+ } else {
+ sendmail_cmd = sendmail_path;
+ }
} else {
sendmail_cmd = sendmail_path;
}
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php