mirror of
https://github.com/php/pecl-mail-mailparse.git
synced 2026-03-23 22:52:14 +01:00
Fix #27 MimeMessage::__construct() throws TypeError with $mode=stream
This commit is contained in:
17
mailparse.c
17
mailparse.c
@@ -249,11 +249,13 @@ PHP_METHOD(mimemessage, __construct)
|
||||
|
||||
/* now check the args */
|
||||
|
||||
if (zend_string_equals_literal(mode, "new"))
|
||||
if (zend_string_equals_literal(mode, "new")) {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
||||
if (source == NULL)
|
||||
if (source == NULL) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (zend_string_equals_literal(mode, "var") && Z_TYPE_P(source) == IS_STRING) {
|
||||
/* source is the actual message */
|
||||
@@ -261,9 +263,8 @@ PHP_METHOD(mimemessage, __construct)
|
||||
|
||||
ZVAL_DUP(&part->source.zval, source);
|
||||
convert_to_string_ex(&part->source.zval);
|
||||
}
|
||||
|
||||
if (zend_string_equals_literal(mode, "file")) {
|
||||
} else if (zend_string_equals_literal(mode, "file")) {
|
||||
/* source is the name of a file */
|
||||
php_stream *srcstream;
|
||||
|
||||
@@ -276,23 +277,23 @@ PHP_METHOD(mimemessage, __construct)
|
||||
}
|
||||
|
||||
php_stream_to_zval(srcstream, &part->source.zval);
|
||||
}
|
||||
if (zend_string_equals_literal(mode, "stream")) {
|
||||
|
||||
} else if (zend_string_equals_literal(mode, "stream")) {
|
||||
|
||||
part->source.kind = mpSTREAM;
|
||||
|
||||
ZVAL_DUP(&part->source.zval, source);
|
||||
convert_to_string_ex(&part->source.zval);
|
||||
}
|
||||
|
||||
/* parse the data from the source */
|
||||
if (part->source.kind == mpSTRING) {
|
||||
php_mimepart_parse(part, Z_STRVAL_P(&part->source.zval), Z_STRLEN_P(&part->source.zval));
|
||||
|
||||
} else if (part->source.kind == mpSTREAM) {
|
||||
php_stream *srcstream;
|
||||
char buf[1024];
|
||||
|
||||
php_stream_from_zval(srcstream, &part->source.zval);
|
||||
|
||||
php_stream_rewind(srcstream);
|
||||
while(!php_stream_eof(srcstream)) {
|
||||
size_t n = php_stream_read(srcstream, buf, sizeof(buf));
|
||||
|
||||
@@ -48,6 +48,7 @@ It can deal with rfc822 and rfc2045 (MIME) compliant messages.
|
||||
<license uri="http://www.php.net/license">PHP</license>
|
||||
<notes>
|
||||
- drop usage of removed mbfl APIs in PHP 8.3
|
||||
- fix GH-27 MimeMessage::__construct() throws TypeError with $mode=stream
|
||||
</notes>
|
||||
<contents>
|
||||
<dir name="/">
|
||||
@@ -80,6 +81,8 @@ It can deal with rfc822 and rfc2045 (MIME) compliant messages.
|
||||
<file name="010.phpt" role="test" />
|
||||
<file name="011.phpt" role="test" />
|
||||
<file name="012.phpt" role="test" />
|
||||
<file name="012-stream.phpt" role="test" />
|
||||
<file name="012-var.phpt" role="test" />
|
||||
<file name="013.phpt" role="test" />
|
||||
<file name="bug001.phpt" role="test" />
|
||||
<file name="bug73110.phpt" role="test" />
|
||||
|
||||
23
tests/012-stream.phpt
Normal file
23
tests/012-stream.phpt
Normal file
@@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
Check mailparse_mimemessage_extract_uue (stream mode)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
/* vim600: sw=4 ts=4 fdm=marker syn=php
|
||||
*/
|
||||
if (!extension_loaded("mailparse")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$fp = fopen(dirname(__FILE__) . "/testdata/oeuue", "rb");
|
||||
$msg = new MimeMessage("stream", $fp);
|
||||
var_dump( $msg->extract_uue(0, MAILPARSE_EXTRACT_RETURN));
|
||||
fclose($fp);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(88) "FooBar - Baaaaa
|
||||
|
||||
Requirements:
|
||||
o php with mailparse
|
||||
o virus scanner (optional)
|
||||
|
||||
|
||||
"
|
||||
22
tests/012-var.phpt
Normal file
22
tests/012-var.phpt
Normal file
@@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
Check mailparse_mimemessage_extract_uue (var mode)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
/* vim600: sw=4 ts=4 fdm=marker syn=php
|
||||
*/
|
||||
if (!extension_loaded("mailparse")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$var = file_get_contents(dirname(__FILE__) . "/testdata/oeuue");
|
||||
$msg = new MimeMessage("var", $var);
|
||||
var_dump( $msg->extract_uue(0, MAILPARSE_EXTRACT_RETURN));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(88) "FooBar - Baaaaa
|
||||
|
||||
Requirements:
|
||||
o php with mailparse
|
||||
o virus scanner (optional)
|
||||
|
||||
|
||||
"
|
||||
@@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Check mailparse_mimemessage_extract_uue
|
||||
Check mailparse_mimemessage_extract_uue (file mode)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
/* vim600: sw=4 ts=4 fdm=marker syn=php
|
||||
|
||||
@@ -4,7 +4,7 @@ Parse messages in testdata dir
|
||||
<?php
|
||||
/* vim600: sw=4 ts=4 fdm=marker syn=php
|
||||
*/
|
||||
if (!extension_loaded("mailparse") || !extension_loaded("zlib")) print "skip"; ?>
|
||||
if (!extension_loaded("mailparse") || !extension_loaded("zlib")) print "skip missing mailparse or zlib"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
|
||||
Reference in New Issue
Block a user