SOURCE

ReaderFromMboxInterface.php

Classes


ReaderFromMboxInterface

interface ReaderFromMboxInterface
      |  
      `--ReaderInterface
           `--Printable

{

Mailbox scanner and e-mail parser interface. Implementations of this interface allow the EmlParser class to scan a mailbox file (or any other source of bytes) containing several e-mails. Basically, an object of this interface provides the next() methods that skips to the next message if available, then the same object can be feed to the EmlParser to parse that message by invoking the readLine() and getLine() methods defined in the ReaderInterface. The getLine() method will return NULL once read the last line of the current message; the client code may then invoke next() again to process the next message. For example, assuming SpecificMboxReader be a class implementing this interface, this skeleton of code displays the headers of all the messages:

$mbox = SpecificMboxReader(...);
while( $mbox->next() ){
    echo "Next message:\n";
    do {
        $mbox->readLine();
        $line = $mbox->getLine();
        if( $line === NULL || $line === "" )
            break;
        echo "$line\n";
    } while(TRUE);
}
$mbox->close();
Note that $line === "" detects the separation line between header and body, while $line === NULL detects the end of the message in case the body is missing. To fully parse each e-mail the skeleton becomes:
$mbox = SpecificMboxReader(...);
while( $mbox->next() ){
    $email = EmlParser::parse($mbox, NULL);
    ...
}
$mbox->close();

Note that the EmlParser::parse() method can throw the EmlFormatException; this exception could be captured and possibly ignored, and scanning may continue with the next message. IOException exception always indicates a fatal failure accessing the mailbox.
For faster scanning of a mailbox, only the headers could be parsed using the EmlParser::parseHeader() method rather than EmlParser::parse(); the next() method will take care to skip all the body parts. For example, this skeleton of code first parses the header, then conditionally parses the body to get the full message:

$mbox = SpecificMboxReader(...);
while( $mbox->next() ){
    $header = EmlParser::parseHeader($mbox, NULL);
    if( $header->getSubject() === "Today report" ){
        $email = EmlParser::parseBody($mbox, $header, NULL);
        ...
    }
}
$mbox->close();

Author: Umberto Salsi <salsi@icosaedro.it>
Version: $Date: 2018/07/16 07:30:24 $

Methods


next()

public boolean next() throws EmlFormatException, IOException

Skip to the beginning of the next message, so that readLine() will read the first line of that message. Please note that the next() method must be invoked to access the first email.
Return: True if a next message does really exist, possibly even empty (zero lines); false at the end of the mailbox.
Throws:
IOException - Failed reading from the mailbox.
EmlFormatException - Something badly wrong with the format of the mailbox.


Inherited methods: __toString(), __toString(), close(), getLine(), readLine()
}

Requirements

PHP Version: 7

Required modules: core, file, phpinfo, spl

Required packages:

../../../AutoloadException.php
../../../CastException.php
../../../InternalException.php
../../../all.php
../../../autoload.php
../../../cast.php
../../../errors.php
../cast/ArrayBothType.php
../cast/ArrayIntType.php
../cast/ArrayStringType.php
../cast/BooleanType.php
../cast/ClassType.php
../cast/FloatType.php
../cast/IntType.php
../cast/MixedType.php
../cast/NullType.php
../cast/ObjectType.php
../cast/ResourceType.php
../cast/StringType.php
../cast/TypeInterface.php
../cast/Types.php
../containers/Printable.php
EmlFormatException.php
ReaderInterface.php
../io/IOException.php

Generated by PHPLint Documentator