Skip to content

Instantly share code, notes, and snippets.

@sotarok
Created June 13, 2010 13:23
Show Gist options
  • Select an option

  • Save sotarok/436653 to your computer and use it in GitHub Desktop.

Select an option

Save sotarok/436653 to your computer and use it in GitHub Desktop.
<?php
/**
*
*/
$dir = '/home/sotarok/tmp/log/mail/';
$file = (glob($dir . '*'));
$mail = explode("\n\n", file_get_contents($file[1]));
$head = array_shift($mail);
$body = implode("\n", $mail);
$info = array();
$head = explode("\n", $head);
foreach ($head as $h) {
if (preg_match('/^([^:]+): (.+)$/', $h, $m)) {
$info[$m[1]] = $m[2];
}
}
preg_match('/charset=(.+)/', $info['Content-Type'], $chars);
$chars = $chars[1];
//var_dump($info, $body);
echo mb_convert_encoding($body, mb_internal_encoding(), $chars);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment