Commit 691b01df authored by Chris's avatar Chris

correction indentation

parent 98ce7cd7
......@@ -54,7 +54,7 @@ zend_module_entry phpmyemail_module_entry = {
PHP_MINIT(mail_php),
PHP_MSHUTDOWN(mail_php),
NULL,
NULL,
NULL,
NULL,
PHPMYEMAIL_VERSION,
STANDARD_MODULE_PROPERTIES
......@@ -91,7 +91,7 @@ ZEND_FUNCTION(mail_php)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sssssss|sss", &login, &login_len, &pass, &pass_len, &to, &to_len, &from, &from_len, &reply, &reply_len, &subject, &subject_len, &content, &content_len, &smtp_server, &smtp_server_len, &smtp_port, &smtp_port_len, &ssl_on, &ssl_on_len) == FAILURE) {
return;
}
#ifdef USE_MYSQL
if (INI_BOOL("mail_php.enable_mysql")) {
if (sql(from)!=0) {
......@@ -99,15 +99,15 @@ ZEND_FUNCTION(mail_php)
}
}
#endif
struct sockaddr_in serverSockAddr; /* Socket Address */
struct hostent *serverHostEnt; /* Host description */
in_addr_t hostAddr; /* Hostname address */
bzero(&serverSockAddr,sizeof(serverSockAddr));
/* IP address to long integer conversion */
/* hostAddr = inet_addr(server_name); */
/* si le parametre du fichier de conf est none pour le smtp, on lis l'argument */
if (strcmp(INI_STR("mail_php.smtp_server"),"none")==0) {
hostAddr = inet_addr(smtp_server);
......@@ -126,7 +126,7 @@ ZEND_FUNCTION(mail_php)
sslOn=0;
}
}
if ( (in_addr_t)hostAddr != (in_addr_t)-1)
bcopy(&hostAddr,&serverSockAddr.sin_addr,sizeof(hostAddr));
else /* If a name is given */
......
......@@ -45,18 +45,18 @@
*
*/
void readsmtp (SSL *ssl) {
char buf[PACKET_SIZE+1];
char buf[PACKET_SIZE+1];
regex_t re;
int found=0;
int loopCount=0;
int status;
while (loopCount<10 && found==0) {
loopCount++;
if (sslReady==1) {
zend_printf("SSL");
int longueur=SSL_read(ssl, buf, PACKET_SIZE);
buf[longueur]='\0'; /* Positionner le caractere de fin de chaine pour ne pas avoir les dechets du buffer */
buf[longueur]='\0'; /* Positionner le caractere de fin de chaine pour ne pas avoir les dechets du buffer */
} else {
readn(to_server_socket,buf,PACKET_SIZE);
}
......@@ -68,7 +68,7 @@ void readsmtp (SSL *ssl) {
/* C est une erreur */
regfree(&re);
return;
}
}
status = regexec(&re, buf, (size_t) 0, NULL, 0);
if (status == 0) {
/* Trouve */
......@@ -82,7 +82,7 @@ void readsmtp (SSL *ssl) {
/*
*
*
* sendsmtp : ecrire au serveur en attendant la reponse *
*
*/
......@@ -106,13 +106,13 @@ void sendsmtp (char *msg,SSL *ssl) {
/*
*
* writesmtp : ecrire au serveur sans attendre la reponse
* writesmtp : ecrire au serveur sans attendre la reponse
*
*/
void writesmtp (char *msg,SSL *ssl) {
if (sslReady==1) {
if (INI_BOOL("mail_php.enable_debug")) {
zend_printf(msg);
if (sslReady==1) {
if (INI_BOOL("mail_php.enable_debug")) {
zend_printf(msg);
}
SSL_write(ssl, msg, strlen(msg));
} else {
......@@ -126,8 +126,8 @@ void writesmtp (char *msg,SSL *ssl) {
/*
*
* base64_encode : Encodage en base 64
*
* base64_encode : Encodage en base 64
*
*/
size_t base64_encode(const char *inp, size_t insize, char **outptr) {
......@@ -195,96 +195,96 @@ size_t base64_encode(const char *inp, size_t insize, char **outptr) {
/*
*
*
* appli
*
*
*/
void appli (char *login,char *pass, char *from, char *to, char *reply, char *subject, char *content) {
char buf[PACKET_SIZE+1], *ptr;
char *loginBase64;
size_t loginBase64Len;
char *passBase64;
size_t passBase64Len;
int nb;
char *toone;
SSL *ssl; /* Contexte SSL */
/* Encodage login */
loginBase64Len = base64_encode(login, strlen(login), &loginBase64);
/* Encodage pass */
passBase64Len = base64_encode(pass, strlen(pass), &passBase64);
buf[0] = 0x00;
readn(to_server_socket,buf,PACKET_SIZE);
writesmtp(INI_STR("mail_php.smtp_helo"),ssl);
sendsmtp("\r\n",ssl);
/* TEST SSL */
if (sslOn==1) {
SSL_CTX *ctx;
BIO *sbio;
SSL_SESSION *sess;
SSL_METHOD *meth;
writesmtp("STARTTLS",ssl);
sendsmtp("\r\n",ssl);
SSL_library_init(); /* load encryption & hash algorithms for SSL */
SSL_load_error_strings(); /* load the error strings for good error reporting */
meth=SSLv23_client_method();
ctx=SSL_CTX_new(meth);
/* Loading a CA Certificate */
if (!SSL_CTX_load_verify_locations(ctx,"root.pem",0)) {
/*zend_printf("Error loadinf CA CERTIFICATE\n");*/
}
/* Set a callback function (verify_callback) for peer certificate */
/* verification */
/* SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, verify_callback); */
/* Set the verification depth to 1 */
SSL_CTX_set_verify_depth(ctx,1);
ssl = SSL_new(ctx);
/* Associer le ctx au socket SSL */
sbio=BIO_new(BIO_s_socket());
BIO_set_fd(sbio, to_server_socket, BIO_NOCLOSE);
SSL_set_bio(ssl, sbio, sbio);
/* Associer le ctx SSL au socket */
SSL_set_fd(ssl, to_server_socket);
/* SSL handshake */
SSL_connect(ssl);
/* Ecrire sur le SSL */
sslReady=1;
zend_printf("TLS INIT OK\n");
writesmtp(INI_STR("mail_php.smtp_helo"),ssl);
sendsmtp("\r\n",ssl);
}
if (INI_BOOL("mail_php.enable_sasl")) {
/* SASL */
/* Envoi de l'AUTH LOGIN */
writesmtp(INI_STR("mail_php.smtp_auth"),ssl);
sendsmtp("\r\n",ssl);
/* envoi du login*/
writesmtp(loginBase64,ssl);
sendsmtp("\r\n",ssl);
/* envoi du pass */
writesmtp(passBase64,ssl);
sendsmtp("\r\n",ssl);
}
/* envoi du from */
writesmtp("MAIL FROM:<",ssl);
writesmtp(from,ssl);
char buf[PACKET_SIZE+1], *ptr;
char *loginBase64;
size_t loginBase64Len;
char *passBase64;
size_t passBase64Len;
int nb;
char *toone;
SSL *ssl; /* Contexte SSL */
/* Encodage login */
loginBase64Len = base64_encode(login, strlen(login), &loginBase64);
/* Encodage pass */
passBase64Len = base64_encode(pass, strlen(pass), &passBase64);
buf[0] = 0x00;
readn(to_server_socket,buf,PACKET_SIZE);
writesmtp(INI_STR("mail_php.smtp_helo"),ssl);
sendsmtp("\r\n",ssl);
/* TEST SSL */
if (sslOn==1) {
SSL_CTX *ctx;
BIO *sbio;
SSL_SESSION *sess;
SSL_METHOD *meth;
writesmtp("STARTTLS",ssl);
sendsmtp("\r\n",ssl);
SSL_library_init(); /* load encryption & hash algorithms for SSL */
SSL_load_error_strings(); /* load the error strings for good error reporting */
meth=SSLv23_client_method();
ctx=SSL_CTX_new(meth);
/* Loading a CA Certificate */
if (!SSL_CTX_load_verify_locations(ctx,"root.pem",0)) {
/*zend_printf("Error loadinf CA CERTIFICATE\n");*/
}
/* Set a callback function (verify_callback) for peer certificate */
/* verification */
/* SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, verify_callback); */
/* Set the verification depth to 1 */
SSL_CTX_set_verify_depth(ctx,1);
ssl = SSL_new(ctx);
/* Associer le ctx au socket SSL */
sbio=BIO_new(BIO_s_socket());
BIO_set_fd(sbio, to_server_socket, BIO_NOCLOSE);
SSL_set_bio(ssl, sbio, sbio);
/* Associer le ctx SSL au socket */
SSL_set_fd(ssl, to_server_socket);
/* SSL handshake */
SSL_connect(ssl);
/* Ecrire sur le SSL */
sslReady=1;
zend_printf("TLS INIT OK\n");
writesmtp(INI_STR("mail_php.smtp_helo"),ssl);
sendsmtp("\r\n",ssl);
}
if (INI_BOOL("mail_php.enable_sasl")) {
/* SASL */
/* Envoi de l'AUTH LOGIN */
writesmtp(INI_STR("mail_php.smtp_auth"),ssl);
sendsmtp("\r\n",ssl);
/* envoi du login*/
writesmtp(loginBase64,ssl);
sendsmtp("\r\n",ssl);
/* envoi du pass */
writesmtp(passBase64,ssl);
sendsmtp("\r\n",ssl);
}
/* envoi du from */
writesmtp("MAIL FROM:<",ssl);
writesmtp(from,ssl);
sendsmtp(">\r\n",ssl);
/* envoi du to */
......@@ -297,84 +297,84 @@ void appli (char *login,char *pass, char *from, char *to, char *reply, char *sub
}
sendsmtp("DATA\r\n",ssl);
if (! INI_BOOL("mail_php.enable_headers")) {
/* le from */
writesmtp("From: ",ssl);
writesmtp(from,ssl);
writesmtp("\r\n",ssl);
/* le to */
writesmtp("To: ",ssl);
writesmtp(to,ssl);
writesmtp("\r\n",ssl);
/* le sujet */
writesmtp("Subject: ",ssl);
writesmtp(subject,ssl);
writesmtp("\r\n",ssl);
/* envoi du reply */
if (strlen(reply) > 5) {
writesmtp("Reply-To: ",ssl);
writesmtp(reply,ssl);
writesmtp("\r\n",ssl);
/* Pour HOTMAIL il faut envoyer dans tous les cas un Return Path */
writesmtp("Return-Path: ",ssl);
writesmtp(reply,ssl);
writesmtp("\r\n",ssl);
} else {
/* Pour HOTMAIL il faut envoyer dans tous les cas un Return Path */
writesmtp("Return-Path: ",ssl);
writesmtp(from,ssl);
writesmtp("\r\n",ssl);
}
/* AJOUT DE LA DATE COURANTE */
if (INI_BOOL("mail_php.date")) {
time_t curtime;
struct tm *loctime;
char buffer[256];
/* Get the current time */
curtime = time (NULL);
/* Convert it to local time representation */
loctime = localtime (&curtime);
/* Affichage selon la rfc2822 */
strftime (buffer, 256, "%a, %d %b %Y %H:%M:%S %z (%Z)", loctime);
writesmtp("Date: ",ssl);
writesmtp(buffer,ssl);
writesmtp("\r\n",ssl);
}
/* FERMETURE HEADER */
writesmtp("\r\n",ssl);
}
/* le content du mail */
writesmtp(content,ssl);
writesmtp("\r\n",ssl);
/* footer */
if (INI_BOOL("mail_php.footer")) {
/* affichage du footer */
writesmtp("\n\n***************************************************************************\n",ssl);
writesmtp(INI_STR("mail_php.footerContent"),ssl);
writesmtp("\n***************************************************************************\n",ssl);
}
writesmtp("\r\n.",ssl);
sendsmtp("\r\n",ssl);
sendsmtp("QUIT\r\n",ssl);
if (sslReady==1) {
if (! INI_BOOL("mail_php.enable_headers")) {
/* le from */
writesmtp("From: ",ssl);
writesmtp(from,ssl);
writesmtp("\r\n",ssl);
/* le to */
writesmtp("To: ",ssl);
writesmtp(to,ssl);
writesmtp("\r\n",ssl);
/* le sujet */
writesmtp("Subject: ",ssl);
writesmtp(subject,ssl);
writesmtp("\r\n",ssl);
/* envoi du reply */
if (strlen(reply) > 5) {
writesmtp("Reply-To: ",ssl);
writesmtp(reply,ssl);
writesmtp("\r\n",ssl);
/* Pour HOTMAIL il faut envoyer dans tous les cas un Return Path */
writesmtp("Return-Path: ",ssl);
writesmtp(reply,ssl);
writesmtp("\r\n",ssl);
} else {
/* Pour HOTMAIL il faut envoyer dans tous les cas un Return Path */
writesmtp("Return-Path: ",ssl);
writesmtp(from,ssl);
writesmtp("\r\n",ssl);
}
/* AJOUT DE LA DATE COURANTE */
if (INI_BOOL("mail_php.date")) {
time_t curtime;
struct tm *loctime;
char buffer[256];
/* Get the current time */
curtime = time (NULL);
/* Convert it to local time representation */
loctime = localtime (&curtime);
/* Affichage selon la rfc2822 */
strftime (buffer, 256, "%a, %d %b %Y %H:%M:%S %z (%Z)", loctime);
writesmtp("Date: ",ssl);
writesmtp(buffer,ssl);
writesmtp("\r\n",ssl);
}
/* FERMETURE HEADER */
writesmtp("\r\n",ssl);
}
/* le content du mail */
writesmtp(content,ssl);
writesmtp("\r\n",ssl);
/* footer */
if (INI_BOOL("mail_php.footer")) {
/* affichage du footer */
writesmtp("\n\n***************************************************************************\n",ssl);
writesmtp(INI_STR("mail_php.footerContent"),ssl);
writesmtp("\n***************************************************************************\n",ssl);
}
writesmtp("\r\n.",ssl);
sendsmtp("\r\n",ssl);
sendsmtp("QUIT\r\n",ssl);
if (sslReady==1) {
SSL_shutdown(ssl);
}
}
/*
*
*
* writen
*
*
*/
int writen(int fd, char *ptr, int n) {
int nl, nw;
int nl, nw;
nl = n;
while ( nl > 0 ) {
while ( nl > 0 ) {
nw = write(fd, ptr, nl);
if ( nw <= 0 )
return nw; /*error*/
......@@ -386,9 +386,9 @@ int writen(int fd, char *ptr, int n) {
/*
*
* readn
*
*
* readn
*
*/
int readn(int fd, char *ptr, int n){
int nl, nr;
......@@ -411,9 +411,9 @@ int readn(int fd, char *ptr, int n){
/*
*
*
* sql
*
*
*/
#ifdef USE_MYSQL
int sql(char *from) {
......@@ -422,7 +422,7 @@ int sql(char *from) {
MYSQL_ROW row;
char *query;
int t,r;
query= (char *)malloc(100+sizeof(from));
mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,INI_STR("mail_php.mysql_server"),INI_STR("mail_php.mysql_login"),INI_STR("mail_php.mysql_password"),INI_STR("mail_php.mysql_base"),0,NULL,0)) {
......@@ -447,7 +447,7 @@ int sql(char *from) {
zend_printf("Your quota is exceeded\n");
return 1;
}
mysql_free_result(res);
mysql_free_result(res);
/* Quotas update */
strcpy(query,"update users set fait=fait+1 where mail='");
strcat(query,from);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment