In the plugin repository there is a nice and simple "movespam" plugin, but it has some bugs when installed on 0.8-beta.
if you try to move a ***SPAM*** marked message from junk folder to inbox first you get an internal server error
PHP Fatal error: Call to protected method rcube_imap::messagecount() from context 'movespam' in /usr/local/www/roundcube/plugins/movespam/movespam.php on line 50
and even with $movespam_seen set to false in config.inc.php it moves the seen message back to junk
I see no way to contact the plugins mantainer/author as he provides no email address in the plugin file.
I fixed it so it works properly now with 0.8-beta.
here goes the code
<?php
/**
* MoveSpam
*
* Automatically move spam messages to the junk folder based on the subject line.
*
* @version 1.0
* @author Ythan
*/
class movespam extends rcube_plugin
{
public $task = 'mail';
private $open_mbox = 'INBOX';
private $spam_mbox = 'JUNK';
private $spam_text = '***SPAM***';
private $move_seen = false;
function init()
{
$rcmail = rcmail::get_instance();
$this->load_config();
$this->spam_mbox = $rcmail->config->get('junk_mbox', null);
$this->spam_text = $rcmail->config->get('movespam_subject', null);
$this->move_seen = $rcmail->config->get('movespam_seen', null);
if($rcmail->task == 'mail') {
$this->add_hook('messages_list', array($this, 'check_headers'));
}
}
function check_headers($mlist)
{
$rcmail = rcmail::get_instance();
$imap = $rcmail->imap;
$this->open_mbox = $imap->get_mailbox_name();
if(is_array($mlist['messages']) && $this->open_mbox != $this->spam_mbox){
foreach($mlist['messages'] as $message){
if (strpos($message->subject, $this->spam_text) === 0){
if (!$message->seen && $this->move_seen){
$spam_uids[] = $message->uid;
}
}
}
if (count($spam_uids)){
$spam_uids_str = implode(',', $spam_uids);
$imap->move_message($spam_uids_str, $this->spam_mbox, $this->open_mbox);
$unseen_count = $imap->count($this->spam_mbox, 'UNSEEN');
$rcmail->output->command('set_unread_count', $this->spam_mbox, $unseen_count, false);
$this->api->output->command('list_mailbox');
$this->api->output->send();
$this->api->output->command('getunread');
$this->api->output->send();
}
}
}
}
Hi!
I found your topic because i am using the same plugin and it seems that after i move a message from Spam folder to Trash it will be moved back to Spam.
I am not very good with php but looking at the changes you made at the code i think that the conditional
if (!$message->seen && $this->move_seen)
Will always evaluate to false if move_seen = false. Even if the message is not seem it wont be moved.
Well, i found a solution. Maybe the plugin needs to be updated to work with the new software versions. I am using Roundcube 0.7.2.
The line:
if (!$message->seen || $this->move_seen)
Should be changed to:
if (!$message->flags[SEEN] || $this->move_seen)
Now it works very well!
file: ./plugins/movespam/movespam.php
change:
$unseen_count = $imap->messagecount($this->spam_mbox, 'UNSEEN');
to
$unseen_count = $imap->count($this->spam_mbox, 'UNSEEN');
messagecount() is protected function
count() is not protected and it is using messagecount() internally
Hi,
I've updated the plugin and fixed a few bugs to have it work with the latest version of Roundcube.
A bug about deleting the spam was also involved, as when delete and click on trash the spam was coming back.
I discovered a little bug in the version 1.2 of movespam plugin.
In the function
function check_headers($mlist) {
I had to comment this line
$RCMAIL->output->show_message('');
because it show a blank message box every time you access the INBOX.
I am using the lat version of Roundcube (0.9.3).