cvs: /php3/functions imap.c imap.h

From: Date: Wed, 12 Jan 2000 08:57:14 +0000
Subject: cvs: /php3/functions imap.c imap.h
Groups: php.dev 
Request: Send a blank email to php-dev+get-14517@lists.php.net to get a copy of this message
fmk Wed Jan 12 00:57:14 2000 EDT Modified files: /php3/functions imap.c imap.h Log: Adding a new function imap_mail() This new function extends the standard mail() finction with cc and bcc headers as well as return path Index: php3/functions/imap.c diff -u php3/functions/imap.c:1.74 php3/functions/imap.c:1.75 --- php3/functions/imap.c:1.74 Fri Dec 31 20:31:15 1999 +++ php3/functions/imap.c Wed Jan 12 00:57:14 2000 @@ -33,7 +33,7 @@ | Andrew Skalski <askalski@chek.com> | +----------------------------------------------------------------------+ */ -/* $Id: imap.c,v 1.74 2000/01/01 04:31:15 sas Exp $ */ +/* $Id: imap.c,v 1.75 2000/01/12 08:57:14 fmk Exp $ */ #define IMAP41 @@ -64,6 +64,7 @@ #include "modules.h" #if (WIN32|WINNT) #include "winsock.h" +#include "win32/imap_sendmail.h" #endif #ifdef IMAP41 @@ -95,6 +96,7 @@ int add_assoc_object(pval *arg, char *key, pval tmp); int add_next_index_object(pval *arg, pval tmp); void imap_add_body( pval *arg, BODY *body ); +int _php3_imap_mail(char *to, char *subject, char *message, char *headers, char *cc, char *bcc, char *rpath); typedef struct php3_imap_le_struct { MAILSTREAM *imap_stream; @@ -194,6 +196,7 @@ {"imap_alerts", php3_imap_alerts, NULL}, {"imap_errors", php3_imap_errors, NULL}, {"imap_last_error", php3_imap_last_error, NULL}, + {"imap_mail", php3_imap_mail, NULL}, {"imap_search", php3_imap_search, NULL}, {"imap_utf8", php3_imap_utf8, NULL}, {NULL, NULL, NULL} @@ -446,6 +449,7 @@ #endif mail_link (&dummydriver); /* link in the dummy driver */ auth_link (&auth_log); /* link in the log authenticator */ + /* lets allow NIL */ REGISTER_MAIN_LONG_CONSTANT("NIL", NIL, CONST_PERSISTENT | CONST_CS); @@ -1506,7 +1510,7 @@ pval *streamind; int ind, ind_type; pils *imap_le_struct; - char date[50]; + char date[100]; if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&streamind) == FAILURE) { WRONG_PARAM_COUNT; @@ -2137,8 +2141,8 @@ PARAMETER *par, *dpar; PART *part; - if(body->type) add_property_long( arg, "type", body->type ); - if(body->encoding) add_property_long( arg, "encoding", body->encoding ); + add_property_long( arg, "type", body->type ); + add_property_long( arg, "encoding", body->encoding ); if ( body->subtype ){ add_property_long( arg, "ifsubtype", 1 ); @@ -2381,7 +2385,7 @@ void php3_imap_mailboxmsginfo(INTERNAL_FUNCTION_PARAMETERS) { pval *streamind; - char date[50]; + char date[100]; int ind, ind_type; unsigned int msgno; pils *imap_le_struct; @@ -3217,6 +3221,122 @@ /* }}} */ +/* {{{ proto int mail(string to, string subject, string message [, string additional_headers [, string cc [, string bcc [, string rpath]]]]) + Send an email message */ +void php3_imap_mail(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *argv[6]; + char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *cc=NULL, *bcc=NULL, *rpath=NULL; + int argc; + TLS_VARS; + + argc = ARG_COUNT(ht); + if (argc < 3 || argc > 7 || getParametersArray(ht, argc, argv) == FAILURE) { + WRONG_PARAM_COUNT; + } + /* To: */ + convert_to_string(argv[0]); + if (argv[0]->value.str.val) { + to = argv[0]->value.str.val; + } else { + php3_error(E_WARNING, "No to field in mail command"); + RETURN_FALSE; + } + + /* Subject: */ + convert_to_string(argv[1]); + if (argv[1]->value.str.val) { + subject = argv[1]->value.str.val; + } else { + php3_error(E_WARNING, "No subject field in mail command"); + RETURN_FALSE; + } + + /* message body */ + convert_to_string(argv[2]); + if (argv[2]->value.str.val) { + message = argv[2]->value.str.val; + } else { + /* this is not really an error, so it is allowed. */ + php3_error(E_WARNING, "No message string in mail command"); + message = NULL; + } + + /* other headers */ + if (argc > 3) { + convert_to_string(argv[3]); + headers = argv[3]->value.str.val; + } + + /* cc */ + if (argc > 4) { + convert_to_string(argv[4]); + cc = argv[4]->value.str.val; + } + + /* bcc */ + if (argc > 5) { + convert_to_string(argv[5]); + bcc = argv[5]->value.str.val; + } + + /* rpath */ + if (argc > 6) { + convert_to_string(argv[6]); + rpath = argv[6]->value.str.val; + } + + if (_php3_imap_mail(to, subject, message, headers, cc, bcc, rpath)){ + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +int _php3_imap_mail(char *to, char *subject, char *message, char *headers, char *cc, char *bcc, char* rpath) +{ +#if MSVC5 + int tsm_err; +#else + FILE *sendmail; + int ret; +#endif + TLS_VARS; + +#if MSVC5 + if (imap_TSendMail(php3_ini.smtp,&tsm_err,headers,subject,to,message,cc,bcc,rpath) != SUCCESS){ + php3_error(E_WARNING, GetSMErrorText(tsm_err)); + return 0; + } +#else + if (!php3_ini.sendmail_path) { + return 0; + } + sendmail = popen(php3_ini.sendmail_path, "w"); + if (sendmail) { + fprintf(sendmail, "To: %s\n", to); + if (cc && cc[0]) fprintf(sendmail, "Cc: %s\n", cc); + if (bcc && bcc[0]) fprintf(sendmail, "Bcc: %s\n", bcc); + fprintf(sendmail, "Subject: %s\n", subject); + if (headers != NULL) { + fprintf(sendmail, "%s\n", headers); + } + fprintf(sendmail, "\n%s\n", message); + ret = pclose(sendmail); + if (ret == -1) { + return 0; + } else { + return 1; + } + } else { + php3_error(E_WARNING, "Could not execute mail delivery program"); + return 0; + } +#endif + return 1; +} + /* {{{ proto array imap_search(int stream_id, string criteria [, long flags]) Return a list of messages matching the criteria. */ void php3_imap_search(INTERNAL_FUNCTION_PARAMETERS) @@ -3264,8 +3384,6 @@ mail_free_messagelist(&imap_messages); } /* }}} */ - - /* Interfaces to C-client */ Index: php3/functions/imap.h diff -u php3/functions/imap.h:1.14 php3/functions/imap.h:1.15 --- php3/functions/imap.h:1.14 Sun Dec 26 10:44:46 1999 +++ php3/functions/imap.h Wed Jan 12 00:57:14 2000 @@ -1,4 +1,4 @@ -/* $Id: imap.h,v 1.14 1999/12/26 18:44:46 rasmus Exp $ */ +/* $Id: imap.h,v 1.15 2000/01/12 08:57:14 fmk Exp $ */ #ifndef _INCLUDED_IMAP_H #define _INCLUDED_IMAP_H @@ -73,6 +73,7 @@ void php3_imap_alerts(INTERNAL_FUNCTION_PARAMETERS); void php3_imap_errors(INTERNAL_FUNCTION_PARAMETERS); void php3_imap_last_error(INTERNAL_FUNCTION_PARAMETERS); +void php3_imap_mail(INTERNAL_FUNCTION_PARAMETERS); void php3_imap_search(INTERNAL_FUNCTION_PARAMETERS); void php3_imap_utf8(INTERNAL_FUNCTION_PARAMETERS); #else

« previous php.dev (#14517) next »