File: dir_learn.php

package info (click to toggle)
roundcube-plugins-extra 1.2.1-20160803
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,660 kB
  • ctags: 1,574
  • sloc: php: 11,361; sh: 91; xml: 90; makefile: 56; python: 54; awk: 51
file content (49 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

/**
 * Copy spam/ham messages to a direcotry for learning later
 * @version 2.0
 * @author Philip Weir
 */

class markasjunk2_dir_learn
{
	public function spam($uids, $mbox)
	{
		$this->_do_messagemove($uids, true);
	}

	public function ham($uids, $mbox)
	{
		$this->_do_messagemove($uids, false);
	}

	private function _do_messagemove($uids, $spam)
	{
	    $rcmail = rcube::get_instance();

		if ($spam)
			$dest_dir = unslashify($rcmail->config->get('markasjunk2_spam_dir'));
		else
			$dest_dir = unslashify($rcmail->config->get('markasjunk2_ham_dir'));

		if (!$dest_dir)
			return;

		$filename = $rcmail->config->get('markasjunk2_filename');
		$filename = str_replace('%u', $_SESSION['username'], $filename);
		$filename = str_replace('%t', ($spam) ? 'spam' : 'ham', $filename);
		$filename = str_replace('%l', $rcmail->user->get_username('local'), $filename);
		$filename = str_replace('%d', $rcmail->user->get_username('domain'), $filename);

		foreach ($uids as $uid) {
			$tmpfname = tempnam($dest_dir, $filename);
			file_put_contents($tmpfname, $rcmail->storage->get_raw_body($uid));

			if ($rcmail->config->get('markasjunk2_debug'))
				rcube::write_log('markasjunk2', $tmpfname);
		}
	}
}

?>