#503: signature encoding in replies
[banana.git] / banana / banana.inc.php.in
index 0166d80..86df250 100644 (file)
@@ -53,7 +53,7 @@ class Banana
      *   $matches[2] = "http://www.polytechnique.org"
      *   $matches[3] = "]"
      */
-    var $url_regexp  = '(["\[])?((?:https?|ftp|news)://(?:&|,?[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?';
+    var $url_regexp  = '(["\[])?((?:https?|ftp|news)://(?:&|\.*,*[a-z@0-9~%$£µ&i#\-+=_/\?])*)(["\]])?';
 
     
     /** Boundary for multipart messages
@@ -316,10 +316,14 @@ class Banana
              . "\n"
              . "Message canceled with Banana";
         if ($this->nntp->post($msg)) {
+            $ndx = $this->spool->getndx($artid) - 1;
+            if ($ndx > 50) {
+                $ndx = 0;
+            }
             $this->spool->delid($id);
             $this->nntp->quit();
             redirectInBanana(Array('group' => $group,
-                           'first' => $id));
+                                   'first' => $ndx));
         } else {
             return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
         }
@@ -335,18 +339,27 @@ class Banana
             $body     = $_POST['body'];
             $target   = $_POST['newsgroups'];
             $followup = $_POST['followup'];
-            $this->state['page'] = 'message';
+            $this->state['page']   = 'action';
+            $this->state['group']  = $group;
+            $this->state['action'] = 'new';
+            if ($id != -1) {
+                $this->state['artid'] = $id;
+            }
         } elseif ($id > 0) {
             $this->nntp->group($group);
             if ($this->_newPost($id)) {
-                $subject  = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post->headers['subject']);
-                $body     = utf8_encode($this->post->name." "._b_("a écrit"))." :\n"
-                                        . wrap($this->post->get_body(), "> ")
-                          . $this->profile['sig'] ? "\n\n-- \n". $this->profile['sig'] : '';
+                $subject  = 'Re: ' . preg_replace("/^re\s*:\s*/i", '', $this->post->headers['subject']);
+                $body     = to_entities(utf8_encode($this->post->name." "._b_("a écrit"))." :\n"
+                                        . wrap($this->post->get_body(), "> "))
+                          . ($this->profile['sig'] ? "\n\n-- \n". $this->profile['sig'] : '');
                 $target   = isset($this->post->headers['followup-to']) ?
                                 $this->post->headers['followup-to'] : $this->post->headers['newsgroups'];
                 $followup = null;
             }
+        } else {
+            $targe   = $group;
+            $subject = $followup = null;
+            $body    = $this->profile['sig'] ? "\n\n-- \n". $this->profile['sig'] : '';
         }
 
         $this->nntp->quit();
@@ -368,7 +381,7 @@ class Banana
                . '<td>' . $this->profile['org'] . '</td></tr>'
                . '<tr><th colspan="2">' . _b_('Corps') . '</th></tr>'
                . '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
-               .  to_entities($body) . '</textarea></td></tr>';
+               .  $body . '</textarea></td></tr>';
         if ($this->can_attach) {
             $html .= '<tr><th colspan="2">' . _b_('Pièce jointe') . '</th></tr>'
                   . '<tr><td colspan="2">'
@@ -376,8 +389,8 @@ class Banana
                   . '<input type="file" name="newpj" size="40"/></td></tr>';
         }
         $html .= '<tr><th colspan="2">';
-        if ($id > 0) {
-            $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
+        if ($id != -1) {
+            $html .= '<input type="hidden" name="artid" value="' . $id . '" />';
         }
         $html .= '<input type="hidden" name="action" value="new" />'
               . '<input type="submit" value="' . _b_('Envoyer le message') . '" /></th></tr>'
@@ -466,11 +479,12 @@ class Banana
         if ($this->nntp->post($msg)) {
             $dir = Array('group' => $group);
             if ($artid != -1) {
-                $dir['first'] = $artid;
+                $dir['artid'] = $artid;
             }
             redirectInBanana($dir);
         } else {
-            return '<p class="error">' . _b_('Impossible de poster le message') . '</p>'
+            return '<p class="error">' . _b_('Impossible de poster le message. Le serveur a retourné l\'erreur :') . '</p>'
+                   . '<pre class="error">' . utf8_encode($this->nntp->lasterrortext) .'</pre>'
                    . $this->action_newFup($group, $artid);
         }
     }