[-]
[+]
|
Changed |
php5-mailparse.changes
|
|
[-]
[+]
|
Changed |
php5-mailparse.spec
^
|
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/README
^
|
@@ -1,165 +0,0 @@
-mailparse library for PHP 4
-===========================
-$Id: README,v 1.3 2002/09/10 11:20:45 wez Exp $
-
-Mailparse is an extension for parsing and working with email messages.
-It can deal with rfc822 and rfc2045 (MIME) compliant messages.
-Mailparse is stream based, which means that it does not keep in-memory
-copies of the files it processes - so it is very resource efficient
-when dealing with large messages.
-
-OO Syntax:
-=============
-<?php
-$file = "/path/to/rfc822/compliant/message";
-// parse the message in $file.
-// The file MUST remain in existence until you are finished using
-// the object, as mailparse does not cache the file in memory.
-// You can also use two alternative syntaxes:
-//
-// Read the message from a variable:
-// $msg =& new MimeMessage("var", $message);
-//
-// Read the message from a stream (from fopen).
-// The stream MUST be seekable, or things will not work correctly.
-// Also, you MUST NOT fclose the stream until you have finished
-// using the message object (or any child objects it returns).
-// $msg =& new MimeMessage("stream", $fp);
-//
-$msg =& new MimeMessage("file", $file);
-
-// Process the message.
-display_part_info("message", $msg);
-
-// Little function to display things
-function display_part_info($caption, &$msgpart)
-{
- echo "Message part: $caption\n";
-
- // The data member corresponds to the information
- // available from the mailparse_msg_get_part_data function.
- // You can access a particular header like this:
- // $subject = $msgpart->data["headers"]["subject"];
- var_dump($msgpart->data);
-
- echo "The headers are:\n";
- // Display the headers (in raw format) to the browser output.
- // You can also use:
- // $msgpart->extract_headers(MAILPARSE_EXTRACT_STREAM, $fp);
- // to write the headers to the supplied stream at it's current
- // position.
- //
- // $var = $msgpart->extract_headers(MAILPARSE_EXTRACT_RETURN);
- // to return the headers in a variable.
- $msgpart->extract_headers(MAILPARSE_EXTRACT_OUTPUT);
-
- // Display the body if this part is intended to be displayed:
- $n = $msgpart->get_child_count();
-
- if ($n == 0) {
- // Return the body as a string (the MAILPARSE_EXTRACT parameter
- // acts just as it does in extract_headers method.
- $body = $msgpart->extract_body(MAILPARSE_EXTRACT_RETURN);
- echo htmlentities($body);
-
- // This function tells you about any uuencoded attachments
- // that are present in this part.
- $uue = $msgpart->enum_uue();
- if ($uue !== false) {
- var_dump($uue);
- foreach($uue as $index => $data) {
- // $data => array("filename" => "original filename",
- // "filesize" => "size of extracted file",
- // );
-
- printf("UUE[%d] %s (%d bytes)\n",
- $index, $data["filename"],
- $data["filesize"]);
-
- // Display the extracted part to the output.
- $msgpart->extract_uue($index, MAILPARSE_EXTRACT_OUTPUT);
-
- }
- }
-
- } else {
- // Recurse and show children of that part
- for ($i = 0; $i < $n; $i++) {
- $part =& $msgpart->get_child($i);
- display_part_info("$caption child $i", $part);
- }
- }
-}
-
-?>
-
-////////////// The rest of this document may be out of date!
-// Take a look at the mailparse section of the online manual
-// for more hints about this stuff.
-
-$mime = mailparse_rfc2045_parse_file($file);
-$ostruct = mailparse_rfc2045_getstructure($mime);
-foreach($ostruct as $st) {
- $section = mailparse_rfc2045_find($mime, $st);
- $struct[$st] = mailparse_rfc2045_getinfo($section);
-}
-var_dump($struct);
-?>
-array mailparse_rfc822_parse_addresses(string addresses)
- parses an rfc822 compliant recipient list, such as that found in To: From:
- headers. Returns a indexed array of assoc. arrays for each recipient:
- array(0 => array("display" => "Wez Furlong", "address" => "wez@php.net"))
-
-resource mailparse_rfc2045_create()
- Create a mime mail resource
-
-boolean mailparse_rfc2045_parse(resource mimemail, string data)
- incrementally parse data into the supplied mime mail resource.
- Concept: you can stream portions of a file at a time, rather than read
- and parse the whole thing.
-
-
-resource mailparse_rfc2045_parse_file(string $filename)
- Parse a file and return a $mime resource.
- The file is opened and streamed through the parser.
- This is the optimal way of parsing a mail file that
- you have on disk.
-
-
-array mailparse_rfc2045_getstructure(resource mimemail)
- returns an array containing a list of message parts in the form:
- array("1", "1.1", "1.2")
-
-resource mailparse_rfc2045_find(resource mimemail, string partname)
- returns an mime mail resource representing the named section
-
-array mailparse_rfc2045_getinfo(resource mimemail)
- returns an array containing the bounds, content type and headers of the
- section.
-
-mailparse_rfc2045_extract_file(resource mimemail, string filename[, string
- callbackfunc])
- Extracts/decodes a message section from the supplied filename.
- If no callback func is supplied, it outputs the results into the current
- output buffer, otherwise it calls the callback with a string parameter
- containing the text.
- The contents of the section will be decoded according to their transfer
- encoding - base64, quoted-printable and uuencoded text are supported.
-
-All operations are done incrementally; streaming the input and output so that
-memory usage is on the whole lower than something like procmail or doing this
-stuff in PHP space. The aim is that it stays this way to handle large
-quantities of email.
-
-TODO:
-=====
-
-. Add support for binhex encoding?
-. Extracting a message part without decoding the transfer encoding so that
- eg: pgp-signatures can be verified.
-
-. Work the other way around - build up a rfc2045 compliant message file from
- simple structure information and filenames/variables.
-
-vim:tw=78
-vim600:syn=php:tw=78
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/config.m4
^
|
@@ -1,18 +0,0 @@
-dnl
-dnl $Id: config.m4,v 1.5 2002/04/06 14:32:34 wez Exp $
-dnl
-
-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
- PHP_NEW_EXTENSION(mailparse, mailparse.c php_mailparse_mime.c php_mailparse_rfc822.c, $ext_shared)
-
- PHP_ADD_MAKEFILE_FRAGMENT
-
-fi
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/mailparse.c
^
|
@@ -1,1532 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id: mailparse.c,v 1.54 2008/01/08 20:20:02 shire Exp $ */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "php.h"
-#include "php_ini.h"
-#include "ext/standard/file.h"
-#include "php_mailparse.h"
-#include "ext/standard/info.h"
-#include "main/php_output.h"
-#include "php_open_temporary_file.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 */
-#define MAILPARSE_DECODE_NOBODY 4 /* don't include the body */
-
-#define MAILPARSE_EXTRACT_OUTPUT 0 /* extract to output buffer */
-#define MAILPARSE_EXTRACT_STREAM 1 /* extract to a stream (caller supplies) */
-#define MAILPARSE_EXTRACT_RETURN 2 /* return extracted data as a string */
-
-static int extract_part(php_mimepart *part, int decode, php_stream *src, void *callbackdata,
- php_mimepart_extract_func_t callback TSRMLS_DC);
-static int extract_callback_stream(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC);
-static int extract_callback_stdout(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC);
-
-static int get_structure_callback(php_mimepart *part, php_mimepart_enumerator *id, void *ptr TSRMLS_DC);
-static int mailparse_get_part_data(php_mimepart *part, zval *return_value TSRMLS_DC);
-static int mailparse_mimemessage_populate(php_mimepart *part, zval *object TSRMLS_DC);
-static size_t mailparse_do_uudecode(php_stream *instream, php_stream *outstream TSRMLS_DC);
-
-static int le_mime_part;
-
-
-static function_entry mimemessage_methods[] = {
- PHP_NAMED_FE(mimemessage, PHP_FN(mailparse_mimemessage), NULL)
- PHP_NAMED_FE(get_child, PHP_FN(mailparse_mimemessage_get_child), NULL)
- PHP_NAMED_FE(get_child_count, PHP_FN(mailparse_mimemessage_get_child_count), NULL)
- PHP_NAMED_FE(get_parent, PHP_FN(mailparse_mimemessage_get_parent), NULL)
- PHP_NAMED_FE(extract_headers, PHP_FN(mailparse_mimemessage_extract_headers), NULL)
- PHP_NAMED_FE(extract_body, PHP_FN(mailparse_mimemessage_extract_body), NULL)
- PHP_NAMED_FE(enum_uue, PHP_FN(mailparse_mimemessage_enum_uue), NULL)
- PHP_NAMED_FE(extract_uue, PHP_FN(mailparse_mimemessage_extract_uue), NULL)
- PHP_NAMED_FE(remove, PHP_FN(mailparse_mimemessage_remove), NULL)
- PHP_NAMED_FE(add_child, PHP_FN(mailparse_mimemessage_add_child), NULL)
- {NULL, NULL, NULL}
-};
-
-static zend_class_entry *mimemsg_class_entry;
-
-function_entry mailparse_functions[] = {
- PHP_FE(mailparse_msg_parse_file, NULL)
- PHP_FE(mailparse_msg_get_part, NULL)
- PHP_FE(mailparse_msg_get_structure, NULL)
- PHP_FE(mailparse_msg_get_part_data, NULL)
- PHP_FE(mailparse_msg_extract_part, NULL)
- PHP_FE(mailparse_msg_extract_part_file, NULL)
- PHP_FE(mailparse_msg_extract_whole_part_file, NULL)
-
- PHP_FE(mailparse_msg_create, NULL)
- PHP_FE(mailparse_msg_free, NULL)
- PHP_FE(mailparse_msg_parse, NULL)
- PHP_FE(mailparse_rfc822_parse_addresses, NULL)
- PHP_FE(mailparse_determine_best_xfer_encoding, NULL)
- PHP_FE(mailparse_stream_encode, NULL)
- PHP_FE(mailparse_uudecode_all, NULL)
-
- PHP_FE(mailparse_test, NULL)
-
- {NULL, NULL, NULL}
-};
-
-zend_module_entry mailparse_module_entry = {
- STANDARD_MODULE_HEADER,
- "mailparse",
- mailparse_functions,
- PHP_MINIT(mailparse),
- PHP_MSHUTDOWN(mailparse),
- PHP_RINIT(mailparse),
- PHP_RSHUTDOWN(mailparse),
- PHP_MINFO(mailparse),
- "2.1.3",
- STANDARD_MODULE_PROPERTIES
-};
-
-ZEND_DECLARE_MODULE_GLOBALS(mailparse)
-
-#ifdef COMPILE_DL_MAILPARSE
-ZEND_GET_MODULE(mailparse)
-#endif
-
-ZEND_RSRC_DTOR_FUNC(mimepart_dtor)
-{
- php_mimepart *part = rsrc->ptr;
-
- if (part->parent == NULL && part->rsrc_id) {
- part->rsrc_id = 0;
- php_mimepart_free(part TSRMLS_CC);
- }
-}
-
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("mailparse.def_charset", "us-ascii", PHP_INI_ALL, OnUpdateString, def_charset, zend_mailparse_globals, mailparse_globals)
-PHP_INI_END()
-
-#define mailparse_msg_name "mailparse_mail_structure"
-
-#define mailparse_fetch_mimepart_resource(rfcvar, zvalarg) ZEND_FETCH_RESOURCE(rfcvar, php_mimepart *, zvalarg, -1, mailparse_msg_name, le_mime_part)
-
-PHP_MAILPARSE_API int php_mailparse_le_mime_part(void)
-{
- return le_mime_part;
-}
-
-PHP_MINIT_FUNCTION(mailparse)
-{
- zend_class_entry mmce;
-
-#ifdef ZTS
- zend_mailparse_globals *mailparse_globals;
-
- ts_allocate_id(&mailparse_globals_id, sizeof(zend_mailparse_globals), NULL, NULL);
- mailparse_globals = ts_resource(mailparse_globals_id);
-#endif
-
- INIT_CLASS_ENTRY(mmce, "mimemessage", mimemessage_methods);
- mimemsg_class_entry = zend_register_internal_class(&mmce TSRMLS_CC);
-
-
- le_mime_part = zend_register_list_destructors_ex(mimepart_dtor, NULL, mailparse_msg_name, module_number);
-
- REGISTER_LONG_CONSTANT("MAILPARSE_EXTRACT_OUTPUT", MAILPARSE_EXTRACT_OUTPUT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("MAILPARSE_EXTRACT_STREAM", MAILPARSE_EXTRACT_STREAM, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("MAILPARSE_EXTRACT_RETURN", MAILPARSE_EXTRACT_RETURN, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_INI_ENTRIES();
-
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(mailparse)
-{
- UNREGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-
-/* {{{ ------------- MimeMessage methods */
-
-static inline php_mimepart *mimemsg_get_object(zval *object TSRMLS_DC)
-{
- zval **zpart;
- php_mimepart *part;
- int type;
-
-
- if (Z_TYPE_P(object) != IS_OBJECT) {
- return NULL;
- }
-
- if (zend_hash_index_find(Z_OBJPROP_P(object), 0, (void**)&zpart) == FAILURE) {
- return NULL;
- }
-
- part = zend_list_find(Z_LVAL_PP(zpart), &type);
-
- if (type != le_mime_part)
- return NULL;
-
- return part;
-}
-
-static int mailparse_mimemessage_populate(php_mimepart *part, zval *object TSRMLS_DC)
-{
- zval *tmp;
-
- MAKE_STD_ZVAL(tmp);
- mailparse_get_part_data(part, tmp TSRMLS_CC);
- add_property_zval(object, "data", tmp);
- ZVAL_DELREF(tmp);
-
- return SUCCESS;
-}
-
-static int mailparse_mimemessage_export(php_mimepart *part, zval *object TSRMLS_DC)
-{
- zval *zpart;
-
- zend_list_addref(part->rsrc_id);
-
- MAKE_STD_ZVAL(zpart);
- php_mimepart_to_zval(zpart, part);
-
- object_init_ex(object, mimemsg_class_entry);
- PZVAL_IS_REF(object) = 1;
- ZVAL_REFCOUNT(object) = 1;
-
- zend_hash_index_update(Z_OBJPROP_P(object), 0, &zpart, sizeof(zval *), NULL);
-
- /* recurses for any of our child parts */
- mailparse_mimemessage_populate(part, object TSRMLS_CC);
-
- return SUCCESS;
-}
-
-PHP_FUNCTION(mailparse_mimemessage)
-{
- zval *object = getThis();
- php_mimepart *part;
- zval *zpart;
- char *mode;
- int mode_len;
- zval *source = NULL;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz!", &mode, &mode_len, &source) == FAILURE)
- RETURN_FALSE;
-
- /* prepare the mime part for this object */
- part = php_mimepart_alloc();
- MAKE_STD_ZVAL(zpart);
- php_mimepart_to_zval(zpart, part);
-
- zend_hash_index_update(Z_OBJPROP_P(object), 0, &zpart, sizeof(zval *), NULL);
-
- /* now check the args */
-
- if (strcmp(mode, "new") == 0)
- RETURN_TRUE;
-
- if (source == NULL)
- RETURN_FALSE;
-
- if (strcmp(mode, "var") == 0 && Z_TYPE_P(source) == IS_STRING) {
- /* source is the actual message */
- part->source.kind = mpSTRING;
-
- *part->source.zval = *source;
- zval_copy_ctor(part->source.zval);
- convert_to_string_ex(&part->source.zval);
- }
-
- if (strcmp(mode, "file") == 0) {
- /* source is the name of a file */
- php_stream *srcstream;
-
- part->source.kind = mpSTREAM;
- convert_to_string_ex(&source);
- srcstream = php_stream_open_wrapper(Z_STRVAL_P(source), "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
-
- if (srcstream == NULL) {
- RETURN_FALSE;
- }
-
- php_stream_to_zval(srcstream, part->source.zval);
- }
- if (strcmp(mode, "stream") == 0) {
- part->source.kind = mpSTREAM;
-
- *part->source.zval = *source;
- zval_copy_ctor(part->source.zval);
- 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) TSRMLS_CC);
- } 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));
- if (n > 0)
- php_mimepart_parse(part, buf, n TSRMLS_CC);
- }
- }
-
- mailparse_mimemessage_populate(part, object TSRMLS_CC);
-}
-
-PHP_FUNCTION(mailparse_mimemessage_remove)
-{
- php_mimepart *part;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
- if (part == NULL)
- RETURN_FALSE;
-
- php_mimepart_remove_from_parent(part TSRMLS_CC);
-}
-
-PHP_FUNCTION(mailparse_mimemessage_add_child)
-{
- php_mimepart *part;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
- if (part == NULL)
- RETURN_FALSE;
-
- php_mimepart_remove_from_parent(part TSRMLS_CC);
-}
-
-
-PHP_FUNCTION(mailparse_mimemessage_get_child_count)
-{
- php_mimepart *part;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
- if (part == NULL)
- RETURN_FALSE;
-
- RETURN_LONG(zend_hash_num_elements(&part->children));
-}
-
-PHP_FUNCTION(mailparse_mimemessage_get_parent)
-{
- php_mimepart *part;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
-
- if (part && part->parent) {
- mailparse_mimemessage_export(part->parent, return_value TSRMLS_CC);
- } else {
- RETURN_NULL();
- }
-}
-
-PHP_FUNCTION(mailparse_mimemessage_get_child)
-{
- php_mimepart *part, *foundpart;
- zval **item_to_find;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
-
- if (part == NULL)
- RETURN_NULL();
-
- if (FAILURE == zend_get_parameters_ex(1, &item_to_find))
- RETURN_NULL();
-
- if (Z_TYPE_PP(item_to_find) == IS_STRING) {
- foundpart = php_mimepart_find_by_name(part, Z_STRVAL_PP(item_to_find) TSRMLS_CC);
- } else {
- foundpart = php_mimepart_find_child_by_position(part, Z_LVAL_PP(item_to_find) TSRMLS_CC);
- }
-
- if (!foundpart) {
- RETURN_NULL();
- }
-
- mailparse_mimemessage_export(foundpart, return_value TSRMLS_CC);
-}
-
-static void mailparse_mimemessage_extract(int flags, INTERNAL_FUNCTION_PARAMETERS)
-{
- php_mimepart *part;
- zval *zarg = NULL;
- php_stream *srcstream, *deststream = NULL;
- long mode = MAILPARSE_EXTRACT_OUTPUT;
- php_mimepart_extract_func_t callback = extract_callback_stdout;
- void *callback_data = NULL;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
-
- RETVAL_NULL();
-
- if (part == NULL)
- return;
-
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lz!", &mode, &zarg))
- return;
-
- switch(mode) {
- case MAILPARSE_EXTRACT_STREAM:
- if (zarg == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 2 must be a stream");
- return;
- }
-
- php_stream_from_zval(deststream, &zarg);
- break;
- case MAILPARSE_EXTRACT_RETURN:
- deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
- break;
- }
-
-
- if (part->source.kind == mpSTRING)
- srcstream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(part->source.zval), Z_STRLEN_P(part->source.zval));
- else
- php_stream_from_zval(srcstream, &part->source.zval);
-
- if (srcstream == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "MimeMessage object is missing a source stream!");
- goto cleanup;
- }
-
- if (deststream != NULL) {
- callback_data = deststream;
- callback = extract_callback_stream;
- }
-
- if (SUCCESS == extract_part(part, flags, srcstream, callback_data, callback TSRMLS_CC)) {
-
- if (mode == MAILPARSE_EXTRACT_RETURN) {
- size_t len;
- char *buf;
-
- buf = php_stream_memory_get_buffer(deststream, &len);
- RETVAL_STRINGL(buf, len, 1);
- } else {
- RETVAL_TRUE;
- }
-
- }
-
-cleanup:
-
- if (part->source.kind == mpSTRING && srcstream)
- php_stream_close(srcstream);
- if (mode == MAILPARSE_EXTRACT_RETURN && deststream)
- php_stream_close(deststream);
-
-}
-
-PHP_FUNCTION(mailparse_mimemessage_extract_headers)
-{
- mailparse_mimemessage_extract(MAILPARSE_DECODE_NOBODY, INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-
-PHP_FUNCTION(mailparse_mimemessage_extract_body)
-{
- mailparse_mimemessage_extract(MAILPARSE_DECODE_NOHEADERS | MAILPARSE_DECODE_8BIT, INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-
-PHP_FUNCTION(mailparse_mimemessage_extract_uue)
-{
- php_mimepart *part;
- zval *zarg = NULL;
- php_stream *srcstream, *deststream = NULL;
- long mode = MAILPARSE_EXTRACT_OUTPUT;
- long index = 0; /* which uue to extract */
- off_t end;
- off_t start_pos;
- char buffer[4096];
- int nparts = 0;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
-
- RETVAL_NULL();
-
- if (part == NULL)
- return;
-
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|lz!", &index, &mode, &zarg))
- return;
-
- switch(mode) {
- case MAILPARSE_EXTRACT_STREAM:
- if (zarg == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 2 must be a stream");
- return;
- }
-
- php_stream_from_zval(deststream, &zarg);
- break;
- case MAILPARSE_EXTRACT_RETURN:
- deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
- break;
- case MAILPARSE_EXTRACT_OUTPUT:
- deststream = php_stream_open_wrapper("php://output", "wb", 0, NULL);
- break;
- }
-
- if (part->source.kind == mpSTRING)
- srcstream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(part->source.zval), Z_STRLEN_P(part->source.zval));
- else
- php_stream_from_zval(srcstream, &part->source.zval);
-
- if (srcstream == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "MimeMessage object is missing a source stream!");
- goto cleanup;
- }
-
- /* position stream at start of the body for this part */
-
- start_pos = part->bodystart;
- end = part->parent ? part->bodyend : part->endpos;
- php_stream_seek(srcstream, start_pos, SEEK_SET);
-
- while(!php_stream_eof(srcstream) && php_stream_gets(srcstream, buffer, sizeof(buffer))) {
- /* Look for the "begin " sequence that identifies a uuencoded file */
- if (strncmp(buffer, "begin ", 6) == 0) {
- char *origfilename;
- int len;
-
- /* parse out the file name.
- * The next 4 bytes are an octal number for perms; ignore it */
- origfilename = &buffer[10];
- /* NUL terminate the filename */
- len = strlen(origfilename);
- while(isspace(origfilename[len-1]))
- origfilename[--len] = '\0';
-
- /* make the return an array */
- if (nparts == index) {
- mailparse_do_uudecode(srcstream, deststream TSRMLS_CC);
- if (mode == MAILPARSE_EXTRACT_RETURN) {
- size_t len;
- char *buf;
-
- buf = php_stream_memory_get_buffer(deststream, &len);
- RETVAL_STRINGL(buf, len, 1);
- } else {
- RETVAL_TRUE;
- }
-
- break;
- } else {
- /* skip that part */
- mailparse_do_uudecode(srcstream, NULL TSRMLS_CC);
- }
- } else {
- if (php_stream_tell(srcstream) >= end)
- break;
- }
- }
-
-cleanup:
-
- if (part->source.kind == mpSTRING && srcstream)
- php_stream_close(srcstream);
- if (mode != MAILPARSE_EXTRACT_STREAM && deststream)
- php_stream_close(deststream);
-
-
-}
-
-PHP_FUNCTION(mailparse_mimemessage_enum_uue)
-{
- php_stream *instream;
- php_mimepart *part;
- off_t end;
- off_t start_pos, curr_pos;
- size_t file_size;
- char buffer[4096];
- int nparts = 0;
- zval *item;
-
- part = mimemsg_get_object(getThis() TSRMLS_CC);
-
- RETVAL_FALSE;
-
- if (part == NULL)
- return;
-
- if (part->source.kind == mpSTRING)
- instream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(part->source.zval), Z_STRLEN_P(part->source.zval));
- else
- php_stream_from_zval(instream, &part->source.zval);
-
- if (instream == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "MimeMessage object is missing a source stream!");
- goto cleanup;
- }
-
- /* position stream at start of the body for this part */
-
- start_pos = part->bodystart;
- end = part->parent ? part->bodyend : part->endpos;
- php_stream_seek(instream, start_pos, SEEK_SET);
-
- while(!php_stream_eof(instream) && php_stream_gets(instream, buffer, sizeof(buffer))) {
- /* Look for the "begin " sequence that identifies a uuencoded file */
- if (strncmp(buffer, "begin ", 6) == 0) {
- char *origfilename;
- int len;
-
- /* parse out the file name.
- * The next 4 bytes are an octal number for perms; ignore it */
- origfilename = &buffer[10];
- /* NUL terminate the filename */
- len = strlen(origfilename);
- while(isspace(origfilename[len-1]))
- origfilename[--len] = '\0';
-
- /* make the return an array */
- if (nparts == 0) {
- array_init(return_value);
- }
-
- /* add an item */
- MAKE_STD_ZVAL(item);
- array_init(item);
- add_assoc_string(item, "filename", origfilename, 1);
- add_assoc_long(item, "start-pos", php_stream_tell(instream));
-
- /* decode it and remember the file size */
- file_size = mailparse_do_uudecode(instream, NULL TSRMLS_CC);
- add_assoc_long(item, "filesize", file_size);
-
- curr_pos = php_stream_tell(instream);
-
- if (curr_pos > end) {
- /* we somehow overran the message boundary; the message itself is
- * probably bogus, so lets cancel this item */
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "uue attachment overran part boundary; this should not happen, message is probably malformed");
- zval_ptr_dtor(&item);
- break;
- }
-
- add_assoc_long(item, "end-pos", curr_pos);
- add_next_index_zval(return_value, item);
- nparts++;
-
- } else {
- if (php_stream_tell(instream) >= end)
- break;
- }
- }
-cleanup:
- if (part->source.kind == mpSTRING && instream)
- php_stream_close(instream);
-
-}
-
-/* --- END ---------- MimeMessage methods }}} */
-
-PHP_MINFO_FUNCTION(mailparse)
-{
- php_info_print_table_start();
- php_info_print_table_header(2, "mailparse support", "enabled");
- php_info_print_table_row(2, "Extension Version", mailparse_module_entry.version);
- php_info_print_table_row(2, "Revision", "$Revision: 1.54 $");
- php_info_print_table_end();
-
- DISPLAY_INI_ENTRIES();
-}
-
-
-PHP_RINIT_FUNCTION(mailparse)
-{
- return SUCCESS;
-}
-
-
-PHP_RSHUTDOWN_FUNCTION(mailparse)
-{
- return SUCCESS;
-}
-
-#define UUDEC(c) (char)(((c)-' ')&077)
-#define UU_NEXT(v) if (line[x] == '\0' || line[x] == '\r' || line[x] == '\n') break; v = line[x++]; v = UUDEC(v)
-static size_t mailparse_do_uudecode(php_stream *instream, php_stream *outstream TSRMLS_DC)
-{
- int x, A, B, C, D, n;
- size_t file_size = 0;
- char line[128];
-
- if (outstream) {
- /* write to outstream */
- while(!php_stream_eof(instream)) {
- if (!php_stream_gets(instream, line, sizeof(line))) {
- break;
- }
- x = 0;
-
- UU_NEXT(n);
-
- while(n != 0) {
- UU_NEXT(A);
- UU_NEXT(B);
- UU_NEXT(C);
- UU_NEXT(D);
-
- if (n-- > 0) {
- file_size++;
- php_stream_putc(outstream, (A << 2) | (B >> 4));
- }
-
- if (n-- > 0) {
- file_size++;
- php_stream_putc(outstream, (B << 4) | (C >> 2));
- }
-
- if (n-- > 0) {
- file_size++;
- php_stream_putc(outstream, (C << 6) | D);
- }
- }
- }
- } else {
- /* skip (and measure) the data, but discard it.
- * This is separated from the version above to speed it up by a few cycles */
-
- while(!php_stream_eof(instream)) {
-
- if (!php_stream_gets(instream, line, sizeof(line))) {
- break;
- }
- x = 0;
-
- UU_NEXT(n);
-
- while(line[x] && n != 0) {
- UU_NEXT(A);
- UU_NEXT(B);
- UU_NEXT(C);
- UU_NEXT(D);
-
- if (n-- > 0) {
- file_size++;
- }
-
- if (n-- > 0) {
- file_size++;
- }
-
- if (n-- > 0) {
- file_size++;
- }
- }
- }
- }
- return file_size;
-}
-
-
-/* {{{ proto array mailparse_uudecode_all(resource fp)
- Scans the data from fp and extract each embedded uuencoded file. Returns an array listing filename information */
-PHP_FUNCTION(mailparse_uudecode_all)
-{
- zval *file, *item;
- char *buffer = NULL;
- char *outpath = NULL;
- int nparts = 0;
- php_stream *instream, *outstream = NULL, *partstream = NULL;
-
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &file))
- return;
-
- php_stream_from_zval(instream, &file);
-
- outstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath);
- if (outstream == NULL) {
- zend_error(E_WARNING, "%s(): unable to open temp file", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
-
- php_stream_rewind(instream);
-
- buffer = emalloc(4096);
- while(php_stream_gets(instream, buffer, 4096)) {
- /* Look for the "begin " sequence that identifies a uuencoded file */
- if (strncmp(buffer, "begin ", 6) == 0) {
- char * origfilename;
- int len;
-
- /* parse out the file name.
- * The next 4 bytes are an octal number for perms; ignore it */
- origfilename = &buffer[10];
- /* NUL terminate the filename */
- len = strlen(origfilename);
- while(isspace(origfilename[len-1]))
- origfilename[--len] = '\0';
-
- /* make the return an array */
- if (nparts == 0) {
- array_init(return_value);
- /* create an initial item representing the file with all uuencoded parts
- * removed */
- MAKE_STD_ZVAL(item);
- array_init(item);
- add_assoc_string(item, "filename", outpath, 0);
- add_next_index_zval(return_value, item);
- }
-
- /* add an item */
- MAKE_STD_ZVAL(item);
- array_init(item);
- add_assoc_string(item, "origfilename", origfilename, 1);
-
- /* create a temp file for the data */
- partstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath);
- if (partstream) {
- nparts++;
- add_assoc_string(item, "filename", outpath, 0);
- add_next_index_zval(return_value, item);
-
- /* decode it */
- mailparse_do_uudecode(instream, partstream TSRMLS_CC);
- php_stream_close(partstream);
- }
- } else {
- /* write to the output file */
- php_stream_write_string(outstream, buffer);
- }
- }
- php_stream_close(outstream);
- php_stream_rewind(instream);
- efree(buffer);
-
- if (nparts == 0) {
- /* delete temporary file */
- unlink(outpath);
- efree(outpath);
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto array mailparse_rfc822_parse_addresses(string addresses)
- Parse addresses and returns a hash containing that data */
-PHP_FUNCTION(mailparse_rfc822_parse_addresses)
-{
- char *addresses;
- int addresses_len;
- php_rfc822_tokenized_t *toks = NULL;
- php_rfc822_addresses_t *addrs = NULL;
- int i;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addresses, &addresses_len) == FAILURE) {
- RETURN_FALSE;
- }
- toks = php_mailparse_rfc822_tokenize((const char*)addresses, 1 TSRMLS_CC);
- addrs = php_rfc822_parse_address_tokens(toks);
-
- array_init(return_value);
-
- for (i = 0; i < addrs->naddrs; i++) {
- zval *item;
-
- MAKE_STD_ZVAL(item);
- array_init(item);
-
- if (addrs->addrs[i].name)
- add_assoc_string(item, "display", addrs->addrs[i].name, 1);
- if (addrs->addrs[i].address)
- add_assoc_string(item, "address", addrs->addrs[i].address, 1);
- add_assoc_bool(item, "is_group", addrs->addrs[i].is_group);
-
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &item, sizeof(item), NULL);
- }
-
- php_rfc822_free_addresses(addrs);
- php_rfc822_tokenize_free(toks);
-}
-/* }}} */
-
-/* {{{ proto string mailparse_determine_best_xfer_encoding(resource fp)
- Figures out the best way of encoding the content read from the file pointer fp, which must be seek-able */
-PHP_FUNCTION(mailparse_determine_best_xfer_encoding)
-{
- zval **file;
- int longline = 0;
- int linelen = 0;
- int c;
- enum mbfl_no_encoding bestenc = mbfl_no_encoding_7bit;
- php_stream *stream;
- char * name;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- php_stream_from_zval(stream, file);
-
- php_stream_rewind(stream);
- while(!php_stream_eof(stream)) {
- c = php_stream_getc(stream);
- if (c == EOF)
- break;
- if (c > 0x80)
- bestenc = mbfl_no_encoding_8bit;
- else if (c == 0) {
- bestenc = mbfl_no_encoding_base64;
- longline = 0;
- break;
- }
- if (c == '\n')
- linelen = 0;
- else if (++linelen > 200)
- longline = 1;
- }
- if (longline)
- bestenc = mbfl_no_encoding_qprint;
- php_stream_rewind(stream);
-
- name = (char *)mbfl_no2preferred_mime_name(bestenc);
- if (name)
- {
- RETVAL_STRING(name, 1);
- }
- else
- {
- RETVAL_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto boolean mailparse_stream_encode(resource sourcefp, resource destfp, string encoding)
- Streams data from source file pointer, apply encoding and write to destfp */
-
-static int mailparse_stream_output(int c, void *stream MAILPARSE_MBSTRING_TSRMLS_DC)
-{
- char buf = c;
- MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD();
-
- return php_stream_write((php_stream*)stream, &buf, 1);
-}
-static int mailparse_stream_flush(void *stream MAILPARSE_MBSTRING_TSRMLS_DC)
-{
- MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD();
- return php_stream_flush((php_stream*)stream);
-}
-
-PHP_FUNCTION(mailparse_stream_encode)
-{
- zval **srcfile, **destfile, **encod;
- php_stream *srcstream, *deststream;
- char *buf;
- size_t len;
- size_t bufsize = 2048;
- enum mbfl_no_encoding enc;
- mbfl_convert_filter *conv = NULL;
-
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &srcfile, &destfile, &encod) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(srcfile) == IS_RESOURCE && Z_LVAL_PP(srcfile) == 0) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(destfile) == IS_RESOURCE && Z_LVAL_PP(destfile) == 0) {
- RETURN_FALSE;
- }
-
- php_stream_from_zval(srcstream, srcfile);
- php_stream_from_zval(deststream, destfile);
-
- convert_to_string_ex(encod);
- enc = mbfl_name2no_encoding(Z_STRVAL_PP(encod));
- if (enc == mbfl_no_encoding_invalid) {
- zend_error(E_WARNING, "%s(): unknown encoding \"%s\"",
- get_active_function_name(TSRMLS_C),
- Z_STRVAL_PP(encod)
- );
- RETURN_FALSE;
- }
-
- buf = emalloc(bufsize);
- RETVAL_TRUE;
-
- conv = mbfl_convert_filter_new(mbfl_no_encoding_8bit,
- enc,
- mailparse_stream_output,
- mailparse_stream_flush,
- deststream
- MAILPARSE_MBSTRING_TSRMLS_CC
- );
-
- if (enc == mbfl_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
- * in front of it and invalidate the content/signature */
- while(!php_stream_eof(srcstream)) {
- if (NULL != php_stream_gets(srcstream, buf, bufsize)) {
- size_t i;
-
- len = strlen(buf);
-
- if (strncmp(buf, "From ", 5) == 0) {
- mbfl_convert_filter_flush(conv MAILPARSE_MBSTRING_TSRMLS_CC);
- php_stream_write(deststream, "=46rom ", 7);
- i = 5;
- } else {
- i = 0;
- }
-
- for (; i<len; i++)
- mbfl_convert_filter_feed(buf[i], conv MAILPARSE_MBSTRING_TSRMLS_CC);
- }
- }
-
- } else {
- while(!php_stream_eof(srcstream)) {
- len = php_stream_read(srcstream, buf, bufsize);
- if (len > 0)
- {
- size_t i;
- for (i=0; i<len; i++)
- mbfl_convert_filter_feed(buf[i], conv MAILPARSE_MBSTRING_TSRMLS_CC);
- }
- }
- }
-
- mbfl_convert_filter_flush(conv MAILPARSE_MBSTRING_TSRMLS_CC);
- mbfl_convert_filter_delete(conv MAILPARSE_MBSTRING_TSRMLS_CC);
- efree(buf);
-}
-/* }}} */
-
-/* {{{ proto void mailparse_msg_parse(resource mimepart, string data)
- Incrementally parse data into buffer */
-PHP_FUNCTION(mailparse_msg_parse)
-{
- char *data;
- int data_len;
- zval *arg;
- php_mimepart *part;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &arg, &data, &data_len) == FAILURE) {
- RETURN_FALSE;
- }
-
- mailparse_fetch_mimepart_resource(part, &arg);
-
- if (FAILURE == php_mimepart_parse(part, data, data_len TSRMLS_CC)) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto resource mailparse_msg_parse_file(string filename)
- Parse file and return a resource representing the structure */
-PHP_FUNCTION(mailparse_msg_parse_file)
-{
- char *filename;
- int filename_len;
- php_mimepart *part;
- char *filebuf;
- php_stream *stream;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
- RETURN_FALSE;
- }
-
- /* open file and read it in */
- stream = php_stream_open_wrapper(filename, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
- if (stream == NULL) {
- RETURN_FALSE;
- }
-
- filebuf = emalloc(MAILPARSE_BUFSIZ);
-
- part = php_mimepart_alloc();
- php_mimepart_to_zval(return_value, part);
-
- while(!php_stream_eof(stream)) {
- int got = php_stream_read(stream, filebuf, MAILPARSE_BUFSIZ);
- if (got > 0) {
- if (FAILURE == php_mimepart_parse(part, filebuf, got TSRMLS_CC)) {
- RETVAL_FALSE;
- break;
- }
- }
- }
- php_stream_close(stream);
- efree(filebuf);
-}
-/* }}} */
-
-/* {{{ proto void mailparse_msg_free(resource mimepart)
- Frees a handle allocated by mailparse_msg_create
-*/
-PHP_FUNCTION(mailparse_msg_free)
-{
- zval *arg;
- php_mimepart *part;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
- RETURN_FALSE;
- }
-
- mailparse_fetch_mimepart_resource(part, &arg);
- /* zend_list_delete(Z_LVAL_P(arg)); */
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int mailparse_msg_create(void)
- Returns a handle that can be used to parse a message */
-PHP_FUNCTION(mailparse_msg_create)
-{
- php_mimepart *part = php_mimepart_alloc();
-
- php_mimepart_to_zval(return_value, part);
-}
-/* }}} */
-
-static int get_structure_callback(php_mimepart *part, php_mimepart_enumerator *id, void *ptr TSRMLS_DC)
-{
- zval *return_value = (zval *)ptr;
- char intbuf[16];
- char buf[256];
- int len, i = 0;
-
- while(id && i < sizeof(buf)) {
- sprintf(intbuf, "%d", id->id);
- len = strlen(intbuf);
- if (len > (sizeof(buf)-i)) {
- /* too many sections: bail */
- zend_error(E_WARNING, "%s(): too many nested sections in message", get_active_function_name(TSRMLS_C));
- return FAILURE;
- }
- sprintf(&buf[i], "%s%c", intbuf, id->next ? '.' : '\0');
- i += len + (id->next ? 1 : 0);
- id = id->next;
- }
- add_next_index_string(return_value, buf,1);
- return SUCCESS;
-}
-
-/* {{{ proto array mailparse_msg_get_structure(resource mimepart)
- Returns an array of mime section names in the supplied message */
-PHP_FUNCTION(mailparse_msg_get_structure)
-{
- zval *arg;
- php_mimepart *part;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
- RETURN_FALSE;
- }
-
- mailparse_fetch_mimepart_resource(part, &arg);
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
- php_mimepart_enum_parts(part, &get_structure_callback, return_value TSRMLS_CC);
-}
-/* }}} */
-
-/* callback for decoding using a "userdefined" php function */
-static int extract_callback_user_func(php_mimepart *part, zval *userfunc, const char *p, size_t n TSRMLS_DC)
-{
- zval *retval;
- zval *arg;
-
- MAKE_STD_ZVAL(retval);
- Z_TYPE_P(retval) = IS_BOOL;
- Z_LVAL_P(retval) = 0;
-
- MAKE_STD_ZVAL(arg);
- ZVAL_STRINGL(arg, (char*)p, (int)n, 1);
-
- /* TODO: use zend_is_callable */
-
- if (call_user_function(EG(function_table), NULL, userfunc, retval, 1, &arg TSRMLS_CC) == FAILURE)
- zend_error(E_WARNING, "%s(): unable to call user function", get_active_function_name(TSRMLS_C));
-
- zval_dtor(retval);
- zval_dtor(arg);
- efree(retval);
- efree(arg);
-
- return 0;
-}
-
-/* callback for decoding to the current output buffer */
-static int extract_callback_stdout(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC)
-{
- ZEND_WRITE(p, n);
- return 0;
-}
-
-/* callback for decoding to a stream */
-static int extract_callback_stream(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC)
-{
- php_stream_write((php_stream*)ptr, p, n);
- return 0;
-}
-
-#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 */
-#define MAILPARSE_DECODE_NOBODY 4 /* don't include the body */
-
-static int extract_part(php_mimepart *part, int decode, php_stream *src, void *callbackdata,
- php_mimepart_extract_func_t callback TSRMLS_DC)
-{
- off_t end;
- off_t start_pos;
- char *filebuf = NULL;
- int ret = FAILURE;
-
- /* figure out where the message part starts/ends */
- start_pos = decode & MAILPARSE_DECODE_NOHEADERS ? part->bodystart : part->startpos;
-
- if (decode & MAILPARSE_DECODE_NOBODY)
- end = part->bodystart;
- else
- end = part->parent ? part->bodyend : part->endpos;
-
- php_mimepart_decoder_prepare(part, decode & MAILPARSE_DECODE_8BIT, callback, callbackdata TSRMLS_CC);
-
- if (php_stream_seek(src, start_pos, SEEK_SET) == -1) {
- zend_error(E_WARNING, "%s(): unable to seek to section start", get_active_function_name(TSRMLS_C));
- goto cleanup;
- }
-
- filebuf = emalloc(MAILPARSE_BUFSIZ);
-
- while (start_pos < end)
- {
- size_t n = MAILPARSE_BUFSIZ - 1;
-
- if ((off_t)n > end - start_pos)
- n = end - start_pos;
-
- n = php_stream_read(src, filebuf, n);
-
- if (n == 0)
- {
- zend_error(E_WARNING, "%s(): error reading from file at offset %d", get_active_function_name(TSRMLS_C), start_pos);
- goto cleanup;
- }
-
- filebuf[n] = '\0';
-
- php_mimepart_decoder_feed(part, filebuf, n TSRMLS_CC);
-
- start_pos += n;
- }
- ret = SUCCESS;
-
-cleanup:
- php_mimepart_decoder_finish(part TSRMLS_CC);
-
- if (filebuf)
- efree(filebuf);
-
- return ret;
-}
-
-static void mailparse_do_extract(INTERNAL_FUNCTION_PARAMETERS, int decode, int isfile)
-{
- zval *zpart, *filename, *callbackfunc = NULL;
- php_mimepart *part;
- php_stream *srcstream = NULL, *deststream = NULL;
- php_mimepart_extract_func_t cbfunc = NULL;
- void *cbdata = NULL;
- int close_src_stream = 0;
-
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &zpart, &filename, &callbackfunc)) {
- RETURN_FALSE;
- }
-
- mailparse_fetch_mimepart_resource(part, &zpart);
-
- /* filename can be a filename or a stream */
- if (Z_TYPE_P(filename) == IS_RESOURCE) {
- php_stream_from_zval(srcstream, &filename);
- } else if (isfile) {
- convert_to_string_ex(&filename);
- srcstream = php_stream_open_wrapper(Z_STRVAL_P(filename), "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
- close_src_stream = 1;
- } else {
- /* filename is the actual data */
- srcstream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(filename), Z_STRLEN_P(filename));
- close_src_stream = 1;
- }
-
- if (srcstream == NULL) {
- RETURN_FALSE;
- }
-
- if (callbackfunc != NULL) {
- if (Z_TYPE_P(callbackfunc) == IS_NULL) {
- cbfunc = extract_callback_stream;
- cbdata = deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
- } else if (Z_TYPE_P(callbackfunc) == IS_RESOURCE) {
- php_stream_from_zval(deststream, &callbackfunc);
- cbfunc = extract_callback_stream;
- cbdata = deststream;
- deststream = NULL; /* don't free this one */
- } else {
- if (Z_TYPE_P(callbackfunc) != IS_ARRAY)
- convert_to_string_ex(&callbackfunc);
- cbfunc = (php_mimepart_extract_func_t)&extract_callback_user_func;
- cbdata = callbackfunc;
- }
- } else {
- cbfunc = extract_callback_stdout;
- cbdata = NULL;
- }
-
- RETVAL_FALSE;
-
- if (SUCCESS == extract_part(part, decode, srcstream, cbdata, cbfunc TSRMLS_CC)) {
-
- if (deststream != NULL) {
- /* return it's contents as a string */
- char *membuf = NULL;
- size_t memlen = 0;
- membuf = php_stream_memory_get_buffer(deststream, &memlen);
- RETVAL_STRINGL(membuf, memlen, 1);
-
- } else {
- RETVAL_TRUE;
- }
- }
-
- if (deststream)
- php_stream_close(deststream);
- if (close_src_stream && srcstream)
- php_stream_close(srcstream);
-}
-
-/* {{{ proto void mailparse_msg_extract_part(resource mimepart, string msgbody[, string callbackfunc])
- Extracts/decodes a message section. If callbackfunc is not specified, the contents will be sent to "stdout" */
-PHP_FUNCTION(mailparse_msg_extract_part)
-{
- mailparse_do_extract(INTERNAL_FUNCTION_PARAM_PASSTHRU, MAILPARSE_DECODE_8BIT | MAILPARSE_DECODE_NOHEADERS, 0);
-}
-/* }}} */
-
-/* {{{ proto string mailparse_msg_extract_whole_part_file(resource mimepart, string filename [, string callbackfunc])
- Extracts a message section including headers without decoding the transfer encoding */
-PHP_FUNCTION(mailparse_msg_extract_whole_part_file)
-{
- mailparse_do_extract(INTERNAL_FUNCTION_PARAM_PASSTHRU, MAILPARSE_DECODE_NONE, 1);
-}
-/* }}} */
-
-/* {{{ proto string mailparse_msg_extract_part_file(resource mimepart, string filename [, string callbackfunc])
- Extracts/decodes a message section, decoding the transfer encoding */
-PHP_FUNCTION(mailparse_msg_extract_part_file)
-{
- mailparse_do_extract(INTERNAL_FUNCTION_PARAM_PASSTHRU, MAILPARSE_DECODE_8BIT | MAILPARSE_DECODE_NOHEADERS, 1);
-}
-/* }}} */
-
-static void add_attr_header_to_zval(char *valuelabel, char *attrprefix, zval *return_value,
- struct php_mimeheader_with_attributes *attr TSRMLS_DC)
-{
- HashPosition pos;
- zval **val;
- char *key, *newkey;
- uint key_len, pref_len;
-
- pref_len = strlen(attrprefix);
-
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attr->attributes), &pos);
- while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(attr->attributes), (void**)&val, &pos)) {
-
- zend_hash_get_current_key_ex(Z_ARRVAL_P(attr->attributes), &key, &key_len, NULL, 0, &pos);
-
- spprintf(&newkey, 0, "%s%s", attrprefix, key);
- add_assoc_string(return_value, newkey, Z_STRVAL_PP(val), 1);
- efree(newkey);
-
- zend_hash_move_forward_ex(Z_ARRVAL_P(attr->attributes), &pos);
- }
-
- /* do this last so that a bogus set of headers like this:
- * Content-Type: multipart/related;
- * boundary="----=_NextPart_00_0017_01C091F4.1B5EF6B0";
- * type="text/html"
- *
- * doesn't overwrite content-type with the type="text/html"
- * value.
- * */
- add_assoc_string(return_value, valuelabel, attr->value, 1);
-}
-
-static void add_header_reference_to_zval(char *headerkey, zval *return_value, zval *headers TSRMLS_DC)
-{
- zval **headerval;
- zval *newhdr;
-
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(headers), headerkey, strlen(headerkey)+1, (void**)&headerval)) {
- MAKE_STD_ZVAL(newhdr);
- *newhdr = **headerval;
- newhdr->refcount = 1;
- zval_copy_ctor(newhdr);
- add_assoc_zval(return_value, headerkey, newhdr);
- }
-}
-
-static int mailparse_get_part_data(php_mimepart *part, zval *return_value TSRMLS_DC)
-{
- zval *headers, **tmpval;
- off_t startpos, endpos, bodystart;
- int nlines, nbodylines;
-
- array_init(return_value);
-
- /* get headers for this section */
- MAKE_STD_ZVAL(headers);
- *headers = *part->headerhash;
- zval_copy_ctor(headers);
-
- add_assoc_zval(return_value, "headers", headers);
-
- php_mimepart_get_offsets(part, &startpos, &endpos, &bodystart, &nlines, &nbodylines);
-
- add_assoc_long(return_value, "starting-pos", startpos);
- add_assoc_long(return_value, "starting-pos-body", bodystart);
- add_assoc_long(return_value, "ending-pos", endpos);
- add_assoc_long(return_value, "ending-pos-body", part->bodyend);
- add_assoc_long(return_value, "line-count", nlines);
- add_assoc_long(return_value, "body-line-count", nbodylines);
-
- if (part->charset)
- add_assoc_string(return_value, "charset", part->charset, 1);
- else
- add_assoc_string(return_value, "charset", MAILPARSEG(def_charset), 1);
-
- if (part->content_transfer_encoding)
- add_assoc_string(return_value, "transfer-encoding", part->content_transfer_encoding, 1);
- else
- add_assoc_string(return_value, "transfer-encoding", "8bit", 1);
-
- if (part->content_type)
- add_attr_header_to_zval("content-type", "content-", return_value, part->content_type TSRMLS_CC);
- else
- add_assoc_string(return_value, "content-type", "text/plain; (error)", 1);
-
- if (part->content_disposition)
- add_attr_header_to_zval("content-disposition", "disposition-", return_value, part->content_disposition TSRMLS_CC);
-
- if (part->content_location)
- add_assoc_string(return_value, "content-location", part->content_location, 1);
-
- if (part->content_base)
- add_assoc_string(return_value, "content-base", part->content_base, 1);
- else
- add_assoc_string(return_value, "content-base", "/", 1);
-
- if (part->boundary)
- add_assoc_string(return_value, "content-boundary", part->boundary, 1);
-
- /* extract the address part of the content-id only */
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(headers), "content-id", sizeof("content-id"), (void**)&tmpval)) {
- php_rfc822_tokenized_t *toks;
- php_rfc822_addresses_t *addrs;
-
- toks = php_mailparse_rfc822_tokenize((const char*)Z_STRVAL_PP(tmpval), 1 TSRMLS_CC);
- addrs = php_rfc822_parse_address_tokens(toks);
- if (addrs->naddrs > 0)
- add_assoc_string(return_value, "content-id", addrs->addrs[0].address, 1);
- php_rfc822_free_addresses(addrs);
- php_rfc822_tokenize_free(toks);
- }
-
- add_header_reference_to_zval("content-description", return_value, headers TSRMLS_CC);
- add_header_reference_to_zval("content-language", return_value, headers TSRMLS_CC);
- add_header_reference_to_zval("content-md5", return_value, headers TSRMLS_CC);
-
- return SUCCESS;
-}
-
-/* {{{ proto array mailparse_msg_get_part_data(resource mimepart)
- Returns an associative array of info about the message */
-PHP_FUNCTION(mailparse_msg_get_part_data)
-{
- zval *arg;
- php_mimepart *part;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
- RETURN_FALSE;
- }
-
- mailparse_fetch_mimepart_resource(part, &arg);
-
- mailparse_get_part_data(part, return_value TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ proto int mailparse_msg_get_part(resource mimepart, string mimesection)
- Returns a handle on a given section in a mimemessage */
-PHP_FUNCTION(mailparse_msg_get_part)
-{
- zval *arg;
- php_mimepart *part, *foundpart;
- char *mimesection;
- int mimesection_len;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &arg, &mimesection, &mimesection_len) == FAILURE) {
- RETURN_FALSE;
- }
-
- mailparse_fetch_mimepart_resource(part, &arg);
-
- foundpart = php_mimepart_find_by_name(part, mimesection TSRMLS_CC);
-
- if (!foundpart) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot find section %s in message", mimesection);
- RETURN_FALSE;
- }
- zend_list_addref(foundpart->rsrc_id);
- php_mimepart_to_zval(return_value, foundpart);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/php_mailparse.h
^
|
@@ -1,120 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Wez Furlong <wez@thebrainroom.com> |
- | Credit also given to Double Precision Inc. who wrote the code that |
- | the support routines for this extension were based upon. |
- +----------------------------------------------------------------------+
- */
-/* $Id: php_mailparse.h,v 1.13 2004/03/07 14:28:37 wez Exp $ */
-
-#ifndef PHP_MAILPARSE_H
-#define PHP_MAILPARSE_H
-
-extern zend_module_entry mailparse_module_entry;
-#define phpext_mailparse_ptr &mailparse_module_entry
-
-#ifdef PHP_WIN32
-#define PHP_MAILPARSE_API __declspec(dllexport)
-#else
-#define PHP_MAILPARSE_API
-#endif
-
-PHP_MINIT_FUNCTION(mailparse);
-PHP_MSHUTDOWN_FUNCTION(mailparse);
-PHP_RINIT_FUNCTION(mailparse);
-PHP_RSHUTDOWN_FUNCTION(mailparse);
-PHP_MINFO_FUNCTION(mailparse);
-
-PHP_FUNCTION(mailparse_msg_parse_file);
-PHP_FUNCTION(mailparse_msg_get_part);
-PHP_FUNCTION(mailparse_msg_get_structure);
-PHP_FUNCTION(mailparse_msg_get_part_data);
-PHP_FUNCTION(mailparse_msg_extract_part);
-PHP_FUNCTION(mailparse_msg_extract_part_file);
-PHP_FUNCTION(mailparse_msg_extract_whole_part_file);
-
-PHP_FUNCTION(mailparse_msg_create);
-PHP_FUNCTION(mailparse_msg_free);
-PHP_FUNCTION(mailparse_msg_parse);
-PHP_FUNCTION(mailparse_msg_parse_file);
-
-PHP_FUNCTION(mailparse_msg_find);
-PHP_FUNCTION(mailparse_msg_getstructure);
-PHP_FUNCTION(mailparse_msg_getinfo);
-PHP_FUNCTION(mailparse_msg_extract);
-PHP_FUNCTION(mailparse_msg_extract_file);
-PHP_FUNCTION(mailparse_rfc822_parse_addresses);
-PHP_FUNCTION(mailparse_determine_best_xfer_encoding);
-PHP_FUNCTION(mailparse_stream_encode);
-PHP_FUNCTION(mailparse_uudecode_all);
-
-PHP_FUNCTION(mailparse_test);
-
-PHP_MAILPARSE_API int php_mailparse_le_mime_part(void);
-
-/* mimemessage object */
-PHP_FUNCTION(mailparse_mimemessage);
-PHP_FUNCTION(mailparse_mimemessage_get_parent);
-PHP_FUNCTION(mailparse_mimemessage_get_child);
-PHP_FUNCTION(mailparse_mimemessage_get_child_count);
-PHP_FUNCTION(mailparse_mimemessage_extract_headers);
-PHP_FUNCTION(mailparse_mimemessage_extract_body);
-PHP_FUNCTION(mailparse_mimemessage_enum_uue);
-PHP_FUNCTION(mailparse_mimemessage_extract_uue);
-PHP_FUNCTION(mailparse_mimemessage_remove);
-PHP_FUNCTION(mailparse_mimemessage_add_child);
-
-/* PHP 4.3.4 moved the mbfilter header around */
-#if PHP_MAJOR_VERSION == 4 && ((PHP_MINOR_VERSION < 3) || (PHP_MINOR_VERSION == 3 && PHP_RELEASE_VERSION < 4))
-# include "ext/mbstring/mbfilter.h"
-# define MAILPARSE_MBSTRING_TSRMLS_CC TSRMLS_CC
-# define MAILPARSE_MBSTRING_TSRMLS_DC TSRMLS_DC
-# define MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD() /* sanity */
-#else
-# include "ext/mbstring/libmbfl/mbfl/mbfilter.h"
-/* ugh, even worse, they changed the signature of the API and made it
- * really slow for threaded PHP builds */
-# define MAILPARSE_MBSTRING_TSRMLS_CC /* pain */
-# define MAILPARSE_MBSTRING_TSRMLS_DC /* pain */
-# define MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD() TSRMLS_FETCH()
-#endif
-
-#include "php_mailparse_rfc822.h"
-#include "php_mailparse_mime.h"
-
-#define MAILPARSE_BUFSIZ 4096
-ZEND_BEGIN_MODULE_GLOBALS(mailparse)
- char * def_charset; /* default charset for use in (re)writing mail */
-ZEND_END_MODULE_GLOBALS(mailparse);
-
-extern ZEND_DECLARE_MODULE_GLOBALS(mailparse);
-
-
-#ifdef ZTS
-#define MAILPARSEG(v) TSRMG(mailparse_globals_id, zend_mailparse_globals *, v)
-#else
-#define MAILPARSEG(v) (mailparse_globals.v)
-#endif
-
-#endif
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim: sw=4 ts=4
- */
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/php_mailparse_mime.c
^
|
@@ -1,967 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id: php_mailparse_mime.c,v 1.22 2008/01/08 20:07:09 shire Exp $ */
-
-#include "php.h"
-#include "php_mailparse.h"
-#include "php_mailparse_mime.h"
-#include "php_mailparse_rfc822.h"
-
-#define MAXLEVELS 20
-#define MAXPARTS 300
-#define IS_MIME_1(part) (((part)->mime_version && strcmp("1.0", (part)->mime_version) == 0) || ((part)->parent))
-#define CONTENT_TYPE_IS(part, contenttypevalue) ((part)->content_type && strcasecmp((part)->content_type->value, contenttypevalue) == 0)
-#define CONTENT_TYPE_ISL(part, contenttypevalue, len) ((part)->content_type && strncasecmp((part)->content_type->value, contenttypevalue, len) == 0)
-
-static void php_mimeheader_free(struct php_mimeheader_with_attributes *attr)
-{
- STR_FREE(attr->value);
- zval_dtor(attr->attributes);
- efree(attr->attributes);
- efree(attr);
-}
-
-static struct php_mimeheader_with_attributes * php_mimeheader_alloc(char *value)
-{
- struct php_mimeheader_with_attributes *attr;
-
- attr = ecalloc(1, sizeof(struct php_mimeheader_with_attributes));
-
- MAKE_STD_ZVAL(attr->attributes);
- array_init(attr->attributes);
-
- attr->value = estrdup(value);
-
- return attr;
-}
-
-void rfc2231_to_mime(smart_str* value_buf, char* value, int charset_p, int prevcharset_p)
-{
- char *strp, *startofvalue = NULL;
- int quotes=0;
- int valuepos;
- int i;
-
- /* Process string, get positions and replace */
- /* Set to start of buffer*/
- if (charset_p) {
-
- /* Previous charset already set so only convert %nn to =nn*/
- if (prevcharset_p) quotes=2;
-
- strp = value;
- while (*strp) {
-
- /* Quote handling*/
- if (*strp == '\'')
- {
- if (quotes <= 1) {
-
- /* End of charset*/
- if (quotes == 0) {
- *strp=0;
- } else {
- startofvalue = strp+1;
- valuepos = i;
- }
-
- quotes++;
- }
- } else {
- /* Replace % with = - quoted printable*/
- if (*strp == '%' && quotes==2)
- {
- *strp = '=';
- }
- }
- strp++;
- }
- }
-
- /* If first encoded token*/
- if (charset_p && !prevcharset_p && startofvalue) {
- smart_str_appends(value_buf, "=?");
- smart_str_appends(value_buf, value);
- smart_str_appends(value_buf, "?Q?");
- smart_str_appends(value_buf, startofvalue);
- }
-
- /* If last encoded token*/
- if (prevcharset_p && !charset_p)
- {
- smart_str_appends(value_buf, "?=");
- }
-
- /* Append value*/
- if ((!charset_p || (prevcharset_p && charset_p)) && value)
- {
- smart_str_appends(value_buf, value);
- }
-}
-
-static struct php_mimeheader_with_attributes *php_mimeheader_alloc_from_tok(php_rfc822_tokenized_t *toks)
-{
- struct php_mimeheader_with_attributes *attr;
- int i, first_semi, next_semi, comments_before_semi, netscape_bug = 0;
- char *name_buf = NULL;
- smart_str value_buf = {0};
- int is_rfc2231_name = 0;
- char *check_name, *check_end_name;
- int charset_p, prevcharset_p = 0;
- int namechanged, currentencoded = 0;
-
- attr = ecalloc(1, sizeof(struct php_mimeheader_with_attributes));
-
- MAKE_STD_ZVAL(attr->attributes);
- array_init(attr->attributes);
-
-/* php_rfc822_print_tokens(toks); */
-
- /* look for optional ; which separates optional attributes from the main value */
- for (first_semi = 2; first_semi < toks->ntokens; first_semi++)
- if (toks->tokens[first_semi].token == ';')
- break;
-
- attr->value = php_rfc822_recombine_tokens(toks, 2, first_semi - 2,
- PHP_RFC822_RECOMBINE_STRTOLOWER | PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
-
- if (first_semi < toks->ntokens)
- first_semi++;
-
- /* Netscape Bug: Messenger sometimes omits the semi when wrapping the
- * the header.
- * That means we have to be even more clever than the spec says that
- * we need to :-/
- * */
-
- while (first_semi < toks->ntokens) {
- /* find the next ; */
- comments_before_semi = 0;
- for (next_semi = first_semi; next_semi < toks->ntokens; next_semi++) {
- if (toks->tokens[next_semi].token == ';')
- break;
- if (toks->tokens[next_semi].token == '(')
- comments_before_semi++;
- }
-
-
- i = first_semi;
- if (i < next_semi) {
- i++;
-
- /* ignore comments */
- while (i < next_semi && toks->tokens[i].token == '(')
- i++;
-
- if (i < next_semi && toks->tokens[i].token == '=') {
- char *name, *value;
-
- /* Here, next_semi --> "name" and i --> "=", so skip "=" sign */
- i++;
-
- /* count those tokens; we expect "token = token" (3 tokens); if there are
- * more than that, then something is quite possibly wrong - Netscape Bug! */
- if (next_semi < toks->ntokens
- && toks->tokens[next_semi].token != ';'
- && next_semi - first_semi - comments_before_semi > 3) {
- next_semi = i + 1;
- netscape_bug = 1;
- }
-
- name = php_rfc822_recombine_tokens(toks, first_semi, 1,
- PHP_RFC822_RECOMBINE_STRTOLOWER|PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
- value = php_rfc822_recombine_tokens(toks, i, next_semi - i,
- PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
-
- /* support rfc2231 mime parameter value
- *
- * Parameter Value Continuations:
- *
- * Content-Type: message/external-body; access-type=URL;
- * URL*0="ftp://";
- * URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
- *
- * is semantically identical to
- *
- * Content-Type: message/external-body; access-type=URL;
- * URL="ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
- *
- * Original rfc2231 support by IceWarp Ltd. <info@icewarp.com>
- */
- check_name = strchr(name, '*');
- if (check_name) {
- currentencoded = 1;
-
- /* Is last char * - charset encoding */
- charset_p = *(name+strlen(name)-1) == '*';
-
- /* Leave only attribute name without * */
- *check_name = 0;
-
- /* New item or continuous */
- if (NULL == name_buf) {
- namechanged = 0;
- name_buf = name;
- } else {
- namechanged = (strcmp(name_buf, name) != 0);
- if (!namechanged) {
- efree(name);
- name = 0;
- }
- }
-
- /* Check if name changed*/
- if (!namechanged) {
-
- /* Append string to buffer - check if to be encoded... */
- rfc2231_to_mime(&value_buf, value, charset_p, prevcharset_p);
- efree(value);
-
- /* Mark previous */
- prevcharset_p = charset_p;
- }
-
- is_rfc2231_name = 1;
- }
-
- /* Last item was encoded */
- if (1 == is_rfc2231_name) {
- /* Name not null and name differs with new name*/
- if (name && strcmp(name_buf, name) != 0) {
- /* Finalize packet */
- rfc2231_to_mime(&value_buf, NULL, 0, prevcharset_p);
-
- add_assoc_string(attr->attributes, name_buf, estrndup(value_buf.c, value_buf.len), 0);
- efree(name_buf);
- smart_str_free(&value_buf);
-
- prevcharset_p = 0;
- is_rfc2231_name = 0;
- name_buf = NULL;
-
- /* New non encoded name*/
- if (!currentencoded) {
- /* Add string*/
- add_assoc_string(attr->attributes, name, value, 0);
- efree(name);
- } else { /* Encoded name changed*/
- if (namechanged) {
- /* Append string to buffer - check if to be encoded... */
- rfc2231_to_mime(&value_buf, value, charset_p, prevcharset_p);
- efree(value);
-
- /* Mark */
- is_rfc2231_name = 1;
- name_buf = name;
- prevcharset_p = charset_p;
- }
- }
-
- namechanged = 0;
- }
- } else {
- add_assoc_string(attr->attributes, name, value, 0);
- efree(name);
- }
- }
- }
-
- if (next_semi < toks->ntokens && !netscape_bug) {
- next_semi++;
- }
-
- first_semi = next_semi;
- netscape_bug = 0;
- }
-
- if (1 == is_rfc2231_name) {
- /* Finalize packet */
- rfc2231_to_mime(&value_buf, NULL, 0, prevcharset_p);
-
- add_assoc_string(attr->attributes, name_buf, estrndup(value_buf.c, value_buf.len), 0);
- efree(name_buf);
- smart_str_free(&value_buf);
- }
-
-
- return attr;
-}
-
-static void php_mimepart_free_child(php_mimepart **part)
-{
- TSRMLS_FETCH();
- php_mimepart_free(*part TSRMLS_CC);
-}
-
-PHP_MAILPARSE_API php_mimepart *php_mimepart_alloc(void)
-{
- php_mimepart *part = ecalloc(1, sizeof(php_mimepart));
-
- part->part_index = 1;
-
- zend_hash_init(&part->children, 0, NULL, (dtor_func_t)php_mimepart_free_child, 0);
-
- MAKE_STD_ZVAL(part->headerhash);
- array_init(part->headerhash);
-
- MAKE_STD_ZVAL(part->source.zval);
-
- /* begin in header parsing mode */
- part->parsedata.in_header = 1;
- part->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, part, php_mailparse_le_mime_part());
-
- return part;
-}
-
-
-PHP_MAILPARSE_API void php_mimepart_free(php_mimepart *part TSRMLS_DC)
-{
- if (part->rsrc_id) {
- long tmp = part->rsrc_id;
- part->rsrc_id = 0;
- zend_list_delete(tmp);
- if (part->parent != NULL && part->parent->rsrc_id > 0)
- return;
- }
-
- /* free contained parts */
-
- zend_hash_destroy(&part->children);
-
- STR_FREE(part->mime_version);
- STR_FREE(part->content_transfer_encoding);
- STR_FREE(part->charset);
- STR_FREE(part->boundary);
- STR_FREE(part->content_base);
- STR_FREE(part->content_location);
-
- if (part->content_type) {
- php_mimeheader_free(part->content_type);
- part->content_type = NULL;
- }
- if (part->content_disposition) {
- php_mimeheader_free(part->content_disposition);
- part->content_disposition = NULL;
- }
-
- smart_str_free(&part->parsedata.workbuf);
- smart_str_free(&part->parsedata.headerbuf);
-
- FREE_ZVAL(part->source.zval);
-
- zval_ptr_dtor(&part->headerhash);
-
- efree(part);
-}
-
-static void php_mimepart_update_positions(php_mimepart *part, size_t newendpos, size_t newbodyend, size_t deltanlines)
-{
- while(part) {
- part->endpos = newendpos;
- part->bodyend = newbodyend;
- part->nlines += deltanlines;
- if (!part->parsedata.in_header)
- part->nbodylines += deltanlines;
- part = part->parent;
- }
-}
-
-PHP_MAILPARSE_API char *php_mimepart_attribute_get(struct php_mimeheader_with_attributes *attr, char *attrname)
-{
- zval **attrval;
-
- if (SUCCESS == zend_hash_find(Z_ARRVAL_P(attr->attributes), attrname, strlen(attrname)+1, (void**)&attrval))
- return Z_STRVAL_PP(attrval);
- return NULL;
-}
-
-#define STR_SET_REPLACE(ptr, newval) do { STR_FREE(ptr); ptr = estrdup(newval); } while(0)
-
-static int php_mimepart_process_header(php_mimepart *part TSRMLS_DC)
-{
- php_rfc822_tokenized_t *toks;
- char *header_key, *header_val, *header_val_stripped;
- zval **zheaderval;
-
- if (part->parsedata.headerbuf.len == 0)
- return SUCCESS;
-
- smart_str_0(&part->parsedata.headerbuf);
-
- /* parse the header line */
- toks = php_mailparse_rfc822_tokenize((const char*)part->parsedata.headerbuf.c, 0 TSRMLS_CC);
-
- /* valid headers consist of at least three tokens, with the first being a string and the
- * second token being a ':' */
- if (toks->ntokens < 2 || toks->tokens[0].token != 0 || toks->tokens[1].token != ':') {
- part->parsedata.headerbuf.len = 0;
-
- php_rfc822_tokenize_free(toks);
- return FAILURE;
- }
-
- /* get a lower-case version of the first token */
- header_key = php_rfc822_recombine_tokens(toks, 0, 1, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|PHP_RFC822_RECOMBINE_STRTOLOWER);
-
- header_val = strchr(part->parsedata.headerbuf.c, ':');
- header_val_stripped = php_rfc822_recombine_tokens(toks, 2, toks->ntokens-2, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|PHP_RFC822_RECOMBINE_STRTOLOWER);
-
- if (header_val) {
- header_val++;
- while (isspace(*header_val))
- header_val++;
-
- /* add the header to the hash.
- * join multiple To: or Cc: lines together */
- if ((strcmp(header_key, "to") == 0 || strcmp(header_key, "cc") == 0) &&
- SUCCESS == zend_hash_find(Z_ARRVAL_P(part->headerhash), header_key, strlen(header_key)+1, (void**)&zheaderval)) {
- int newlen;
- char *newstr;
-
- newlen = strlen(header_val) + Z_STRLEN_PP(zheaderval) + 3;
- newstr = emalloc(newlen);
-
- strcpy(newstr, Z_STRVAL_PP(zheaderval));
- strcat(newstr, ", ");
- strcat(newstr, header_val);
- add_assoc_string(part->headerhash, header_key, newstr, 0);
- } else {
- if(zend_hash_find(Z_ARRVAL_P(part->headerhash), header_key, strlen(header_key)+1, (void**)&zheaderval) == SUCCESS) {
- if(Z_TYPE_PP(zheaderval) == IS_ARRAY) {
- add_next_index_string(*zheaderval, header_val, 1);
- } else {
- /* Create a nested array if there is more than one of the same header */
- zval *zarr;
- MAKE_STD_ZVAL(zarr);
- array_init(zarr);
- add_next_index_zval(zarr, *zheaderval);
- add_next_index_string(zarr, header_val, 1);
- ZVAL_ADDREF(*zheaderval); /* Don't destroy this just yet, we'll move it */
- add_assoc_zval(part->headerhash, header_key, zarr);
- ZVAL_DELREF(*zheaderval);
- }
- } else {
- add_assoc_string(part->headerhash, header_key, header_val, 1);
- }
- }
-
- /* if it is useful, keep a pointer to it in the mime part */
- if (strcmp(header_key, "mime-version") == 0)
- STR_SET_REPLACE(part->mime_version, header_val_stripped);
-
- if (strcmp(header_key, "content-location") == 0) {
- STR_FREE(part->content_location);
- part->content_location = php_rfc822_recombine_tokens(toks, 2, toks->ntokens-2, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
- }
- if (strcmp(header_key, "content-base") == 0) {
- STR_FREE(part->content_base);
- part->content_base = php_rfc822_recombine_tokens(toks, 2, toks->ntokens-2, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
- }
-
- if (strcmp(header_key, "content-transfer-encoding") == 0)
- STR_SET_REPLACE(part->content_transfer_encoding, header_val_stripped);
- if (strcmp(header_key, "content-type") == 0) {
- char *charset, *boundary;
-
- if (part->content_type) {
- php_mimeheader_free(part->content_type);
- part->content_type = NULL;
- }
-
- part->content_type = php_mimeheader_alloc_from_tok(toks);
-
- boundary = php_mimepart_attribute_get(part->content_type, "boundary");
- if (boundary) {
- part->boundary = estrdup(boundary);
- }
-
- charset = php_mimepart_attribute_get(part->content_type, "charset");
- if (charset) {
- STR_SET_REPLACE(part->charset, charset);
- }
- }
- if (strcmp(header_key, "content-disposition") == 0) {
- part->content_disposition = php_mimeheader_alloc_from_tok(toks);
- }
-
- }
- STR_FREE(header_key);
- STR_FREE(header_val_stripped);
-
- php_rfc822_tokenize_free(toks);
-
- /* zero the buffer size */
- part->parsedata.headerbuf.len = 0;
- return SUCCESS;
-}
-
-static php_mimepart *alloc_new_child_part(php_mimepart *parentpart, size_t startpos, int inherit)
-{
- php_mimepart *child = php_mimepart_alloc();
- int ret;
-
- parentpart->parsedata.lastpart = child;
- child->parent = parentpart;
-
- child->source.kind = parentpart->source.kind;
- if (parentpart->source.kind != mpNONE) {
- *child->source.zval = *parentpart->source.zval;
- zval_copy_ctor(child->source.zval);
- }
-
- ret = zend_hash_next_index_insert(&parentpart->children, (void*)&child, sizeof(php_mimepart *), NULL);
- child->startpos = child->endpos = child->bodystart = child->bodyend = startpos;
-
- if (inherit) {
- if (parentpart->content_transfer_encoding)
- child->content_transfer_encoding = estrdup(parentpart->content_transfer_encoding);
- if (parentpart->charset)
- child->charset = estrdup(parentpart->charset);
- }
-
- return child;
-}
-
-PHP_MAILPARSE_API void php_mimepart_get_offsets(php_mimepart *part, off_t *start, off_t *end, off_t *start_body, int *nlines, int *nbodylines)
-{
- *start = part->startpos;
- *end = part->endpos;
- *nlines = part->nlines;
- *nbodylines = part->nbodylines;
- *start_body = part->bodystart;
-
- /* Adjust for newlines in mime parts */
- if (part->parent) {
- *end = part->bodyend;
- if (*nlines)
- --*nlines;
- if (*nbodylines)
- --*nbodylines;
- }
-}
-
-static int php_mimepart_process_line(php_mimepart *workpart TSRMLS_DC)
-{
- size_t origcount, linelen;
- char *c;
-
- /* sanity check */
- if (zend_hash_num_elements(&workpart->children) > MAXPARTS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "MIME message too complex");
- return FAILURE;
- }
-
- c = workpart->parsedata.workbuf.c;
- smart_str_0(&workpart->parsedata.workbuf);
-
- /* strip trailing \r\n -- we always have a trailing \n */
- origcount = workpart->parsedata.workbuf.len;
- linelen = origcount - 1;
- if (linelen && c[linelen-1] == '\r')
- --linelen;
-
- /* Discover which part we were last working on */
- while (workpart->parsedata.lastpart) {
- int bound_len;
- php_mimepart *lastpart = workpart->parsedata.lastpart;
-
- if (lastpart->parsedata.completed) {
- php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1);
- return SUCCESS;
- }
- if (workpart->boundary == NULL || workpart->parsedata.in_header) {
- workpart = lastpart;
- continue;
- }
- bound_len = strlen(workpart->boundary);
-
- /* Look for a boundary */
- if (c[0] == '-' && c[1] == '-' && linelen >= 2+bound_len && strncasecmp(workpart->boundary, c+2, bound_len) == 0) {
- php_mimepart *newpart;
-
- /* is it the final boundary ? */
- if (linelen >= 4 + bound_len && strncmp(c+2+bound_len, "--", 2) == 0) {
- lastpart->parsedata.completed = 1;
- php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1);
- return SUCCESS;
- }
-
- newpart = alloc_new_child_part(workpart, workpart->endpos + origcount, 1);
- php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1);
- newpart->mime_version = estrdup(workpart->mime_version);
- newpart->parsedata.in_header = 1;
- return SUCCESS;
- }
- workpart = lastpart;
- }
-
- if (!workpart->parsedata.in_header) {
- if (!workpart->parsedata.completed && !workpart->parsedata.lastpart) {
- /* update the body/part end positions.
- * For multipart messages, the final newline belongs to the boundary.
- * Otherwise it belongs to the body
- * */
- if (workpart->parent && CONTENT_TYPE_ISL(workpart->parent, "multipart/", 10)) {
- php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1);
- } else {
- php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1);
- }
- }
- } else {
-
- if (linelen > 0) {
-
- php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1);
-
- if(*c == ' ' || *c == '\t') {
- /* This doesn't technically confirm to rfc2822, as we're replacing \t with \s, but this seems to fix
- * cases where clients incorrectly fold by inserting a \t character.
- */
- smart_str_appendl(&workpart->parsedata.headerbuf, " ", 1);
- c++; linelen--;
- } else {
- php_mimepart_process_header(workpart TSRMLS_CC);
- }
- /* save header for possible continuation */
- smart_str_appendl(&workpart->parsedata.headerbuf, c, linelen);
-
- } else {
- /* end of headers */
- php_mimepart_process_header(workpart TSRMLS_CC);
-
- /* start of body */
- workpart->parsedata.in_header = 0;
- workpart->bodystart = workpart->endpos + origcount;
- php_mimepart_update_positions(workpart, workpart->bodystart, workpart->bodystart, 1);
- --workpart->nbodylines;
-
- /* some broken mailers include the content-type header but not a mime-version header.
- * Let's relax and pretend they said they were mime 1.0 compatible */
- if (workpart->mime_version == NULL && workpart->content_type != NULL)
- workpart->mime_version = estrdup("1.0");
-
- if (!IS_MIME_1(workpart)) {
- /* if we don't understand the MIME version, discard the content-type and
- * boundary */
- if (workpart->content_disposition) {
- php_mimeheader_free(workpart->content_disposition);
- workpart->content_disposition = NULL;
- }
- if (workpart->boundary) {
- efree(workpart->boundary);
- workpart->boundary = NULL;
- }
- if (workpart->content_type) {
- php_mimeheader_free(workpart->content_type);
- workpart->content_type = NULL;
- }
- workpart->content_type = php_mimeheader_alloc("text/plain");
- }
- /* if there is no content type, default to text/plain, but use multipart/digest when in
- * a multipart/rfc822 message */
- if (IS_MIME_1(workpart) && workpart->content_type == NULL) {
- char *def_type = "text/plain";
-
- if (workpart->parent && CONTENT_TYPE_IS(workpart->parent, "multipart/digest"))
- def_type = "message/rfc822";
-
- workpart->content_type = php_mimeheader_alloc(def_type);
- }
-
- /* if no charset had previously been set, either through inheritance or by an
- * explicit content-type header, default to us-ascii */
- if (workpart->charset == NULL) {
- workpart->charset = estrdup(MAILPARSEG(def_charset));
- }
-
- if (CONTENT_TYPE_IS(workpart, "message/rfc822")) {
- workpart = alloc_new_child_part(workpart, workpart->bodystart, 0);
- workpart->parsedata.in_header = 1;
- return SUCCESS;
-
- }
-
- /* create a section for the preamble that precedes the first boundary */
- if (workpart->boundary) {
- workpart = alloc_new_child_part(workpart, workpart->bodystart, 1);
- workpart->parsedata.in_header = 0;
- workpart->parsedata.is_dummy = 1;
- return SUCCESS;
- }
-
- return SUCCESS;
- }
-
- }
-
- return SUCCESS;
-}
-
-PHP_MAILPARSE_API int php_mimepart_parse(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC)
-{
- size_t len;
-
- while(bufsize > 0) {
- /* look for EOL */
- for (len = 0; len < bufsize; len++)
- if (buf[len] == '\n')
- break;
- if (len < bufsize && buf[len] == '\n') {
- ++len;
- smart_str_appendl(&part->parsedata.workbuf, buf, len);
- php_mimepart_process_line(part TSRMLS_CC);
- part->parsedata.workbuf.len = 0;
- } else {
- smart_str_appendl(&part->parsedata.workbuf, buf, len);
- }
-
- buf += len;
- bufsize -= len;
- }
- return SUCCESS;
-}
-
-static int enum_parts_recurse(php_mimepart_enumerator *top, php_mimepart_enumerator **child,
- php_mimepart *part, mimepart_enumerator_func callback, void *ptr TSRMLS_DC)
-{
- php_mimepart_enumerator next;
- php_mimepart **childpart;
- HashPosition pos;
-
- *child = NULL;
- if (FAILURE == (*callback)(part, top, ptr TSRMLS_CC))
- return FAILURE;
-
- *child = &next;
- next.id = 1;
-
- if (CONTENT_TYPE_ISL(part, "multipart/", 10))
- next.id = 0;
-
- zend_hash_internal_pointer_reset_ex(&part->children, &pos);
- while (SUCCESS == zend_hash_get_current_data_ex(&part->children, (void**)&childpart, &pos)) {
- if (next.id)
- if (FAILURE == enum_parts_recurse(top, &next.next, *childpart, callback, ptr TSRMLS_CC))
- return FAILURE;
- next.id++;
- zend_hash_move_forward_ex(&part->children, &pos);
- }
- return SUCCESS;
-}
-
-PHP_MAILPARSE_API void php_mimepart_enum_parts(php_mimepart *part, mimepart_enumerator_func callback, void *ptr TSRMLS_DC)
-{
- php_mimepart_enumerator top;
- top.id = 1;
-
- enum_parts_recurse(&top, &top.next, part, callback, ptr TSRMLS_CC);
-}
-
-PHP_MAILPARSE_API void php_mimepart_enum_child_parts(php_mimepart *part, mimepart_child_enumerator_func callback, void *ptr TSRMLS_DC)
-{
- HashPosition pos;
- php_mimepart **childpart;
- int index = 0;
-
- zend_hash_internal_pointer_reset_ex(&part->children, &pos);
- while (SUCCESS == zend_hash_get_current_data_ex(&part->children, (void**)&childpart, &pos)) {
- if (FAILURE == (*callback)(part, *childpart, index, ptr TSRMLS_CC))
- return;
-
- zend_hash_move_forward_ex(&part->children, &pos);
- index++;
- }
-}
-
-struct find_part_struct {
- const char *searchfor;
- php_mimepart *foundpart;
-};
-
-static int find_part_callback(php_mimepart *part, php_mimepart_enumerator *id, void *ptr TSRMLS_DC)
-{
- struct find_part_struct *find = ptr;
- const unsigned char *num = (const unsigned char*)find->searchfor;
- unsigned int n;
-
- while (id) {
- if (!isdigit((int)*num))
- return SUCCESS;
- /* convert from decimal to int */
- n = 0;
- while (isdigit((int)*num))
- n = (n * 10) + (*num++ - '0');
- if (*num) {
- if (*num != '.')
- return SUCCESS;
- num++;
- }
- if (n != (unsigned int)id->id) {
- return SUCCESS;
- }
- id = id->next;
- }
- if (*num == 0)
- find->foundpart = part;
-
- return SUCCESS;
-}
-
-PHP_MAILPARSE_API php_mimepart *php_mimepart_find_by_name(php_mimepart *parent, const char *name TSRMLS_DC)
-{
- struct find_part_struct find = { name, NULL };
- php_mimepart_enum_parts(parent, find_part_callback, &find TSRMLS_CC);
- return find.foundpart;
-}
-
-PHP_MAILPARSE_API php_mimepart *php_mimepart_find_child_by_position(php_mimepart *parent, int position TSRMLS_DC)
-{
- HashPosition pos;
- php_mimepart **childpart = NULL;
-
- zend_hash_internal_pointer_reset_ex(&parent->children, &pos);
- while(position-- > 0)
- if (FAILURE == zend_hash_move_forward_ex(&parent->children, &pos))
- return NULL;
-
- if (FAILURE == zend_hash_get_current_data_ex(&parent->children, (void**)&childpart, &pos))
- return NULL;
-
- if(childpart) {
- return *childpart;
- } else {
- return NULL;
- }
-
-}
-
-static int filter_into_work_buffer(int c, void *dat MAILPARSE_MBSTRING_TSRMLS_DC)
-{
- php_mimepart *part = dat;
- MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD();
-
- smart_str_appendc(&part->parsedata.workbuf, c);
-
- if (part->parsedata.workbuf.len >= 4096) {
-
- part->extract_func(part, part->extract_context, part->parsedata.workbuf.c, part->parsedata.workbuf.len TSRMLS_CC);
- part->parsedata.workbuf.len = 0;
- }
-
- return c;
-}
-
-PHP_MAILPARSE_API void php_mimepart_decoder_prepare(php_mimepart *part, int do_decode, php_mimepart_extract_func_t decoder, void *ptr TSRMLS_DC)
-{
- enum mbfl_no_encoding from = mbfl_no_encoding_8bit;
-
- if (do_decode && part->content_transfer_encoding) {
- from = mbfl_name2no_encoding(part->content_transfer_encoding);
- if (from == mbfl_no_encoding_invalid) {
- if (strcasecmp("binary", part->content_transfer_encoding) != 0) {
- zend_error(E_WARNING, "%s(): mbstring doesn't know how to decode %s transfer encoding!",
- get_active_function_name(TSRMLS_C),
- part->content_transfer_encoding);
- }
- from = mbfl_no_encoding_8bit;
- }
- }
-
- part->extract_func = decoder;
- part->extract_context = ptr;
- part->parsedata.workbuf.len = 0;
-
- if (do_decode) {
- if (from == mbfl_no_encoding_8bit || from == mbfl_no_encoding_7bit) {
- part->extract_filter = NULL;
- } else {
- part->extract_filter = mbfl_convert_filter_new(
- from, mbfl_no_encoding_8bit,
- filter_into_work_buffer,
- NULL,
- part
- MAILPARSE_MBSTRING_TSRMLS_CC
- );
- }
- }
-
-}
-
-PHP_MAILPARSE_API void php_mimepart_decoder_finish(php_mimepart *part TSRMLS_DC)
-{
- if (part->extract_filter) {
- mbfl_convert_filter_flush(part->extract_filter MAILPARSE_MBSTRING_TSRMLS_CC);
- mbfl_convert_filter_delete(part->extract_filter MAILPARSE_MBSTRING_TSRMLS_CC);
- }
- if (part->extract_func && part->parsedata.workbuf.len > 0) {
- part->extract_func(part, part->extract_context, part->parsedata.workbuf.c, part->parsedata.workbuf.len TSRMLS_CC);
- part->parsedata.workbuf.len = 0;
- }
-}
-
-PHP_MAILPARSE_API int php_mimepart_decoder_feed(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC)
-{
- if (buf && bufsize) {
- int i;
-
- if (part->extract_filter) {
- for (i = 0; i < bufsize; i++) {
- if (mbfl_convert_filter_feed(buf[i], part->extract_filter MAILPARSE_MBSTRING_TSRMLS_CC) < 0) {
- zend_error(E_WARNING, "%s() - filter conversion failed. Input message is probably incorrectly encoded\n",
- get_active_function_name(TSRMLS_C));
- return -1;
- }
- }
- } else {
- return part->extract_func(part, part->extract_context, buf, bufsize TSRMLS_CC);
- }
- }
- return 0;
-}
-
-PHP_MAILPARSE_API void php_mimepart_remove_from_parent(php_mimepart *part TSRMLS_DC)
-{
- php_mimepart *parent = part->parent;
- HashPosition pos;
- php_mimepart **childpart;
-
- if (parent == NULL)
- return;
-
- part->parent = NULL;
-
- zend_hash_internal_pointer_reset_ex(&parent->children, &pos);
- while(SUCCESS == zend_hash_get_current_data_ex(&parent->children, (void**)&childpart, &pos)) {
-
- if (SUCCESS == zend_hash_get_current_data_ex(&parent->children, (void**)&childpart, &pos)) {
- if (*childpart == part) {
- ulong h;
- zend_hash_get_current_key_ex(&parent->children, NULL, NULL, &h, 0, &pos);
- zend_hash_index_del(&parent->children, h);
- break;
- }
- }
- zend_hash_move_forward_ex(&parent->children, &pos);
- }
-}
-
-PHP_MAILPARSE_API void php_mimepart_add_child(php_mimepart *part, php_mimepart *child TSRMLS_DC)
-{
-
-}
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/php_mailparse_mime.h
^
|
@@ -1,112 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id: php_mailparse_mime.h,v 1.7 2004/03/07 14:28:37 wez Exp $ */
-
-#ifndef php_mailparse_mime_h
-#define php_mailparse_mime_h
-
-#include "ext/standard/php_smart_str.h"
-
-typedef struct _php_mimepart php_mimepart;
-
-struct php_mimeheader_with_attributes {
- char *value;
- zval *attributes;
-};
-
-PHP_MAILPARSE_API char *php_mimepart_attribute_get(struct php_mimeheader_with_attributes *attr, char *attrname);
-
-typedef int (*php_mimepart_extract_func_t)(php_mimepart *part, void *context, const char *buf, size_t n TSRMLS_DC);
-
-/* this is used to remember the source of a mime part.
- * It is used mainly for writeable mime parts. */
-struct php_mimepart_source {
- enum { mpNONE, mpSTRING, mpSTREAM } kind;
- zval *zval;
-};
-
-struct _php_mimepart {
- php_mimepart *parent;
- long rsrc_id; /* for auto-cleanup */
- int part_index; /* sequence number of this part */
- HashTable children; /* child parts */
-
- struct php_mimepart_source source;
-
- off_t startpos, endpos; /* offsets of this part in the message */
- off_t bodystart, bodyend; /* offsets of the body content of this part */
- size_t nlines, nbodylines; /* number of lines in section/body */
-
- char *mime_version;
- char *content_transfer_encoding;
- char *content_location;
- char *content_base;
- char *boundary;
- char *charset;
-
- struct php_mimeheader_with_attributes *content_type, *content_disposition;
-
- zval *headerhash; /* a record of all the headers */
-
- /* these are used during part extraction */
- php_mimepart_extract_func_t extract_func;
- mbfl_convert_filter *extract_filter;
- void *extract_context;
-
- /* these are used during parsing */
- struct {
- int in_header:1;
- int is_dummy:1;
- int completed:1;
-
- smart_str workbuf;
- smart_str headerbuf;
- php_mimepart *lastpart;
- } parsedata;
-
-};
-
-PHP_MAILPARSE_API php_mimepart *php_mimepart_alloc(void);
-PHP_MAILPARSE_API void php_mimepart_free(php_mimepart *part TSRMLS_DC);
-PHP_MAILPARSE_API int php_mimepart_parse(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC);
-PHP_MAILPARSE_API void php_mimepart_get_offsets(php_mimepart *part, off_t *start, off_t *end, off_t *start_body, int *nlines, int *nbodylines);
-
-PHP_MAILPARSE_API void php_mimepart_decoder_prepare(php_mimepart *part, int do_decode, php_mimepart_extract_func_t decoder, void *ptr TSRMLS_DC);
-PHP_MAILPARSE_API void php_mimepart_decoder_finish(php_mimepart *part TSRMLS_DC);
-PHP_MAILPARSE_API int php_mimepart_decoder_feed(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC);
-
-#define php_mimepart_to_zval(zval, part) ZVAL_RESOURCE(zval, part->rsrc_id)
-
-typedef struct _php_mimepart_enumerator php_mimepart_enumerator;
-struct _php_mimepart_enumerator {
- php_mimepart_enumerator *next;
- int id;
-};
-typedef int (*mimepart_enumerator_func)(php_mimepart *part, php_mimepart_enumerator *enumerator, void *ptr TSRMLS_DC);
-typedef int (*mimepart_child_enumerator_func)(php_mimepart *parentpart, php_mimepart *child, int childindex, void *ptr TSRMLS_DC);
-
-PHP_MAILPARSE_API void php_mimepart_enum_parts(php_mimepart *part, mimepart_enumerator_func callback, void *ptr TSRMLS_DC);
-PHP_MAILPARSE_API void php_mimepart_enum_child_parts(php_mimepart *part, mimepart_child_enumerator_func callback, void *ptr TSRMLS_DC);
-PHP_MAILPARSE_API php_mimepart *php_mimepart_find_by_name(php_mimepart *parent, const char *name TSRMLS_DC);
-PHP_MAILPARSE_API php_mimepart *php_mimepart_find_child_by_position(php_mimepart *parent, int position TSRMLS_DC);
-
-PHP_MAILPARSE_API void php_mimepart_remove_from_parent(php_mimepart *part TSRMLS_DC);
-PHP_MAILPARSE_API void php_mimepart_add_child(php_mimepart *part, php_mimepart *child TSRMLS_DC);
-
-#endif
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/php_mailparse_rfc822.c
^
|
@@ -1,678 +0,0 @@
-/* Generated by re2c 0.5 on Sun Mar 7 13:35:34 2004 */
-#line 1 "/home/wez/src/php/pecl/mailparse/php_mailparse_rfc822.re"
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id: php_mailparse_rfc822.c,v 1.14 2004/12/28 18:55:20 wez Exp $ */
-
-#include "php.h"
-#include "php_mailparse.h"
-#include "php_mailparse_rfc822.h"
-#include "ext/standard/php_string.h"
-#include "ext/standard/php_smart_str.h"
-#line 39
-
-
-#line 48
-
-
-#define YYFILL(n) if (YYCURSOR == YYLIMIT) goto stop
-#define YYCTYPE unsigned char
-#define YYCURSOR p
-#define YYLIMIT q
-#define YYMARKER r
-
-#define DEBUG_RFC822_SCANNER 0
-
-#if DEBUG_RFC822_SCANNER
-# define DBG_STATE(lbl) printf(lbl " %d:%c %d:%c\n", *YYCURSOR, *YYCURSOR, *start, *start)
-#else
-# define DBG_STATE(lbl)
-#endif
-
-#define ADD_ATOM_TOKEN() do { if (tokens) { tokens->token = *start; tokens->value = start; tokens->valuelen = 1; tokens++; } ++*ntokens; } while (0)
-#define REPORT_ERR(msg) do { if (report_errors) zend_error(E_WARNING, "input is not rfc822 compliant: %s", msg); } while(0)
-/* Tokenize a header. tokens may be NULL, in which case the number of tokens are
- counted, allowing the caller to allocate enough room */
-static void tokenize(const char *header, php_rfc822_token_t *tokens, int *ntokens, int report_errors TSRMLS_DC)
-{
- register const char *p, *q, *start;
- int in_bracket = 0;
-
-/* NB: parser assumes that the header has two bytes of NUL terminator */
-
- YYCURSOR = header;
- YYLIMIT = YYCURSOR + strlen(YYCURSOR) + 1;
-
- *ntokens = 0;
-
-state_ground:
- start = YYCURSOR;
-
-#if DEBUG_RFC822_SCANNER
-printf("ground: start=%p limit=%p cursor=%p: [%d] %s\n", start, YYLIMIT, YYCURSOR, *YYCURSOR, YYCURSOR);
-#endif
-
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 0, 192, 192, 192, 192, 192, 192, 192,
- 192, 96, 96, 192, 192, 96, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 96, 64, 0, 192, 192, 64, 192, 192,
- 64, 64, 192, 192, 64, 192, 64, 64,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 64, 64, 64, 64, 64, 64,
- 64, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 64, 192, 64, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- 192, 192, 192, 192, 192, 192, 192, 192,
- };
- goto yy0;
-yy1: ++YYCURSOR;
-yy0:
- if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
- yych = *YYCURSOR;
- if(yybm[0+yych] & 32) goto yy4;
- if(yych <= '-'){
- if(yych <= '%'){
- if(yych <= '!'){
- if(yych <= '\000') goto yy2;
- if(yych <= ' ') goto yy21;
- goto yy19;
- } else {
- if(yych <= '"') goto yy12;
- if(yych <= '$') goto yy21;
- goto yy19;
- }
- } else {
- if(yych <= ')'){
- if(yych <= '\'') goto yy21;
- if(yych <= '(') goto yy10;
- goto yy7;
- } else {
- if(yych == ',') goto yy19;
- goto yy21;
- }
- }
- } else {
- if(yych <= '>'){
- if(yych <= ';'){
- if(yych <= '/') goto yy19;
- if(yych <= '9') goto yy21;
- goto yy19;
- } else {
- if(yych <= '<') goto yy15;
- if(yych <= '=') goto yy19;
- goto yy17;
- }
- } else {
- if(yych <= '['){
- if(yych <= '@') goto yy19;
- if(yych <= 'Z') goto yy21;
- goto yy19;
- } else {
- if(yych <= '\\') goto yy9;
- if(yych <= ']') goto yy19;
- goto yy21;
- }
- }
- }
-yy2: yych = *++YYCURSOR;
-yy3:
-#line 88
- { goto stop; }
-yy4: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy5: if(yybm[0+yych] & 32) goto yy4;
-yy6:
-#line 89
- { DBG_STATE("SPACE"); goto state_ground; }
-yy7: yych = *++YYCURSOR;
-yy8:
-#line 90
- { REPORT_ERR("token not valid in ground state"); goto state_ground; }
-yy9: yych = *++YYCURSOR;
- if(yybm[0+yych] & 128) goto yy21;
- goto yy8;
-yy10: yych = *++YYCURSOR;
-yy11:
-#line 91
- { DBG_STATE("START COMMENT");
- if (tokens) {
- tokens->token = '(';
- tokens->value = start;
- tokens->valuelen = 0;
- }
- goto state_comment;
- }
-yy12: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy13: if(yybm[0+yych] & 64) goto yy12;
- if(yych >= '\001') goto yy26;
-yy14:yy15: yych = *++YYCURSOR;
- if(yych == '>') goto yy24;
-yy16:
-#line 123
- { DBG_STATE("LANGLE");
- if (in_bracket) {
- REPORT_ERR("already in < bracket");
- goto state_ground;
- }
- in_bracket = 1;
- ADD_ATOM_TOKEN();
- goto state_ground;
- }
-yy17: yych = *++YYCURSOR;
-yy18:
-#line 132
- { DBG_STATE("RANGLE");
- if (!in_bracket) {
- REPORT_ERR("not in < bracket");
- goto state_ground;
- }
- in_bracket = 0;
- ADD_ATOM_TOKEN();
- goto state_ground;
- }
-yy19: yych = *++YYCURSOR;
-yy20:
-#line 141
- { DBG_STATE("ATOM"); ADD_ATOM_TOKEN(); goto state_ground; }
-yy21: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy22: if(yybm[0+yych] & 128) goto yy21;
-yy23:
-#line 142
- { DBG_STATE("ANY");
- if (tokens) {
- tokens->token = 0;
- tokens->valuelen = YYCURSOR - start;
- tokens->value = start;
- tokens++;
- }
- ++*ntokens;
- goto state_ground;
- }
-yy24: yych = *++YYCURSOR;
-yy25:
-#line 110
- { DBG_STATE("NULL <>");
- ADD_ATOM_TOKEN();
- if (tokens) {
- tokens->token = 0;
- tokens->value = "";
- tokens->valuelen = 0;
- tokens++;
- }
- ++*ntokens;
- start++;
- ADD_ATOM_TOKEN();
- goto state_ground;
- }
-yy26: yych = *++YYCURSOR;
-yy27:
-#line 99
- { DBG_STATE("QUOTE STRING");
- if (tokens) {
- tokens->token = '"';
- tokens->value = start + 1;
- tokens->valuelen = YYCURSOR - start - 2;
- tokens++;
- }
- ++*ntokens;
-
- goto state_ground;
- }
-}
-#line 152
-
-
-state_comment:
- {
- int comment_depth = 1;
- while (1) {
- if (*YYCURSOR == 0) {
- /* unexpected end of header */
- REPORT_ERR("unexpected end of header");
- /* fake a quoted string for this last token */
- if (tokens)
- tokens->token = '"';
- ++*ntokens;
- return;
- } else if (*YYCURSOR == '(') {
- comment_depth++;
- } else if (*YYCURSOR == ')' && --comment_depth == 0) {
- /* end of nested comment sequence */
- YYCURSOR++;
- if (tokens)
- tokens->valuelen++;
- break;
- } else if (*YYCURSOR == '\\' && YYCURSOR[1]) {
- YYCURSOR++;
- if (tokens)
- tokens->valuelen++;
- }
- YYCURSOR++;
- }
- if (tokens) {
- tokens->valuelen = YYCURSOR - tokens->value;
- tokens++;
- }
- ++*ntokens;
- goto state_ground;
- }
-stop:
-#if DEBUG_RFC822_SCANNER
- printf("STOPing parser ntokens=%d YYCURSOR=%p YYLIMIT=%p start=%p cursor=[%d] %s start=%s\n", *ntokens,
- YYCURSOR, YYLIMIT, start, *YYCURSOR, YYCURSOR, start);
-#else
- ;
-#endif
-}
-
-PHP_MAILPARSE_API php_rfc822_tokenized_t *php_mailparse_rfc822_tokenize(const char *header, int report_errors TSRMLS_DC)
-{
- php_rfc822_tokenized_t *toks = ecalloc(1, sizeof(php_rfc822_tokenized_t));
- int len = strlen(header);
-
- toks->buffer = emalloc(len + 2);
- strcpy(toks->buffer, header);
- toks->buffer[len] = 0;
- toks->buffer[len+1] = 0; /* mini hack: the parser sometimes relies in this */
-
- tokenize(toks->buffer, NULL, &toks->ntokens, report_errors TSRMLS_CC);
- toks->tokens = toks->ntokens ? ecalloc(toks->ntokens, sizeof(php_rfc822_token_t)) : NULL;
- tokenize(toks->buffer, toks->tokens, &toks->ntokens, report_errors TSRMLS_CC);
- return toks;
-}
-
-PHP_MAILPARSE_API void php_rfc822_tokenize_free(php_rfc822_tokenized_t *toks)
-{
- if (toks->tokens)
- efree(toks->tokens);
- efree(toks->buffer);
- efree(toks);
-}
-
-PHP_MAILPARSE_API char *php_rfc822_recombine_tokens(php_rfc822_tokenized_t *toks, int first_token, int n_tokens, int flags)
-{
- char *ret = NULL;
- int i, upper, last_was_atom = 0, this_is_atom = 0, tok_equiv;
- size_t len = 1; /* for the NUL terminator */
-
- upper = first_token + n_tokens;
- if (upper > toks->ntokens)
- upper = toks->ntokens;
-
- for (i = first_token; i < upper; i++, last_was_atom = this_is_atom) {
-
- tok_equiv = toks->tokens[i].token;
- if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
- tok_equiv = '"';
-
- if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
- continue;
- if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
- continue;
-
- this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
- if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS)
- len++; /* allow room for a space */
-
- if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
- len += 2;
-
- len += toks->tokens[i].valuelen;
- }
-
- last_was_atom = this_is_atom = 0;
-
- ret = emalloc(len);
-
- for (i = first_token, len = 0; i < upper; i++, last_was_atom = this_is_atom) {
- const char *tokvalue;
- int toklen;
-
- tok_equiv = toks->tokens[i].token;
- if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
- tok_equiv = '"';
-
- if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
- continue;
- if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
- continue;
-
- tokvalue = toks->tokens[i].value;
- toklen = toks->tokens[i].valuelen;
-
- this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
- if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS) {
- ret[len] = ' ';
- len++;
- }
- if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
- ret[len++] = '"';
-
- if (toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES) {
- /* don't include ( and ) in the output string */
- tokvalue++;
- toklen -= 2;
- }
-
- memcpy(ret + len, tokvalue, toklen);
- len += toklen;
-
- if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
- ret[len++] = '"';
-
- }
- ret[len] = 0;
-
- if (flags & PHP_RFC822_RECOMBINE_STRTOLOWER)
- php_strtolower(ret, len);
-
- return ret;
-}
-
-static void parse_address_tokens(php_rfc822_tokenized_t *toks,
- php_rfc822_addresses_t *addrs, int *naddrs)
-{
- int start_tok = 0, iaddr = 0, i, in_group = 0, group_lbl_start, group_lbl_end;
- int a_start, a_count; /* position and count for address part of a name */
- smart_str group_addrs = { 0, };
- char *address_value = NULL;
-
-address: /* mailbox / group */
-
- if (start_tok >= toks->ntokens) {
- /* the end */
- *naddrs = iaddr;
- smart_str_free(&group_addrs);
- return;
- }
-
- /* look ahead to determine if we are dealing with a group */
- for (i = start_tok; i < toks->ntokens; i++)
- if (toks->tokens[i].token != 0 && toks->tokens[i].token != '"')
- break;
-
- if (i < toks->ntokens && toks->tokens[i].token == ':') {
- /* it's a group */
- in_group = 1;
- group_lbl_start = start_tok;
- group_lbl_end = i;
-
- /* we want the address for the group to include the leading ":" and the trailing ";" */
- start_tok = i;
- }
-
-mailbox: /* addr-spec / phrase route-addr */
- if (start_tok >= toks->ntokens) {
- /* the end */
- *naddrs = iaddr;
- smart_str_free(&group_addrs);
- return;
- }
-
- /* skip spurious commas */
- while (start_tok < toks->ntokens && (toks->tokens[start_tok].token == ','
- || toks->tokens[start_tok].token == ';'))
- start_tok++;
-
- /* look ahead: if we find a '<' before we find an '@', we are dealing with
- a route-addr, otherwise we have an addr-spec */
- for (i = start_tok; i < toks->ntokens && toks->tokens[i].token != ';'
- && toks->tokens[i].token != ',' && toks->tokens[i].token != '<'; i++)
- ;
-
- /* the stuff from start_tok to i - 1 is the display name part */
- if (addrs && !in_group && i - start_tok > 0) {
- int j, has_comments = 0, has_strings = 0;
- switch(toks->tokens[i].token) {
- case ';': case ',': case '<':
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS);
- break;
- default:
- /* it's only the display name if there are quoted strings or comments in there */
- for (j = start_tok; j < i; j++) {
- if (toks->tokens[j].token == '(')
- has_comments = 1;
- if (toks->tokens[j].token == '"')
- has_strings = 1;
- }
- if (has_comments && !has_strings) {
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok,
- i - start_tok,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS | PHP_RFC822_RECOMBINE_COMMENTS_ONLY
- | PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES
- );
- } else if (has_strings) {
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS);
-
- }
-
- }
-
- }
-
- if (i < toks->ntokens && toks->tokens[i].token == '<') {
- int j;
- /* RFC822: route-addr = "<" [route] addr-spec ">" */
- /* look for the closing '>' and recombine as the address part */
-
- for (j = i; j < toks->ntokens && toks->tokens[j].token != '>'; j++)
- ;
-
- if (addrs) {
- a_start = i;
- a_count = j-i;
- /* if an address is enclosed in <>, leave them out of the the
- * address value that we return */
- if (toks->tokens[a_start].token == '<') {
- a_start++;
- a_count--;
- }
- address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS|
- PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
- PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
- }
-
- start_tok = ++j;
- } else {
- /* RFC822: addr-spec = local-part "@" domain */
- if (addrs) {
- a_start = start_tok;
- a_count = i - start_tok;
- /* if an address is enclosed in <>, leave them out of the the
- * address value that we return */
- if (toks->tokens[a_start].token == '<') {
- a_start++;
- a_count--;
- }
-
- address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS|
- PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
- PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
- }
- start_tok = i;
- }
-
- if (addrs && address_value) {
-
- /* if no display name has been given, use the address */
- if (addrs->addrs[iaddr].name == NULL) {
- addrs->addrs[iaddr].name = estrdup(address_value);
- }
-
- if (in_group) {
- if (group_addrs.len)
- smart_str_appendl(&group_addrs, ",", 1);
- smart_str_appends(&group_addrs, address_value);
- efree(address_value);
- } else {
- addrs->addrs[iaddr].address = address_value;
- }
- address_value = NULL;
- }
-
- if (!in_group) {
- iaddr++;
- goto address;
- }
- /* still dealing with a group. If we find a ";", that's the end of the group */
- if ((start_tok < toks->ntokens && toks->tokens[start_tok].token == ';') || start_tok == toks->ntokens) {
- /* end of group */
-
- if (addrs) {
- smart_str_appendl(&group_addrs, ";", 1);
- smart_str_0(&group_addrs);
- addrs->addrs[iaddr].address = estrdup(group_addrs.c);
- group_addrs.len = 0;
-
- STR_FREE(addrs->addrs[iaddr].name);
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, group_lbl_start,
- group_lbl_end - group_lbl_start,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS);
-
- addrs->addrs[iaddr].is_group = 1;
- }
-
- iaddr++;
- in_group = 0;
- start_tok++;
- goto address;
- }
- /* look for more mailboxes in this group */
- goto mailbox;
-}
-
-PHP_MAILPARSE_API php_rfc822_addresses_t *php_rfc822_parse_address_tokens(php_rfc822_tokenized_t *toks)
-{
- php_rfc822_addresses_t *addrs = ecalloc(1, sizeof(php_rfc822_addresses_t));
-
- parse_address_tokens(toks, NULL, &addrs->naddrs);
- addrs->addrs = addrs->naddrs ? ecalloc(addrs->naddrs, sizeof(php_rfc822_address_t)) : NULL;
- parse_address_tokens(toks, addrs, &addrs->naddrs);
-
- return addrs;
-}
-
-PHP_MAILPARSE_API void php_rfc822_free_addresses(php_rfc822_addresses_t *addrs)
-{
- int i;
- for (i = 0; i < addrs->naddrs; i++) {
- if (addrs->addrs[i].name)
- STR_FREE(addrs->addrs[i].name);
- STR_FREE(addrs->addrs[i].address);
- }
- if (addrs->addrs)
- efree(addrs->addrs);
- efree(addrs);
-}
-void php_rfc822_print_addresses(php_rfc822_addresses_t *addrs)
-{
- int i;
- printf("printing addresses %p\n", addrs); fflush(stdout);
- for (i = 0; i < addrs->naddrs; i++) {
- printf("addr %d: name=%s address=%s\n", i, addrs->addrs[i].name, addrs->addrs[i].address);
- }
-}
-
-
-void php_rfc822_print_tokens(php_rfc822_tokenized_t *toks)
-{
- int i;
- for (i = 0; i < toks->ntokens; i++) {
- printf("token %d: token=%d/%c len=%d value=%s\n", i, toks->tokens[i].token, toks->tokens[i].token,
- toks->tokens[i].valuelen, toks->tokens[i].value);
- }
-}
-
-PHP_FUNCTION(mailparse_test)
-{
- char *header;
- long header_len;
- php_rfc822_tokenized_t *toks;
- php_rfc822_addresses_t *addrs;
- struct rfc822t *t;
- int i;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len) == FAILURE) {
- RETURN_FALSE;
- }
-
-
-#if 0
- t = mailparse_rfc822t_alloc(header, NULL);
- for (i = 0; i < t->ntokens; i++) {
- printf("token %d: token=%d/%c len=%d value=%s\n", i, t->tokens[i].token, t->tokens[i].token,
- t->tokens[i].len, t->tokens[i].ptr);
-
- }
- mailparse_rfc822t_free(t);
-
- printf("--- and now:\n");
-#endif
-
- toks = php_mailparse_rfc822_tokenize((const char*)header, 1 TSRMLS_CC);
- php_rfc822_print_tokens(toks);
-
- addrs = php_rfc822_parse_address_tokens(toks);
- php_rfc822_print_addresses(addrs);
- php_rfc822_free_addresses(addrs);
-
- php_rfc822_tokenize_free(toks);
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker syn=c
- * vim<600: sw=4 ts=4
- */
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/php_mailparse_rfc822.re
^
|
@@ -1,563 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP Version 4 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
- */
-/* $Id: php_mailparse_rfc822.re,v 1.12 2004/12/28 18:55:05 wez Exp $ */
-
-#include "php.h"
-#include "php_mailparse.h"
-#include "php_mailparse_rfc822.h"
-#include "ext/standard/php_string.h"
-#include "ext/standard/php_smart_str.h"
-/*!re2c
-CHAR = [\000-\177];
-ALPHA = [\101-\132]|[\141-\172];
-DIGIT = [\060-\071];
-CTL = [\000-\037]|[\177];
-CR = [\015];
-LF = [\012];
-SPACE = [\040];
-HTAB = [\011];
-CRLF = CR LF;
-LWSPCHAR = SPACE|HTAB;
-LWSP = ( CRLF? LWSPCHAR)+;
-specials = [()<>@,;:\\".\[\]];
-delimiters = (specials|LWSP);
-*/
-
-/*!re2c
-NUL = [\000];
-any = [\001-\377];
-space = (HTAB|SPACE|CR|LF);
-atom = [@,;:.%!?=/\[\]];
-allspecials = (atom|[()<>"]|space);
-other = any\allspecials;
-*/
-
-#define YYFILL(n) if (YYCURSOR == YYLIMIT) goto stop
-#define YYCTYPE unsigned char
-#define YYCURSOR p
-#define YYLIMIT q
-#define YYMARKER r
-
-#define DEBUG_RFC822_SCANNER 0
-
-#if DEBUG_RFC822_SCANNER
-# define DBG_STATE(lbl) printf(lbl " %d:%c %d:%c\n", *YYCURSOR, *YYCURSOR, *start, *start)
-#else
-# define DBG_STATE(lbl)
-#endif
-
-#define ADD_ATOM_TOKEN() do { if (tokens) { tokens->token = *start; tokens->value = start; tokens->valuelen = 1; tokens++; } ++*ntokens; } while (0)
-#define REPORT_ERR(msg) do { if (report_errors) zend_error(E_WARNING, "input is not rfc822 compliant: %s", msg); } while(0)
-/* Tokenize a header. tokens may be NULL, in which case the number of tokens are
- counted, allowing the caller to allocate enough room */
-static void tokenize(const char *header, php_rfc822_token_t *tokens, int *ntokens, int report_errors TSRMLS_DC)
-{
- register const char *p, *q, *start;
- int in_bracket = 0;
-
-/* NB: parser assumes that the header has two bytes of NUL terminator */
-
- YYCURSOR = header;
- YYLIMIT = YYCURSOR + strlen(YYCURSOR) + 1;
-
- *ntokens = 0;
-
-state_ground:
- start = YYCURSOR;
-
-#if DEBUG_RFC822_SCANNER
-printf("ground: start=%p limit=%p cursor=%p: [%d] %s\n", start, YYLIMIT, YYCURSOR, *YYCURSOR, YYCURSOR);
-#endif
-
-/*!re2c
- NUL { goto stop; }
- space+ { DBG_STATE("SPACE"); goto state_ground; }
- (")"|"\\") { REPORT_ERR("token not valid in ground state"); goto state_ground; }
- "(" { DBG_STATE("START COMMENT");
- if (tokens) {
- tokens->token = '(';
- tokens->value = start;
- tokens->valuelen = 0;
- }
- goto state_comment;
- }
- ["] (any\["])* ["] { DBG_STATE("QUOTE STRING");
- if (tokens) {
- tokens->token = '"';
- tokens->value = start + 1;
- tokens->valuelen = YYCURSOR - start - 2;
- tokens++;
- }
- ++*ntokens;
-
- goto state_ground;
- }
- "<" ">" { DBG_STATE("NULL <>");
- ADD_ATOM_TOKEN();
- if (tokens) {
- tokens->token = 0;
- tokens->value = "";
- tokens->valuelen = 0;
- tokens++;
- }
- ++*ntokens;
- start++;
- ADD_ATOM_TOKEN();
- goto state_ground;
- }
- "<" { DBG_STATE("LANGLE");
- if (in_bracket) {
- REPORT_ERR("already in < bracket");
- goto state_ground;
- }
- in_bracket = 1;
- ADD_ATOM_TOKEN();
- goto state_ground;
- }
- ">" { DBG_STATE("RANGLE");
- if (!in_bracket) {
- REPORT_ERR("not in < bracket");
- goto state_ground;
- }
- in_bracket = 0;
- ADD_ATOM_TOKEN();
- goto state_ground;
- }
- atom { DBG_STATE("ATOM"); ADD_ATOM_TOKEN(); goto state_ground; }
- other+ { DBG_STATE("ANY");
- if (tokens) {
- tokens->token = 0;
- tokens->valuelen = YYCURSOR - start;
- tokens->value = start;
- tokens++;
- }
- ++*ntokens;
- goto state_ground;
- }
-*/
-
-state_comment:
- {
- int comment_depth = 1;
- while (1) {
- if (*YYCURSOR == 0) {
- /* unexpected end of header */
- REPORT_ERR("unexpected end of header");
- /* fake a quoted string for this last token */
- if (tokens)
- tokens->token = '"';
- ++*ntokens;
- return;
- } else if (*YYCURSOR == '(') {
- comment_depth++;
- } else if (*YYCURSOR == ')' && --comment_depth == 0) {
- /* end of nested comment sequence */
- YYCURSOR++;
- if (tokens)
- tokens->valuelen++;
- break;
- } else if (*YYCURSOR == '\\' && YYCURSOR[1]) {
- YYCURSOR++;
- if (tokens)
- tokens->valuelen++;
- }
- YYCURSOR++;
- }
- if (tokens) {
- tokens->valuelen = YYCURSOR - tokens->value;
- tokens++;
- }
- ++*ntokens;
- goto state_ground;
- }
-stop:
-#if DEBUG_RFC822_SCANNER
- printf("STOPing parser ntokens=%d YYCURSOR=%p YYLIMIT=%p start=%p cursor=[%d] %s start=%s\n", *ntokens,
- YYCURSOR, YYLIMIT, start, *YYCURSOR, YYCURSOR, start);
-#else
- ;
-#endif
-}
-
-PHP_MAILPARSE_API php_rfc822_tokenized_t *php_mailparse_rfc822_tokenize(const char *header, int report_errors TSRMLS_DC)
-{
- php_rfc822_tokenized_t *toks = ecalloc(1, sizeof(php_rfc822_tokenized_t));
- int len = strlen(header);
-
- toks->buffer = emalloc(len + 2);
- strcpy(toks->buffer, header);
- toks->buffer[len] = 0;
- toks->buffer[len+1] = 0; /* mini hack: the parser sometimes relies in this */
-
- tokenize(toks->buffer, NULL, &toks->ntokens, report_errors TSRMLS_CC);
- toks->tokens = toks->ntokens ? ecalloc(toks->ntokens, sizeof(php_rfc822_token_t)) : NULL;
- tokenize(toks->buffer, toks->tokens, &toks->ntokens, report_errors TSRMLS_CC);
- return toks;
-}
-
-PHP_MAILPARSE_API void php_rfc822_tokenize_free(php_rfc822_tokenized_t *toks)
-{
- if (toks->tokens)
- efree(toks->tokens);
- efree(toks->buffer);
- efree(toks);
-}
-
-PHP_MAILPARSE_API char *php_rfc822_recombine_tokens(php_rfc822_tokenized_t *toks, int first_token, int n_tokens, int flags)
-{
- char *ret = NULL;
- int i, upper, last_was_atom = 0, this_is_atom = 0, tok_equiv;
- size_t len = 1; /* for the NUL terminator */
-
- upper = first_token + n_tokens;
- if (upper > toks->ntokens)
- upper = toks->ntokens;
-
- for (i = first_token; i < upper; i++, last_was_atom = this_is_atom) {
-
- tok_equiv = toks->tokens[i].token;
- if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
- tok_equiv = '"';
-
- if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
- continue;
- if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
- continue;
-
- this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
- if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS)
- len++; /* allow room for a space */
-
- if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
- len += 2;
-
- len += toks->tokens[i].valuelen;
- }
-
- last_was_atom = this_is_atom = 0;
-
- ret = emalloc(len);
-
- for (i = first_token, len = 0; i < upper; i++, last_was_atom = this_is_atom) {
- const char *tokvalue;
- int toklen;
-
- tok_equiv = toks->tokens[i].token;
- if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
- tok_equiv = '"';
-
- if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
- continue;
- if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
- continue;
-
- tokvalue = toks->tokens[i].value;
- toklen = toks->tokens[i].valuelen;
-
- this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
- if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS) {
- ret[len] = ' ';
- len++;
- }
- if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
- ret[len++] = '"';
-
- if (toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES) {
- /* don't include ( and ) in the output string */
- tokvalue++;
- toklen -= 2;
- }
-
- memcpy(ret + len, tokvalue, toklen);
- len += toklen;
-
- if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
- ret[len++] = '"';
-
- }
- ret[len] = 0;
-
- if (flags & PHP_RFC822_RECOMBINE_STRTOLOWER)
- php_strtolower(ret, len);
-
- return ret;
-}
-
-static void parse_address_tokens(php_rfc822_tokenized_t *toks,
- php_rfc822_addresses_t *addrs, int *naddrs)
-{
- int start_tok = 0, iaddr = 0, i, in_group = 0, group_lbl_start, group_lbl_end;
- int a_start, a_count; /* position and count for address part of a name */
- smart_str group_addrs = { 0, };
- char *address_value = NULL;
-
-address: /* mailbox / group */
-
- if (start_tok >= toks->ntokens) {
- /* the end */
- *naddrs = iaddr;
- smart_str_free(&group_addrs);
- return;
- }
-
- /* look ahead to determine if we are dealing with a group */
- for (i = start_tok; i < toks->ntokens; i++)
- if (toks->tokens[i].token != 0 && toks->tokens[i].token != '"')
- break;
-
- if (i < toks->ntokens && toks->tokens[i].token == ':') {
- /* it's a group */
- in_group = 1;
- group_lbl_start = start_tok;
- group_lbl_end = i;
-
- /* we want the address for the group to include the leading ":" and the trailing ";" */
- start_tok = i;
- }
-
-mailbox: /* addr-spec / phrase route-addr */
- if (start_tok >= toks->ntokens) {
- /* the end */
- *naddrs = iaddr;
- smart_str_free(&group_addrs);
- return;
- }
-
- /* skip spurious commas */
- while (start_tok < toks->ntokens && (toks->tokens[start_tok].token == ','
- || toks->tokens[start_tok].token == ';'))
- start_tok++;
-
- /* look ahead: if we find a '<' before we find an '@', we are dealing with
- a route-addr, otherwise we have an addr-spec */
- for (i = start_tok; i < toks->ntokens && toks->tokens[i].token != ';'
- && toks->tokens[i].token != ',' && toks->tokens[i].token != '<'; i++)
- ;
-
- /* the stuff from start_tok to i - 1 is the display name part */
- if (addrs && !in_group && i - start_tok > 0) {
- int j, has_comments = 0, has_strings = 0;
- switch(toks->tokens[i].token) {
- case ';': case ',': case '<':
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS);
- break;
- default:
- /* it's only the display name if there are quoted strings or comments in there */
- for (j = start_tok; j < i; j++) {
- if (toks->tokens[j].token == '(')
- has_comments = 1;
- if (toks->tokens[j].token == '"')
- has_strings = 1;
- }
- if (has_comments && !has_strings) {
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok,
- i - start_tok,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS | PHP_RFC822_RECOMBINE_COMMENTS_ONLY
- | PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES
- );
-B
- } else if (has_strings) {
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS);
-
- }
-
- }
-
- }
-
- if (i < toks->ntokens && toks->tokens[i].token == '<') {
- int j;
- /* RFC822: route-addr = "<" [route] addr-spec ">" */
- /* look for the closing '>' and recombine as the address part */
-
- for (j = i; j < toks->ntokens && toks->tokens[j].token != '>'; j++)
- ;
-
- if (addrs) {
- a_start = i;
- a_count = j-i;
- /* if an address is enclosed in <>, leave them out of the the
- * address value that we return */
- if (toks->tokens[a_start].token == '<') {
- a_start++;
- a_count--;
- }
- address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS|
- PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
- PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
- }
-
- start_tok = ++j;
- } else {
- /* RFC822: addr-spec = local-part "@" domain */
- if (addrs) {
- a_start = start_tok;
- a_count = i - start_tok;
- /* if an address is enclosed in <>, leave them out of the the
- * address value that we return */
- if (toks->tokens[a_start].token == '<') {
- a_start++;
- a_count--;
- }
-
- address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS|
- PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
- PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
- }
- start_tok = i;
- }
-
- if (addrs && address_value) {
-
- /* if no display name has been given, use the address */
- if (addrs->addrs[iaddr].name == NULL) {
- addrs->addrs[iaddr].name = estrdup(address_value);
- }
-
- if (in_group) {
- if (group_addrs.len)
- smart_str_appendl(&group_addrs, ",", 1);
- smart_str_appends(&group_addrs, address_value);
- efree(address_value);
- } else {
- addrs->addrs[iaddr].address = address_value;
- }
- address_value = NULL;
- }
-
- if (!in_group) {
- iaddr++;
- goto address;
- }
- /* still dealing with a group. If we find a ";", that's the end of the group */
- if ((start_tok < toks->ntokens && toks->tokens[start_tok].token == ';') || start_tok == toks->ntokens) {
- /* end of group */
-
- if (addrs) {
- smart_str_appendl(&group_addrs, ";", 1);
- smart_str_0(&group_addrs);
- addrs->addrs[iaddr].address = estrdup(group_addrs.c);
- group_addrs.len = 0;
-
- STR_FREE(addrs->addrs[iaddr].name);
- addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, group_lbl_start,
- group_lbl_end - group_lbl_start,
- PHP_RFC822_RECOMBINE_SPACE_ATOMS);
-
- addrs->addrs[iaddr].is_group = 1;
- }
-
- iaddr++;
- in_group = 0;
- start_tok++;
- goto address;
- }
- /* look for more mailboxes in this group */
- goto mailbox;
-}
-
-PHP_MAILPARSE_API php_rfc822_addresses_t *php_rfc822_parse_address_tokens(php_rfc822_tokenized_t *toks)
-{
- php_rfc822_addresses_t *addrs = ecalloc(1, sizeof(php_rfc822_addresses_t));
-
- parse_address_tokens(toks, NULL, &addrs->naddrs);
- addrs->addrs = addrs->naddrs ? ecalloc(addrs->naddrs, sizeof(php_rfc822_address_t)) : NULL;
- parse_address_tokens(toks, addrs, &addrs->naddrs);
-
- return addrs;
-}
-
-PHP_MAILPARSE_API void php_rfc822_free_addresses(php_rfc822_addresses_t *addrs)
-{
- int i;
- for (i = 0; i < addrs->naddrs; i++) {
- if (addrs->addrs[i].name)
- STR_FREE(addrs->addrs[i].name);
- STR_FREE(addrs->addrs[i].address);
- }
- if (addrs->addrs)
- efree(addrs->addrs);
- efree(addrs);
-}
-void php_rfc822_print_addresses(php_rfc822_addresses_t *addrs)
-{
- int i;
- printf("printing addresses %p\n", addrs); fflush(stdout);
- for (i = 0; i < addrs->naddrs; i++) {
- printf("addr %d: name=%s address=%s\n", i, addrs->addrs[i].name, addrs->addrs[i].address);
- }
-}
-
-
-void php_rfc822_print_tokens(php_rfc822_tokenized_t *toks)
-{
- int i;
- for (i = 0; i < toks->ntokens; i++) {
- printf("token %d: token=%d/%c len=%d value=%s\n", i, toks->tokens[i].token, toks->tokens[i].token,
- toks->tokens[i].valuelen, toks->tokens[i].value);
- }
-}
-
-PHP_FUNCTION(mailparse_test)
-{
- char *header;
- long header_len;
- php_rfc822_tokenized_t *toks;
- php_rfc822_addresses_t *addrs;
- struct rfc822t *t;
- int i;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len) == FAILURE) {
- RETURN_FALSE;
- }
-
-
-#if 0
- t = mailparse_rfc822t_alloc(header, NULL);
- for (i = 0; i < t->ntokens; i++) {
- printf("token %d: token=%d/%c len=%d value=%s\n", i, t->tokens[i].token, t->tokens[i].token,
- t->tokens[i].len, t->tokens[i].ptr);
-
- }
- mailparse_rfc822t_free(t);
-
- printf("--- and now:\n");
-#endif
-
- toks = php_mailparse_rfc822_tokenize((const char*)header, 1 TSRMLS_CC);
- php_rfc822_print_tokens(toks);
-
- addrs = php_rfc822_parse_address_tokens(toks);
- php_rfc822_print_addresses(addrs);
- php_rfc822_free_addresses(addrs);
-
- php_rfc822_tokenize_free(toks);
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker syn=c
- * vim<600: sw=4 ts=4
- */
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/tests/testdata/mime.txt
^
|
@@ -1,47 +0,0 @@
-Return-Path: <wez@thebrainroom.com>
-Received: from TITAN (titan.brainnet.i [192.168.2.7])
- by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g87BfJ721279
- for <wez@thebrainroom.com>; Sat, 7 Sep 2002 12:41:19 +0100
-X-Authentication-Warning: zaneeb.brainnet.i: Host titan.brainnet.i [192.168.2.7] claimed to be TITAN
-From: "Wez Furlong" <wez@thebrainroom.com>
-To: <wez@thebrainroom.com>
-Subject: mime attach
-Date: Sat, 7 Sep 2002 12:41:14 +0100
-Message-ID: <000601c25663$78b7fcf0$0702a8c0@TITAN>
-MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="----=_NextPart_000_0007_01C2566B.DA7C64F0"
-X-Priority: 3 (Normal)
-X-MSMail-Priority: Normal
-X-Mailer: Microsoft Outlook, Build 10.0.2627
-Importance: Normal
-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
-X-TBR-DestBox: user.wez (auth as wez) (wez:)
-
-This is a multi-part message in MIME format.
-
-------=_NextPart_000_0007_01C2566B.DA7C64F0
-Content-Type: text/plain;
- charset="us-ascii"
-Content-Transfer-Encoding: 7bit
-
-this is a message with regular mime attachment.
-
-------=_NextPart_000_0007_01C2566B.DA7C64F0
-Content-Type: application/octet-stream;
- name="README"
-Content-Transfer-Encoding: quoted-printable
-Content-Disposition: attachment;
- filename="README"
-
-FooBar - blah blah blah foo bar bar baaaa=0A=
-=0A=
-Requirements: =0A=
- o php with mailparse=0A=
- o virus scanner (optional)=0A=
- =0A=
-=0A=
-
-------=_NextPart_000_0007_01C2566B.DA7C64F0--
-
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/tests/testdata/phpcvs1.txt
^
|
@@ -1,141 +0,0 @@
-Return-Path: <php-cvs-return-15542-wez.php.cvs=thebrainroom.com@lists.php.net>
-Received: from secure.thebrainroom.com (raq338.uk2net.com [213.239.42.171])
- by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g9SLLB208234
- for <wez.php.cvs@thebrainroom.com>; Mon, 28 Oct 2002 21:21:11 GMT
-X-Authentication-Warning: zaneeb.brainnet.i: Host raq338.uk2net.com [213.239.42.171] claimed to be secure.thebrainroom.com
-Received: from pb1.pair.com (pb1.pair.com [216.92.131.4])
- by secure.thebrainroom.com (8.9.3/8.9.3) with SMTP id SAA02428
- for <wez.php.cvs@thebrainroom.com>; Mon, 28 Oct 2002 18:50:26 GMT
-Received: (qmail 63230 invoked by uid 1010); 28 Oct 2002 18:36:34 -0000
-Mailing-List: contact php-cvs-help@lists.php.net; run by ezmlm
-Precedence: bulk
-list-help: <mailto:php-cvs-help@lists.php.net>
-list-unsubscribe: <mailto:php-cvs-unsubscribe@lists.php.net>
-list-post: <mailto:php-cvs@lists.php.net>
-Delivered-To: mailing list php-cvs@lists.php.net
-Received: (qmail 63215 invoked from network); 28 Oct 2002 18:36:33 -0000
-Reply-to: marcus.boerger@post.rwth-aachen.de
-Message-Id: <5.1.0.14.2.20021028193555.01d47c20@mailbox.rwth-aachen.de>
-X-Mailer: QUALCOMM Windows Eudora Version 5.1
-Date: Mon, 28 Oct 2002 19:36:10 +0100
-To: Melvyn Sopacua <msopacua@idg.nl>
-From: marcus.boerger@t-online.de (Marcus =?iso-8859-1?Q?B=F6rger?=)
-Cc: php-cvs@lists.php.net
-In-Reply-To: <5.1.0.14.2.20021028192151.039729e0@yoshimo.webtechs.idg.nl
- >
-References: <5.1.0.14.2.20021028190015.01d4d650@mailbox.rwth-aachen.de>
- <5.1.0.14.2.20021028183051.03c18958@yoshimo.webtechs.idg.nl>
- <cvshelly1035825322@cvsserver>
-Mime-Version: 1.0
-Content-Type: multipart/alternative;
- boundary="=====================_71195359==_.ALT"
-X-Sender: 520072483730-0001@t-dialin.net
-X-Spam-Status: No, tests=bogofilter, spamicity=0.0% likelihood
-Subject: Re: [PHP-CVS] cvs: php4 /ext/iconv/tests
-X-TBR-DestBox: user.wez.php.cvs (auth as wez) (wez.php.cvs:)
-
---=====================_71195359==_.ALT
-Content-Type: text/plain; charset="iso-8859-1"; format=flowed
-Content-Transfer-Encoding: quoted-printable
-
-Then what about:
-
-cvs -z3 -q diff skipif.inc test.inc (in directory=20
-S:\php4-HEAD\ext\iconv\tests\)
-Index: skipif.inc
-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
-RCS file: /repository/php4/ext/iconv/tests/skipif.inc,v
-retrieving revision 1.2
-diff -u -r1.2 skipif.inc
---- skipif.inc 28 Oct 2002 17:15:21 -0000 1.2
-+++ skipif.inc 28 Oct 2002 18:35:25 -0000
-@@ -1,10 +1,11 @@
- <?php
- // This script prints "skip" if condition does not meet.
-
--if (!extension_loaded("iconv") && ini_get("enable_dl")) {
-- $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
-- @dl("iconv$dlext");
--}
-+// Do not dl load extension
-+//if (!extension_loaded("iconv") && ini_get("enable_dl")) {
-+// $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
-+// @dl("iconv$dlext");
-+//}
- if (!extension_loaded("iconv")) {
- die("skip iconv extension not available\n");
- }
-Index: test.inc
-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
-RCS file: /repository/php4/ext/iconv/tests/test.inc,v
-retrieving revision 1.1
-diff -u -r1.1 test.inc
---- test.inc 28 Oct 2002 17:15:21 -0000 1.1
-+++ test.inc 28 Oct 2002 18:35:25 -0000
-@@ -1,8 +1,7 @@
- <?php
--// This script prints "skip" if condition does not meet.
--
--if (!extension_loaded("iconv") && ini_get("enable_dl")) {
-- $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
-- @dl("iconv$dlext");
--}
-+// Do not dl load extension
-+//if (!extension_loaded("iconv") && ini_get("enable_dl")) {
-+// $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
-+// @dl("iconv$dlext");
-+//}
- ?>
-
-At 19:30 28.10.2002, Melvyn Sopacua wrote:
->At 19:01 28-10-2002, Marcus B=F6rger wrote:
->
->>At 18:33 28.10.2002, Melvyn Sopacua wrote:
->>>At 18:15 28-10-2002, Marcus B=F6rger wrote:
->>>
->>>> Log:
->>>> fix this tests
->>>> -they did not dl load module in test....
->>>
->>>Yes, exactly as they shouldn't.
->>>
->>>It's been discussed. Why did you revert that?
->>>
->>>The main reason - to repeat it:
->>>./configure --prefix=3D/previous/install
->>>
->>>dl('foo.so') =3D> foo.so version is previous install, not current!
->>
->>I did so because skipif.inc did so. Maybe we remove that code
->>from both skipif.inc and test.inc now. Feel free to do that.
->
->Ok, then that was a left over.
->
->IMHO we should do a complete overhaul of */tests/* and remove any dl()
->code, or come up with something, that will force the modules/ directory
->on the testkit.
->
->This is again a good reason to setup php.ini-test.
->Windows will then be a problem, which kinda makes the dl() thingy=
- troublesome
->as well.
->
->The only thing I can think of to work around it, is to use a configure
->option, that writes --with-test-modules-dir=3D into php.ini-test. But=
- that's
->prolly overkill.
->
->
->
->Met vriendelijke groeten / With kind regards,
->
->Webmaster IDG.nl
->Melvyn Sopacua
->
-
---=====================_71195359==_.ALT--
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/tests/testdata/qp.txt
^
|
@@ -1,47 +0,0 @@
-Return-Path: <wez@thebrainroom.com>
-Received: from TITAN (titan.brainnet.i [192.168.2.7])
- by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g87Bel721254
- for <wez@thebrainroom.com>; Sat, 7 Sep 2002 12:40:47 +0100
-X-Authentication-Warning: zaneeb.brainnet.i: Host titan.brainnet.i [192.168.2.7] claimed to be TITAN
-From: "Wez Furlong" <wez@thebrainroom.com>
-To: <wez@thebrainroom.com>
-Subject: qp attachments
-Date: Sat, 7 Sep 2002 12:40:37 +0100
-Message-ID: <000201c25663$65e80250$0702a8c0@TITAN>
-MIME-Version: 1.0
-Content-Type: multipart/mixed;
- boundary="----=_NextPart_000_0003_01C2566B.C7AC6A50"
-X-Priority: 3 (Normal)
-X-MSMail-Priority: Normal
-X-Mailer: Microsoft Outlook, Build 10.0.2627
-Importance: Normal
-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
-X-TBR-DestBox: user.wez (auth as wez) (wez:)
-
-This is a multi-part message in MIME format.
-
-------=_NextPart_000_0003_01C2566B.C7AC6A50
-Content-Type: text/plain;
- charset="us-ascii"
-Content-Transfer-Encoding: 7bit
-
-this is a message with a qp attachment.
-
-------=_NextPart_000_0003_01C2566B.C7AC6A50
-Content-Type: application/octet-stream;
- name="README"
-Content-Transfer-Encoding: quoted-printable
-Content-Disposition: attachment;
- filename="README"
-
-Xnti rpam and gnti yirusjkools for bendmail=0A=
-=0A=
-Requirements: =0A=
- o php with mailparse=0A=
- o virus scanner (optional)=0A=
- =0A=
-=0A=
-
-------=_NextPart_000_0003_01C2566B.C7AC6A50--
-
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/mailparse-2.1.3/tests/testdata/uue.txt
^
|
@@ -1,27 +0,0 @@
-Return-Path: <wez@thebrainroom.com>
-Received: from TITAN (titan.brainnet.i [192.168.2.7])
- by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g87Be5721229
- for <wez@thebrainroom.com>; Sat, 7 Sep 2002 12:40:05 +0100
-X-Authentication-Warning: zaneeb.brainnet.i: Host titan.brainnet.i [192.168.2.7] claimed to be TITAN
-From: "Wez Furlong" <wez@thebrainroom.com>
-To: <wez@thebrainroom.com>
-Subject: UUEncoded attachments
-Date: Sat, 7 Sep 2002 12:39:55 +0100
-Message-ID: <000001c25663$4cd5b460$0702a8c0@TITAN>
-X-Priority: 3 (Normal)
-X-MSMail-Priority: Normal
-X-Mailer: Microsoft Outlook, Build 10.0.2627
-Importance: Normal
-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
-X-TBR-DestBox: user.wez (auth as wez) (wez:)
-
-Hello, this is a message with UUE attachments.
-
-
-begin 644 README.dat
-M1F]O0F%R("T@0F%A86%A"@I297%U:7)E;65N=',Z(`H);R!P:'`@=VET:"!M
-K86EL<&%R<V4*("`@(&\@=FER=7,@<V-A;FYE<B`H;W!T:6]N86PI"@D*"@``
-`
-end
-
-
|
[-]
[+]
|
Deleted |
mailparse-2.1.3.tgz/package2.xml
^
|
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.6.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <name>mailparse</name>
- <channel>pecl.php.net</channel>
- <summary>Email message manipulation</summary>
- <description>Mailparse is an extension for parsing and working with email messages.
-It can deal with rfc822 and rfc2045 (MIME) compliant messages.</description>
- <lead>
- <name>Wez Furlong</name>
- <user>wez</user>
- <email>wez@php.net</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Brian Shire</name>
- <user>shire</user>
- <email>shire@php.net</email>
- <active>yes</active>
- </lead>
- <date>2008-01-08</date>
- <time>12:20:20</time>
- <version>
- <release>2.1.3</release>
- <api>2.1.3</api>
- </version>
- <stability>
- <release>stable</release>
- <api>stable</api>
- </stability>
- <license uri="http://www.php.net/license">PHP</license>
- <notes>Fixed problems with continuation lines introduced in 2.1.2.
-Fixed bug #6862.</notes>
- <contents>
- <dir name="/">
- <file md5sum="53a80aaa80c4264b358eb2c60bb70f97" name="tests/testdata/mime.exp" role="test" />
- <file md5sum="ed5aba19aa42ac10156eb6d749ad0fbf" name="tests/testdata/mime.txt" role="test" />
- <file md5sum="ed47320fa50fba1fe1f6cb90abd74d09" name="tests/testdata/oeuue" role="test" />
- <file md5sum="88ee73e6ef5f7e07cddc04db9c885d52" name="tests/testdata/phpcvs1.exp" role="test" />
- <file md5sum="f7be9f6bed87394b3af84aff45239676" name="tests/testdata/phpcvs1.txt" role="test" />
- <file md5sum="a5d25e0a5045b170abd46d8ca74302bc" name="tests/testdata/qp.exp" role="test" />
- <file md5sum="81b87b78d7762f264cbc8d1e191ebfc3" name="tests/testdata/qp.txt" role="test" />
- <file md5sum="462339fc59cc461c296d9b3e4fefe884" name="tests/testdata/uue.exp" role="test" />
- <file md5sum="69479efe0cad811f153a7f76cc54ff98" name="tests/testdata/uue.txt" role="test" />
- <file md5sum="f0714afb709996bb1a5783575d8e3838" name="tests/001.phpt" role="test" />
- <file md5sum="834efdde9d108bf98c36fba03354a741" name="tests/002.phpt" role="test" />
- <file md5sum="aeb46fa1168291d439a2b11983b9c154" name="tests/003.phpt" role="test" />
- <file md5sum="e7bac3f8bd6dfd70162f8cc34d3fc7f4" name="tests/004.phpt" role="test" />
- <file md5sum="5e8fffaaebcb7aaf4a63e3dc04124ba3" name="tests/005.phpt" role="test" />
- <file md5sum="30f7d959fadf0ab26be2388d79d7ac96" name="tests/006.phpt" role="test" />
- <file md5sum="61aeda485a2d98ce8eee07b6cb9b76cd" name="tests/007.phpt" role="test" />
- <file md5sum="2ce1e38622f0936f3bc4b080dc793124" name="tests/008.phpt" role="test" />
- <file md5sum="827514b0c55482451558d8c963b1fa6c" name="tests/009.phpt" role="test" />
- <file md5sum="f6cf49eb9c74d37a0402f960e470e19c" name="tests/010.phpt" role="test" />
- <file md5sum="492a524ead5534fb72e03b649740cd16" name="tests/parse_test_messages.phpt" role="test" />
- <file md5sum="ee37da618df919516c118618184d37c7" name="config.m4" role="src" />
- <file md5sum="c08b3ff0db4689c0966c84d097ef4bcd" name="CREDITS" role="doc" />
- <file md5sum="ea8b0add6697761e33ba4d20f824b2be" name="mailparse.c" role="src" />
- <file md5sum="8df385f2c03c3c9d7681a208249badd6" name="Makefile.frag" role="src" />
- <file md5sum="0eb6c6daffbc51439c888a608c66657a" name="php_mailparse.h" role="src" />
- <file md5sum="1ebf48c9794b486c0f9ff8490030ff0b" name="php_mailparse_mime.c" role="src" />
- <file md5sum="3600973dcff0fdb5c965d580c2857093" name="php_mailparse_mime.h" role="src" />
- <file md5sum="89a45cf304424a49de76ec75606ca037" name="php_mailparse_rfc822.c" role="src" />
- <file md5sum="6617162843109ab224bba5f439892ade" name="php_mailparse_rfc822.h" role="src" />
- <file md5sum="0e85b4b1926b500db077553eb0206e37" name="php_mailparse_rfc822.re" role="src" />
- <file md5sum="3be11219d46c7356e06ce2a50f761747" name="README" role="doc" />
- <file md5sum="41aa8420372a5676cbfaf9af2b12cb7a" name="try.php" role="doc" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.3.0</min>
- <max>6.0.0</max>
- </php>
- <pearinstaller>
- <min>1.4.0a1</min>
- </pearinstaller>
- <extension>
- <name>mbstring</name>
- </extension>
- </required>
- </dependencies>
- <providesextension>mailparse</providesextension>
- <extsrcrelease />
-</package>
|
|
Deleted |
mailparse-2.1.4.tgz
^
|
|
Deleted |
mailparse-2.1.5.tgz
^
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/CREDITS
^
|
(renamed from mailparse-2.1.3/CREDITS)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/CREDITS
^
|
(renamed from mailparse-2.1.3/CREDITS)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/Makefile.frag
^
|
(renamed from mailparse-2.1.3/Makefile.frag)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/Makefile.frag
^
|
(renamed from mailparse-2.1.3/Makefile.frag)
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/README
^
|
@@ -0,0 +1,165 @@
+mailparse library for PHP 4
+===========================
+$Id: README 95386 2002-09-10 11:20:45Z wez $
+
+Mailparse is an extension for parsing and working with email messages.
+It can deal with rfc822 and rfc2045 (MIME) compliant messages.
+Mailparse is stream based, which means that it does not keep in-memory
+copies of the files it processes - so it is very resource efficient
+when dealing with large messages.
+
+OO Syntax:
+=============
+<?php
+$file = "/path/to/rfc822/compliant/message";
+// parse the message in $file.
+// The file MUST remain in existence until you are finished using
+// the object, as mailparse does not cache the file in memory.
+// You can also use two alternative syntaxes:
+//
+// Read the message from a variable:
+// $msg =& new MimeMessage("var", $message);
+//
+// Read the message from a stream (from fopen).
+// The stream MUST be seekable, or things will not work correctly.
+// Also, you MUST NOT fclose the stream until you have finished
+// using the message object (or any child objects it returns).
+// $msg =& new MimeMessage("stream", $fp);
+//
+$msg =& new MimeMessage("file", $file);
+
+// Process the message.
+display_part_info("message", $msg);
+
+// Little function to display things
+function display_part_info($caption, &$msgpart)
+{
+ echo "Message part: $caption\n";
+
+ // The data member corresponds to the information
+ // available from the mailparse_msg_get_part_data function.
+ // You can access a particular header like this:
+ // $subject = $msgpart->data["headers"]["subject"];
+ var_dump($msgpart->data);
+
+ echo "The headers are:\n";
+ // Display the headers (in raw format) to the browser output.
+ // You can also use:
+ // $msgpart->extract_headers(MAILPARSE_EXTRACT_STREAM, $fp);
+ // to write the headers to the supplied stream at it's current
+ // position.
+ //
+ // $var = $msgpart->extract_headers(MAILPARSE_EXTRACT_RETURN);
+ // to return the headers in a variable.
+ $msgpart->extract_headers(MAILPARSE_EXTRACT_OUTPUT);
+
+ // Display the body if this part is intended to be displayed:
+ $n = $msgpart->get_child_count();
+
+ if ($n == 0) {
+ // Return the body as a string (the MAILPARSE_EXTRACT parameter
+ // acts just as it does in extract_headers method.
+ $body = $msgpart->extract_body(MAILPARSE_EXTRACT_RETURN);
+ echo htmlentities($body);
+
+ // This function tells you about any uuencoded attachments
+ // that are present in this part.
+ $uue = $msgpart->enum_uue();
+ if ($uue !== false) {
+ var_dump($uue);
+ foreach($uue as $index => $data) {
+ // $data => array("filename" => "original filename",
+ // "filesize" => "size of extracted file",
+ // );
+
+ printf("UUE[%d] %s (%d bytes)\n",
+ $index, $data["filename"],
+ $data["filesize"]);
+
+ // Display the extracted part to the output.
+ $msgpart->extract_uue($index, MAILPARSE_EXTRACT_OUTPUT);
+
+ }
+ }
+
+ } else {
+ // Recurse and show children of that part
+ for ($i = 0; $i < $n; $i++) {
+ $part =& $msgpart->get_child($i);
+ display_part_info("$caption child $i", $part);
+ }
+ }
+}
+
+?>
+
+////////////// The rest of this document may be out of date!
+// Take a look at the mailparse section of the online manual
+// for more hints about this stuff.
+
+$mime = mailparse_rfc2045_parse_file($file);
+$ostruct = mailparse_rfc2045_getstructure($mime);
+foreach($ostruct as $st) {
+ $section = mailparse_rfc2045_find($mime, $st);
+ $struct[$st] = mailparse_rfc2045_getinfo($section);
+}
+var_dump($struct);
+?>
+array mailparse_rfc822_parse_addresses(string addresses)
+ parses an rfc822 compliant recipient list, such as that found in To: From:
+ headers. Returns a indexed array of assoc. arrays for each recipient:
+ array(0 => array("display" => "Wez Furlong", "address" => "wez@php.net"))
+
+resource mailparse_rfc2045_create()
+ Create a mime mail resource
+
+boolean mailparse_rfc2045_parse(resource mimemail, string data)
+ incrementally parse data into the supplied mime mail resource.
+ Concept: you can stream portions of a file at a time, rather than read
+ and parse the whole thing.
+
+
+resource mailparse_rfc2045_parse_file(string $filename)
+ Parse a file and return a $mime resource.
+ The file is opened and streamed through the parser.
+ This is the optimal way of parsing a mail file that
+ you have on disk.
+
+
+array mailparse_rfc2045_getstructure(resource mimemail)
+ returns an array containing a list of message parts in the form:
+ array("1", "1.1", "1.2")
+
+resource mailparse_rfc2045_find(resource mimemail, string partname)
+ returns an mime mail resource representing the named section
+
+array mailparse_rfc2045_getinfo(resource mimemail)
+ returns an array containing the bounds, content type and headers of the
+ section.
+
+mailparse_rfc2045_extract_file(resource mimemail, string filename[, string
+ callbackfunc])
+ Extracts/decodes a message section from the supplied filename.
+ If no callback func is supplied, it outputs the results into the current
+ output buffer, otherwise it calls the callback with a string parameter
+ containing the text.
+ The contents of the section will be decoded according to their transfer
+ encoding - base64, quoted-printable and uuencoded text are supported.
+
+All operations are done incrementally; streaming the input and output so that
+memory usage is on the whole lower than something like procmail or doing this
+stuff in PHP space. The aim is that it stays this way to handle large
+quantities of email.
+
+TODO:
+=====
+
+. Add support for binhex encoding?
+. Extracting a message part without decoding the transfer encoding so that
+ eg: pgp-signatures can be verified.
+
+. Work the other way around - build up a rfc2045 compliant message file from
+ simple structure information and filenames/variables.
+
+vim:tw=78
+vim600:syn=php:tw=78
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/config.m4
^
|
@@ -0,0 +1,18 @@
+dnl
+dnl $Id: config.m4 76818 2002-04-06 14:32:34Z wez $
+dnl
+
+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
+ PHP_NEW_EXTENSION(mailparse, mailparse.c php_mailparse_mime.c php_mailparse_rfc822.c, $ext_shared)
+
+ PHP_ADD_MAKEFILE_FRAGMENT
+
+fi
+
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/mailparse.c
^
|
@@ -0,0 +1,1550 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: mailparse.c 305002 2010-10-31 15:46:48Z cataphract $ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/file.h"
+#include "php_mailparse.h"
+#include "ext/standard/info.h"
+#include "main/php_output.h"
+#include "php_open_temporary_file.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 */
+#define MAILPARSE_DECODE_NOBODY 4 /* don't include the body */
+
+#define MAILPARSE_EXTRACT_OUTPUT 0 /* extract to output buffer */
+#define MAILPARSE_EXTRACT_STREAM 1 /* extract to a stream (caller supplies) */
+#define MAILPARSE_EXTRACT_RETURN 2 /* return extracted data as a string */
+
+static int extract_part(php_mimepart *part, int decode, php_stream *src, void *callbackdata,
+ php_mimepart_extract_func_t callback TSRMLS_DC);
+static int extract_callback_stream(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC);
+static int extract_callback_stdout(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC);
+
+static int get_structure_callback(php_mimepart *part, php_mimepart_enumerator *id, void *ptr TSRMLS_DC);
+static int mailparse_get_part_data(php_mimepart *part, zval *return_value TSRMLS_DC);
+static int mailparse_mimemessage_populate(php_mimepart *part, zval *object TSRMLS_DC);
+static size_t mailparse_do_uudecode(php_stream *instream, php_stream *outstream TSRMLS_DC);
+
+static int le_mime_part;
+
+
+static zend_function_entry mimemessage_methods[] = {
+ PHP_NAMED_FE(mimemessage, PHP_FN(mailparse_mimemessage), NULL)
+ PHP_NAMED_FE(get_child, PHP_FN(mailparse_mimemessage_get_child), NULL)
+ PHP_NAMED_FE(get_child_count, PHP_FN(mailparse_mimemessage_get_child_count), NULL)
+ PHP_NAMED_FE(get_parent, PHP_FN(mailparse_mimemessage_get_parent), NULL)
+ PHP_NAMED_FE(extract_headers, PHP_FN(mailparse_mimemessage_extract_headers), NULL)
+ PHP_NAMED_FE(extract_body, PHP_FN(mailparse_mimemessage_extract_body), NULL)
+ PHP_NAMED_FE(enum_uue, PHP_FN(mailparse_mimemessage_enum_uue), NULL)
+ PHP_NAMED_FE(extract_uue, PHP_FN(mailparse_mimemessage_extract_uue), NULL)
+ PHP_NAMED_FE(remove, PHP_FN(mailparse_mimemessage_remove), NULL)
+ PHP_NAMED_FE(add_child, PHP_FN(mailparse_mimemessage_add_child), NULL)
+ {NULL, NULL, NULL}
+};
+
+static zend_class_entry *mimemsg_class_entry;
+
+zend_function_entry mailparse_functions[] = {
+ PHP_FE(mailparse_msg_parse_file, NULL)
+ PHP_FE(mailparse_msg_get_part, NULL)
+ PHP_FE(mailparse_msg_get_structure, NULL)
+ PHP_FE(mailparse_msg_get_part_data, NULL)
+ PHP_FE(mailparse_msg_extract_part, NULL)
+ PHP_FE(mailparse_msg_extract_part_file, NULL)
+ PHP_FE(mailparse_msg_extract_whole_part_file, NULL)
+
+ PHP_FE(mailparse_msg_create, NULL)
+ PHP_FE(mailparse_msg_free, NULL)
+ PHP_FE(mailparse_msg_parse, NULL)
+ PHP_FE(mailparse_rfc822_parse_addresses, NULL)
+ PHP_FE(mailparse_determine_best_xfer_encoding, NULL)
+ PHP_FE(mailparse_stream_encode, NULL)
+ PHP_FE(mailparse_uudecode_all, NULL)
+
+ PHP_FE(mailparse_test, NULL)
+
+ {NULL, NULL, NULL}
+};
+
+zend_module_entry mailparse_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "mailparse",
+ mailparse_functions,
+ PHP_MINIT(mailparse),
+ PHP_MSHUTDOWN(mailparse),
+ PHP_RINIT(mailparse),
+ PHP_RSHUTDOWN(mailparse),
+ PHP_MINFO(mailparse),
+ PHP_MAILPARSE_VERSION,
+ STANDARD_MODULE_PROPERTIES
+};
+
+ZEND_DECLARE_MODULE_GLOBALS(mailparse)
+
+#ifdef COMPILE_DL_MAILPARSE
+ZEND_GET_MODULE(mailparse)
+#endif
+
+ZEND_RSRC_DTOR_FUNC(mimepart_dtor)
+{
+ php_mimepart *part = rsrc->ptr;
+
+ if (part->parent == NULL && part->rsrc_id) {
+ part->rsrc_id = 0;
+ php_mimepart_free(part TSRMLS_CC);
+ }
+}
+
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("mailparse.def_charset", "us-ascii", PHP_INI_ALL, OnUpdateString, def_charset, zend_mailparse_globals, mailparse_globals)
+PHP_INI_END()
+
+#define mailparse_msg_name "mailparse_mail_structure"
+
+#define mailparse_fetch_mimepart_resource(rfcvar, zvalarg) ZEND_FETCH_RESOURCE(rfcvar, php_mimepart *, zvalarg, -1, mailparse_msg_name, le_mime_part)
+
+PHP_MAILPARSE_API int php_mailparse_le_mime_part(void)
+{
+ return le_mime_part;
+}
+
+PHP_MINIT_FUNCTION(mailparse)
+{
+ zend_class_entry mmce;
+
+#ifdef ZTS
+ zend_mailparse_globals *mailparse_globals;
+
+ ts_allocate_id(&mailparse_globals_id, sizeof(zend_mailparse_globals), NULL, NULL);
+ mailparse_globals = ts_resource(mailparse_globals_id);
+#endif
+
+ INIT_CLASS_ENTRY(mmce, "mimemessage", mimemessage_methods);
+ mimemsg_class_entry = zend_register_internal_class(&mmce TSRMLS_CC);
+
+
+ le_mime_part = zend_register_list_destructors_ex(mimepart_dtor, NULL, mailparse_msg_name, module_number);
+
+ REGISTER_LONG_CONSTANT("MAILPARSE_EXTRACT_OUTPUT", MAILPARSE_EXTRACT_OUTPUT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MAILPARSE_EXTRACT_STREAM", MAILPARSE_EXTRACT_STREAM, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("MAILPARSE_EXTRACT_RETURN", MAILPARSE_EXTRACT_RETURN, CONST_CS | CONST_PERSISTENT);
+
+ REGISTER_INI_ENTRIES();
+
+ return SUCCESS;
+}
+
+PHP_MSHUTDOWN_FUNCTION(mailparse)
+{
+ UNREGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+
+/* {{{ ------------- MimeMessage methods */
+
+static inline php_mimepart *mimemsg_get_object(zval *object TSRMLS_DC)
+{
+ zval **zpart;
+ php_mimepart *part;
+ int type;
+
+
+ if (Z_TYPE_P(object) != IS_OBJECT) {
+ return NULL;
+ }
+
+ if (zend_hash_index_find(Z_OBJPROP_P(object), 0, (void**)&zpart) == FAILURE) {
+ return NULL;
+ }
+
+ part = zend_list_find(Z_LVAL_PP(zpart), &type);
+
+ if (type != le_mime_part)
+ return NULL;
+
+ return part;
+}
+
+static int mailparse_mimemessage_populate(php_mimepart *part, zval *object TSRMLS_DC)
+{
+ zval *tmp;
+
+ MAKE_STD_ZVAL(tmp);
+ mailparse_get_part_data(part, tmp TSRMLS_CC);
+ add_property_zval(object, "data", tmp);
+ Z_DELREF_P(tmp);
+
+ return SUCCESS;
+}
+
+static int mailparse_mimemessage_export(php_mimepart *part, zval *object TSRMLS_DC)
+{
+ zval *zpart;
+
+ zend_list_addref(part->rsrc_id);
+
+ MAKE_STD_ZVAL(zpart);
+ php_mimepart_to_zval(zpart, part);
+
+ object_init_ex(object, mimemsg_class_entry);
+
+ Z_SET_ISREF_TO_P(object, 1);
+ Z_SET_REFCOUNT_P(object, 1);
+
+ zend_hash_index_update(Z_OBJPROP_P(object), 0, &zpart, sizeof(zval *), NULL);
+
+ /* recurses for any of our child parts */
+ mailparse_mimemessage_populate(part, object TSRMLS_CC);
+
+ return SUCCESS;
+}
+
+PHP_FUNCTION(mailparse_mimemessage)
+{
+ zval *object = getThis();
+ php_mimepart *part;
+ zval *zpart;
+ char *mode;
+ int mode_len;
+ zval *source = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz!", &mode, &mode_len, &source) == FAILURE)
+ RETURN_FALSE;
+
+ /* prepare the mime part for this object */
+ part = php_mimepart_alloc(TSRMLS_C);
+ MAKE_STD_ZVAL(zpart);
+ php_mimepart_to_zval(zpart, part);
+
+ zend_hash_index_update(Z_OBJPROP_P(object), 0, &zpart, sizeof(zval *), NULL);
+
+ /* now check the args */
+
+ if (strcmp(mode, "new") == 0)
+ RETURN_TRUE;
+
+ if (source == NULL)
+ RETURN_FALSE;
+
+ if (strcmp(mode, "var") == 0 && Z_TYPE_P(source) == IS_STRING) {
+ /* source is the actual message */
+ part->source.kind = mpSTRING;
+
+ *part->source.zval = *source;
+ zval_copy_ctor(part->source.zval);
+ Z_SET_REFCOUNT_P(part->source.zval, 1);
+ convert_to_string_ex(&part->source.zval);
+ }
+
+ if (strcmp(mode, "file") == 0) {
+ /* source is the name of a file */
+ php_stream *srcstream;
+
+ part->source.kind = mpSTREAM;
+ convert_to_string_ex(&source);
+ srcstream = php_stream_open_wrapper(Z_STRVAL_P(source), "rb", ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
+
+ if (srcstream == NULL) {
+ RETURN_FALSE;
+ }
+
+ php_stream_to_zval(srcstream, part->source.zval);
+ }
+ if (strcmp(mode, "stream") == 0) {
+ part->source.kind = mpSTREAM;
+
+ *part->source.zval = *source;
+ zval_copy_ctor(part->source.zval);
+ Z_SET_REFCOUNT_P(part->source.zval, 1);
+ 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) TSRMLS_CC);
+ } 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));
+ if (n > 0)
+ php_mimepart_parse(part, buf, n TSRMLS_CC);
+ }
+ }
+
+ mailparse_mimemessage_populate(part, object TSRMLS_CC);
+}
+
+PHP_FUNCTION(mailparse_mimemessage_remove)
+{
+ php_mimepart *part;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+ if (part == NULL)
+ RETURN_FALSE;
+
+ php_mimepart_remove_from_parent(part TSRMLS_CC);
+}
+
+PHP_FUNCTION(mailparse_mimemessage_add_child)
+{
+ php_mimepart *part;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+ if (part == NULL)
+ RETURN_FALSE;
+
+ php_mimepart_remove_from_parent(part TSRMLS_CC);
+}
+
+
+PHP_FUNCTION(mailparse_mimemessage_get_child_count)
+{
+ php_mimepart *part;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+ if (part == NULL)
+ RETURN_FALSE;
+
+ RETURN_LONG(zend_hash_num_elements(&part->children));
+}
+
+PHP_FUNCTION(mailparse_mimemessage_get_parent)
+{
+ php_mimepart *part;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+
+ if (part && part->parent) {
+ mailparse_mimemessage_export(part->parent, return_value TSRMLS_CC);
+ } else {
+ RETURN_NULL();
+ }
+}
+
+PHP_FUNCTION(mailparse_mimemessage_get_child)
+{
+ php_mimepart *part, *foundpart;
+ zval *item_to_find;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+
+ if (part == NULL)
+ RETURN_NULL();
+
+ if (FAILURE == zend_get_parameters(ht, 1, &item_to_find))
+ RETURN_NULL();
+
+ if (Z_TYPE_P(item_to_find) == IS_STRING) {
+ foundpart = php_mimepart_find_by_name(part, Z_STRVAL_P(item_to_find) TSRMLS_CC);
+ } else {
+ foundpart = php_mimepart_find_child_by_position(part, Z_LVAL_P(item_to_find) TSRMLS_CC);
+ }
+
+ if (!foundpart) {
+ RETURN_NULL();
+ }
+
+ mailparse_mimemessage_export(foundpart, return_value TSRMLS_CC);
+}
+
+static void mailparse_mimemessage_extract(int flags, INTERNAL_FUNCTION_PARAMETERS)
+{
+ php_mimepart *part;
+ zval *zarg = NULL;
+ php_stream *srcstream, *deststream = NULL;
+ long mode = MAILPARSE_EXTRACT_OUTPUT;
+ php_mimepart_extract_func_t callback = extract_callback_stdout;
+ void *callback_data = NULL;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+
+ RETVAL_NULL();
+
+ if (part == NULL)
+ return;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lz!", &mode, &zarg))
+ return;
+
+ switch(mode) {
+ case MAILPARSE_EXTRACT_STREAM:
+ if (zarg == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 2 must be a stream");
+ return;
+ }
+
+ php_stream_from_zval(deststream, &zarg);
+ break;
+ case MAILPARSE_EXTRACT_RETURN:
+ deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
+ break;
+ }
+
+
+ if (part->source.kind == mpSTRING)
+ srcstream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(part->source.zval), Z_STRLEN_P(part->source.zval));
+ else
+ php_stream_from_zval(srcstream, &part->source.zval);
+
+ if (srcstream == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "MimeMessage object is missing a source stream!");
+ goto cleanup;
+ }
+
+ if (deststream != NULL) {
+ callback_data = deststream;
+ callback = extract_callback_stream;
+ }
+
+ if (SUCCESS == extract_part(part, flags, srcstream, callback_data, callback TSRMLS_CC)) {
+
+ if (mode == MAILPARSE_EXTRACT_RETURN) {
+ size_t len;
+ char *buf;
+
+ buf = php_stream_memory_get_buffer(deststream, &len);
+ RETVAL_STRINGL(buf, len, 1);
+ } else {
+ RETVAL_TRUE;
+ }
+
+ }
+
+cleanup:
+
+ if (part->source.kind == mpSTRING && srcstream)
+ php_stream_close(srcstream);
+ if (mode == MAILPARSE_EXTRACT_RETURN && deststream)
+ php_stream_close(deststream);
+
+}
+
+PHP_FUNCTION(mailparse_mimemessage_extract_headers)
+{
+ mailparse_mimemessage_extract(MAILPARSE_DECODE_NOBODY, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+
+PHP_FUNCTION(mailparse_mimemessage_extract_body)
+{
+ mailparse_mimemessage_extract(MAILPARSE_DECODE_NOHEADERS | MAILPARSE_DECODE_8BIT, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+
+PHP_FUNCTION(mailparse_mimemessage_extract_uue)
+{
+ php_mimepart *part;
+ zval *zarg = NULL;
+ php_stream *srcstream, *deststream = NULL;
+ long mode = MAILPARSE_EXTRACT_OUTPUT;
+ long index = 0; /* which uue to extract */
+ off_t end;
+ off_t start_pos;
+ char buffer[4096];
+ int nparts = 0;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+
+ RETVAL_NULL();
+
+ if (part == NULL)
+ return;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|lz!", &index, &mode, &zarg))
+ return;
+
+ switch(mode) {
+ case MAILPARSE_EXTRACT_STREAM:
+ if (zarg == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 2 must be a stream");
+ return;
+ }
+
+ php_stream_from_zval(deststream, &zarg);
+ break;
+ case MAILPARSE_EXTRACT_RETURN:
+ deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
+ break;
+ case MAILPARSE_EXTRACT_OUTPUT:
+ deststream = php_stream_open_wrapper("php://output", "wb", 0, NULL);
+ break;
+ }
+
+ if (part->source.kind == mpSTRING)
+ srcstream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(part->source.zval), Z_STRLEN_P(part->source.zval));
+ else
+ php_stream_from_zval(srcstream, &part->source.zval);
+
+ if (srcstream == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "MimeMessage object is missing a source stream!");
+ goto cleanup;
+ }
+
+ /* position stream at start of the body for this part */
+
+ start_pos = part->bodystart;
+ end = part->parent ? part->bodyend : part->endpos;
+ php_stream_seek(srcstream, start_pos, SEEK_SET);
+
+ while(!php_stream_eof(srcstream) && php_stream_gets(srcstream, buffer, sizeof(buffer))) {
+ /* Look for the "begin " sequence that identifies a uuencoded file */
+ if (strncmp(buffer, "begin ", 6) == 0) {
+ char *origfilename;
+ int len;
+
+ /* parse out the file name.
+ * The next 4 bytes are an octal number for perms; ignore it */
+ origfilename = &buffer[10];
+ /* NUL terminate the filename */
+ len = strlen(origfilename);
+ while(isspace(origfilename[len-1]))
+ origfilename[--len] = '\0';
+
+ /* make the return an array */
+ if (nparts == index) {
+ mailparse_do_uudecode(srcstream, deststream TSRMLS_CC);
+ if (mode == MAILPARSE_EXTRACT_RETURN) {
+ size_t len;
+ char *buf;
+
+ buf = php_stream_memory_get_buffer(deststream, &len);
+ RETVAL_STRINGL(buf, len, 1);
+ } else {
+ RETVAL_TRUE;
+ }
+
+ break;
+ } else {
+ /* skip that part */
+ mailparse_do_uudecode(srcstream, NULL TSRMLS_CC);
+ }
+ } else {
+ if (php_stream_tell(srcstream) >= end)
+ break;
+ }
+ }
+
+cleanup:
+
+ if (part->source.kind == mpSTRING && srcstream)
+ php_stream_close(srcstream);
+ if (mode != MAILPARSE_EXTRACT_STREAM && deststream)
+ php_stream_close(deststream);
+
+
+}
+
+PHP_FUNCTION(mailparse_mimemessage_enum_uue)
+{
+ php_stream *instream;
+ php_mimepart *part;
+ off_t end;
+ off_t start_pos, curr_pos;
+ size_t file_size;
+ char buffer[4096];
+ int nparts = 0;
+ zval *item;
+
+ part = mimemsg_get_object(getThis() TSRMLS_CC);
+
+ RETVAL_FALSE;
+
+ if (part == NULL)
+ return;
+
+ if (part->source.kind == mpSTRING)
+ instream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(part->source.zval), Z_STRLEN_P(part->source.zval));
+ else
+ php_stream_from_zval(instream, &part->source.zval);
+
+ if (instream == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "MimeMessage object is missing a source stream!");
+ goto cleanup;
+ }
+
+ /* position stream at start of the body for this part */
+
+ start_pos = part->bodystart;
+ end = part->parent ? part->bodyend : part->endpos;
+ php_stream_seek(instream, start_pos, SEEK_SET);
+
+ while(!php_stream_eof(instream) && php_stream_gets(instream, buffer, sizeof(buffer))) {
+ /* Look for the "begin " sequence that identifies a uuencoded file */
+ if (strncmp(buffer, "begin ", 6) == 0) {
+ char *origfilename;
+ int len;
+
+ /* parse out the file name.
+ * The next 4 bytes are an octal number for perms; ignore it */
+ origfilename = &buffer[10];
+ /* NUL terminate the filename */
+ len = strlen(origfilename);
+ while(isspace(origfilename[len-1]))
+ origfilename[--len] = '\0';
+
+ /* make the return an array */
+ if (nparts == 0) {
+ array_init(return_value);
+ }
+
+ /* add an item */
+ MAKE_STD_ZVAL(item);
+ array_init(item);
+ add_assoc_string(item, "filename", origfilename, 1);
+ add_assoc_long(item, "start-pos", php_stream_tell(instream));
+
+ /* decode it and remember the file size */
+ file_size = mailparse_do_uudecode(instream, NULL TSRMLS_CC);
+ add_assoc_long(item, "filesize", file_size);
+
+ curr_pos = php_stream_tell(instream);
+
+ if (curr_pos > end) {
+ /* we somehow overran the message boundary; the message itself is
+ * probably bogus, so lets cancel this item */
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "uue attachment overran part boundary; this should not happen, message is probably malformed");
+ zval_ptr_dtor(&item);
+ break;
+ }
+
+ add_assoc_long(item, "end-pos", curr_pos);
+ add_next_index_zval(return_value, item);
+ nparts++;
+
+ } else {
+ if (php_stream_tell(instream) >= end)
+ break;
+ }
+ }
+cleanup:
+ if (part->source.kind == mpSTRING && instream)
+ php_stream_close(instream);
+
+}
+
+/* --- END ---------- MimeMessage methods }}} */
+
+PHP_MINFO_FUNCTION(mailparse)
+{
+ php_info_print_table_start();
+ php_info_print_table_header(2, "mailparse support", "enabled");
+ php_info_print_table_row(2, "Extension Version", PHP_MAILPARSE_VERSION);
+ php_info_print_table_row(2, "Revision", "$Revision: 305002 $");
+ php_info_print_table_end();
+
+ DISPLAY_INI_ENTRIES();
+}
+
+
+PHP_RINIT_FUNCTION(mailparse)
+{
+ return SUCCESS;
+}
+
+
+PHP_RSHUTDOWN_FUNCTION(mailparse)
+{
+ return SUCCESS;
+}
+
+#define UUDEC(c) (char)(((c)-' ')&077)
+#define UU_NEXT(v) if (line[x] == '\0' || line[x] == '\r' || line[x] == '\n') break; v = line[x++]; v = UUDEC(v)
+static size_t mailparse_do_uudecode(php_stream *instream, php_stream *outstream TSRMLS_DC)
+{
+ int x, A, B, C, D, n;
+ size_t file_size = 0;
+ char line[128];
+
+ if (outstream) {
+ /* write to outstream */
+ while(!php_stream_eof(instream)) {
+ if (!php_stream_gets(instream, line, sizeof(line))) {
+ break;
+ }
+ x = 0;
+
+ UU_NEXT(n);
+
+ while(n != 0) {
+ UU_NEXT(A);
+ UU_NEXT(B);
+ UU_NEXT(C);
+ UU_NEXT(D);
+
+ if (n-- > 0) {
+ file_size++;
+ php_stream_putc(outstream, (A << 2) | (B >> 4));
+ }
+
+ if (n-- > 0) {
+ file_size++;
+ php_stream_putc(outstream, (B << 4) | (C >> 2));
+ }
+
+ if (n-- > 0) {
+ file_size++;
+ php_stream_putc(outstream, (C << 6) | D);
+ }
+ }
+ }
+ } else {
+ /* skip (and measure) the data, but discard it.
+ * This is separated from the version above to speed it up by a few cycles */
+
+ while(!php_stream_eof(instream)) {
+
+ if (!php_stream_gets(instream, line, sizeof(line))) {
+ break;
+ }
+ x = 0;
+
+ UU_NEXT(n);
+
+ while(line[x] && n != 0) {
+ UU_NEXT(A);
+ UU_NEXT(B);
+ UU_NEXT(C);
+ UU_NEXT(D);
+
+ if (n-- > 0) {
+ file_size++;
+ }
+
+ if (n-- > 0) {
+ file_size++;
+ }
+
+ if (n-- > 0) {
+ file_size++;
+ }
+ }
+ }
+ }
+ return file_size;
+}
+
+
+/* {{{ proto array mailparse_uudecode_all(resource fp)
+ Scans the data from fp and extract each embedded uuencoded file. Returns an array listing filename information */
+PHP_FUNCTION(mailparse_uudecode_all)
+{
+ zval *file, *item;
+ char *buffer = NULL;
+ char *outpath = NULL;
+ int nparts = 0;
+ php_stream *instream, *outstream = NULL, *partstream = NULL;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &file))
+ return;
+
+ php_stream_from_zval(instream, &file);
+
+ outstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath);
+ if (outstream == NULL) {
+ zend_error(E_WARNING, "%s(): unable to open temp file", get_active_function_name(TSRMLS_C));
+ RETURN_FALSE;
+ }
+
+ php_stream_rewind(instream);
+
+ buffer = emalloc(4096);
+ while(php_stream_gets(instream, buffer, 4096)) {
+ /* Look for the "begin " sequence that identifies a uuencoded file */
+ if (strncmp(buffer, "begin ", 6) == 0) {
+ char * origfilename;
+ int len;
+
+ /* parse out the file name.
+ * The next 4 bytes are an octal number for perms; ignore it */
+ origfilename = &buffer[10];
+ /* NUL terminate the filename */
+ len = strlen(origfilename);
+ while(isspace(origfilename[len-1]))
+ origfilename[--len] = '\0';
+
+ /* make the return an array */
+ if (nparts == 0) {
+ array_init(return_value);
+ /* create an initial item representing the file with all uuencoded parts
+ * removed */
+ MAKE_STD_ZVAL(item);
+ array_init(item);
+ add_assoc_string(item, "filename", outpath, 0);
+ add_next_index_zval(return_value, item);
+ }
+
+ /* add an item */
+ MAKE_STD_ZVAL(item);
+ array_init(item);
+ add_assoc_string(item, "origfilename", origfilename, 1);
+
+ /* create a temp file for the data */
+ partstream = php_stream_fopen_temporary_file(NULL, "mailparse", &outpath);
+ if (partstream) {
+ nparts++;
+ add_assoc_string(item, "filename", outpath, 0);
+ add_next_index_zval(return_value, item);
+
+ /* decode it */
+ mailparse_do_uudecode(instream, partstream TSRMLS_CC);
+ php_stream_close(partstream);
+ }
+ } else {
+ /* write to the output file */
+ php_stream_write_string(outstream, buffer);
+ }
+ }
+ php_stream_close(outstream);
+ php_stream_rewind(instream);
+ efree(buffer);
+
+ if (nparts == 0) {
+ /* delete temporary file */
+ unlink(outpath);
+ efree(outpath);
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto array mailparse_rfc822_parse_addresses(string addresses)
+ Parse addresses and returns a hash containing that data */
+PHP_FUNCTION(mailparse_rfc822_parse_addresses)
+{
+ char *addresses;
+ int addresses_len;
+ php_rfc822_tokenized_t *toks = NULL;
+ php_rfc822_addresses_t *addrs = NULL;
+ int i;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addresses, &addresses_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+ toks = php_mailparse_rfc822_tokenize((const char*)addresses, 1 TSRMLS_CC);
+ addrs = php_rfc822_parse_address_tokens(toks);
+
+ array_init(return_value);
+
+ for (i = 0; i < addrs->naddrs; i++) {
+ zval *item;
+
+ MAKE_STD_ZVAL(item);
+ array_init(item);
+
+ if (addrs->addrs[i].name)
+ add_assoc_string(item, "display", addrs->addrs[i].name, 1);
+ if (addrs->addrs[i].address)
+ add_assoc_string(item, "address", addrs->addrs[i].address, 1);
+ add_assoc_bool(item, "is_group", addrs->addrs[i].is_group);
+
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &item, sizeof(item), NULL);
+ }
+
+ php_rfc822_free_addresses(addrs);
+ php_rfc822_tokenize_free(toks);
+}
+/* }}} */
+
+/* {{{ proto string mailparse_determine_best_xfer_encoding(resource fp)
+ Figures out the best way of encoding the content read from the file pointer fp, which must be seek-able */
+PHP_FUNCTION(mailparse_determine_best_xfer_encoding)
+{
+ zval *file;
+ int longline = 0;
+ int linelen = 0;
+ int c;
+ enum mbfl_no_encoding bestenc = mbfl_no_encoding_7bit;
+ php_stream *stream;
+ char * name;
+
+ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters(ht, 1, &file) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ php_stream_from_zval(stream, &file);
+
+ php_stream_rewind(stream);
+ while(!php_stream_eof(stream)) {
+ c = php_stream_getc(stream);
+ if (c == EOF)
+ break;
+ if (c > 0x80)
+ bestenc = mbfl_no_encoding_8bit;
+ else if (c == 0) {
+ bestenc = mbfl_no_encoding_base64;
+ longline = 0;
+ break;
+ }
+ if (c == '\n')
+ linelen = 0;
+ else if (++linelen > 200)
+ longline = 1;
+ }
+ if (longline)
+ bestenc = mbfl_no_encoding_qprint;
+ php_stream_rewind(stream);
+
+ name = (char *)mbfl_no2preferred_mime_name(bestenc);
+ if (name)
+ {
+ RETVAL_STRING(name, 1);
+ }
+ else
+ {
+ RETVAL_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto boolean mailparse_stream_encode(resource sourcefp, resource destfp, string encoding)
+ Streams data from source file pointer, apply encoding and write to destfp */
+
+static int mailparse_stream_output(int c, void *stream MAILPARSE_MBSTRING_TSRMLS_DC)
+{
+ char buf = c;
+ MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD();
+
+ return php_stream_write((php_stream*)stream, &buf, 1);
+}
+static int mailparse_stream_flush(void *stream MAILPARSE_MBSTRING_TSRMLS_DC)
+{
+ MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD();
+ return php_stream_flush((php_stream*)stream);
+}
+
+PHP_FUNCTION(mailparse_stream_encode)
+{
+ zval *srcfile, *destfile, *encod;
+ php_stream *srcstream, *deststream;
+ char *buf;
+ size_t len;
+ size_t bufsize = 2048;
+ enum mbfl_no_encoding enc;
+ mbfl_convert_filter *conv = NULL;
+
+ if (ZEND_NUM_ARGS() != 3 || zend_get_parameters(ht, 3, &srcfile, &destfile, &encod) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if (Z_TYPE_P(srcfile) == IS_RESOURCE && Z_LVAL_P(srcfile) == 0) {
+ RETURN_FALSE;
+ }
+ if (Z_TYPE_P(destfile) == IS_RESOURCE && Z_LVAL_P(destfile) == 0) {
+ RETURN_FALSE;
+ }
+
+ php_stream_from_zval(srcstream, &srcfile);
+ php_stream_from_zval(deststream, &destfile);
+
+ convert_to_string_ex(&encod);
+ enc = mbfl_name2no_encoding(Z_STRVAL_P(encod));
+ if (enc == mbfl_no_encoding_invalid) {
+ zend_error(E_WARNING, "%s(): unknown encoding \"%s\"",
+ get_active_function_name(TSRMLS_C),
+ Z_STRVAL_P(encod)
+ );
+ RETURN_FALSE;
+ }
+
+ buf = emalloc(bufsize);
+ RETVAL_TRUE;
+
+ conv = mbfl_convert_filter_new(mbfl_no_encoding_8bit,
+ enc,
+ mailparse_stream_output,
+ mailparse_stream_flush,
+ deststream
+ MAILPARSE_MBSTRING_TSRMLS_CC
+ );
+
+ if (enc == mbfl_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
+ * in front of it and invalidate the content/signature */
+ while(!php_stream_eof(srcstream)) {
+ if (NULL != php_stream_gets(srcstream, buf, bufsize)) {
+ size_t i;
+
+ len = strlen(buf);
+
+ if (strncmp(buf, "From ", 5) == 0) {
+ mbfl_convert_filter_flush(conv MAILPARSE_MBSTRING_TSRMLS_CC);
+ php_stream_write(deststream, "=46rom ", 7);
+ i = 5;
+ } else {
+ i = 0;
+ }
+
+ for (; i<len; i++)
+ mbfl_convert_filter_feed(buf[i], conv MAILPARSE_MBSTRING_TSRMLS_CC);
+ }
+ }
+
+ } else {
+ while(!php_stream_eof(srcstream)) {
+ len = php_stream_read(srcstream, buf, bufsize);
+ if (len > 0)
+ {
+ size_t i;
+ for (i=0; i<len; i++)
+ mbfl_convert_filter_feed(buf[i], conv MAILPARSE_MBSTRING_TSRMLS_CC);
+ }
+ }
+ }
+
+ mbfl_convert_filter_flush(conv MAILPARSE_MBSTRING_TSRMLS_CC);
+ mbfl_convert_filter_delete(conv MAILPARSE_MBSTRING_TSRMLS_CC);
+ efree(buf);
+}
+/* }}} */
+
+/* {{{ proto void mailparse_msg_parse(resource mimepart, string data)
+ Incrementally parse data into buffer */
+PHP_FUNCTION(mailparse_msg_parse)
+{
+ char *data;
+ int data_len;
+ zval *arg;
+ php_mimepart *part;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &arg, &data, &data_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ mailparse_fetch_mimepart_resource(part, &arg);
+
+ if (FAILURE == php_mimepart_parse(part, data, data_len TSRMLS_CC)) {
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto resource mailparse_msg_parse_file(string filename)
+ Parse file and return a resource representing the structure */
+PHP_FUNCTION(mailparse_msg_parse_file)
+{
+ char *filename;
+ int filename_len;
+ php_mimepart *part;
+ char *filebuf;
+ php_stream *stream;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ /* open file and read it in */
+ stream = php_stream_open_wrapper(filename, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
+ if (stream == NULL) {
+ RETURN_FALSE;
+ }
+
+ filebuf = emalloc(MAILPARSE_BUFSIZ);
+
+ part = php_mimepart_alloc(TSRMLS_C);
+ php_mimepart_to_zval(return_value, part);
+
+ while(!php_stream_eof(stream)) {
+ int got = php_stream_read(stream, filebuf, MAILPARSE_BUFSIZ);
+ if (got > 0) {
+ if (FAILURE == php_mimepart_parse(part, filebuf, got TSRMLS_CC)) {
+ RETVAL_FALSE;
+ break;
+ }
+ }
+ }
+ php_stream_close(stream);
+ efree(filebuf);
+}
+/* }}} */
+
+/* {{{ proto void mailparse_msg_free(resource mimepart)
+ Frees a handle allocated by mailparse_msg_create
+*/
+PHP_FUNCTION(mailparse_msg_free)
+{
+ zval *arg;
+ php_mimepart *part;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ mailparse_fetch_mimepart_resource(part, &arg);
+ /* zend_list_delete(Z_LVAL_P(arg)); */
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto int mailparse_msg_create(void)
+ Returns a handle that can be used to parse a message */
+PHP_FUNCTION(mailparse_msg_create)
+{
+ php_mimepart *part = php_mimepart_alloc(TSRMLS_C);
+
+ php_mimepart_to_zval(return_value, part);
+}
+/* }}} */
+
+static int get_structure_callback(php_mimepart *part, php_mimepart_enumerator *id, void *ptr TSRMLS_DC)
+{
+ zval *return_value = (zval *)ptr;
+ char intbuf[16];
+ char *buf;
+ int buf_size;
+ int len, i = 0;
+
+ buf_size = 1024;
+ buf = emalloc(buf_size);
+ while(id && i < buf_size) {
+ sprintf(intbuf, "%d", id->id);
+ len = strlen(intbuf);
+ if (len > (buf_size-i)) {
+ /* too many sections: bail */
+ zend_error(E_WARNING, "%s(): too many nested sections in message", get_active_function_name(TSRMLS_C));
+ return FAILURE;
+ }
+ if ((i + len + 1) >= buf_size) {
+ buf_size = buf_size << 1;
+ buf = erealloc(buf, buf_size);
+ if (!buf) {
+ zend_error(E_ERROR, "The structure buffer has been exceeded (%d). Please try decreasing the nesting depth of messages and report this to the developers.", buf_size);
+ }
+ }
+ sprintf(&buf[i], "%s%c", intbuf, id->next ? '.' : '\0');
+ i += len + (id->next ? 1 : 0);
+ id = id->next;
+ }
+ add_next_index_string(return_value, buf,0);
+ return SUCCESS;
+}
+
+/* {{{ proto array mailparse_msg_get_structure(resource mimepart)
+ Returns an array of mime section names in the supplied message */
+PHP_FUNCTION(mailparse_msg_get_structure)
+{
+ zval *arg;
+ php_mimepart *part;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ mailparse_fetch_mimepart_resource(part, &arg);
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ php_mimepart_enum_parts(part, &get_structure_callback, return_value TSRMLS_CC);
+}
+/* }}} */
+
+/* callback for decoding using a "userdefined" php function */
+static int extract_callback_user_func(php_mimepart *part, zval *userfunc, const char *p, size_t n TSRMLS_DC)
+{
+ zval *retval;
+ zval *arg;
+
+ MAKE_STD_ZVAL(retval);
+ Z_TYPE_P(retval) = IS_BOOL;
+ Z_LVAL_P(retval) = 0;
+
+ MAKE_STD_ZVAL(arg);
+ ZVAL_STRINGL(arg, (char*)p, (int)n, 1);
+
+ /* TODO: use zend_is_callable */
+
+ if (call_user_function(EG(function_table), NULL, userfunc, retval, 1, &arg TSRMLS_CC) == FAILURE)
+ zend_error(E_WARNING, "%s(): unable to call user function", get_active_function_name(TSRMLS_C));
+
+ zval_dtor(retval);
+ zval_dtor(arg);
+ efree(retval);
+ efree(arg);
+
+ return 0;
+}
+
+/* callback for decoding to the current output buffer */
+static int extract_callback_stdout(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC)
+{
+ ZEND_WRITE(p, n);
+ return 0;
+}
+
+/* callback for decoding to a stream */
+static int extract_callback_stream(php_mimepart *part, void *ptr, const char *p, size_t n TSRMLS_DC)
+{
+ php_stream_write((php_stream*)ptr, p, n);
+ return 0;
+}
+
+#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 */
+#define MAILPARSE_DECODE_NOBODY 4 /* don't include the body */
+
+static int extract_part(php_mimepart *part, int decode, php_stream *src, void *callbackdata,
+ php_mimepart_extract_func_t callback TSRMLS_DC)
+{
+ off_t end;
+ off_t start_pos;
+ char *filebuf = NULL;
+ int ret = FAILURE;
+
+ /* figure out where the message part starts/ends */
+ start_pos = decode & MAILPARSE_DECODE_NOHEADERS ? part->bodystart : part->startpos;
+
+ if (decode & MAILPARSE_DECODE_NOBODY)
+ end = part->bodystart;
+ else
+ end = part->parent ? part->bodyend : part->endpos;
+
+ php_mimepart_decoder_prepare(part, decode & MAILPARSE_DECODE_8BIT, callback, callbackdata TSRMLS_CC);
+
+ if (php_stream_seek(src, start_pos, SEEK_SET) == -1) {
+ zend_error(E_WARNING, "%s(): unable to seek to section start", get_active_function_name(TSRMLS_C));
+ goto cleanup;
+ }
+
+ filebuf = emalloc(MAILPARSE_BUFSIZ);
+
+ while (start_pos < end)
+ {
+ size_t n = MAILPARSE_BUFSIZ - 1;
+
+ if ((off_t)n > end - start_pos)
+ n = end - start_pos;
+
+ n = php_stream_read(src, filebuf, n);
+
+ if (n == 0)
+ {
+ zend_error(E_WARNING, "%s(): error reading from file at offset %lld", get_active_function_name(TSRMLS_C), start_pos);
+ goto cleanup;
+ }
+
+ filebuf[n] = '\0';
+
+ php_mimepart_decoder_feed(part, filebuf, n TSRMLS_CC);
+
+ start_pos += n;
+ }
+ ret = SUCCESS;
+
+cleanup:
+ php_mimepart_decoder_finish(part TSRMLS_CC);
+
+ if (filebuf)
+ efree(filebuf);
+
+ return ret;
+}
+
+static void mailparse_do_extract(INTERNAL_FUNCTION_PARAMETERS, int decode, int isfile)
+{
+ zval *zpart, *filename, *callbackfunc = NULL;
+ php_mimepart *part;
+ php_stream *srcstream = NULL, *deststream = NULL;
+ php_mimepart_extract_func_t cbfunc = NULL;
+ void *cbdata = NULL;
+ int close_src_stream = 0;
+
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &zpart, &filename, &callbackfunc)) {
+ RETURN_FALSE;
+ }
+
+ mailparse_fetch_mimepart_resource(part, &zpart);
+
+ /* filename can be a filename or a stream */
+ if (Z_TYPE_P(filename) == IS_RESOURCE) {
+ php_stream_from_zval(srcstream, &filename);
+ } else if (isfile) {
+ convert_to_string_ex(&filename);
+ srcstream = php_stream_open_wrapper(Z_STRVAL_P(filename), "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
+ close_src_stream = 1;
+ } else {
+ /* filename is the actual data */
+ srcstream = php_stream_memory_open(TEMP_STREAM_READONLY, Z_STRVAL_P(filename), Z_STRLEN_P(filename));
+ close_src_stream = 1;
+ }
+
+ if (srcstream == NULL) {
+ RETURN_FALSE;
+ }
+
+ if (callbackfunc != NULL) {
+ if (Z_TYPE_P(callbackfunc) == IS_NULL) {
+ cbfunc = extract_callback_stream;
+ cbdata = deststream = php_stream_memory_create(TEMP_STREAM_DEFAULT);
+ } else if (Z_TYPE_P(callbackfunc) == IS_RESOURCE) {
+ php_stream_from_zval(deststream, &callbackfunc);
+ cbfunc = extract_callback_stream;
+ cbdata = deststream;
+ deststream = NULL; /* don't free this one */
+ } else {
+ if (Z_TYPE_P(callbackfunc) != IS_ARRAY)
+ convert_to_string_ex(&callbackfunc);
+ cbfunc = (php_mimepart_extract_func_t)&extract_callback_user_func;
+ cbdata = callbackfunc;
+ }
+ } else {
+ cbfunc = extract_callback_stdout;
+ cbdata = NULL;
+ }
+
+ RETVAL_FALSE;
+
+ if (SUCCESS == extract_part(part, decode, srcstream, cbdata, cbfunc TSRMLS_CC)) {
+
+ if (deststream != NULL) {
+ /* return it's contents as a string */
+ char *membuf = NULL;
+ size_t memlen = 0;
+ membuf = php_stream_memory_get_buffer(deststream, &memlen);
+ RETVAL_STRINGL(membuf, memlen, 1);
+
+ } else {
+ RETVAL_TRUE;
+ }
+ }
+
+ if (deststream)
+ php_stream_close(deststream);
+ if (close_src_stream && srcstream)
+ php_stream_close(srcstream);
+}
+
+/* {{{ proto void mailparse_msg_extract_part(resource mimepart, string msgbody[, string callbackfunc])
+ Extracts/decodes a message section. If callbackfunc is not specified, the contents will be sent to "stdout" */
+PHP_FUNCTION(mailparse_msg_extract_part)
+{
+ mailparse_do_extract(INTERNAL_FUNCTION_PARAM_PASSTHRU, MAILPARSE_DECODE_8BIT | MAILPARSE_DECODE_NOHEADERS, 0);
+}
+/* }}} */
+
+/* {{{ proto string mailparse_msg_extract_whole_part_file(resource mimepart, string filename [, string callbackfunc])
+ Extracts a message section including headers without decoding the transfer encoding */
+PHP_FUNCTION(mailparse_msg_extract_whole_part_file)
+{
+ mailparse_do_extract(INTERNAL_FUNCTION_PARAM_PASSTHRU, MAILPARSE_DECODE_NONE, 1);
+}
+/* }}} */
+
+/* {{{ proto string mailparse_msg_extract_part_file(resource mimepart, string filename [, string callbackfunc])
+ Extracts/decodes a message section, decoding the transfer encoding */
+PHP_FUNCTION(mailparse_msg_extract_part_file)
+{
+ mailparse_do_extract(INTERNAL_FUNCTION_PARAM_PASSTHRU, MAILPARSE_DECODE_8BIT | MAILPARSE_DECODE_NOHEADERS, 1);
+}
+/* }}} */
+
+static void add_attr_header_to_zval(char *valuelabel, char *attrprefix, zval *return_value,
+ struct php_mimeheader_with_attributes *attr TSRMLS_DC)
+{
+ HashPosition pos;
+ zval **val;
+ char *key, *newkey;
+ long num_index;
+ uint key_len, pref_len;
+
+ pref_len = strlen(attrprefix);
+
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(attr->attributes), &pos);
+ while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(attr->attributes), (void**)&val, &pos)) {
+
+ zend_hash_get_current_key_ex(Z_ARRVAL_P(attr->attributes), &key, &key_len, &num_index, 0, &pos);
+
+ if (key_len) {
+ spprintf(&newkey, 0, "%s%s", attrprefix, key);
+ } else {
+ spprintf(&newkey, 0, "%s%d", attrprefix, num_index);
+ }
+ add_assoc_string(return_value, newkey, Z_STRVAL_PP(val), 1);
+ efree(newkey);
+
+ zend_hash_move_forward_ex(Z_ARRVAL_P(attr->attributes), &pos);
+ }
+
+ /* do this last so that a bogus set of headers like this:
+ * Content-Type: multipart/related;
+ * boundary="----=_NextPart_00_0017_01C091F4.1B5EF6B0";
+ * type="text/html"
+ *
+ * doesn't overwrite content-type with the type="text/html"
+ * value.
+ * */
+ add_assoc_string(return_value, valuelabel, attr->value, 1);
+}
+
+static void add_header_reference_to_zval(char *headerkey, zval *return_value, zval *headers TSRMLS_DC)
+{
+ zval **headerval;
+ zval *newhdr;
+
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(headers), headerkey, strlen(headerkey)+1, (void**)&headerval)) {
+ MAKE_STD_ZVAL(newhdr);
+ *newhdr = **headerval;
+ Z_SET_REFCOUNT_P(newhdr, 1);
+ zval_copy_ctor(newhdr);
+ add_assoc_zval(return_value, headerkey, newhdr);
+ }
+}
+
+static int mailparse_get_part_data(php_mimepart *part, zval *return_value TSRMLS_DC)
+{
+ zval *headers, **tmpval;
+ off_t startpos, endpos, bodystart;
+ int nlines, nbodylines;
+
+ array_init(return_value);
+
+ /* get headers for this section */
+ MAKE_STD_ZVAL(headers);
+ *headers = *part->headerhash;
+ zval_copy_ctor(headers);
+
+ add_assoc_zval(return_value, "headers", headers);
+
+ php_mimepart_get_offsets(part, &startpos, &endpos, &bodystart, &nlines, &nbodylines);
+
+ add_assoc_long(return_value, "starting-pos", startpos);
+ add_assoc_long(return_value, "starting-pos-body", bodystart);
+ add_assoc_long(return_value, "ending-pos", endpos);
+ add_assoc_long(return_value, "ending-pos-body", part->bodyend);
+ add_assoc_long(return_value, "line-count", nlines);
+ add_assoc_long(return_value, "body-line-count", nbodylines);
+
+ if (part->charset)
+ add_assoc_string(return_value, "charset", part->charset, 1);
+ else
+ add_assoc_string(return_value, "charset", MAILPARSEG(def_charset), 1);
+
+ if (part->content_transfer_encoding)
+ add_assoc_string(return_value, "transfer-encoding", part->content_transfer_encoding, 1);
+ else
+ add_assoc_string(return_value, "transfer-encoding", "8bit", 1);
+
+ if (part->content_type)
+ add_attr_header_to_zval("content-type", "content-", return_value, part->content_type TSRMLS_CC);
+ else
+ add_assoc_string(return_value, "content-type", "text/plain; (error)", 1);
+
+ if (part->content_disposition)
+ add_attr_header_to_zval("content-disposition", "disposition-", return_value, part->content_disposition TSRMLS_CC);
+
+ if (part->content_location)
+ add_assoc_string(return_value, "content-location", part->content_location, 1);
+
+ if (part->content_base)
+ add_assoc_string(return_value, "content-base", part->content_base, 1);
+ else
+ add_assoc_string(return_value, "content-base", "/", 1);
+
+ if (part->boundary)
+ add_assoc_string(return_value, "content-boundary", part->boundary, 1);
+
+ /* extract the address part of the content-id only */
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(headers), "content-id", sizeof("content-id"), (void**)&tmpval)) {
+ php_rfc822_tokenized_t *toks;
+ php_rfc822_addresses_t *addrs;
+
+ toks = php_mailparse_rfc822_tokenize((const char*)Z_STRVAL_PP(tmpval), 1 TSRMLS_CC);
+ addrs = php_rfc822_parse_address_tokens(toks);
+ if (addrs->naddrs > 0)
+ add_assoc_string(return_value, "content-id", addrs->addrs[0].address, 1);
+ php_rfc822_free_addresses(addrs);
+ php_rfc822_tokenize_free(toks);
+ }
+
+ add_header_reference_to_zval("content-description", return_value, headers TSRMLS_CC);
+ add_header_reference_to_zval("content-language", return_value, headers TSRMLS_CC);
+ add_header_reference_to_zval("content-md5", return_value, headers TSRMLS_CC);
+
+ return SUCCESS;
+}
+
+/* {{{ proto array mailparse_msg_get_part_data(resource mimepart)
+ Returns an associative array of info about the message */
+PHP_FUNCTION(mailparse_msg_get_part_data)
+{
+ zval *arg;
+ php_mimepart *part;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ mailparse_fetch_mimepart_resource(part, &arg);
+
+ mailparse_get_part_data(part, return_value TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto int mailparse_msg_get_part(resource mimepart, string mimesection)
+ Returns a handle on a given section in a mimemessage */
+PHP_FUNCTION(mailparse_msg_get_part)
+{
+ zval *arg;
+ php_mimepart *part, *foundpart;
+ char *mimesection;
+ int mimesection_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &arg, &mimesection, &mimesection_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ mailparse_fetch_mimepart_resource(part, &arg);
+
+ foundpart = php_mimepart_find_by_name(part, mimesection TSRMLS_CC);
+
+ if (!foundpart) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot find section %s in message", mimesection);
+ RETURN_FALSE;
+ }
+ zend_list_addref(foundpart->rsrc_id);
+ php_mimepart_to_zval(return_value, foundpart);
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse.h
^
|
@@ -0,0 +1,134 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com> |
+ | Credit also given to Double Precision Inc. who wrote the code that |
+ | the support routines for this extension were based upon. |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: php_mailparse.h 276739 2009-03-03 23:09:08Z shire $ */
+
+#ifndef PHP_MAILPARSE_H
+#define PHP_MAILPARSE_H
+
+extern zend_module_entry mailparse_module_entry;
+#define phpext_mailparse_ptr &mailparse_module_entry
+
+#define PHP_MAILPARSE_VERSION "2.1.6"
+
+#ifdef PHP_WIN32
+#define PHP_MAILPARSE_API __declspec(dllexport)
+#else
+#define PHP_MAILPARSE_API
+#endif
+
+#ifndef Z_SET_REFCOUNT_P
+# if PHP_MAJOR_VERSION < 6 && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3)
+# define Z_SET_REFCOUNT_P(pz, rc) (pz)->refcount = rc
+# define Z_UNSET_ISREF_P(pz) (pz)->is_ref = 0
+# define Z_DELREF_P(pz) (pz)->refcount--
+# define Z_REFCOUNT_P(pz) (pz)->refcount
+# define Z_ISREF_P(pz) (pz)->is_ref
+# define Z_ADDREF_P(pz) (pz)->refcount++
+# define Z_SET_ISREF_TO_P(pz, isref) (pz)->is_ref = isref
+# endif
+#endif
+
+PHP_MINIT_FUNCTION(mailparse);
+PHP_MSHUTDOWN_FUNCTION(mailparse);
+PHP_RINIT_FUNCTION(mailparse);
+PHP_RSHUTDOWN_FUNCTION(mailparse);
+PHP_MINFO_FUNCTION(mailparse);
+
+PHP_FUNCTION(mailparse_msg_parse_file);
+PHP_FUNCTION(mailparse_msg_get_part);
+PHP_FUNCTION(mailparse_msg_get_structure);
+PHP_FUNCTION(mailparse_msg_get_part_data);
+PHP_FUNCTION(mailparse_msg_extract_part);
+PHP_FUNCTION(mailparse_msg_extract_part_file);
+PHP_FUNCTION(mailparse_msg_extract_whole_part_file);
+
+PHP_FUNCTION(mailparse_msg_create);
+PHP_FUNCTION(mailparse_msg_free);
+PHP_FUNCTION(mailparse_msg_parse);
+PHP_FUNCTION(mailparse_msg_parse_file);
+
+PHP_FUNCTION(mailparse_msg_find);
+PHP_FUNCTION(mailparse_msg_getstructure);
+PHP_FUNCTION(mailparse_msg_getinfo);
+PHP_FUNCTION(mailparse_msg_extract);
+PHP_FUNCTION(mailparse_msg_extract_file);
+PHP_FUNCTION(mailparse_rfc822_parse_addresses);
+PHP_FUNCTION(mailparse_determine_best_xfer_encoding);
+PHP_FUNCTION(mailparse_stream_encode);
+PHP_FUNCTION(mailparse_uudecode_all);
+
+PHP_FUNCTION(mailparse_test);
+
+PHP_MAILPARSE_API int php_mailparse_le_mime_part(void);
+
+/* mimemessage object */
+PHP_FUNCTION(mailparse_mimemessage);
+PHP_FUNCTION(mailparse_mimemessage_get_parent);
+PHP_FUNCTION(mailparse_mimemessage_get_child);
+PHP_FUNCTION(mailparse_mimemessage_get_child_count);
+PHP_FUNCTION(mailparse_mimemessage_extract_headers);
+PHP_FUNCTION(mailparse_mimemessage_extract_body);
+PHP_FUNCTION(mailparse_mimemessage_enum_uue);
+PHP_FUNCTION(mailparse_mimemessage_extract_uue);
+PHP_FUNCTION(mailparse_mimemessage_remove);
+PHP_FUNCTION(mailparse_mimemessage_add_child);
+
+/* PHP 4.3.4 moved the mbfilter header around */
+#if PHP_MAJOR_VERSION == 4 && ((PHP_MINOR_VERSION < 3) || (PHP_MINOR_VERSION == 3 && PHP_RELEASE_VERSION < 4))
+# include "ext/mbstring/mbfilter.h"
+# define MAILPARSE_MBSTRING_TSRMLS_CC TSRMLS_CC
+# define MAILPARSE_MBSTRING_TSRMLS_DC TSRMLS_DC
+# define MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD() /* sanity */
+#else
+# include "ext/mbstring/libmbfl/mbfl/mbfilter.h"
+/* ugh, even worse, they changed the signature of the API and made it
+ * really slow for threaded PHP builds */
+# define MAILPARSE_MBSTRING_TSRMLS_CC /* pain */
+# define MAILPARSE_MBSTRING_TSRMLS_DC /* pain */
+# define MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD() TSRMLS_FETCH()
+#endif
+
+#include "php_mailparse_rfc822.h"
+#include "php_mailparse_mime.h"
+
+#define MAILPARSE_BUFSIZ 4096
+ZEND_BEGIN_MODULE_GLOBALS(mailparse)
+ char * def_charset; /* default charset for use in (re)writing mail */
+ZEND_END_MODULE_GLOBALS(mailparse);
+
+extern ZEND_DECLARE_MODULE_GLOBALS(mailparse);
+
+
+#ifdef ZTS
+#define MAILPARSEG(v) TSRMG(mailparse_globals_id, zend_mailparse_globals *, v)
+#else
+#define MAILPARSEG(v) (mailparse_globals.v)
+#endif
+
+#endif
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim: sw=4 ts=4
+ */
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse_mime.c
^
|
@@ -0,0 +1,968 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: php_mailparse_mime.c 305002 2010-10-31 15:46:48Z cataphract $ */
+
+#include "php.h"
+#include "php_mailparse.h"
+#include "php_mailparse_mime.h"
+#include "php_mailparse_rfc822.h"
+
+#define MAXLEVELS 20
+#define MAXPARTS 300
+#define IS_MIME_1(part) (((part)->mime_version && strcmp("1.0", (part)->mime_version) == 0) || ((part)->parent))
+#define CONTENT_TYPE_IS(part, contenttypevalue) ((part)->content_type && strcasecmp((part)->content_type->value, contenttypevalue) == 0)
+#define CONTENT_TYPE_ISL(part, contenttypevalue, len) ((part)->content_type && strncasecmp((part)->content_type->value, contenttypevalue, len) == 0)
+
+static void php_mimeheader_free(struct php_mimeheader_with_attributes *attr)
+{
+ STR_FREE(attr->value);
+ zval_dtor(attr->attributes);
+ efree(attr->attributes);
+ efree(attr);
+}
+
+static struct php_mimeheader_with_attributes * php_mimeheader_alloc(char *value)
+{
+ struct php_mimeheader_with_attributes *attr;
+
+ attr = ecalloc(1, sizeof(struct php_mimeheader_with_attributes));
+
+ MAKE_STD_ZVAL(attr->attributes);
+ array_init(attr->attributes);
+
+ attr->value = estrdup(value);
+
+ return attr;
+}
+
+void rfc2231_to_mime(smart_str* value_buf, char* value, int charset_p, int prevcharset_p)
+{
+ char *strp, *startofvalue = NULL;
+ int quotes = 0;
+
+ /* Process string, get positions and replace */
+ /* Set to start of buffer*/
+ if (charset_p) {
+
+ /* Previous charset already set so only convert %nn to =nn*/
+ if (prevcharset_p) quotes=2;
+
+ strp = value;
+ while (*strp) {
+
+ /* Quote handling*/
+ if (*strp == '\'')
+ {
+ if (quotes <= 1) {
+
+ /* End of charset*/
+ if (quotes == 0) {
+ *strp=0;
+ } else {
+ startofvalue = strp+1;
+ }
+
+ quotes++;
+ }
+ } else {
+ /* Replace % with = - quoted printable*/
+ if (*strp == '%' && quotes==2)
+ {
+ *strp = '=';
+ }
+ }
+ strp++;
+ }
+ }
+
+ /* If first encoded token*/
+ if (charset_p && !prevcharset_p && startofvalue) {
+ smart_str_appends(value_buf, "=?");
+ smart_str_appends(value_buf, value);
+ smart_str_appends(value_buf, "?Q?");
+ smart_str_appends(value_buf, startofvalue);
+ }
+
+ /* If last encoded token*/
+ if (prevcharset_p && !charset_p)
+ {
+ smart_str_appends(value_buf, "?=");
+ }
+
+ /* Append value*/
+ if ((!charset_p || (prevcharset_p && charset_p)) && value)
+ {
+ smart_str_appends(value_buf, value);
+ }
+}
+
+static struct php_mimeheader_with_attributes *php_mimeheader_alloc_from_tok(php_rfc822_tokenized_t *toks)
+{
+ struct php_mimeheader_with_attributes *attr;
+ int i, first_semi, next_semi, comments_before_semi, netscape_bug = 0;
+ char *name_buf = NULL;
+ smart_str value_buf = {0};
+ int is_rfc2231_name = 0;
+ char *check_name;
+ int charset_p, prevcharset_p = 0;
+ int namechanged, currentencoded = 0;
+
+ attr = ecalloc(1, sizeof(struct php_mimeheader_with_attributes));
+
+ MAKE_STD_ZVAL(attr->attributes);
+ array_init(attr->attributes);
+
+/* php_rfc822_print_tokens(toks); */
+
+ /* look for optional ; which separates optional attributes from the main value */
+ for (first_semi = 2; first_semi < toks->ntokens; first_semi++)
+ if (toks->tokens[first_semi].token == ';')
+ break;
+
+ attr->value = php_rfc822_recombine_tokens(toks, 2, first_semi - 2,
+ PHP_RFC822_RECOMBINE_STRTOLOWER | PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
+
+ if (first_semi < toks->ntokens)
+ first_semi++;
+
+ /* Netscape Bug: Messenger sometimes omits the semi when wrapping the
+ * the header.
+ * That means we have to be even more clever than the spec says that
+ * we need to :-/
+ * */
+
+ while (first_semi < toks->ntokens) {
+ /* find the next ; */
+ comments_before_semi = 0;
+ for (next_semi = first_semi; next_semi < toks->ntokens; next_semi++) {
+ if (toks->tokens[next_semi].token == ';')
+ break;
+ if (toks->tokens[next_semi].token == '(')
+ comments_before_semi++;
+ }
+
+
+ i = first_semi;
+ if (i < next_semi) {
+ i++;
+
+ /* ignore comments */
+ while (i < next_semi && toks->tokens[i].token == '(')
+ i++;
+
+ if (i < next_semi && toks->tokens[i].token == '=') {
+ char *name, *value;
+
+ /* Here, next_semi --> "name" and i --> "=", so skip "=" sign */
+ i++;
+
+ /* count those tokens; we expect "token = token" (3 tokens); if there are
+ * more than that, then something is quite possibly wrong - Netscape Bug! */
+ if (next_semi < toks->ntokens
+ && toks->tokens[next_semi].token != ';'
+ && next_semi - first_semi - comments_before_semi > 3) {
+ next_semi = i + 1;
+ netscape_bug = 1;
+ }
+
+ name = php_rfc822_recombine_tokens(toks, first_semi, 1,
+ PHP_RFC822_RECOMBINE_STRTOLOWER|PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
+ value = php_rfc822_recombine_tokens(toks, i, next_semi - i,
+ PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
+
+ /* support rfc2231 mime parameter value
+ *
+ * Parameter Value Continuations:
+ *
+ * Content-Type: message/external-body; access-type=URL;
+ * URL*0="ftp://";
+ * URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
+ *
+ * is semantically identical to
+ *
+ * Content-Type: message/external-body; access-type=URL;
+ * URL="ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
+ *
+ * Original rfc2231 support by IceWarp Ltd. <info@icewarp.com>
+ */
+ check_name = strchr(name, '*');
+ if (check_name) {
+ currentencoded = 1;
+
+ /* Is last char * - charset encoding */
+ charset_p = *(name+strlen(name)-1) == '*';
+
+ /* Leave only attribute name without * */
+ *check_name = 0;
+
+ /* New item or continuous */
+ if (NULL == name_buf) {
+ namechanged = 0;
+ name_buf = name;
+ } else {
+ namechanged = (strcmp(name_buf, name) != 0);
+ if (!namechanged) {
+ efree(name);
+ name = 0;
+ }
+ }
+
+ /* Check if name changed*/
+ if (!namechanged) {
+
+ /* Append string to buffer - check if to be encoded... */
+ rfc2231_to_mime(&value_buf, value, charset_p, prevcharset_p);
+ efree(value);
+
+ /* Mark previous */
+ prevcharset_p = charset_p;
+ }
+
+ is_rfc2231_name = 1;
+ }
+
+ /* Last item was encoded */
+ if (1 == is_rfc2231_name) {
+ /* Name not null and name differs with new name*/
+ if (name && strcmp(name_buf, name) != 0) {
+ /* Finalize packet */
+ rfc2231_to_mime(&value_buf, NULL, 0, prevcharset_p);
+
+ add_assoc_string(attr->attributes, name_buf, estrndup(value_buf.c, value_buf.len), 0);
+ efree(name_buf);
+ smart_str_free(&value_buf);
+
+ prevcharset_p = 0;
+ is_rfc2231_name = 0;
+ name_buf = NULL;
+
+ /* New non encoded name*/
+ if (!currentencoded) {
+ /* Add string*/
+ add_assoc_string(attr->attributes, name, value, 0);
+ efree(name);
+ } else { /* Encoded name changed*/
+ if (namechanged) {
+ /* Append string to buffer - check if to be encoded... */
+ rfc2231_to_mime(&value_buf, value, charset_p, prevcharset_p);
+ efree(value);
+
+ /* Mark */
+ is_rfc2231_name = 1;
+ name_buf = name;
+ prevcharset_p = charset_p;
+ }
+ }
+
+ namechanged = 0;
+ }
+ } else {
+ add_assoc_string(attr->attributes, name, value, 0);
+ efree(name);
+ }
+ }
+ }
+
+ if (next_semi < toks->ntokens && !netscape_bug) {
+ next_semi++;
+ }
+
+ first_semi = next_semi;
+ netscape_bug = 0;
+ }
+
+ if (1 == is_rfc2231_name) {
+ /* Finalize packet */
+ rfc2231_to_mime(&value_buf, NULL, 0, prevcharset_p);
+
+ add_assoc_string(attr->attributes, name_buf, estrndup(value_buf.c, value_buf.len), 0);
+ efree(name_buf);
+ smart_str_free(&value_buf);
+ }
+
+
+ return attr;
+}
+
+static void php_mimepart_free_child(php_mimepart **part)
+{
+ TSRMLS_FETCH();
+ php_mimepart_free(*part TSRMLS_CC);
+}
+
+PHP_MAILPARSE_API php_mimepart *php_mimepart_alloc(TSRMLS_D)
+{
+ php_mimepart *part = ecalloc(1, sizeof(php_mimepart));
+
+ part->part_index = 1;
+
+ zend_hash_init(&part->children, 0, NULL, (dtor_func_t)php_mimepart_free_child, 0);
+
+ MAKE_STD_ZVAL(part->headerhash);
+ array_init(part->headerhash);
+
+ MAKE_STD_ZVAL(part->source.zval);
+ Z_TYPE_P(part->source.zval) = IS_NULL;
+
+ /* begin in header parsing mode */
+ part->parsedata.in_header = 1;
+ part->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, part, php_mailparse_le_mime_part());
+
+ return part;
+}
+
+
+PHP_MAILPARSE_API void php_mimepart_free(php_mimepart *part TSRMLS_DC)
+{
+ if (part->rsrc_id) {
+ long tmp = part->rsrc_id;
+ part->rsrc_id = 0;
+ zend_list_delete(tmp);
+ if (part->parent != NULL && part->parent->rsrc_id > 0)
+ return;
+ }
+
+ /* free contained parts */
+
+ zend_hash_destroy(&part->children);
+
+ STR_FREE(part->mime_version);
+ STR_FREE(part->content_transfer_encoding);
+ STR_FREE(part->charset);
+ STR_FREE(part->boundary);
+ STR_FREE(part->content_base);
+ STR_FREE(part->content_location);
+
+ if (part->content_type) {
+ php_mimeheader_free(part->content_type);
+ part->content_type = NULL;
+ }
+ if (part->content_disposition) {
+ php_mimeheader_free(part->content_disposition);
+ part->content_disposition = NULL;
+ }
+
+ smart_str_free(&part->parsedata.workbuf);
+ smart_str_free(&part->parsedata.headerbuf);
+
+ zval_ptr_dtor(&part->source.zval);
+
+ zval_ptr_dtor(&part->headerhash);
+
+ efree(part);
+}
+
+static void php_mimepart_update_positions(php_mimepart *part, size_t newendpos, size_t newbodyend, size_t deltanlines)
+{
+ while(part) {
+ part->endpos = newendpos;
+ part->bodyend = newbodyend;
+ part->nlines += deltanlines;
+ if (!part->parsedata.in_header)
+ part->nbodylines += deltanlines;
+ part = part->parent;
+ }
+}
+
+PHP_MAILPARSE_API char *php_mimepart_attribute_get(struct php_mimeheader_with_attributes *attr, char *attrname)
+{
+ zval **attrval;
+
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(attr->attributes), attrname, strlen(attrname)+1, (void**)&attrval))
+ return Z_STRVAL_PP(attrval);
+ return NULL;
+}
+
+#define STR_SET_REPLACE(ptr, newval) do { STR_FREE(ptr); ptr = estrdup(newval); } while(0)
+
+static int php_mimepart_process_header(php_mimepart *part TSRMLS_DC)
+{
+ php_rfc822_tokenized_t *toks;
+ char *header_key, *header_val, *header_val_stripped;
+ zval **zheaderval;
+
+ if (part->parsedata.headerbuf.len == 0)
+ return SUCCESS;
+
+ smart_str_0(&part->parsedata.headerbuf);
+
+ /* parse the header line */
+ toks = php_mailparse_rfc822_tokenize((const char*)part->parsedata.headerbuf.c, 0 TSRMLS_CC);
+
+ /* valid headers consist of at least three tokens, with the first being a string and the
+ * second token being a ':' */
+ if (toks->ntokens < 2 || toks->tokens[0].token != 0 || toks->tokens[1].token != ':') {
+ part->parsedata.headerbuf.len = 0;
+
+ php_rfc822_tokenize_free(toks);
+ return FAILURE;
+ }
+
+ /* get a lower-case version of the first token */
+ header_key = php_rfc822_recombine_tokens(toks, 0, 1, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|PHP_RFC822_RECOMBINE_STRTOLOWER);
+
+ header_val = strchr(part->parsedata.headerbuf.c, ':');
+ header_val_stripped = php_rfc822_recombine_tokens(toks, 2, toks->ntokens-2, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|PHP_RFC822_RECOMBINE_STRTOLOWER);
+
+ if (header_val) {
+ header_val++;
+ while (isspace(*header_val))
+ header_val++;
+
+ /* add the header to the hash.
+ * join multiple To: or Cc: lines together */
+ if ((strcmp(header_key, "to") == 0 || strcmp(header_key, "cc") == 0) &&
+ SUCCESS == zend_hash_find(Z_ARRVAL_P(part->headerhash), header_key, strlen(header_key)+1, (void**)&zheaderval)) {
+ int newlen;
+ char *newstr;
+
+ newlen = strlen(header_val) + Z_STRLEN_PP(zheaderval) + 3;
+ newstr = emalloc(newlen);
+
+ strcpy(newstr, Z_STRVAL_PP(zheaderval));
+ strcat(newstr, ", ");
+ strcat(newstr, header_val);
+ add_assoc_string(part->headerhash, header_key, newstr, 0);
+ } else {
+ if(zend_hash_find(Z_ARRVAL_P(part->headerhash), header_key, strlen(header_key)+1, (void**)&zheaderval) == SUCCESS) {
+ if(Z_TYPE_PP(zheaderval) == IS_ARRAY) {
+ add_next_index_string(*zheaderval, header_val, 1);
+ } else {
+ /* Create a nested array if there is more than one of the same header */
+ zval *zarr;
+ MAKE_STD_ZVAL(zarr);
+ array_init(zarr);
+ Z_ADDREF_P(*zheaderval);
+
+ add_next_index_zval(zarr, *zheaderval);
+ add_next_index_string(zarr, header_val, 1);
+ add_assoc_zval(part->headerhash, header_key, zarr);
+ }
+ } else {
+ add_assoc_string(part->headerhash, header_key, header_val, 1);
+ }
+ }
+
+ /* if it is useful, keep a pointer to it in the mime part */
+ if (strcmp(header_key, "mime-version") == 0)
+ STR_SET_REPLACE(part->mime_version, header_val_stripped);
+
+ if (strcmp(header_key, "content-location") == 0) {
+ STR_FREE(part->content_location);
+ part->content_location = php_rfc822_recombine_tokens(toks, 2, toks->ntokens-2, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
+ }
+ if (strcmp(header_key, "content-base") == 0) {
+ STR_FREE(part->content_base);
+ part->content_base = php_rfc822_recombine_tokens(toks, 2, toks->ntokens-2, PHP_RFC822_RECOMBINE_IGNORE_COMMENTS);
+ }
+
+ if (strcmp(header_key, "content-transfer-encoding") == 0)
+ STR_SET_REPLACE(part->content_transfer_encoding, header_val_stripped);
+ if (strcmp(header_key, "content-type") == 0) {
+ char *charset, *boundary;
+
+ if (part->content_type) {
+ php_mimeheader_free(part->content_type);
+ part->content_type = NULL;
+ }
+
+ part->content_type = php_mimeheader_alloc_from_tok(toks);
+
+ boundary = php_mimepart_attribute_get(part->content_type, "boundary");
+ if (boundary) {
+ part->boundary = estrdup(boundary);
+ }
+
+ charset = php_mimepart_attribute_get(part->content_type, "charset");
+ if (charset) {
+ STR_SET_REPLACE(part->charset, charset);
+ }
+ }
+ if (strcmp(header_key, "content-disposition") == 0) {
+ part->content_disposition = php_mimeheader_alloc_from_tok(toks);
+ }
+
+ }
+ STR_FREE(header_key);
+ STR_FREE(header_val_stripped);
+
+ php_rfc822_tokenize_free(toks);
+
+ /* zero the buffer size */
+ part->parsedata.headerbuf.len = 0;
+ return SUCCESS;
+}
+
+static php_mimepart *alloc_new_child_part(php_mimepart *parentpart, size_t startpos, int inherit TSRMLS_DC)
+{
+ php_mimepart *child = php_mimepart_alloc(TSRMLS_C);
+ int ret;
+
+ parentpart->parsedata.lastpart = child;
+ child->parent = parentpart;
+
+ child->source.kind = parentpart->source.kind;
+ if (parentpart->source.kind != mpNONE) {
+ *child->source.zval = *parentpart->source.zval;
+ zval_copy_ctor(child->source.zval);
+ }
+
+ ret = zend_hash_next_index_insert(&parentpart->children, (void*)&child, sizeof(php_mimepart *), NULL);
+ child->startpos = child->endpos = child->bodystart = child->bodyend = startpos;
+
+ if (inherit) {
+ if (parentpart->content_transfer_encoding)
+ child->content_transfer_encoding = estrdup(parentpart->content_transfer_encoding);
+ if (parentpart->charset)
+ child->charset = estrdup(parentpart->charset);
+ }
+
+ return child;
+}
+
+PHP_MAILPARSE_API void php_mimepart_get_offsets(php_mimepart *part, off_t *start, off_t *end, off_t *start_body, int *nlines, int *nbodylines)
+{
+ *start = part->startpos;
+ *end = part->endpos;
+ *nlines = part->nlines;
+ *nbodylines = part->nbodylines;
+ *start_body = part->bodystart;
+
+ /* Adjust for newlines in mime parts */
+ if (part->parent) {
+ *end = part->bodyend;
+ if (*nlines)
+ --*nlines;
+ if (*nbodylines)
+ --*nbodylines;
+ }
+}
+
+static int php_mimepart_process_line(php_mimepart *workpart TSRMLS_DC)
+{
+ size_t origcount, linelen;
+ char *c;
+
+ /* sanity check */
+ if (zend_hash_num_elements(&workpart->children) > MAXPARTS) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "MIME message too complex");
+ return FAILURE;
+ }
+
+ c = workpart->parsedata.workbuf.c;
+ smart_str_0(&workpart->parsedata.workbuf);
+
+ /* strip trailing \r\n -- we always have a trailing \n */
+ origcount = workpart->parsedata.workbuf.len;
+ linelen = origcount - 1;
+ if (linelen && c[linelen-1] == '\r')
+ --linelen;
+
+ /* Discover which part we were last working on */
+ while (workpart->parsedata.lastpart) {
+ size_t bound_len;
+ php_mimepart *lastpart = workpart->parsedata.lastpart;
+
+ if (lastpart->parsedata.completed) {
+ php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1);
+ return SUCCESS;
+ }
+ if (workpart->boundary == NULL || workpart->parsedata.in_header) {
+ workpart = lastpart;
+ continue;
+ }
+ bound_len = strlen(workpart->boundary);
+
+ /* Look for a boundary */
+ if (c[0] == '-' && c[1] == '-' && linelen >= 2+bound_len && strncasecmp(workpart->boundary, c+2, bound_len) == 0) {
+ php_mimepart *newpart;
+
+ /* is it the final boundary ? */
+ if (linelen >= 4 + bound_len && strncmp(c+2+bound_len, "--", 2) == 0) {
+ lastpart->parsedata.completed = 1;
+ php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1);
+ return SUCCESS;
+ }
+
+ newpart = alloc_new_child_part(workpart, workpart->endpos + origcount, 1 TSRMLS_CC);
+ php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1);
+ newpart->mime_version = estrdup(workpart->mime_version);
+ newpart->parsedata.in_header = 1;
+ return SUCCESS;
+ }
+ workpart = lastpart;
+ }
+
+ if (!workpart->parsedata.in_header) {
+ if (!workpart->parsedata.completed && !workpart->parsedata.lastpart) {
+ /* update the body/part end positions.
+ * For multipart messages, the final newline belongs to the boundary.
+ * Otherwise it belongs to the body
+ * */
+ if (workpart->parent && CONTENT_TYPE_ISL(workpart->parent, "multipart/", 10)) {
+ php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1);
+ } else {
+ php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + origcount, 1);
+ }
+ }
+ } else {
+
+ if (linelen > 0) {
+
+ php_mimepart_update_positions(workpart, workpart->endpos + origcount, workpart->endpos + linelen, 1);
+
+ if(*c == ' ' || *c == '\t') {
+ /* This doesn't technically confirm to rfc2822, as we're replacing \t with \s, but this seems to fix
+ * cases where clients incorrectly fold by inserting a \t character.
+ */
+ smart_str_appendl(&workpart->parsedata.headerbuf, " ", 1);
+ c++; linelen--;
+ } else {
+ php_mimepart_process_header(workpart TSRMLS_CC);
+ }
+ /* save header for possible continuation */
+ smart_str_appendl(&workpart->parsedata.headerbuf, c, linelen);
+
+ } else {
+ /* end of headers */
+ php_mimepart_process_header(workpart TSRMLS_CC);
+
+ /* start of body */
+ workpart->parsedata.in_header = 0;
+ workpart->bodystart = workpart->endpos + origcount;
+ php_mimepart_update_positions(workpart, workpart->bodystart, workpart->bodystart, 1);
+ --workpart->nbodylines;
+
+ /* some broken mailers include the content-type header but not a mime-version header.
+ * Let's relax and pretend they said they were mime 1.0 compatible */
+ if (workpart->mime_version == NULL && workpart->content_type != NULL)
+ workpart->mime_version = estrdup("1.0");
+
+ if (!IS_MIME_1(workpart)) {
+ /* if we don't understand the MIME version, discard the content-type and
+ * boundary */
+ if (workpart->content_disposition) {
+ php_mimeheader_free(workpart->content_disposition);
+ workpart->content_disposition = NULL;
+ }
+ if (workpart->boundary) {
+ efree(workpart->boundary);
+ workpart->boundary = NULL;
+ }
+ if (workpart->content_type) {
+ php_mimeheader_free(workpart->content_type);
+ workpart->content_type = NULL;
+ }
+ workpart->content_type = php_mimeheader_alloc("text/plain");
+ }
+ /* if there is no content type, default to text/plain, but use multipart/digest when in
+ * a multipart/rfc822 message */
+ if (IS_MIME_1(workpart) && workpart->content_type == NULL) {
+ char *def_type = "text/plain";
+
+ if (workpart->parent && CONTENT_TYPE_IS(workpart->parent, "multipart/digest"))
+ def_type = "message/rfc822";
+
+ workpart->content_type = php_mimeheader_alloc(def_type);
+ }
+
+ /* if no charset had previously been set, either through inheritance or by an
+ * explicit content-type header, default to us-ascii */
+ if (workpart->charset == NULL) {
+ workpart->charset = estrdup(MAILPARSEG(def_charset));
+ }
+
+ if (CONTENT_TYPE_IS(workpart, "message/rfc822")) {
+ workpart = alloc_new_child_part(workpart, workpart->bodystart, 0 TSRMLS_CC);
+ workpart->parsedata.in_header = 1;
+ return SUCCESS;
+
+ }
+
+ /* create a section for the preamble that precedes the first boundary */
+ if (workpart->boundary) {
+ workpart = alloc_new_child_part(workpart, workpart->bodystart, 1 TSRMLS_CC);
+ workpart->parsedata.in_header = 0;
+ workpart->parsedata.is_dummy = 1;
+ return SUCCESS;
+ }
+
+ return SUCCESS;
+ }
+
+ }
+
+ return SUCCESS;
+}
+
+PHP_MAILPARSE_API int php_mimepart_parse(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC)
+{
+ size_t len;
+
+ while(bufsize > 0) {
+ /* look for EOL */
+ for (len = 0; len < bufsize; len++)
+ if (buf[len] == '\n')
+ break;
+ if (len < bufsize && buf[len] == '\n') {
+ ++len;
+ smart_str_appendl(&part->parsedata.workbuf, buf, len);
+ php_mimepart_process_line(part TSRMLS_CC);
+ part->parsedata.workbuf.len = 0;
+ } else {
+ smart_str_appendl(&part->parsedata.workbuf, buf, len);
+ }
+
+ buf += len;
+ bufsize -= len;
+ }
+ return SUCCESS;
+}
+
+static int enum_parts_recurse(php_mimepart_enumerator *top, php_mimepart_enumerator **child,
+ php_mimepart *part, mimepart_enumerator_func callback, void *ptr TSRMLS_DC)
+{
+ php_mimepart_enumerator next;
+ php_mimepart **childpart;
+ HashPosition pos;
+
+ *child = NULL;
+ if (FAILURE == (*callback)(part, top, ptr TSRMLS_CC))
+ return FAILURE;
+
+ *child = &next;
+ next.id = 1;
+
+ if (CONTENT_TYPE_ISL(part, "multipart/", 10))
+ next.id = 0;
+
+ zend_hash_internal_pointer_reset_ex(&part->children, &pos);
+ while (SUCCESS == zend_hash_get_current_data_ex(&part->children, (void**)&childpart, &pos)) {
+ if (next.id)
+ if (FAILURE == enum_parts_recurse(top, &next.next, *childpart, callback, ptr TSRMLS_CC))
+ return FAILURE;
+ next.id++;
+ zend_hash_move_forward_ex(&part->children, &pos);
+ }
+ return SUCCESS;
+}
+
+PHP_MAILPARSE_API void php_mimepart_enum_parts(php_mimepart *part, mimepart_enumerator_func callback, void *ptr TSRMLS_DC)
+{
+ php_mimepart_enumerator top;
+ top.id = 1;
+
+ enum_parts_recurse(&top, &top.next, part, callback, ptr TSRMLS_CC);
+}
+
+PHP_MAILPARSE_API void php_mimepart_enum_child_parts(php_mimepart *part, mimepart_child_enumerator_func callback, void *ptr TSRMLS_DC)
+{
+ HashPosition pos;
+ php_mimepart **childpart;
+ int index = 0;
+
+ zend_hash_internal_pointer_reset_ex(&part->children, &pos);
+ while (SUCCESS == zend_hash_get_current_data_ex(&part->children, (void**)&childpart, &pos)) {
+ if (FAILURE == (*callback)(part, *childpart, index, ptr TSRMLS_CC))
+ return;
+
+ zend_hash_move_forward_ex(&part->children, &pos);
+ index++;
+ }
+}
+
+struct find_part_struct {
+ const char *searchfor;
+ php_mimepart *foundpart;
+};
+
+static int find_part_callback(php_mimepart *part, php_mimepart_enumerator *id, void *ptr TSRMLS_DC)
+{
+ struct find_part_struct *find = ptr;
+ const unsigned char *num = (const unsigned char*)find->searchfor;
+ unsigned int n;
+
+ while (id) {
+ if (!isdigit((int)*num))
+ return SUCCESS;
+ /* convert from decimal to int */
+ n = 0;
+ while (isdigit((int)*num))
+ n = (n * 10) + (*num++ - '0');
+ if (*num) {
+ if (*num != '.')
+ return SUCCESS;
+ num++;
+ }
+ if (n != (unsigned int)id->id) {
+ return SUCCESS;
+ }
+ id = id->next;
+ }
+ if (*num == 0)
+ find->foundpart = part;
+
+ return SUCCESS;
+}
+
+PHP_MAILPARSE_API php_mimepart *php_mimepart_find_by_name(php_mimepart *parent, const char *name TSRMLS_DC)
+{
+ struct find_part_struct find;
+
+ find.searchfor = name;
+ find.foundpart = NULL;
+ php_mimepart_enum_parts(parent, find_part_callback, &find TSRMLS_CC);
+ return find.foundpart;
+}
+
+PHP_MAILPARSE_API php_mimepart *php_mimepart_find_child_by_position(php_mimepart *parent, int position TSRMLS_DC)
+{
+ HashPosition pos;
+ php_mimepart **childpart = NULL;
+
+ zend_hash_internal_pointer_reset_ex(&parent->children, &pos);
+ while(position-- > 0)
+ if (FAILURE == zend_hash_move_forward_ex(&parent->children, &pos))
+ return NULL;
+
+ if (FAILURE == zend_hash_get_current_data_ex(&parent->children, (void**)&childpart, &pos))
+ return NULL;
+
+ if(childpart) {
+ return *childpart;
+ } else {
+ return NULL;
+ }
+
+}
+
+static int filter_into_work_buffer(int c, void *dat MAILPARSE_MBSTRING_TSRMLS_DC)
+{
+ php_mimepart *part = dat;
+ MAILPARSE_MBSTRING_TSRMLS_FETCH_IF_BRAIN_DEAD();
+
+ smart_str_appendc(&part->parsedata.workbuf, c);
+
+ if (part->parsedata.workbuf.len >= 4096) {
+
+ part->extract_func(part, part->extract_context, part->parsedata.workbuf.c, part->parsedata.workbuf.len TSRMLS_CC);
+ part->parsedata.workbuf.len = 0;
+ }
+
+ return c;
+}
+
+PHP_MAILPARSE_API void php_mimepart_decoder_prepare(php_mimepart *part, int do_decode, php_mimepart_extract_func_t decoder, void *ptr TSRMLS_DC)
+{
+ enum mbfl_no_encoding from = mbfl_no_encoding_8bit;
+
+ if (do_decode && part->content_transfer_encoding) {
+ from = mbfl_name2no_encoding(part->content_transfer_encoding);
+ if (from == mbfl_no_encoding_invalid) {
+ if (strcasecmp("binary", part->content_transfer_encoding) != 0) {
+ zend_error(E_WARNING, "%s(): mbstring doesn't know how to decode %s transfer encoding!",
+ get_active_function_name(TSRMLS_C),
+ part->content_transfer_encoding);
+ }
+ from = mbfl_no_encoding_8bit;
+ }
+ }
+
+ part->extract_func = decoder;
+ part->extract_context = ptr;
+ part->parsedata.workbuf.len = 0;
+
+ if (do_decode) {
+ if (from == mbfl_no_encoding_8bit || from == mbfl_no_encoding_7bit) {
+ part->extract_filter = NULL;
+ } else {
+ part->extract_filter = mbfl_convert_filter_new(
+ from, mbfl_no_encoding_8bit,
+ filter_into_work_buffer,
+ NULL,
+ part
+ MAILPARSE_MBSTRING_TSRMLS_CC
+ );
+ }
+ }
+
+}
+
+PHP_MAILPARSE_API void php_mimepart_decoder_finish(php_mimepart *part TSRMLS_DC)
+{
+ if (part->extract_filter) {
+ mbfl_convert_filter_flush(part->extract_filter MAILPARSE_MBSTRING_TSRMLS_CC);
+ mbfl_convert_filter_delete(part->extract_filter MAILPARSE_MBSTRING_TSRMLS_CC);
+ }
+ if (part->extract_func && part->parsedata.workbuf.len > 0) {
+ part->extract_func(part, part->extract_context, part->parsedata.workbuf.c, part->parsedata.workbuf.len TSRMLS_CC);
+ part->parsedata.workbuf.len = 0;
+ }
+}
+
+PHP_MAILPARSE_API int php_mimepart_decoder_feed(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC)
+{
+ if (buf && bufsize) {
+ size_t i;
+
+ if (part->extract_filter) {
+ for (i = 0; i < bufsize; i++) {
+ if (mbfl_convert_filter_feed(buf[i], part->extract_filter MAILPARSE_MBSTRING_TSRMLS_CC) < 0) {
+ zend_error(E_WARNING, "%s() - filter conversion failed. Input message is probably incorrectly encoded\n",
+ get_active_function_name(TSRMLS_C));
+ return -1;
+ }
+ }
+ } else {
+ return part->extract_func(part, part->extract_context, buf, bufsize TSRMLS_CC);
+ }
+ }
+ return 0;
+}
+
+PHP_MAILPARSE_API void php_mimepart_remove_from_parent(php_mimepart *part TSRMLS_DC)
+{
+ php_mimepart *parent = part->parent;
+ HashPosition pos;
+ php_mimepart **childpart;
+
+ if (parent == NULL)
+ return;
+
+ part->parent = NULL;
+
+ zend_hash_internal_pointer_reset_ex(&parent->children, &pos);
+ while(SUCCESS == zend_hash_get_current_data_ex(&parent->children, (void**)&childpart, &pos)) {
+
+ if (SUCCESS == zend_hash_get_current_data_ex(&parent->children, (void**)&childpart, &pos)) {
+ if (*childpart == part) {
+ ulong h;
+ zend_hash_get_current_key_ex(&parent->children, NULL, NULL, &h, 0, &pos);
+ zend_hash_index_del(&parent->children, h);
+ break;
+ }
+ }
+ zend_hash_move_forward_ex(&parent->children, &pos);
+ }
+}
+
+PHP_MAILPARSE_API void php_mimepart_add_child(php_mimepart *part, php_mimepart *child TSRMLS_DC)
+{
+
+}
+
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse_mime.h
^
|
@@ -0,0 +1,112 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: php_mailparse_mime.h 305002 2010-10-31 15:46:48Z cataphract $ */
+
+#ifndef php_mailparse_mime_h
+#define php_mailparse_mime_h
+
+#include "ext/standard/php_smart_str.h"
+
+typedef struct _php_mimepart php_mimepart;
+
+struct php_mimeheader_with_attributes {
+ char *value;
+ zval *attributes;
+};
+
+PHP_MAILPARSE_API char *php_mimepart_attribute_get(struct php_mimeheader_with_attributes *attr, char *attrname);
+
+typedef int (*php_mimepart_extract_func_t)(php_mimepart *part, void *context, const char *buf, size_t n TSRMLS_DC);
+
+/* this is used to remember the source of a mime part.
+ * It is used mainly for writeable mime parts. */
+struct php_mimepart_source {
+ enum { mpNONE, mpSTRING, mpSTREAM } kind;
+ zval *zval;
+};
+
+struct _php_mimepart {
+ php_mimepart *parent;
+ long rsrc_id; /* for auto-cleanup */
+ int part_index; /* sequence number of this part */
+ HashTable children; /* child parts */
+
+ struct php_mimepart_source source;
+
+ off_t startpos, endpos; /* offsets of this part in the message */
+ off_t bodystart, bodyend; /* offsets of the body content of this part */
+ size_t nlines, nbodylines; /* number of lines in section/body */
+
+ char *mime_version;
+ char *content_transfer_encoding;
+ char *content_location;
+ char *content_base;
+ char *boundary;
+ char *charset;
+
+ struct php_mimeheader_with_attributes *content_type, *content_disposition;
+
+ zval *headerhash; /* a record of all the headers */
+
+ /* these are used during part extraction */
+ php_mimepart_extract_func_t extract_func;
+ mbfl_convert_filter *extract_filter;
+ void *extract_context;
+
+ /* these are used during parsing */
+ struct {
+ int in_header:1;
+ int is_dummy:1;
+ int completed:1;
+
+ smart_str workbuf;
+ smart_str headerbuf;
+ php_mimepart *lastpart;
+ } parsedata;
+
+};
+
+PHP_MAILPARSE_API php_mimepart *php_mimepart_alloc(TSRMLS_D);
+PHP_MAILPARSE_API void php_mimepart_free(php_mimepart *part TSRMLS_DC);
+PHP_MAILPARSE_API int php_mimepart_parse(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC);
+PHP_MAILPARSE_API void php_mimepart_get_offsets(php_mimepart *part, off_t *start, off_t *end, off_t *start_body, int *nlines, int *nbodylines);
+
+PHP_MAILPARSE_API void php_mimepart_decoder_prepare(php_mimepart *part, int do_decode, php_mimepart_extract_func_t decoder, void *ptr TSRMLS_DC);
+PHP_MAILPARSE_API void php_mimepart_decoder_finish(php_mimepart *part TSRMLS_DC);
+PHP_MAILPARSE_API int php_mimepart_decoder_feed(php_mimepart *part, const char *buf, size_t bufsize TSRMLS_DC);
+
+#define php_mimepart_to_zval(zval, part) ZVAL_RESOURCE(zval, part->rsrc_id)
+
+typedef struct _php_mimepart_enumerator php_mimepart_enumerator;
+struct _php_mimepart_enumerator {
+ php_mimepart_enumerator *next;
+ int id;
+};
+typedef int (*mimepart_enumerator_func)(php_mimepart *part, php_mimepart_enumerator *enumerator, void *ptr TSRMLS_DC);
+typedef int (*mimepart_child_enumerator_func)(php_mimepart *parentpart, php_mimepart *child, int childindex, void *ptr TSRMLS_DC);
+
+PHP_MAILPARSE_API void php_mimepart_enum_parts(php_mimepart *part, mimepart_enumerator_func callback, void *ptr TSRMLS_DC);
+PHP_MAILPARSE_API void php_mimepart_enum_child_parts(php_mimepart *part, mimepart_child_enumerator_func callback, void *ptr TSRMLS_DC);
+PHP_MAILPARSE_API php_mimepart *php_mimepart_find_by_name(php_mimepart *parent, const char *name TSRMLS_DC);
+PHP_MAILPARSE_API php_mimepart *php_mimepart_find_child_by_position(php_mimepart *parent, int position TSRMLS_DC);
+
+PHP_MAILPARSE_API void php_mimepart_remove_from_parent(php_mimepart *part TSRMLS_DC);
+PHP_MAILPARSE_API void php_mimepart_add_child(php_mimepart *part, php_mimepart *child TSRMLS_DC);
+
+#endif
+
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse_rfc822.c
^
|
@@ -0,0 +1,702 @@
+/* Generated by re2c 0.13.5 on Wed May 6 23:37:32 2009 */
+#line 1 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: php_mailparse_rfc822.c 280053 2009-05-07 06:41:59Z shire $ */
+
+#include "php.h"
+#include "php_mailparse.h"
+#include "php_mailparse_rfc822.h"
+#include "ext/standard/php_string.h"
+#include "ext/standard/php_smart_str.h"
+#line 39 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+
+
+#line 48 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+
+
+#define YYFILL(n) if (YYCURSOR == YYLIMIT) goto stop
+#define YYCTYPE unsigned char
+#define YYCURSOR p
+#define YYLIMIT q
+#define YYMARKER r
+
+#define DEBUG_RFC822_SCANNER 0
+
+#if DEBUG_RFC822_SCANNER
+# define DBG_STATE(lbl) printf(lbl " %d:%c %d:%c\n", *YYCURSOR, *YYCURSOR, *start, *start)
+#else
+# define DBG_STATE(lbl)
+#endif
+
+#define ADD_ATOM_TOKEN() do { if (tokens) { tokens->token = *start; tokens->value = start; tokens->valuelen = 1; tokens++; } ++*ntokens; } while (0)
+#define REPORT_ERR(msg) do { if (report_errors) zend_error(E_WARNING, "input is not rfc822 compliant: %s", msg); } while(0)
+/* Tokenize a header. tokens may be NULL, in which case the number of tokens are
+ counted, allowing the caller to allocate enough room */
+static void tokenize(const char *header, php_rfc822_token_t *tokens, int *ntokens, int report_errors TSRMLS_DC)
+{
+ register const char *p, *q, *start;
+ int in_bracket = 0;
+
+/* NB: parser assumes that the header has two bytes of NUL terminator */
+
+ YYCURSOR = header;
+ YYLIMIT = YYCURSOR + strlen(YYCURSOR) + 1;
+
+ *ntokens = 0;
+
+state_ground:
+ start = YYCURSOR;
+
+#if DEBUG_RFC822_SCANNER
+printf("ground: start=%p limit=%p cursor=%p: [%d] %s\n", start, YYLIMIT, YYCURSOR, *YYCURSOR, YYCURSOR);
+#endif
+
+
+#line 72 "<stdout>"
+{
+ YYCTYPE yych;
+ static const unsigned char yybm[] = {
+ 0, 192, 192, 192, 192, 192, 192, 192,
+ 192, 96, 96, 192, 192, 96, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 96, 64, 0, 192, 192, 64, 192, 192,
+ 64, 64, 192, 192, 64, 192, 64, 64,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 64, 64, 64, 64, 64, 64,
+ 64, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 64, 192, 64, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 192,
+ };
+
+ if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
+ yych = *YYCURSOR;
+ if (yybm[0+yych] & 32) {
+ goto yy4;
+ }
+ if (yych <= '-') {
+ if (yych <= '%') {
+ if (yych <= '!') {
+ if (yych <= 0x00) goto yy2;
+ if (yych <= ' ') goto yy21;
+ goto yy19;
+ } else {
+ if (yych <= '"') goto yy12;
+ if (yych <= '$') goto yy21;
+ goto yy19;
+ }
+ } else {
+ if (yych <= ')') {
+ if (yych <= '\'') goto yy21;
+ if (yych <= '(') goto yy10;
+ goto yy7;
+ } else {
+ if (yych == ',') goto yy19;
+ goto yy21;
+ }
+ }
+ } else {
+ if (yych <= '>') {
+ if (yych <= ';') {
+ if (yych <= '/') goto yy19;
+ if (yych <= '9') goto yy21;
+ goto yy19;
+ } else {
+ if (yych <= '<') goto yy15;
+ if (yych <= '=') goto yy19;
+ goto yy17;
+ }
+ } else {
+ if (yych <= '[') {
+ if (yych <= '@') goto yy19;
+ if (yych <= 'Z') goto yy21;
+ goto yy19;
+ } else {
+ if (yych <= '\\') goto yy9;
+ if (yych <= ']') goto yy19;
+ goto yy21;
+ }
+ }
+ }
+yy2:
+ ++YYCURSOR;
+#line 88 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { goto stop; }
+#line 163 "<stdout>"
+yy4:
+ ++YYCURSOR;
+ if (YYLIMIT <= YYCURSOR) YYFILL(1);
+ yych = *YYCURSOR;
+ if (yybm[0+yych] & 32) {
+ goto yy4;
+ }
+#line 89 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("SPACE"); goto state_ground; }
+#line 173 "<stdout>"
+yy7:
+ ++YYCURSOR;
+yy8:
+#line 90 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { REPORT_ERR("token not valid in ground state"); goto state_ground; }
+#line 179 "<stdout>"
+yy9:
+ yych = *++YYCURSOR;
+ if (yybm[0+yych] & 128) {
+ goto yy21;
+ }
+ goto yy8;
+yy10:
+ ++YYCURSOR;
+#line 91 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("START COMMENT");
+ if (tokens) {
+ tokens->token = '(';
+ tokens->value = start;
+ tokens->valuelen = 0;
+ }
+ goto state_comment;
+ }
+#line 197 "<stdout>"
+yy12:
+ ++YYCURSOR;
+ if (YYLIMIT <= YYCURSOR) YYFILL(1);
+ yych = *YYCURSOR;
+ if (yybm[0+yych] & 64) {
+ goto yy12;
+ }
+ if (yych >= 0x01) goto yy26;
+yy15:
+ ++YYCURSOR;
+ if ((yych = *YYCURSOR) == '>') goto yy24;
+#line 123 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("LANGLE");
+ if (in_bracket) {
+ REPORT_ERR("already in < bracket");
+ goto state_ground;
+ }
+ in_bracket = 1;
+ ADD_ATOM_TOKEN();
+ goto state_ground;
+ }
+#line 219 "<stdout>"
+yy17:
+ ++YYCURSOR;
+#line 132 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("RANGLE");
+ if (!in_bracket) {
+ REPORT_ERR("not in < bracket");
+ goto state_ground;
+ }
+ in_bracket = 0;
+ ADD_ATOM_TOKEN();
+ goto state_ground;
+ }
+#line 232 "<stdout>"
+yy19:
+ ++YYCURSOR;
+#line 141 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("ATOM"); ADD_ATOM_TOKEN(); goto state_ground; }
+#line 237 "<stdout>"
+yy21:
+ ++YYCURSOR;
+ if (YYLIMIT <= YYCURSOR) YYFILL(1);
+ yych = *YYCURSOR;
+ if (yybm[0+yych] & 128) {
+ goto yy21;
+ }
+#line 142 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("ANY");
+ if (tokens) {
+ tokens->token = 0;
+ tokens->valuelen = YYCURSOR - start;
+ tokens->value = start;
+ tokens++;
+ }
+ ++*ntokens;
+ goto state_ground;
+ }
+#line 256 "<stdout>"
+yy24:
+ ++YYCURSOR;
+#line 110 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("NULL <>");
+ ADD_ATOM_TOKEN();
+ if (tokens) {
+ tokens->token = 0;
+ tokens->value = "";
+ tokens->valuelen = 0;
+ tokens++;
+ }
+ ++*ntokens;
+ start++;
+ ADD_ATOM_TOKEN();
+ goto state_ground;
+ }
+#line 273 "<stdout>"
+yy26:
+ ++YYCURSOR;
+#line 99 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+ { DBG_STATE("QUOTE STRING");
+ if (tokens) {
+ tokens->token = '"';
+ tokens->value = start + 1;
+ tokens->valuelen = YYCURSOR - start - 2;
+ tokens++;
+ }
+ ++*ntokens;
+
+ goto state_ground;
+ }
+#line 288 "<stdout>"
+}
+#line 152 "/Users/shire/data/mailparse/git/mailparse/php_mailparse_rfc822.re"
+
+
+state_comment:
+ {
+ int comment_depth = 1;
+ while (1) {
+ if (*YYCURSOR == 0) {
+ /* unexpected end of header */
+ REPORT_ERR("unexpected end of header");
+ /* fake a quoted string for this last token */
+ if (tokens)
+ tokens->token = '"';
+ ++*ntokens;
+ return;
+ } else if (*YYCURSOR == '(') {
+ comment_depth++;
+ } else if (*YYCURSOR == ')' && --comment_depth == 0) {
+ /* end of nested comment sequence */
+ YYCURSOR++;
+ if (tokens)
+ tokens->valuelen++;
+ break;
+ } else if (*YYCURSOR == '\\' && YYCURSOR[1]) {
+ YYCURSOR++;
+ if (tokens)
+ tokens->valuelen++;
+ }
+ YYCURSOR++;
+ }
+ if (tokens) {
+ tokens->valuelen = YYCURSOR - tokens->value;
+ tokens++;
+ }
+ ++*ntokens;
+ goto state_ground;
+ }
+stop:
+#if DEBUG_RFC822_SCANNER
+ printf("STOPing parser ntokens=%d YYCURSOR=%p YYLIMIT=%p start=%p cursor=[%d] %s start=%s\n", *ntokens,
+ YYCURSOR, YYLIMIT, start, *YYCURSOR, YYCURSOR, start);
+#else
+ ;
+#endif
+}
+
+PHP_MAILPARSE_API php_rfc822_tokenized_t *php_mailparse_rfc822_tokenize(const char *header, int report_errors TSRMLS_DC)
+{
+ php_rfc822_tokenized_t *toks = ecalloc(1, sizeof(php_rfc822_tokenized_t));
+ int len = strlen(header);
+
+ toks->buffer = emalloc(len + 2);
+ strcpy(toks->buffer, header);
+ toks->buffer[len] = 0;
+ toks->buffer[len+1] = 0; /* mini hack: the parser sometimes relies in this */
+
+ tokenize(toks->buffer, NULL, &toks->ntokens, report_errors TSRMLS_CC);
+ toks->tokens = toks->ntokens ? ecalloc(toks->ntokens, sizeof(php_rfc822_token_t)) : NULL;
+ tokenize(toks->buffer, toks->tokens, &toks->ntokens, report_errors TSRMLS_CC);
+ return toks;
+}
+
+PHP_MAILPARSE_API void php_rfc822_tokenize_free(php_rfc822_tokenized_t *toks)
+{
+ if (toks->tokens)
+ efree(toks->tokens);
+ efree(toks->buffer);
+ efree(toks);
+}
+
+PHP_MAILPARSE_API char *php_rfc822_recombine_tokens(php_rfc822_tokenized_t *toks, int first_token, int n_tokens, int flags)
+{
+ char *ret = NULL;
+ int i, upper, last_was_atom = 0, this_is_atom = 0, tok_equiv;
+ size_t len = 1; /* for the NUL terminator */
+
+ upper = first_token + n_tokens;
+ if (upper > toks->ntokens)
+ upper = toks->ntokens;
+
+ for (i = first_token; i < upper; i++, last_was_atom = this_is_atom) {
+
+ tok_equiv = toks->tokens[i].token;
+ if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
+ tok_equiv = '"';
+
+ if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
+ continue;
+ if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
+ continue;
+
+ this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
+ if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS)
+ len++; /* allow room for a space */
+
+ if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
+ len += 2;
+
+ len += toks->tokens[i].valuelen;
+ }
+
+ last_was_atom = this_is_atom = 0;
+
+ ret = emalloc(len);
+
+ for (i = first_token, len = 0; i < upper; i++, last_was_atom = this_is_atom) {
+ const char *tokvalue;
+ int toklen;
+
+ tok_equiv = toks->tokens[i].token;
+ if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
+ tok_equiv = '"';
+
+ if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
+ continue;
+ if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
+ continue;
+
+ tokvalue = toks->tokens[i].value;
+ toklen = toks->tokens[i].valuelen;
+
+ this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
+ if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS) {
+ ret[len] = ' ';
+ len++;
+ }
+ if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
+ ret[len++] = '"';
+
+ if (toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES) {
+ /* don't include ( and ) in the output string */
+ tokvalue++;
+ toklen -= 2;
+ }
+
+ memcpy(ret + len, tokvalue, toklen);
+ len += toklen;
+
+ if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
+ ret[len++] = '"';
+
+ }
+ ret[len] = 0;
+
+ if (flags & PHP_RFC822_RECOMBINE_STRTOLOWER)
+ php_strtolower(ret, len);
+
+ return ret;
+}
+
+static void parse_address_tokens(php_rfc822_tokenized_t *toks,
+ php_rfc822_addresses_t *addrs, int *naddrs)
+{
+ int start_tok = 0, iaddr = 0, i, in_group = 0, group_lbl_start, group_lbl_end;
+ int a_start, a_count; /* position and count for address part of a name */
+ smart_str group_addrs = { 0, };
+ char *address_value = NULL;
+
+address: /* mailbox / group */
+
+ if (start_tok >= toks->ntokens) {
+ /* the end */
+ *naddrs = iaddr;
+ smart_str_free(&group_addrs);
+ return;
+ }
+
+ /* look ahead to determine if we are dealing with a group */
+ for (i = start_tok; i < toks->ntokens; i++)
+ if (toks->tokens[i].token != 0 && toks->tokens[i].token != '"')
+ break;
+
+ if (i < toks->ntokens && toks->tokens[i].token == ':') {
+ /* it's a group */
+ in_group = 1;
+ group_lbl_start = start_tok;
+ group_lbl_end = i;
+
+ /* we want the address for the group to include the leading ":" and the trailing ";" */
+ start_tok = i;
+ }
+
+mailbox: /* addr-spec / phrase route-addr */
+ if (start_tok >= toks->ntokens) {
+ /* the end */
+ *naddrs = iaddr;
+ smart_str_free(&group_addrs);
+ return;
+ }
+
+ /* skip spurious commas */
+ while (start_tok < toks->ntokens && (toks->tokens[start_tok].token == ','
+ || toks->tokens[start_tok].token == ';'))
+ start_tok++;
+
+ /* look ahead: if we find a '<' before we find an '@', we are dealing with
+ a route-addr, otherwise we have an addr-spec */
+ for (i = start_tok; i < toks->ntokens && toks->tokens[i].token != ';'
+ && toks->tokens[i].token != ',' && toks->tokens[i].token != '<'; i++)
+ ;
+
+ /* the stuff from start_tok to i - 1 is the display name part */
+ if (addrs && !in_group && i - start_tok > 0) {
+ int j, has_comments = 0, has_strings = 0;
+ switch(toks->tokens[i].token) {
+ case ';': case ',': case '<':
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS);
+ break;
+ default:
+ /* it's only the display name if there are quoted strings or comments in there */
+ for (j = start_tok; j < i; j++) {
+ if (toks->tokens[j].token == '(')
+ has_comments = 1;
+ if (toks->tokens[j].token == '"')
+ has_strings = 1;
+ }
+ if (has_comments && !has_strings) {
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok,
+ i - start_tok,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS | PHP_RFC822_RECOMBINE_COMMENTS_ONLY
+ | PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES
+ );
+ } else if (has_strings) {
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS);
+
+ }
+
+ }
+
+ }
+
+ if (i < toks->ntokens && toks->tokens[i].token == '<') {
+ int j;
+ /* RFC822: route-addr = "<" [route] addr-spec ">" */
+ /* look for the closing '>' and recombine as the address part */
+
+ for (j = i; j < toks->ntokens && toks->tokens[j].token != '>'; j++)
+ ;
+
+ if (addrs) {
+ a_start = i;
+ a_count = j-i;
+ /* if an address is enclosed in <>, leave them out of the the
+ * address value that we return */
+ if (toks->tokens[a_start].token == '<') {
+ a_start++;
+ a_count--;
+ }
+ address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS|
+ PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
+ PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
+ }
+
+ start_tok = ++j;
+ } else {
+ /* RFC822: addr-spec = local-part "@" domain */
+ if (addrs) {
+ a_start = start_tok;
+ a_count = i - start_tok;
+ /* if an address is enclosed in <>, leave them out of the the
+ * address value that we return */
+ if (toks->tokens[a_start].token == '<') {
+ a_start++;
+ a_count--;
+ }
+
+ address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS|
+ PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
+ PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
+ }
+ start_tok = i;
+ }
+
+ if (addrs && address_value) {
+
+ /* if no display name has been given, use the address */
+ if (addrs->addrs[iaddr].name == NULL) {
+ addrs->addrs[iaddr].name = estrdup(address_value);
+ }
+
+ if (in_group) {
+ if (group_addrs.len)
+ smart_str_appendl(&group_addrs, ",", 1);
+ smart_str_appends(&group_addrs, address_value);
+ efree(address_value);
+ } else {
+ addrs->addrs[iaddr].address = address_value;
+ }
+ address_value = NULL;
+ }
+
+ if (!in_group) {
+ iaddr++;
+ goto address;
+ }
+ /* still dealing with a group. If we find a ";", that's the end of the group */
+ if ((start_tok < toks->ntokens && toks->tokens[start_tok].token == ';') || start_tok == toks->ntokens) {
+ /* end of group */
+
+ if (addrs) {
+ smart_str_appendl(&group_addrs, ";", 1);
+ smart_str_0(&group_addrs);
+ addrs->addrs[iaddr].address = estrdup(group_addrs.c);
+ group_addrs.len = 0;
+
+ STR_FREE(addrs->addrs[iaddr].name);
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, group_lbl_start,
+ group_lbl_end - group_lbl_start,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS);
+
+ addrs->addrs[iaddr].is_group = 1;
+ }
+
+ iaddr++;
+ in_group = 0;
+ start_tok++;
+ goto address;
+ }
+ /* look for more mailboxes in this group */
+ goto mailbox;
+}
+
+PHP_MAILPARSE_API php_rfc822_addresses_t *php_rfc822_parse_address_tokens(php_rfc822_tokenized_t *toks)
+{
+ php_rfc822_addresses_t *addrs = ecalloc(1, sizeof(php_rfc822_addresses_t));
+
+ parse_address_tokens(toks, NULL, &addrs->naddrs);
+ if (addrs->naddrs) {
+ addrs->addrs = ecalloc(addrs->naddrs, sizeof(php_rfc822_address_t));
+ parse_address_tokens(toks, addrs, &addrs->naddrs);
+ }
+
+ return addrs;
+}
+
+PHP_MAILPARSE_API void php_rfc822_free_addresses(php_rfc822_addresses_t *addrs)
+{
+ int i;
+ for (i = 0; i < addrs->naddrs; i++) {
+ if (addrs->addrs[i].name)
+ STR_FREE(addrs->addrs[i].name);
+ STR_FREE(addrs->addrs[i].address);
+ }
+ if (addrs->addrs)
+ efree(addrs->addrs);
+ efree(addrs);
+}
+void php_rfc822_print_addresses(php_rfc822_addresses_t *addrs)
+{
+ int i;
+ printf("printing addresses %p\n", addrs); fflush(stdout);
+ for (i = 0; i < addrs->naddrs; i++) {
+ printf("addr %d: name=%s address=%s\n", i, addrs->addrs[i].name, addrs->addrs[i].address);
+ }
+}
+
+
+void php_rfc822_print_tokens(php_rfc822_tokenized_t *toks)
+{
+ int i;
+ for (i = 0; i < toks->ntokens; i++) {
+ printf("token %d: token=%d/%c len=%d value=%s\n", i, toks->tokens[i].token, toks->tokens[i].token,
+ toks->tokens[i].valuelen, toks->tokens[i].value);
+ }
+}
+
+PHP_FUNCTION(mailparse_test)
+{
+ char *header;
+ long header_len;
+ php_rfc822_tokenized_t *toks;
+ php_rfc822_addresses_t *addrs;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+
+#if 0
+ {
+ struct rfc822t *t = mailparse_rfc822t_alloc(header, NULL);
+ for (i = 0; i < t->ntokens; i++) {
+ printf("token %d: token=%d/%c len=%d value=%s\n", i, t->tokens[i].token, t->tokens[i].token,
+ t->tokens[i].len, t->tokens[i].ptr);
+
+ }
+ mailparse_rfc822t_free(t);
+
+ printf("--- and now:\n");
+ }
+#endif
+
+ toks = php_mailparse_rfc822_tokenize((const char*)header, 1 TSRMLS_CC);
+ php_rfc822_print_tokens(toks);
+
+ addrs = php_rfc822_parse_address_tokens(toks);
+ php_rfc822_print_addresses(addrs);
+ php_rfc822_free_addresses(addrs);
+
+ php_rfc822_tokenize_free(toks);
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker syn=c
+ * vim<600: sw=4 ts=4
+ */
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse_rfc822.h
^
|
(renamed from mailparse-2.1.3/php_mailparse_rfc822.h)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse_rfc822.h
^
|
(renamed from mailparse-2.1.3/php_mailparse_rfc822.h)
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/php_mailparse_rfc822.re
^
|
@@ -0,0 +1,564 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Wez Furlong <wez@thebrainroom.com> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: php_mailparse_rfc822.re 280053 2009-05-07 06:41:59Z shire $ */
+
+#include "php.h"
+#include "php_mailparse.h"
+#include "php_mailparse_rfc822.h"
+#include "ext/standard/php_string.h"
+#include "ext/standard/php_smart_str.h"
+/*!re2c
+CHAR = [\000-\177];
+ALPHA = [\101-\132]|[\141-\172];
+DIGIT = [\060-\071];
+CTL = [\000-\037]|[\177];
+CR = [\015];
+LF = [\012];
+SPACE = [\040];
+HTAB = [\011];
+CRLF = CR LF;
+LWSPCHAR = SPACE|HTAB;
+LWSP = ( CRLF? LWSPCHAR)+;
+specials = [()<>@,;:\\".\[\]];
+delimiters = (specials|LWSP);
+*/
+
+/*!re2c
+NUL = [\000];
+any = [\001-\377];
+space = (HTAB|SPACE|CR|LF);
+atom = [@,;:.%!?=/\[\]];
+allspecials = (atom|[()<>"]|space);
+other = any\allspecials;
+*/
+
+#define YYFILL(n) if (YYCURSOR == YYLIMIT) goto stop
+#define YYCTYPE unsigned char
+#define YYCURSOR p
+#define YYLIMIT q
+#define YYMARKER r
+
+#define DEBUG_RFC822_SCANNER 0
+
+#if DEBUG_RFC822_SCANNER
+# define DBG_STATE(lbl) printf(lbl " %d:%c %d:%c\n", *YYCURSOR, *YYCURSOR, *start, *start)
+#else
+# define DBG_STATE(lbl)
+#endif
+
+#define ADD_ATOM_TOKEN() do { if (tokens) { tokens->token = *start; tokens->value = start; tokens->valuelen = 1; tokens++; } ++*ntokens; } while (0)
+#define REPORT_ERR(msg) do { if (report_errors) zend_error(E_WARNING, "input is not rfc822 compliant: %s", msg); } while(0)
+/* Tokenize a header. tokens may be NULL, in which case the number of tokens are
+ counted, allowing the caller to allocate enough room */
+static void tokenize(const char *header, php_rfc822_token_t *tokens, int *ntokens, int report_errors TSRMLS_DC)
+{
+ register const char *p, *q, *start;
+ int in_bracket = 0;
+
+/* NB: parser assumes that the header has two bytes of NUL terminator */
+
+ YYCURSOR = header;
+ YYLIMIT = YYCURSOR + strlen(YYCURSOR) + 1;
+
+ *ntokens = 0;
+
+state_ground:
+ start = YYCURSOR;
+
+#if DEBUG_RFC822_SCANNER
+printf("ground: start=%p limit=%p cursor=%p: [%d] %s\n", start, YYLIMIT, YYCURSOR, *YYCURSOR, YYCURSOR);
+#endif
+
+/*!re2c
+ NUL { goto stop; }
+ space+ { DBG_STATE("SPACE"); goto state_ground; }
+ (")"|"\\") { REPORT_ERR("token not valid in ground state"); goto state_ground; }
+ "(" { DBG_STATE("START COMMENT");
+ if (tokens) {
+ tokens->token = '(';
+ tokens->value = start;
+ tokens->valuelen = 0;
+ }
+ goto state_comment;
+ }
+ ["] (any\["])* ["] { DBG_STATE("QUOTE STRING");
+ if (tokens) {
+ tokens->token = '"';
+ tokens->value = start + 1;
+ tokens->valuelen = YYCURSOR - start - 2;
+ tokens++;
+ }
+ ++*ntokens;
+
+ goto state_ground;
+ }
+ "<" ">" { DBG_STATE("NULL <>");
+ ADD_ATOM_TOKEN();
+ if (tokens) {
+ tokens->token = 0;
+ tokens->value = "";
+ tokens->valuelen = 0;
+ tokens++;
+ }
+ ++*ntokens;
+ start++;
+ ADD_ATOM_TOKEN();
+ goto state_ground;
+ }
+ "<" { DBG_STATE("LANGLE");
+ if (in_bracket) {
+ REPORT_ERR("already in < bracket");
+ goto state_ground;
+ }
+ in_bracket = 1;
+ ADD_ATOM_TOKEN();
+ goto state_ground;
+ }
+ ">" { DBG_STATE("RANGLE");
+ if (!in_bracket) {
+ REPORT_ERR("not in < bracket");
+ goto state_ground;
+ }
+ in_bracket = 0;
+ ADD_ATOM_TOKEN();
+ goto state_ground;
+ }
+ atom { DBG_STATE("ATOM"); ADD_ATOM_TOKEN(); goto state_ground; }
+ other+ { DBG_STATE("ANY");
+ if (tokens) {
+ tokens->token = 0;
+ tokens->valuelen = YYCURSOR - start;
+ tokens->value = start;
+ tokens++;
+ }
+ ++*ntokens;
+ goto state_ground;
+ }
+*/
+
+state_comment:
+ {
+ int comment_depth = 1;
+ while (1) {
+ if (*YYCURSOR == 0) {
+ /* unexpected end of header */
+ REPORT_ERR("unexpected end of header");
+ /* fake a quoted string for this last token */
+ if (tokens)
+ tokens->token = '"';
+ ++*ntokens;
+ return;
+ } else if (*YYCURSOR == '(') {
+ comment_depth++;
+ } else if (*YYCURSOR == ')' && --comment_depth == 0) {
+ /* end of nested comment sequence */
+ YYCURSOR++;
+ if (tokens)
+ tokens->valuelen++;
+ break;
+ } else if (*YYCURSOR == '\\' && YYCURSOR[1]) {
+ YYCURSOR++;
+ if (tokens)
+ tokens->valuelen++;
+ }
+ YYCURSOR++;
+ }
+ if (tokens) {
+ tokens->valuelen = YYCURSOR - tokens->value;
+ tokens++;
+ }
+ ++*ntokens;
+ goto state_ground;
+ }
+stop:
+#if DEBUG_RFC822_SCANNER
+ printf("STOPing parser ntokens=%d YYCURSOR=%p YYLIMIT=%p start=%p cursor=[%d] %s start=%s\n", *ntokens,
+ YYCURSOR, YYLIMIT, start, *YYCURSOR, YYCURSOR, start);
+#else
+ ;
+#endif
+}
+
+PHP_MAILPARSE_API php_rfc822_tokenized_t *php_mailparse_rfc822_tokenize(const char *header, int report_errors TSRMLS_DC)
+{
+ php_rfc822_tokenized_t *toks = ecalloc(1, sizeof(php_rfc822_tokenized_t));
+ int len = strlen(header);
+
+ toks->buffer = emalloc(len + 2);
+ strcpy(toks->buffer, header);
+ toks->buffer[len] = 0;
+ toks->buffer[len+1] = 0; /* mini hack: the parser sometimes relies in this */
+
+ tokenize(toks->buffer, NULL, &toks->ntokens, report_errors TSRMLS_CC);
+ toks->tokens = toks->ntokens ? ecalloc(toks->ntokens, sizeof(php_rfc822_token_t)) : NULL;
+ tokenize(toks->buffer, toks->tokens, &toks->ntokens, report_errors TSRMLS_CC);
+ return toks;
+}
+
+PHP_MAILPARSE_API void php_rfc822_tokenize_free(php_rfc822_tokenized_t *toks)
+{
+ if (toks->tokens)
+ efree(toks->tokens);
+ efree(toks->buffer);
+ efree(toks);
+}
+
+PHP_MAILPARSE_API char *php_rfc822_recombine_tokens(php_rfc822_tokenized_t *toks, int first_token, int n_tokens, int flags)
+{
+ char *ret = NULL;
+ int i, upper, last_was_atom = 0, this_is_atom = 0, tok_equiv;
+ size_t len = 1; /* for the NUL terminator */
+
+ upper = first_token + n_tokens;
+ if (upper > toks->ntokens)
+ upper = toks->ntokens;
+
+ for (i = first_token; i < upper; i++, last_was_atom = this_is_atom) {
+
+ tok_equiv = toks->tokens[i].token;
+ if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
+ tok_equiv = '"';
+
+ if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
+ continue;
+ if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
+ continue;
+
+ this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
+ if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS)
+ len++; /* allow room for a space */
+
+ if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
+ len += 2;
+
+ len += toks->tokens[i].valuelen;
+ }
+
+ last_was_atom = this_is_atom = 0;
+
+ ret = emalloc(len);
+
+ for (i = first_token, len = 0; i < upper; i++, last_was_atom = this_is_atom) {
+ const char *tokvalue;
+ int toklen;
+
+ tok_equiv = toks->tokens[i].token;
+ if (tok_equiv == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES)
+ tok_equiv = '"';
+
+ if (flags & PHP_RFC822_RECOMBINE_IGNORE_COMMENTS && tok_equiv == '(')
+ continue;
+ if (flags & PHP_RFC822_RECOMBINE_COMMENTS_ONLY && tok_equiv != '(' && !(toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES))
+ continue;
+
+ tokvalue = toks->tokens[i].value;
+ toklen = toks->tokens[i].valuelen;
+
+ this_is_atom = php_rfc822_token_is_atom(toks->tokens[i].token);
+ if (this_is_atom && last_was_atom && flags & PHP_RFC822_RECOMBINE_SPACE_ATOMS) {
+ ret[len] = ' ';
+ len++;
+ }
+ if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
+ ret[len++] = '"';
+
+ if (toks->tokens[i].token == '(' && flags & PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES) {
+ /* don't include ( and ) in the output string */
+ tokvalue++;
+ toklen -= 2;
+ }
+
+ memcpy(ret + len, tokvalue, toklen);
+ len += toklen;
+
+ if (flags & PHP_RFC822_RECOMBINE_INCLUDE_QUOTES && tok_equiv == '"')
+ ret[len++] = '"';
+
+ }
+ ret[len] = 0;
+
+ if (flags & PHP_RFC822_RECOMBINE_STRTOLOWER)
+ php_strtolower(ret, len);
+
+ return ret;
+}
+
+static void parse_address_tokens(php_rfc822_tokenized_t *toks,
+ php_rfc822_addresses_t *addrs, int *naddrs)
+{
+ int start_tok = 0, iaddr = 0, i, in_group = 0, group_lbl_start, group_lbl_end;
+ int a_start, a_count; /* position and count for address part of a name */
+ smart_str group_addrs = { 0, };
+ char *address_value = NULL;
+
+address: /* mailbox / group */
+
+ if (start_tok >= toks->ntokens) {
+ /* the end */
+ *naddrs = iaddr;
+ smart_str_free(&group_addrs);
+ return;
+ }
+
+ /* look ahead to determine if we are dealing with a group */
+ for (i = start_tok; i < toks->ntokens; i++)
+ if (toks->tokens[i].token != 0 && toks->tokens[i].token != '"')
+ break;
+
+ if (i < toks->ntokens && toks->tokens[i].token == ':') {
+ /* it's a group */
+ in_group = 1;
+ group_lbl_start = start_tok;
+ group_lbl_end = i;
+
+ /* we want the address for the group to include the leading ":" and the trailing ";" */
+ start_tok = i;
+ }
+
+mailbox: /* addr-spec / phrase route-addr */
+ if (start_tok >= toks->ntokens) {
+ /* the end */
+ *naddrs = iaddr;
+ smart_str_free(&group_addrs);
+ return;
+ }
+
+ /* skip spurious commas */
+ while (start_tok < toks->ntokens && (toks->tokens[start_tok].token == ','
+ || toks->tokens[start_tok].token == ';'))
+ start_tok++;
+
+ /* look ahead: if we find a '<' before we find an '@', we are dealing with
+ a route-addr, otherwise we have an addr-spec */
+ for (i = start_tok; i < toks->ntokens && toks->tokens[i].token != ';'
+ && toks->tokens[i].token != ',' && toks->tokens[i].token != '<'; i++)
+ ;
+
+ /* the stuff from start_tok to i - 1 is the display name part */
+ if (addrs && !in_group && i - start_tok > 0) {
+ int j, has_comments = 0, has_strings = 0;
+ switch(toks->tokens[i].token) {
+ case ';': case ',': case '<':
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS);
+ break;
+ default:
+ /* it's only the display name if there are quoted strings or comments in there */
+ for (j = start_tok; j < i; j++) {
+ if (toks->tokens[j].token == '(')
+ has_comments = 1;
+ if (toks->tokens[j].token == '"')
+ has_strings = 1;
+ }
+ if (has_comments && !has_strings) {
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok,
+ i - start_tok,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS | PHP_RFC822_RECOMBINE_COMMENTS_ONLY
+ | PHP_RFC822_RECOMBINE_COMMENTS_TO_QUOTES
+ );
+ } else if (has_strings) {
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, start_tok, i - start_tok,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS);
+
+ }
+
+ }
+
+ }
+
+ if (i < toks->ntokens && toks->tokens[i].token == '<') {
+ int j;
+ /* RFC822: route-addr = "<" [route] addr-spec ">" */
+ /* look for the closing '>' and recombine as the address part */
+
+ for (j = i; j < toks->ntokens && toks->tokens[j].token != '>'; j++)
+ ;
+
+ if (addrs) {
+ a_start = i;
+ a_count = j-i;
+ /* if an address is enclosed in <>, leave them out of the the
+ * address value that we return */
+ if (toks->tokens[a_start].token == '<') {
+ a_start++;
+ a_count--;
+ }
+ address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS|
+ PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
+ PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
+ }
+
+ start_tok = ++j;
+ } else {
+ /* RFC822: addr-spec = local-part "@" domain */
+ if (addrs) {
+ a_start = start_tok;
+ a_count = i - start_tok;
+ /* if an address is enclosed in <>, leave them out of the the
+ * address value that we return */
+ if (toks->tokens[a_start].token == '<') {
+ a_start++;
+ a_count--;
+ }
+
+ address_value = php_rfc822_recombine_tokens(toks, a_start, a_count,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS|
+ PHP_RFC822_RECOMBINE_IGNORE_COMMENTS|
+ PHP_RFC822_RECOMBINE_INCLUDE_QUOTES);
+ }
+ start_tok = i;
+ }
+
+ if (addrs && address_value) {
+
+ /* if no display name has been given, use the address */
+ if (addrs->addrs[iaddr].name == NULL) {
+ addrs->addrs[iaddr].name = estrdup(address_value);
+ }
+
+ if (in_group) {
+ if (group_addrs.len)
+ smart_str_appendl(&group_addrs, ",", 1);
+ smart_str_appends(&group_addrs, address_value);
+ efree(address_value);
+ } else {
+ addrs->addrs[iaddr].address = address_value;
+ }
+ address_value = NULL;
+ }
+
+ if (!in_group) {
+ iaddr++;
+ goto address;
+ }
+ /* still dealing with a group. If we find a ";", that's the end of the group */
+ if ((start_tok < toks->ntokens && toks->tokens[start_tok].token == ';') || start_tok == toks->ntokens) {
+ /* end of group */
+
+ if (addrs) {
+ smart_str_appendl(&group_addrs, ";", 1);
+ smart_str_0(&group_addrs);
+ addrs->addrs[iaddr].address = estrdup(group_addrs.c);
+ group_addrs.len = 0;
+
+ STR_FREE(addrs->addrs[iaddr].name);
+ addrs->addrs[iaddr].name = php_rfc822_recombine_tokens(toks, group_lbl_start,
+ group_lbl_end - group_lbl_start,
+ PHP_RFC822_RECOMBINE_SPACE_ATOMS);
+
+ addrs->addrs[iaddr].is_group = 1;
+ }
+
+ iaddr++;
+ in_group = 0;
+ start_tok++;
+ goto address;
+ }
+ /* look for more mailboxes in this group */
+ goto mailbox;
+}
+
+PHP_MAILPARSE_API php_rfc822_addresses_t *php_rfc822_parse_address_tokens(php_rfc822_tokenized_t *toks)
+{
+ php_rfc822_addresses_t *addrs = ecalloc(1, sizeof(php_rfc822_addresses_t));
+
+ parse_address_tokens(toks, NULL, &addrs->naddrs);
+ if (addrs->naddrs) {
+ addrs->addrs = ecalloc(addrs->naddrs, sizeof(php_rfc822_address_t));
+ parse_address_tokens(toks, addrs, &addrs->naddrs);
+ }
+
+ return addrs;
+}
+
+PHP_MAILPARSE_API void php_rfc822_free_addresses(php_rfc822_addresses_t *addrs)
+{
+ int i;
+ for (i = 0; i < addrs->naddrs; i++) {
+ if (addrs->addrs[i].name)
+ STR_FREE(addrs->addrs[i].name);
+ STR_FREE(addrs->addrs[i].address);
+ }
+ if (addrs->addrs)
+ efree(addrs->addrs);
+ efree(addrs);
+}
+void php_rfc822_print_addresses(php_rfc822_addresses_t *addrs)
+{
+ int i;
+ printf("printing addresses %p\n", addrs); fflush(stdout);
+ for (i = 0; i < addrs->naddrs; i++) {
+ printf("addr %d: name=%s address=%s\n", i, addrs->addrs[i].name, addrs->addrs[i].address);
+ }
+}
+
+
+void php_rfc822_print_tokens(php_rfc822_tokenized_t *toks)
+{
+ int i;
+ for (i = 0; i < toks->ntokens; i++) {
+ printf("token %d: token=%d/%c len=%d value=%s\n", i, toks->tokens[i].token, toks->tokens[i].token,
+ toks->tokens[i].valuelen, toks->tokens[i].value);
+ }
+}
+
+PHP_FUNCTION(mailparse_test)
+{
+ char *header;
+ long header_len;
+ php_rfc822_tokenized_t *toks;
+ php_rfc822_addresses_t *addrs;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+
+#if 0
+ {
+ struct rfc822t *t = mailparse_rfc822t_alloc(header, NULL);
+ for (i = 0; i < t->ntokens; i++) {
+ printf("token %d: token=%d/%c len=%d value=%s\n", i, t->tokens[i].token, t->tokens[i].token,
+ t->tokens[i].len, t->tokens[i].ptr);
+
+ }
+ mailparse_rfc822t_free(t);
+
+ printf("--- and now:\n");
+ }
+#endif
+
+ toks = php_mailparse_rfc822_tokenize((const char*)header, 1 TSRMLS_CC);
+ php_rfc822_print_tokens(toks);
+
+ addrs = php_rfc822_parse_address_tokens(toks);
+ php_rfc822_print_addresses(addrs);
+ php_rfc822_free_addresses(addrs);
+
+ php_rfc822_tokenize_free(toks);
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker syn=c
+ * vim<600: sw=4 ts=4
+ */
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/001.phpt
^
|
(renamed from mailparse-2.1.3/tests/001.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/001.phpt
^
|
(renamed from mailparse-2.1.3/tests/001.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/002.phpt
^
|
(renamed from mailparse-2.1.3/tests/002.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/002.phpt
^
|
(renamed from mailparse-2.1.3/tests/002.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/003.phpt
^
|
(renamed from mailparse-2.1.3/tests/003.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/003.phpt
^
|
(renamed from mailparse-2.1.3/tests/003.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/004.phpt
^
|
(renamed from mailparse-2.1.3/tests/004.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/004.phpt
^
|
(renamed from mailparse-2.1.3/tests/004.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/005.phpt
^
|
(renamed from mailparse-2.1.3/tests/005.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/005.phpt
^
|
(renamed from mailparse-2.1.3/tests/005.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/006.phpt
^
|
(renamed from mailparse-2.1.3/tests/006.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/006.phpt
^
|
(renamed from mailparse-2.1.3/tests/006.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/007.phpt
^
|
(renamed from mailparse-2.1.3/tests/007.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/007.phpt
^
|
(renamed from mailparse-2.1.3/tests/007.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/008.phpt
^
|
(renamed from mailparse-2.1.3/tests/008.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/008.phpt
^
|
(renamed from mailparse-2.1.3/tests/008.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/009.phpt
^
|
(renamed from mailparse-2.1.3/tests/009.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/009.phpt
^
|
(renamed from mailparse-2.1.3/tests/009.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/010.phpt
^
|
(renamed from mailparse-2.1.3/tests/010.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/010.phpt
^
|
(renamed from mailparse-2.1.3/tests/010.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/parse_test_messages.phpt
^
|
(renamed from mailparse-2.1.3/tests/parse_test_messages.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/parse_test_messages.phpt
^
|
(renamed from mailparse-2.1.3/tests/parse_test_messages.phpt)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/mime.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/mime.exp)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/mime.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/mime.exp)
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/mime.txt
^
|
@@ -0,0 +1,47 @@
+Return-Path: <wez@thebrainroom.com>
+Received: from TITAN (titan.brainnet.i [192.168.2.7])
+ by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g87BfJ721279
+ for <wez@thebrainroom.com>; Sat, 7 Sep 2002 12:41:19 +0100
+X-Authentication-Warning: zaneeb.brainnet.i: Host titan.brainnet.i [192.168.2.7] claimed to be TITAN
+From: "Wez Furlong" <wez@thebrainroom.com>
+To: <wez@thebrainroom.com>
+Subject: mime attach
+Date: Sat, 7 Sep 2002 12:41:14 +0100
+Message-ID: <000601c25663$78b7fcf0$0702a8c0@TITAN>
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+ boundary="----=_NextPart_000_0007_01C2566B.DA7C64F0"
+X-Priority: 3 (Normal)
+X-MSMail-Priority: Normal
+X-Mailer: Microsoft Outlook, Build 10.0.2627
+Importance: Normal
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
+X-TBR-DestBox: user.wez (auth as wez) (wez:)
+
+This is a multi-part message in MIME format.
+
+------=_NextPart_000_0007_01C2566B.DA7C64F0
+Content-Type: text/plain;
+ charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+this is a message with regular mime attachment.
+
+------=_NextPart_000_0007_01C2566B.DA7C64F0
+Content-Type: application/octet-stream;
+ name="README"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment;
+ filename="README"
+
+FooBar - blah blah blah foo bar bar baaaa=0A=
+=0A=
+Requirements: =0A=
+ o php with mailparse=0A=
+ o virus scanner (optional)=0A=
+ =0A=
+=0A=
+
+------=_NextPart_000_0007_01C2566B.DA7C64F0--
+
+
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/oeuue
^
|
(renamed from mailparse-2.1.3/tests/testdata/oeuue)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/oeuue
^
|
(renamed from mailparse-2.1.3/tests/testdata/oeuue)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/phpcvs1.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/phpcvs1.exp)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/phpcvs1.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/phpcvs1.exp)
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/phpcvs1.txt
^
|
@@ -0,0 +1,141 @@
+Return-Path: <php-cvs-return-15542-wez.php.cvs=thebrainroom.com@lists.php.net>
+Received: from secure.thebrainroom.com (raq338.uk2net.com [213.239.42.171])
+ by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g9SLLB208234
+ for <wez.php.cvs@thebrainroom.com>; Mon, 28 Oct 2002 21:21:11 GMT
+X-Authentication-Warning: zaneeb.brainnet.i: Host raq338.uk2net.com [213.239.42.171] claimed to be secure.thebrainroom.com
+Received: from pb1.pair.com (pb1.pair.com [216.92.131.4])
+ by secure.thebrainroom.com (8.9.3/8.9.3) with SMTP id SAA02428
+ for <wez.php.cvs@thebrainroom.com>; Mon, 28 Oct 2002 18:50:26 GMT
+Received: (qmail 63230 invoked by uid 1010); 28 Oct 2002 18:36:34 -0000
+Mailing-List: contact php-cvs-help@lists.php.net; run by ezmlm
+Precedence: bulk
+list-help: <mailto:php-cvs-help@lists.php.net>
+list-unsubscribe: <mailto:php-cvs-unsubscribe@lists.php.net>
+list-post: <mailto:php-cvs@lists.php.net>
+Delivered-To: mailing list php-cvs@lists.php.net
+Received: (qmail 63215 invoked from network); 28 Oct 2002 18:36:33 -0000
+Reply-to: marcus.boerger@post.rwth-aachen.de
+Message-Id: <5.1.0.14.2.20021028193555.01d47c20@mailbox.rwth-aachen.de>
+X-Mailer: QUALCOMM Windows Eudora Version 5.1
+Date: Mon, 28 Oct 2002 19:36:10 +0100
+To: Melvyn Sopacua <msopacua@idg.nl>
+From: marcus.boerger@t-online.de (Marcus =?iso-8859-1?Q?B=F6rger?=)
+Cc: php-cvs@lists.php.net
+In-Reply-To: <5.1.0.14.2.20021028192151.039729e0@yoshimo.webtechs.idg.nl
+ >
+References: <5.1.0.14.2.20021028190015.01d4d650@mailbox.rwth-aachen.de>
+ <5.1.0.14.2.20021028183051.03c18958@yoshimo.webtechs.idg.nl>
+ <cvshelly1035825322@cvsserver>
+Mime-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="=====================_71195359==_.ALT"
+X-Sender: 520072483730-0001@t-dialin.net
+X-Spam-Status: No, tests=bogofilter, spamicity=0.0% likelihood
+Subject: Re: [PHP-CVS] cvs: php4 /ext/iconv/tests
+X-TBR-DestBox: user.wez.php.cvs (auth as wez) (wez.php.cvs:)
+
+--=====================_71195359==_.ALT
+Content-Type: text/plain; charset="iso-8859-1"; format=flowed
+Content-Transfer-Encoding: quoted-printable
+
+Then what about:
+
+cvs -z3 -q diff skipif.inc test.inc (in directory=20
+S:\php4-HEAD\ext\iconv\tests\)
+Index: skipif.inc
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
+RCS file: /repository/php4/ext/iconv/tests/skipif.inc,v
+retrieving revision 1.2
+diff -u -r1.2 skipif.inc
+--- skipif.inc 28 Oct 2002 17:15:21 -0000 1.2
++++ skipif.inc 28 Oct 2002 18:35:25 -0000
+@@ -1,10 +1,11 @@
+ <?php
+ // This script prints "skip" if condition does not meet.
+
+-if (!extension_loaded("iconv") && ini_get("enable_dl")) {
+- $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
+- @dl("iconv$dlext");
+-}
++// Do not dl load extension
++//if (!extension_loaded("iconv") && ini_get("enable_dl")) {
++// $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
++// @dl("iconv$dlext");
++//}
+ if (!extension_loaded("iconv")) {
+ die("skip iconv extension not available\n");
+ }
+Index: test.inc
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
+RCS file: /repository/php4/ext/iconv/tests/test.inc,v
+retrieving revision 1.1
+diff -u -r1.1 test.inc
+--- test.inc 28 Oct 2002 17:15:21 -0000 1.1
++++ test.inc 28 Oct 2002 18:35:25 -0000
+@@ -1,8 +1,7 @@
+ <?php
+-// This script prints "skip" if condition does not meet.
+-
+-if (!extension_loaded("iconv") && ini_get("enable_dl")) {
+- $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
+- @dl("iconv$dlext");
+-}
++// Do not dl load extension
++//if (!extension_loaded("iconv") && ini_get("enable_dl")) {
++// $dlext =3D (substr(PHP_OS, 0, 3) =3D=3D "WIN") ? ".dll" : ".so";
++// @dl("iconv$dlext");
++//}
+ ?>
+
+At 19:30 28.10.2002, Melvyn Sopacua wrote:
+>At 19:01 28-10-2002, Marcus B=F6rger wrote:
+>
+>>At 18:33 28.10.2002, Melvyn Sopacua wrote:
+>>>At 18:15 28-10-2002, Marcus B=F6rger wrote:
+>>>
+>>>> Log:
+>>>> fix this tests
+>>>> -they did not dl load module in test....
+>>>
+>>>Yes, exactly as they shouldn't.
+>>>
+>>>It's been discussed. Why did you revert that?
+>>>
+>>>The main reason - to repeat it:
+>>>./configure --prefix=3D/previous/install
+>>>
+>>>dl('foo.so') =3D> foo.so version is previous install, not current!
+>>
+>>I did so because skipif.inc did so. Maybe we remove that code
+>>from both skipif.inc and test.inc now. Feel free to do that.
+>
+>Ok, then that was a left over.
+>
+>IMHO we should do a complete overhaul of */tests/* and remove any dl()
+>code, or come up with something, that will force the modules/ directory
+>on the testkit.
+>
+>This is again a good reason to setup php.ini-test.
+>Windows will then be a problem, which kinda makes the dl() thingy=
+ troublesome
+>as well.
+>
+>The only thing I can think of to work around it, is to use a configure
+>option, that writes --with-test-modules-dir=3D into php.ini-test. But=
+ that's
+>prolly overkill.
+>
+>
+>
+>Met vriendelijke groeten / With kind regards,
+>
+>Webmaster IDG.nl
+>Melvyn Sopacua
+>
+
+--=====================_71195359==_.ALT--
+
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/qp.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/qp.exp)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/qp.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/qp.exp)
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/qp.txt
^
|
@@ -0,0 +1,47 @@
+Return-Path: <wez@thebrainroom.com>
+Received: from TITAN (titan.brainnet.i [192.168.2.7])
+ by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g87Bel721254
+ for <wez@thebrainroom.com>; Sat, 7 Sep 2002 12:40:47 +0100
+X-Authentication-Warning: zaneeb.brainnet.i: Host titan.brainnet.i [192.168.2.7] claimed to be TITAN
+From: "Wez Furlong" <wez@thebrainroom.com>
+To: <wez@thebrainroom.com>
+Subject: qp attachments
+Date: Sat, 7 Sep 2002 12:40:37 +0100
+Message-ID: <000201c25663$65e80250$0702a8c0@TITAN>
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+ boundary="----=_NextPart_000_0003_01C2566B.C7AC6A50"
+X-Priority: 3 (Normal)
+X-MSMail-Priority: Normal
+X-Mailer: Microsoft Outlook, Build 10.0.2627
+Importance: Normal
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
+X-TBR-DestBox: user.wez (auth as wez) (wez:)
+
+This is a multi-part message in MIME format.
+
+------=_NextPart_000_0003_01C2566B.C7AC6A50
+Content-Type: text/plain;
+ charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+this is a message with a qp attachment.
+
+------=_NextPart_000_0003_01C2566B.C7AC6A50
+Content-Type: application/octet-stream;
+ name="README"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment;
+ filename="README"
+
+Xnti rpam and gnti yirusjkools for bendmail=0A=
+=0A=
+Requirements: =0A=
+ o php with mailparse=0A=
+ o virus scanner (optional)=0A=
+ =0A=
+=0A=
+
+------=_NextPart_000_0003_01C2566B.C7AC6A50--
+
+
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/uue.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/uue.exp)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/uue.exp
^
|
(renamed from mailparse-2.1.3/tests/testdata/uue.exp)
|
[-]
[+]
|
Added |
mailparse-2.1.6.tgz/mailparse-2.1.6/tests/testdata/uue.txt
^
|
@@ -0,0 +1,27 @@
+Return-Path: <wez@thebrainroom.com>
+Received: from TITAN (titan.brainnet.i [192.168.2.7])
+ by zaneeb.brainnet.i (8.10.2/8.10.2/SuSE Linux 8.10.0-0.3) with ESMTP id g87Be5721229
+ for <wez@thebrainroom.com>; Sat, 7 Sep 2002 12:40:05 +0100
+X-Authentication-Warning: zaneeb.brainnet.i: Host titan.brainnet.i [192.168.2.7] claimed to be TITAN
+From: "Wez Furlong" <wez@thebrainroom.com>
+To: <wez@thebrainroom.com>
+Subject: UUEncoded attachments
+Date: Sat, 7 Sep 2002 12:39:55 +0100
+Message-ID: <000001c25663$4cd5b460$0702a8c0@TITAN>
+X-Priority: 3 (Normal)
+X-MSMail-Priority: Normal
+X-Mailer: Microsoft Outlook, Build 10.0.2627
+Importance: Normal
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
+X-TBR-DestBox: user.wez (auth as wez) (wez:)
+
+Hello, this is a message with UUE attachments.
+
+
+begin 644 README.dat
+M1F]O0F%R("T@0F%A86%A"@I297%U:7)E;65N=',Z(`H);R!P:'`@=VET:"!M
+K86EL<&%R<V4*("`@(&\@=FER=7,@<V-A;FYE<B`H;W!T:6]N86PI"@D*"@``
+`
+end
+
+
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/try.php
^
|
(renamed from mailparse-2.1.3/try.php)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/mailparse-2.1.6/try.php
^
|
(renamed from mailparse-2.1.3/try.php)
|
[-]
[+]
|
Changed |
mailparse-2.1.6.tgz/package.xml
^
|
@@ -1,70 +1,94 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
-<package version="1.0" packagerversion="1.6.1">
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>mailparse</name>
+ <channel>pecl.php.net</channel>
<summary>Email message manipulation</summary>
<description>Mailparse is an extension for parsing and working with email messages.
-It can deal with rfc822 and rfc2045 (MIME) compliant messages.
- </description>
- <maintainers>
- <maintainer>
- <user>wez</user>
- <name>Wez Furlong</name>
- <email>wez@php.net</email>
- <role>lead</role>
- </maintainer>
- <maintainer>
- <user>shire</user>
- <name>Brian Shire</name>
- <email>shire@php.net</email>
- <role>lead</role>
- </maintainer>
- </maintainers>
- <release>
- <version>2.1.3</version>
- <date>2008-01-08</date>
- <license>PHP</license>
- <state>stable</state>
- <notes>Fixed problems with continuation lines introduced in 2.1.2.
-Fixed bug #6862.
- </notes>
- <deps>
- <dep type="ext" rel="has">mbstring</dep>
- <dep type="php" rel="ge" version="4.3.0"/>
- </deps>
- <filelist>
- <file role="src" name="config.m4"/>
- <file role="src" name="mailparse.c"/>
- <file role="src" name="Makefile.frag"/>
- <file role="src" name="php_mailparse.h"/>
- <file role="src" name="php_mailparse_mime.c"/>
- <file role="src" name="php_mailparse_mime.h"/>
- <file role="src" name="php_mailparse_rfc822.re"/>
- <file role="src" name="php_mailparse_rfc822.c"/>
- <file role="src" name="php_mailparse_rfc822.h"/>
- <file role="doc" name="CREDITS"/>
- <file role="doc" name="README"/>
- <file role="doc" name="try.php"/>
- <file role="test" name="tests/testdata/mime.exp"/>
- <file role="test" name="tests/testdata/mime.txt"/>
- <file role="test" name="tests/testdata/phpcvs1.exp"/>
- <file role="test" name="tests/testdata/phpcvs1.txt"/>
- <file role="test" name="tests/testdata/qp.exp"/>
- <file role="test" name="tests/testdata/qp.txt"/>
- <file role="test" name="tests/testdata/uue.exp"/>
- <file role="test" name="tests/testdata/uue.txt"/>
- <file role="test" name="tests/testdata/oeuue"/>
- <file role="test" name="tests/001.phpt"/>
- <file role="test" name="tests/002.phpt"/>
- <file role="test" name="tests/003.phpt"/>
- <file role="test" name="tests/004.phpt"/>
- <file role="test" name="tests/005.phpt"/>
- <file role="test" name="tests/006.phpt"/>
- <file role="test" name="tests/007.phpt"/>
- <file role="test" name="tests/008.phpt"/>
- <file role="test" name="tests/009.phpt"/>
- <file role="test" name="tests/010.phpt"/>
- <file role="test" name="tests/parse_test_messages.phpt"/>
- </filelist>
- </release>
+It can deal with rfc822 and rfc2045 (MIME) compliant messages.</description>
+ <lead>
+ <name>Wez Furlong</name>
+ <user>wez</user>
+ <email>wez@php.net</email>
+ <active>yes</active>
+ </lead>
+ <lead>
+ <name>Brian Shire</name>
+ <user>shire</user>
+ <email>shire@php.net</email>
+ <active>yes</active>
+ </lead>
+ <lead>
+ <name>John Jawed</name>
+ <user>jawed</user>
+ <email>jawed@php.net</email>
+ <active>yes</active>
+ </lead>
+ <date>2012-03-09</date>
+ <time>09:52:16</time>
+ <version>
+ <release>2.1.6</release>
+ <api>2.1.6</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <license uri="http://www.php.net/license">PHP</license>
+ <notes>
+- PHP 5.4 compatibility
+- BUG: Fixed TSRM build
+- BUG: Don't attempt parse addresses if # of addresses is 0
+ </notes>
+ <contents>
+ <dir name="/">
+ <file md5sum="53a80aaa80c4264b358eb2c60bb70f97" name="tests/testdata/mime.exp" role="test" />
+ <file md5sum="9977c29a7cc66506e951c194c9854a7e" name="tests/testdata/mime.txt" role="test" />
+ <file md5sum="ed47320fa50fba1fe1f6cb90abd74d09" name="tests/testdata/oeuue" role="test" />
+ <file md5sum="88ee73e6ef5f7e07cddc04db9c885d52" name="tests/testdata/phpcvs1.exp" role="test" />
+ <file md5sum="11811181d1f553961a12f8f40bdc7146" name="tests/testdata/phpcvs1.txt" role="test" />
+ <file md5sum="a5d25e0a5045b170abd46d8ca74302bc" name="tests/testdata/qp.exp" role="test" />
+ <file md5sum="35f66ee80b6bfb54ca75c728c233eb79" name="tests/testdata/qp.txt" role="test" />
+ <file md5sum="462339fc59cc461c296d9b3e4fefe884" name="tests/testdata/uue.exp" role="test" />
+ <file md5sum="50456b53bbc58888a88180576e5f444d" name="tests/testdata/uue.txt" role="test" />
+ <file md5sum="f0714afb709996bb1a5783575d8e3838" name="tests/001.phpt" role="test" />
+ <file md5sum="834efdde9d108bf98c36fba03354a741" name="tests/002.phpt" role="test" />
+ <file md5sum="aeb46fa1168291d439a2b11983b9c154" name="tests/003.phpt" role="test" />
+ <file md5sum="e7bac3f8bd6dfd70162f8cc34d3fc7f4" name="tests/004.phpt" role="test" />
+ <file md5sum="5e8fffaaebcb7aaf4a63e3dc04124ba3" name="tests/005.phpt" role="test" />
+ <file md5sum="30f7d959fadf0ab26be2388d79d7ac96" name="tests/006.phpt" role="test" />
+ <file md5sum="61aeda485a2d98ce8eee07b6cb9b76cd" name="tests/007.phpt" role="test" />
+ <file md5sum="2ce1e38622f0936f3bc4b080dc793124" name="tests/008.phpt" role="test" />
+ <file md5sum="827514b0c55482451558d8c963b1fa6c" name="tests/009.phpt" role="test" />
+ <file md5sum="f6cf49eb9c74d37a0402f960e470e19c" name="tests/010.phpt" role="test" />
+ <file md5sum="492a524ead5534fb72e03b649740cd16" name="tests/parse_test_messages.phpt" role="test" />
+ <file md5sum="a14d5e68e7423c4eb915a8334c36d488" name="config.m4" role="src" />
+ <file md5sum="c08b3ff0db4689c0966c84d097ef4bcd" name="CREDITS" role="doc" />
+ <file md5sum="38e2fa0fa7e0c6f2404979b81013d773" name="mailparse.c" role="src" />
+ <file md5sum="8df385f2c03c3c9d7681a208249badd6" name="Makefile.frag" role="src" />
+ <file md5sum="96c7f5d19c679c4d5ae29cc0afaaadbb" name="php_mailparse.h" role="src" />
+ <file md5sum="b85a5e97387e1ee61c206e90df72cfbf" name="php_mailparse_mime.c" role="src" />
+ <file md5sum="5bf2e53f08c9c0541e8c15c5f90313c5" name="php_mailparse_mime.h" role="src" />
+ <file md5sum="a1a61f80905ecd9f2bc827b52a2a92ce" name="php_mailparse_rfc822.c" role="src" />
+ <file md5sum="6617162843109ab224bba5f439892ade" name="php_mailparse_rfc822.h" role="src" />
+ <file md5sum="c8f1c114cad45da2f552528028ec48e4" name="php_mailparse_rfc822.re" role="src" />
+ <file md5sum="76a94bb94e02664620339f780186ea1f" name="README" role="doc" />
+ <file md5sum="41aa8420372a5676cbfaf9af2b12cb7a" name="try.php" role="doc" />
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>4.3.0</min>
+ <max>6.0.0</max>
+ </php>
+ <pearinstaller>
+ <min>1.4.0a1</min>
+ </pearinstaller>
+ <extension>
+ <name>mbstring</name>
+ </extension>
+ </required>
+ </dependencies>
+ <providesextension>mailparse</providesextension>
+ <extsrcrelease />
</package>
|