#!/usr/bin/php
mailDir = __DIR__ . '/mail';
$this->ms = WBClass::create('WBMail_Mime_Storage_String');
}
public function setMailDir($dir)
{
$this->mailDir = $dir;
}
public function list()
{
$di = new DirectoryIterator($this->mailDir);
$list = array();
foreach ($di as $i) {
if ($i->isDot() || $i->isDir()) {
continue;
}
$list[] = array('name' => $i->getFilename());
}
usort($list, array($this, 'fileNameCompare'));
foreach ($list as $i => $file) {
printf(' % 3d) %s' . "\n", $i + 1, $file['name']);
// printf('
%2$s' . "\n", $_SERVER['PHP_SELF'], $i->getFilename());
}
}
protected function fileNameCompare($a, $b)
{
if ($a['name'] > $b['name']) {
return 1;
}
if ($a['name'] > $b['name']) {
return -1;
}
return 0;
}
public function pareFile($file)
{
$buffer = file_get_contents($this->mailDir . '/' . $file);
$this->ms->loadFromString($buffer);
/** @var WBMail_Mime */
$mail = $this->ms->getMimeMail();
$format = "%20s: %s\n";
printf($format, 'From', $mail->getFrom()->get());
printf($format, 'To', $mail->getRcpt()->get());
printf($format, 'Subject', $mail->getSubject());
echo str_repeat('--------8<', 6) . "--------\n";
echo $mail->getPlainBody() . "\n";
echo str_repeat('--------8<', 6) . "--------\n";
echo "Attachments: " . $mail->countAttachments() ."\n";
for ($i = 0; $i < $mail->countAttachments(); ++$i ) {
$att = $mail->getAttachment($i);
printf("%d) %s (%s) size: %d\n",$i, $att->getName(), $att->getMime(), $att->getSize());
}
echo "\n";
}
}
$sut = new mailMimeTester();
if (2 > count($_SERVER['argv'])) {
$sut->list();
}
$first = array_shift($_SERVER['argv']);
while (!empty($_SERVER['argv'])) {
$file = array_shift($_SERVER['argv']);
$sut->pareFile($file);
}
exit(0);