function email_count() { /** CLASSES **/ if (!class_exists('PEAR')) { require_once 'classes/PEAR-1.9.5/PEAR.php'; } if (!class_exists('Mail_Mbox')) { require_once 'classes/Mail/Mbox.php'; } //reads a mbox file $mbox = new Mail_Mbox($this->mail); $mbox->open(); $count = $mbox->size(); return $count; }
/** * While the bug was incorrect, it showed that we do not * escape messages properly. * Here we test that escaped messages are stored and read * properly. * * @link http://pear.php.net/bugs/bug.php?id=16758 * * @return void */ public function testBug16758() { $msg = <<<MBX From someone.who@loves.you Subject: test From now on, no more bugs! >From what I said... >>From where are you coming? MBX; //file does not exist yet $mbox = new Mail_Mbox(self::$filecopy); $this->assertTrue($mbox->open()); $this->assertTrue($mbox->append($msg)); $mbox->close(); $mbox = new Mail_Mbox(self::$filecopy); $this->assertTrue($mbox->open()); $this->assertEquals(1, $mbox->size()); $this->assertEquals($msg, $mbox->get(0)); }
{ echo 'Mbox has ' . $mbox->size() . ' messages.' . "\n"; for ($n = 0; $n < $mbox->size(); $n++) { $message = $mbox->get($n); preg_match('/Subject: (.*)$/m', $message, $matches); $subject = $matches[1]; echo 'Mail #' . $n . ': ' . $subject . "\n"; } echo "\n"; } //make a copy of the demo file $original = dirname(__FILE__) . '/demobox'; $file = tempnam('/tmp', 'mbox-copy-'); copy($original, $file); echo 'Using file ' . $file . "\n"; $mbox = new Mail_Mbox($file); $mbox->open(); listSubjects($mbox); echo 'append a message to the end of the box' . "\n"; $message = $mbox->get(0) . "\n" . 'This is a copy of the mail'; $mbox->insert($message); listSubjects($mbox); echo 'insert a message before the second message' . "\n"; $message = $mbox->get(0) . "\n" . 'This is another copy of the mail'; $mbox->insert($message, 1); listSubjects($mbox); echo 'remove the last message' . "\n"; $mbox->remove($mbox->size() - 1); listSubjects($mbox); echo 'remove the first two messages' . "\n"; $mbox->remove(array(0, 1));
<?php //read the subjects of the demo mailbox require_once 'Mail/Mbox.php'; //reads a mbox file $file = dirname(__FILE__) . '/demobox'; echo 'Using file ' . $file . "\n"; $mbox = new Mail_Mbox($file); $mbox->open(); for ($n = 0; $n < $mbox->size(); $n++) { $message = $mbox->get($n); preg_match('/Subject: (.*)$/m', $message, $matches); $subject = $matches[1]; echo 'Mail #' . $n . ': ' . $subject . "\n"; } $mbox->close();
$res = db_query($sql); if ($res && db_numrows($res) > 0) { $stderr = fopen('php://stderr', 'w'); fwrite($stderr, "Cannot import messages from archive.\nThere are already messages in the database for {$list} ({$mbox_file})\n"); fclose($stderr); exit; } } else { // get 3rd argument $temp_file = $argv[3]; // get temp file parent dir $forumml_tmp = $info->getPropertyValueForName('forumml_tmp'); $mbox_file = $forumml_tmp . "/" . $temp_file; } // Open the mail that has been temporary stored $mbox = new Mail_Mbox($mbox_file); $mbox->open(); if (PEAR::isError($mbox)) { print "Unable to open mbox: " . $mbox->getMessage() . PHP_EOL; } else { $nbMailInserted = 0; $num_msg = $mbox->size(); for ($i = 0; $i < $num_msg; $i++) { $thisMessage = $mbox->get($i); if (PEAR::isError($thisMessage)) { print "Unable to get message {$i}: " . $thisMessage->getMessage() . PHP_EOL; } else { // Decode email $args['include_bodies'] = TRUE; $args['decode_bodies'] = TRUE; $args['decode_headers'] = TRUE;