return Banana::$page->run();
}
+ /** Build and post a new message
+ * @return postid (or -1 if the message has not been found)
+ */
+ public function post($dest, $reply, $subject, $body)
+ {
+ $hdrs = Banana::$protocole->requestedHeaders();
+ $headers = Banana::$profile['headers'];
+ $headers[$hdrs['dest']] = $dest;
+ if ($reply) {
+ $headers[$hdrs['reply']] = $reply;
+ }
+ $headers['Subject'] = $subject;
+ $msg = BananaMessage::newMessage($headers, $body);
+ if (Banana::$protocole->send($msg)) {
+ Banana::$group = ($reply ? $reply : $dest);
+ $this->loadSpool(Banana::$group);
+ return Banana::$spool->getPostId($subject);
+ }
+ return -1;
+ }
+
/** Return the CSS code to include in the headers
*/
public function css()
$hdr_values = array();
foreach ($hdrs as $header) {
$hdr_values[$header] = isset($headers[$header]['fixed']) ? $headers[$header]['fixed'] : @$_POST[$header];
+ if ($headers != 'Subject') {
+ $hdr_values[$header] = str_replace(', ', ',', $hdr_values[$header]);
+ }
}
if ($artid) {
$old =& $this->loadMessage($group, $artid);
}
if (!is_null($msg)) {
if (Banana::$protocole->send($msg)) {
- Banana::$page->redirect(array('group' => $group, 'artid' => $artid));
+ $newid = Banana::$spool->updateUnread(Banana::$profile['lastnews']);
+ Banana::$page->redirect(array('group' => $group, 'artid' => $newid ? $newid : $artid));
}
Banana::$page->trig(_b_('Une erreur est survenue lors de l\'envoi du message :') . '<br />'
. Banana::$protocole->lastError());
return true;
}
- private function updateUnread($since)
+ public function updateUnread($since)
{
if (empty($since)) {
return;
return $id_cur;
}
+ /** Return the last post id with the given subject
+ * @param subject
+ */
+ public function getPostId($subject)
+ {
+ $subject = trim($subject);
+ $id = max(array_keys($this->overview));
+ while (isset($this->overview[$id])) {
+ $test = $this->overview[$id]->subject;
+ if (function_exists('hook_formatDisplayHeader')) {
+ $val = hook_formatDisplayHeader('subject', $test, true);
+ if (is_array($val)) {
+ $test = $val[0];
+ } else {
+ $test = $val;
+ }
+ }
+ $test = trim($test);
+ echo $test . " - " . $subject . "\n";
+ if ($test == $subject) {
+ return $id;
+ }
+ $id--;
+ }
+ return -1;
+ }
+
/** Returns previous thread root index
* @param id INTEGER message number
*/