/** * Constructor. * * @param mixed $data The mbox data. Either a resource or a filename * as interpreted by fopen() (string). * @param integer $limit Limit to this many messages; additional messages * will throw an exception. * * @throws Horde_Mail_Parse_Exception */ public function __construct($data, $limit = null) { $this->_data = is_resource($data) ? $data : @fopen($data, 'r'); if ($this->_data === false) { throw new Horde_Mail_Exception(Horde_Mail_Translation::t("Could not parse mailbox data.")); } rewind($this->_data); $i = 0; $last_line = null; /* Is this a MBOX format file? */ $mbox = false; while (!feof($this->_data)) { if (is_null($last_line)) { $start = ftell($this->_data); } $line = fgets($this->_data); if (is_null($last_line)) { ltrim($line); } if (substr($line, 0, 5) == 'From ') { if (is_null($last_line)) { /* This file is in MBOX format. */ $mbox = true; } elseif (!$mbox || trim($last_line) !== '') { continue; } if ($limit && $i++ > $limit) { throw new Horde_Mail_Exception(sprintf(Horde_Mail_Translation::t("Imported mailbox contains more than enforced limit of %u messages."), $limit)); } $from_line = explode(' ', $line, 3); try { $date = new DateTime($from_line[2]); } catch (Exception $e) { $date = null; } $this->_parsed[] = array('date' => $date, 'start' => ftell($this->_data)); } /* Strip all empty lines before first data. */ if (!is_null($last_line) || trim($line) !== '') { $last_line = $line; } } /* This was a single message, not a MBOX file. */ if (empty($this->_parsed)) { $this->_parsed[] = array('date' => false, 'start' => $start); } }
/** */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Mail'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Mail/locale'; return parent::ngettext($singular, $plural, $number); }