Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin movespam after update 1.6.0 -> 1.6.2 #9070

Closed
ZeM2008 opened this issue Jul 18, 2023 · 1 comment
Closed

Plugin movespam after update 1.6.0 -> 1.6.2 #9070

ZeM2008 opened this issue Jul 18, 2023 · 1 comment

Comments

@ZeM2008
Copy link

ZeM2008 commented Jul 18, 2023

Hello!
After update 1.6.0 -> 1.6.2
Plugin movespam

Jul 18 10:38:17 WWW Roundcube: PHP Fatal error: Uncaught Error: Call to a member function get_folder() on null in /var/www/roundcube/plugins/movespam/movespam.php:35
Jul 18 10:38:17 WWW Roundcube: Stack trace:
Jul 18 10:38:17 WWW Roundcube: #0 /var/www/roundcube/program/lib/Roundcube/rcube_plugin_api.php(520): movespam->check_headers()
Jul 18 10:38:17 WWW Roundcube: #1 /var/www/roundcube/program/actions/mail/index.php(468): rcube_plugin_api->exec_hook()
Jul 18 10:38:17 WWW Roundcube: #2 /var/www/roundcube/program/actions/mail/list.php(123): rcmail_action_mail_index::js_message_list()
Jul 18 10:38:17 WWW Roundcube: #3 /var/www/roundcube/program/include/rcmail.php(282): rcmail_action_mail_list->run()
Jul 18 10:38:17 WWW Roundcube: #4 /var/www/roundcube/index.php(278): rcmail->action_handler()
Jul 18 10:38:17 WWW Roundcube: #5 {main}
Jul 18 10:38:17 WWW Roundcube: thrown in /var/www/roundcube/plugins/movespam/movespam.php on line 35
....
35 $this->open_mbox = $imap->get_folder();

How to fix ?

Full 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_folder();
		
		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->flags[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();
			}
		}
	}
}
?>
@alecpl
Copy link
Member

alecpl commented Jul 18, 2023

I believe the '$imap' property has been removed much earlier than in 1.6.

Replace $imap = $rcmail->imap; with $imap = $rcmail->get_storage();.

@alecpl alecpl closed this as completed Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants