* Copyright (C) 2012 Nicolas Grekas - p@tchwork.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the (at your option):
 * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
 * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
 */
namespace Patchwork\Stream\Parser;

use Patchwork\Stream\Parser;
Parser::createTag('T_MAIL_HEADER');
Parser::createTag('T_MAIL_BOUNDARY');
Parser::createTag('T_MAIL_BODY');
Parser::createTag('T_MAIL_MALFORMED');
Parser::createTag('T_MIME_BOUNDARY');
Parser::createTag('T_MIME_IGNORE');
/**
 * The Mail parser tags lines of an RFC822 message and
 * exposes its MIME structure to other dependent parsers.
 *
 * @todo Detect and warn for malformed messages
 */
class Mail extends Parser
{
    const TSPECIALS_822 = '()<>@,;:\\".[]';
    const TSPECIALS_2045 = '()<>@,;:\\"/[]?=';
    const EMAIL_RX = '/[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*/';
    // From the HTML5 spec
    protected $envelope;
    protected $mimePart = array('type' => false, 'index' => 0, 'depth' => 0, 'parent' => false, 'encoding' => '7bit', 'boundary' => false, 'defaultType' => false, 'boundarySelector' => array());
    protected $type;
<?php

/*
 * Copyright (C) 2012 Nicolas Grekas - p@tchwork.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the (at your option):
 * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
 * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
 */
namespace Patchwork\Stream\Parser\Mail;

use Patchwork\Stream\Parser;
Parser::createTag('T_BOUNCE_EXCLUSIVITY');
/**
 * The Bounce mail parser does nothing on its own but acts as a container
 * for child sub-parsers that extract bounce data, each child specialized
 * on one type of bounce format.
 *
 * @todo Write a child parser that extracts the final recipient from the DSN
 *       when the original recipient is a forward. See X-Actual-Recipient.
 */
class Bounce extends Parser
{
    protected $bounceClass = 'dsn';
    protected $bounceReports = array();
    protected $hasExclusivity = false;
    public function __construct(parent $parent)
    {
        parent::__construct($parent);
        $this->register(array('catchBounceExclusivity' => T_BOUNCE_EXCLUSIVITY));