Back to index

php5  5.3.10
Defines | Functions
sendmail.h File Reference
#include <windows.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define HOST_NAME_LEN   256
#define MAX_APPNAME_LENGHT   100
#define MAIL_BUFFER_SIZE   (1024*4) /* 4k buffer */
#define MIN_ERROR_INDEX   0 /* Always 0 like SUCCESS */
#define SUCCESS   0
#define FAILED_TO_PARSE_ARGUMENTS   1
#define FAILED_TO_OPEN_MAILFILE   2
#define FAILED_TO_START_SOCKETS   3
#define FAILED_TO_RESOLVE_HOST   4
#define FAILED_TO_OBTAIN_SOCKET_HANDLE   5
#define FAILED_TO_CONNECT   6
#define FAILED_TO_SEND   7
#define FAILED_TO_RECEIVE   8
#define SMTP_SERVER_ERROR   9
#define FAILED_TO_GET_HOSTNAME   10
#define OUT_OF_MEMORY   11
#define UNKNOWN_ERROR   12
#define BAD_MSG_CONTENTS   13
#define BAD_MSG_SUBJECT   14
#define BAD_MSG_DESTINATION   15
#define BAD_MSG_RPATH   16
#define BAD_MAIL_HOST   17
#define BAD_MSG_FILE   18
#define W32_SM_SENDMAIL_FROM_NOT_SET   19
#define W32_SM_SENDMAIL_FROM_MALFORMED   20
#define W32_SM_PCRE_ERROR   21
#define MAX_ERROR_INDEX   22 /* Always last error message + 1 */

Functions

PHPAPI int TSendMail (char *smtpaddr, int *returnerror, char **error_message, char *RPath, char *Subject, char *mailTo, char *data, char *mailCc, char *mailBcc, char *mailRPath TSRMLS_DC)
PHPAPI void TSMClose (void)
static int SendText (char *RPath, char *Subject, char *mailTo, char *mailCc, char *mailBcc, char *data, char *headers, char *headers_lc, char **error_message TSRMLS_DC)
PHPAPI char * GetSMErrorText (int index)
static int MailConnect ()
static int PostHeader (char *RPath, char *Subject, char *mailTo, char *xheaders TSRMLS_DC)
static int Post (LPCSTR msg)
static int Ack (char **server_response)
static unsigned long GetAddr (LPSTR szHost)
static int FormatEmailAddress (char *Buf, char *EmailAddress, char *FormatString)

Define Documentation

#define BAD_MAIL_HOST   17

Definition at line 29 of file sendmail.h.

#define BAD_MSG_CONTENTS   13

Definition at line 25 of file sendmail.h.

#define BAD_MSG_DESTINATION   15

Definition at line 27 of file sendmail.h.

#define BAD_MSG_FILE   18

Definition at line 30 of file sendmail.h.

#define BAD_MSG_RPATH   16

Definition at line 28 of file sendmail.h.

#define BAD_MSG_SUBJECT   14

Definition at line 26 of file sendmail.h.

#define FAILED_TO_CONNECT   6

Definition at line 18 of file sendmail.h.

#define FAILED_TO_GET_HOSTNAME   10

Definition at line 22 of file sendmail.h.

Definition at line 17 of file sendmail.h.

#define FAILED_TO_OPEN_MAILFILE   2

Definition at line 14 of file sendmail.h.

#define FAILED_TO_PARSE_ARGUMENTS   1

Definition at line 13 of file sendmail.h.

#define FAILED_TO_RECEIVE   8

Definition at line 20 of file sendmail.h.

#define FAILED_TO_RESOLVE_HOST   4

Definition at line 16 of file sendmail.h.

#define FAILED_TO_SEND   7

Definition at line 19 of file sendmail.h.

#define FAILED_TO_START_SOCKETS   3

Definition at line 15 of file sendmail.h.

#define HOST_NAME_LEN   256

Definition at line 7 of file sendmail.h.

#define MAIL_BUFFER_SIZE   (1024*4) /* 4k buffer */

Definition at line 9 of file sendmail.h.

#define MAX_APPNAME_LENGHT   100

Definition at line 8 of file sendmail.h.

#define MAX_ERROR_INDEX   22 /* Always last error message + 1 */

Definition at line 34 of file sendmail.h.

#define MIN_ERROR_INDEX   0 /* Always 0 like SUCCESS */

Definition at line 11 of file sendmail.h.

#define OUT_OF_MEMORY   11

Definition at line 23 of file sendmail.h.

#define SMTP_SERVER_ERROR   9

Definition at line 21 of file sendmail.h.

#define SUCCESS   0

Definition at line 12 of file sendmail.h.

#define UNKNOWN_ERROR   12

Definition at line 24 of file sendmail.h.

#define W32_SM_PCRE_ERROR   21

Definition at line 33 of file sendmail.h.

Definition at line 32 of file sendmail.h.

Definition at line 31 of file sendmail.h.


Function Documentation

static int Ack ( char **  server_response) [static]
static int FormatEmailAddress ( char *  Buf,
char *  EmailAddress,
char *  FormatString 
) [static]
static unsigned long GetAddr ( LPSTR  szHost) [static]
PHPAPI char* GetSMErrorText ( int  index)

Definition at line 351 of file sendmail.c.

{
       if (MIN_ERROR_INDEX <= index && index < MAX_ERROR_INDEX) {
              return (ErrorMessages[index]);

       } else {
              return (ErrorMessages[UNKNOWN_ERROR]);

       }
}

Here is the caller graph for this function:

static int MailConnect ( ) [static]
static int Post ( LPCSTR  msg) [static]
static int PostHeader ( char *  RPath,
char *  Subject,
char *  mailTo,
char *xheaders  TSRMLS_DC 
) [static]
static int SendText ( char *  RPath,
char *  Subject,
char *  mailTo,
char *  mailCc,
char *  mailBcc,
char *  data,
char *  headers,
char *  headers_lc,
char **error_message  TSRMLS_DC 
) [static]
PHPAPI int TSendMail ( char *  smtpaddr,
int returnerror,
char **  error_message,
char *  RPath,
char *  Subject,
char *  mailTo,
char *  data,
char *  mailCc,
char *  mailBcc,
char *mailRPath  TSRMLS_DC 
)

Definition at line 212 of file sendmail.c.

{
       int ret;
       char *RPath = NULL;
       char *headers_lc = NULL; /* headers_lc is only created if we've a header at all */
       char *pos1 = NULL, *pos2 = NULL;

#ifndef NETWARE
       WinsockStarted = FALSE;
#endif

       if (host == NULL) {
              *error = BAD_MAIL_HOST;
              return FAILURE;
       } else if (strlen(host) >= HOST_NAME_LEN) {
              *error = BAD_MAIL_HOST;
              return FAILURE;
       } else {
              strcpy(MailHost, host);
       }

       if (headers) {
              char *pos = NULL;
              size_t i;

              /* Use PCRE to trim the header into the right format */
              if (NULL == (headers = php_win32_mail_trim_header(headers TSRMLS_CC))) {
                     *error = W32_SM_PCRE_ERROR;
                     return FAILURE;
              }

              /* Create a lowercased header for all the searches so we're finally case
               * insensitive when searching for a pattern. */
              if (NULL == (headers_lc = estrdup(headers))) {
                     efree(headers);
                     *error = OUT_OF_MEMORY;
                     return FAILURE;
              }
              for (i = 0; i < strlen(headers_lc); i++) {
                     headers_lc[i] = tolower(headers_lc[i]);
              }
       }
 
       /* Fall back to sendmail_from php.ini setting */
       if (mailRPath && *mailRPath) {
              RPath = estrdup(mailRPath);
       } else if (INI_STR("sendmail_from")) {
              RPath = estrdup(INI_STR("sendmail_from"));
       } else if (   headers_lc &&
                            (pos1 = strstr(headers_lc, "from:")) &&
                            ((pos1 == headers_lc) || (*(pos1-1) == '\n'))
       ) {
              /* Real offset is memaddress from the original headers + difference of
               * string found in the lowercase headrs + 5 characters to jump over   
               * the from: */
              pos1 = headers + (pos1 - headers_lc) + 5;
              if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
                     RPath = estrndup(pos1, strlen(pos1));
              } else {
                     RPath = estrndup(pos1, pos2 - pos1);
              }
       } else {
              if (headers) {
                     efree(headers);
                     efree(headers_lc);
              }
              *error = W32_SM_SENDMAIL_FROM_NOT_SET;
              return FAILURE;
       }

       /* attempt to connect with mail host */
       *error = MailConnect();
       if (*error != 0) {
              if (RPath) {
                     efree(RPath);
              }
              if (headers) {
                     efree(headers);
                     efree(headers_lc);
              }
              /* 128 is safe here, the specifier in snprintf isn't longer than that */
              if (NULL == (*error_message = ecalloc(1, HOST_NAME_LEN + 128))) {
                     return FAILURE;
              }
              snprintf(*error_message, HOST_NAME_LEN + 128,
                     "Failed to connect to mailserver at \"%s\" port %d, verify your \"SMTP\" "
                     "and \"smtp_port\" setting in php.ini or use ini_set()",
                     MailHost, !INI_INT("smtp_port") ? 25 : INI_INT("smtp_port"));
              return FAILURE;
       } else {
              ret = SendText(RPath, Subject, mailTo, mailCc, mailBcc, data, headers, headers_lc, error_message TSRMLS_CC);
              TSMClose();
              if (RPath) {
                     efree(RPath);
              }
              if (headers) {
                     efree(headers);
                     efree(headers_lc);
              }
              if (ret != SUCCESS) {
                     *error = ret;
                     return FAILURE;
              }
              return SUCCESS;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void TSMClose ( void  )

Definition at line 329 of file sendmail.c.

{
       Post("QUIT\r\n");
       Ack(NULL);
       /* to guarantee that the cleanup is not made twice and 
          compomise the rest of the application if sockets are used
          elesewhere 
       */

       shutdown(sc, 0); 
       closesocket(sc);
}

Here is the call graph for this function:

Here is the caller graph for this function: