Mailparse
- Введение
- Installing/Configuring
- Предопределенные константы
- Mailparse Функции
- mailparse_determine_best_xfer_encoding — Gets the best way of encoding
- mailparse_msg_create — Create a mime mail resource
- mailparse_msg_extract_part_file — Extracts/decodes a message section
- mailparse_msg_extract_part — Extracts/decodes a message section
- mailparse_msg_extract_whole_part_file — Extracts a message section including headers without decoding the transfer encoding
- mailparse_msg_free — Frees a MIME resource
- mailparse_msg_get_part_data — Returns an associative array of info about the message
- mailparse_msg_get_part — Returns a handle on a given section in a mimemessage
- mailparse_msg_get_structure — Returns an array of mime section names in the supplied message
- mailparse_msg_parse_file — Parses a file
- mailparse_msg_parse — Incrementally parse data into buffer
- mailparse_rfc822_parse_addresses — Parse RFC 822 compliant addresses
- mailparse_stream_encode — Streams data from source file pointer, apply encoding and write to destfp
- mailparse_uudecode_all — Scans the data from fp and extract each embedded uuencoded file
Коментарии
I've put together an open source mail parser class using mailpase functions.
http://code.google.com/p/php-mime-mail-parser/
This should make it more straight forward to parse the email. Example usage:
<?php
// mail parser class
require_once('MimeMailParser.class.php');
$path = 'path/to/mail.txt';
$Parser = new MimeMailParser();
$Parser->setPath($path);
$to = $Parser->getHeader('to');
$from = $Parser->getHeader('from');
$subject = $Parser->getHeader('subject');
$text = $Parser->getMessageBody('text');
$html = $Parser->getMessageBody('html');
$attachments = $Parser->getAttachments();
// saving attachments
$save_dir = '/path/to/save/attachments/';
foreach($attachments as $attachment) {
// get the attachment name
$filename = $attachment->filename;
// write the file to the directory you want to save it in
if ($fp = fopen($save_dir.$filename, 'w')) {
while($bytes = $attachment->read()) {
fwrite($fp, $bytes);
}
fclose($fp);
}
}
?>
Hope this helps.