Author Topic: movespam plugin errors with 0.8-beta [with FIX]  (Read 9282 times)

Offline asavah

  • Newbie
  • *
  • Posts: 1
movespam plugin errors with 0.8-beta [with FIX]
« on: April 26, 2012, 04:16:38 PM »
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
Code: [Select]
PHP Fatal error:  Call to protected method rcube_imap::messagecount() from context 'movespam' in /usr/local/www/roundcube/plugins/movespam/movespam.php on line 50and 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

Code: [Select]
<?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_countfalse);
                                
$this->api->output->command('list_mailbox');
                                
$this->api->output->send();
                                
$this->api->output->command('getunread');
                                
$this->api->output->send();
                        }
                }
        }
}

Offline mark_valley

  • Newbie
  • *
  • Posts: 8
Re: movespam plugin errors with 0.8-beta [with FIX]
« Reply #1 on: June 19, 2012, 09:09:50 PM »
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.
« Last Edit: June 21, 2012, 03:25:33 PM by mark_valley »

Offline mark_valley

  • Newbie
  • *
  • Posts: 8
Re: movespam plugin errors with 0.8-beta [with FIX]
« Reply #2 on: June 21, 2012, 03:24:04 PM »
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!

Offline capsx

  • Newbie
  • *
  • Posts: 3
Re: movespam plugin errors with 0.8-beta [with FIX]
« Reply #3 on: January 02, 2013, 08:01:08 AM »
file: ./plugins/movespam/movespam.php
change:

Code: [Select]
$unseen_count = $imap->messagecount($this->spam_mbox, 'UNSEEN');
to

Code: [Select]
$unseen_count = $imap->count($this->spam_mbox, 'UNSEEN');
messagecount() is protected function
count() is not protected and it is using messagecount() internally

Offline stremblay

  • Newbie
  • *
  • Posts: 9
Re: movespam plugin errors with 0.8-beta [with FIX]
« Reply #4 on: May 23, 2013, 11:24:01 AM »
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.

Offline zeuslinux

  • Newbie
  • *
  • Posts: 6
Re: movespam plugin errors with 0.8-beta [with FIX]
« Reply #5 on: September 10, 2013, 03:21:27 PM »
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).