parsing raw email in php

前端 未结 14 500
猫巷女王i
猫巷女王i 2020-12-23 20:50

I\'m looking for good/working/simple to use php code for parsing raw email into parts.

I\'ve written a couple of brute force solutions, but every time, one small cha

14条回答
  •  情深已故
    2020-12-23 21:27

    There is a library for parsing raw email message into php array - http://flourishlib.com/api/fMailbox#parseMessage.

    The static method parseMessage() can be used to parse a full MIME email message into the same format that fetchMessage() returns, minus the uid key.

    $parsed_message = fMailbox::parseMessage(file_get_contents('/path/to/email'));

    Here is an example of a parsed message:

    array(
        'received' => '28 Apr 2010 22:00:38 -0400',
        'headers'  => array(
            'received' => array(
                0 => '(qmail 25838 invoked from network); 28 Apr 2010 22:00:38 -0400',
                1 => 'from example.com (HELO ?192.168.10.2?) (example) by example.com with (DHE-RSA-AES256-SHA encrypted) SMTP; 28 Apr 2010 22:00:38 -0400'
            ),
            'message-id' => '<4BD8E815.1050209@flourishlib.com>',
            'date' => 'Wed, 28 Apr 2010 21:59:49 -0400',
            'from' => array(
                'personal' => 'Will Bond',
                'mailbox'  => 'tests',
                'host'     => 'flourishlib.com'
            ),
            'user-agent'   => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4',
            'mime-version' => '1.0',
            'to' => array(
                0 => array(
                    'mailbox' => 'tests',
                    'host'    => 'flourishlib.com'
                )
            ),
            'subject' => 'This message is encrypted'
        ),
        'text'      => 'This message is encrypted',
        'decrypted' => TRUE,
        'uid'       => 15
    );
    

提交回复
热议问题