X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fmbox.inc.php;h=1ddb5d519063f984a1aabdb44a2df122ce8ebeb4;hb=598a1c538cde55ef90fcacd7d09d36e025f64dee;hp=c36bb5c492167172c6bd955ff04fe1df281a7f0c;hpb=7027794fb616f65d8910305c9fed9037a751b875;p=banana.git diff --git a/banana/mbox.inc.php b/banana/mbox.inc.php index c36bb5c..1ddb5d5 100644 --- a/banana/mbox.inc.php +++ b/banana/mbox.inc.php @@ -13,8 +13,6 @@ require_once dirname(__FILE__) . '/message.inc.php'; class BananaMBox implements BananaProtocoleInterface { - private $boxname; - private $file = null; private $filesize = null; private $current_id = null; @@ -30,10 +28,9 @@ class BananaMBox implements BananaProtocoleInterface /** Build a protocole handler plugged on the given box */ - public function __construct($box = null) + public function __construct() { - $this->boxname = $box; - $filename = $this->getFileName($box); + $filename = $this->getFileName(Banana::$group); if (is_null($filename)) { return; } @@ -61,10 +58,10 @@ class BananaMBox implements BananaProtocoleInterface */ public function isValid() { - return is_null($this->boxname) || !is_null($this->file); + return !Banana::$group || $this->file; } - /** Indicate last error n° + /** Indicate last error n° */ public function lastErrNo() { @@ -93,31 +90,47 @@ class BananaMBox implements BananaProtocoleInterface */ public function getBoxList($mode = Banana::BOXES_ALL, $since = 0, $withstats = false) { - return array($this->boxname => array('desc' => '', 'msgnum' => 0, 'unread' => 0)); + return array(Banana::$group => array('desc' => '', 'msgnum' => 0, 'unread' => 0)); } /** Return a message * @param id Id of the emssage (can be either an Message-id or a message index) - * @param msg_headers Headers to process - * @param is_msgid If is set, $id is en Message-Id * @return A BananaMessage or null if the given id can't be retreived */ - public function getMessage($id, array $msg_headers = array(), $is_msgid = false) + public function &getMessage($id) { - if ($is_msgid || !is_numeric($id)) { - if (is_null(Banana::$spool)) { - return null; + $message = null; + if (!is_numeric($id)) { + if (!Banana::$spool) { + return $message; } $id = Banana::$spool->ids[$id]; } $message = $this->readMessages(array($id)); if (empty($message)) { - return null; + $message = null; + return $message; } - $msg = new BananaMessage($message[$id]['message']); - return $msg; + return new BananaMessage($message[$id]['message']); } + /** Return the sources of the given message + */ + public function getMessageSource($id) + { + $message = null; + if (!is_numeric($id)) { + if (!Banana::$spool) { + return $message; + } + $id = Banana::$spool->ids[$id]; + } + $message = $this->readMessages(array($id)); + return implode("\n", $message[$id]['message']); + } + + /** Compute the number of messages of the box + */ private function getCount() { $this->count = count(Banana::$spool->overview); @@ -156,9 +169,9 @@ class BananaMBox implements BananaProtocoleInterface $headers[$id] = array('beginning' => $message['beginning'], 'end' => $message['end']); } if ($header == 'date') { - $headers[$id][$header] = strtotime($message['message'][$header]); + $headers[$id][$header] = @strtotime($message['message'][$header]); } else { - $headers[$id][$header] = $message['message'][$header]; + $headers[$id][$header] = @$message['message'][$header]; } } } @@ -238,6 +251,18 @@ class BananaMBox implements BananaProtocoleInterface return 'MBOX'; } + /** Return the spool filename + */ + public function filename() + { + @list($mail, $domain) = explode('@', Banana::$group); + $file = ""; + if (isset($domain)) { + $file = $domain . '_'; + } + return $file . $mail; + } + ####### # Filesystem functions ####### @@ -248,11 +273,7 @@ class BananaMBox implements BananaProtocoleInterface return null; } @list($mail, $domain) = explode('@', $box); - if ($mail == 'staff') { - return '/home/x2003bruneau/staff.polytechnique.org_innovation.mbox'; - } else { - return '/var/mail/' . $mail; - } + return Banana::$mbox_path . '/' . $mail; } ####### @@ -399,7 +420,7 @@ class BananaMBox implements BananaProtocoleInterface */ private function &readMessages(array $ids, $strip = false, $from = false) { - if (!is_null($this->messages)) { + if ($this->messages) { return $this->messages; } sort($ids); @@ -427,5 +448,5 @@ class BananaMBox implements BananaProtocoleInterface } } -// vim:set et sw=4 sts=4 ts=4: +// vim:set et sw=4 sts=4 ts=4 enc=utf-8: ?>