Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ PHP_ARG_ENABLE(mailparse, whether to enable mailparse support,
[ --enable-mailparse Enable mailparse support.])

if test "$PHP_MAILPARSE" != "no"; then
if test "$ext_shared" != "yes" && test "$enable_mbstring" != "yes"; then
AC_MSG_WARN(Activating mbstring)
enable_mbstring=yes
fi

AC_MSG_CHECKING(libmbfl headers)
if test -f $abs_srcdir/ext/mbstring/libmbfl/mbfl/mbfilter.h; then
dnl build in php-src tree
AC_MSG_RESULT(found in $abs_srcdir/ext/mbstring)
elif test -f $phpincludedir/ext/mbstring/libmbfl/mbfl/mbfilter.h; then
dnl build alone
AC_MSG_RESULT(found in $phpincludedir/ext/mbstring)
else
AC_MSG_ERROR(mbstring extension with libmbfl is missing)
fi

PHP_NEW_EXTENSION(mailparse, mailparse.c php_mailparse_mime.c php_mailparse_rfc822.c, $ext_shared)
PHP_ADD_EXTENSION_DEP(mailparse, mbstring, true)
PHP_NEW_EXTENSION(mailparse, mailparse.c php_mailparse_mime.c php_mailparse_rfc822.c mailparse_encoding.c, $ext_shared)
PHP_ADD_MAKEFILE_FRAGMENT
fi
16 changes: 4 additions & 12 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
ARG_ENABLE("mailparse", "MAILPARSE support", "no");

if (PHP_MAILPARSE != "no") {
EXTENSION('mailparse', 'mailparse.c php_mailparse_mime.c php_mailparse_rfc822.c mailparse_encoding.c');
AC_DEFINE('HAVE_MAILPARSE', 1);

if (PHP_MBSTRING == "no") {
WARNING("mailparse requires mbstring");
} else {
EXTENSION('mailparse', 'mailparse.c php_mailparse_mime.c php_mailparse_rfc822.c');
AC_DEFINE('HAVE_MAILPARSE', 1);


// MFO.WriteLine(configure_module_dirname + "\\php_mailparse_rfc822.c: " + configure_module_dirname + "\\php_mailparse_rfc822.re");
// MFO.WriteLine("\t$(RE2C) -b " + configure_module_dirname + "\\php_mailparse_rfc822.re > " + configure_module_dirname + "\\php_mailparse_rfc822.c");

ADD_EXTENSION_DEP('mailparse', 'mbstring');
}
// MFO.WriteLine(configure_module_dirname + "\\php_mailparse_rfc822.c: " + configure_module_dirname + "\\php_mailparse_rfc822.re");
// MFO.WriteLine("\t$(RE2C) -b " + configure_module_dirname + "\\php_mailparse_rfc822.re > " + configure_module_dirname + "\\php_mailparse_rfc822.c");
}
72 changes: 34 additions & 38 deletions mailparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

#include "arginfo.h"

/* just in case the config check doesn't enable mbstring automatically */
#if !HAVE_MBSTRING
#error The mailparse extension requires the mbstring extension!
#endif

#define MAILPARSE_DECODE_NONE 0 /* include headers and leave section untouched */
#define MAILPARSE_DECODE_8BIT 1 /* decode body into 8-bit */
#define MAILPARSE_DECODE_NOHEADERS 2 /* don't include the headers */
Expand Down Expand Up @@ -92,15 +87,8 @@ zend_function_entry mailparse_functions[] = {
PHP_FE_END
};

static const zend_module_dep mailparse_deps[] = {
ZEND_MOD_REQUIRED("mbstring")
ZEND_MOD_END
};

zend_module_entry mailparse_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
mailparse_deps,
STANDARD_MODULE_HEADER,
"mailparse",
mailparse_functions,
PHP_MINIT(mailparse),
Expand Down Expand Up @@ -914,7 +902,7 @@ PHP_FUNCTION(mailparse_determine_best_xfer_encoding)
int longline = 0;
int linelen = 0;
int c;
enum mbfl_no_encoding bestenc = mbfl_no_encoding_7bit;
enum mb_no_encoding bestenc = mb_no_encoding_7bit;
php_stream *stream;
char * name;

Expand All @@ -930,9 +918,9 @@ PHP_FUNCTION(mailparse_determine_best_xfer_encoding)
if (c == EOF)
break;
if (c > 0x80)
bestenc = mbfl_no_encoding_8bit;
bestenc = mb_no_encoding_8bit;
else if (c == 0) {
bestenc = mbfl_no_encoding_base64;
bestenc = mb_no_encoding_base64;
longline = 0;
break;
}
Expand All @@ -942,20 +930,28 @@ PHP_FUNCTION(mailparse_determine_best_xfer_encoding)
longline = 1;
}
if (longline) {
bestenc = mbfl_no_encoding_qprint;
bestenc = mb_no_encoding_qprint;
}
php_stream_rewind(stream);

#if PHP_VERSION_ID < 80100
name = (char *)mbfl_no2preferred_mime_name(bestenc);
#else
name = (char *)mbfl_encoding_preferred_mime_name(mbfl_no2encoding(bestenc));
#endif
if (name) {
RETVAL_STRING(name);
} else {
RETVAL_FALSE;
/* Get the MIME name for the encoding */
switch (bestenc) {
case mb_no_encoding_7bit:
name = "7bit";
break;
case mb_no_encoding_8bit:
name = "8bit";
break;
case mb_no_encoding_base64:
name = "BASE64";
break;
case mb_no_encoding_qprint:
name = "quoted-printable";
break;
default:
RETURN_FALSE;
}
RETVAL_STRING(name);
}
/* }}} */

Expand All @@ -981,9 +977,9 @@ PHP_FUNCTION(mailparse_stream_encode)
char *buf;
size_t len;
size_t bufsize = 2048;
const mbfl_encoding *encoding;
enum mbfl_no_encoding enc;
mbfl_convert_filter *conv = NULL;
const mb_encoding *encoding;
enum mb_no_encoding enc;
mb_convert_filter *conv = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrS", &srcfile, &destfile, &encod) == FAILURE) {
RETURN_FALSE;
Expand All @@ -999,7 +995,7 @@ PHP_FUNCTION(mailparse_stream_encode)
php_stream_from_zval(srcstream, srcfile);
php_stream_from_zval(deststream, destfile);

encoding = mbfl_name2encoding(ZSTR_VAL(encod));
encoding = mb_name2encoding(ZSTR_VAL(encod));
if (encoding) {
enc = encoding->no_encoding;
} else {
Expand All @@ -1013,14 +1009,14 @@ PHP_FUNCTION(mailparse_stream_encode)
buf = emalloc(bufsize);
RETVAL_TRUE;

conv = mbfl_convert_filter_new(mbfl_no2encoding(mbfl_no_encoding_8bit),
mbfl_no2encoding(enc),
conv = mb_convert_filter_new(mb_no2encoding(mb_no_encoding_8bit),
mb_no2encoding(enc),
mailparse_stream_output,
mailparse_stream_flush,
deststream
);

if (enc == mbfl_no_encoding_qprint) {
if (enc == mb_no_encoding_qprint) {
/* If the qp encoded section is going to be digitally signed,
* it is a good idea to make sure that lines that begin "From "
* have the letter F encoded, so that MTAs do not stick a > character
Expand All @@ -1032,15 +1028,15 @@ PHP_FUNCTION(mailparse_stream_encode)
len = strlen(buf);

if (strncmp(buf, "From ", 5) == 0) {
mbfl_convert_filter_flush(conv);
mb_convert_filter_flush(conv);
php_stream_write(deststream, "=46rom ", 7);
i = 5;
} else {
i = 0;
}

for (; i<len; i++)
mbfl_convert_filter_feed(buf[i], conv);
mb_convert_filter_feed(buf[i], conv);
}
}

Expand All @@ -1051,13 +1047,13 @@ PHP_FUNCTION(mailparse_stream_encode)
{
size_t i;
for (i=0; i<len; i++)
mbfl_convert_filter_feed(buf[i], conv);
mb_convert_filter_feed(buf[i], conv);
}
}
}

mbfl_convert_filter_flush(conv);
mbfl_convert_filter_delete(conv);
mb_convert_filter_flush(conv);
mb_convert_filter_delete(conv);
efree(buf);
}
/* }}} */
Expand Down
Loading
Loading