1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Spam reporting driver utilizing a local binary.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2013-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Spam_Program implements IMP_Spam_Base
24: {
25: /**
26: * Binary location.
27: *
28: * @var string
29: */
30: protected $_binary;
31:
32: /**
33: * Constructor.
34: *
35: * @param string $binary Binary location.
36: */
37: public function __construct($binary)
38: {
39: $this->_binary = $binary;
40: }
41:
42: /**
43: */
44: public function report(IMP_Contents $contents, $action)
45: {
46: /* Use a pipe to write the message contents. This should be
47: * secure. */
48: $proc = proc_open(
49: $this->_binary,
50: array(
51: 0 => array('pipe', 'r'),
52: 1 => array('pipe', 'w'),
53: 2 => array('pipe', 'w')
54: ),
55: $pipes
56: );
57: if (!is_resource($proc)) {
58: Horde::log(sprintf('Cannot open spam reporting program: %s', $proc), 'ERR');
59: return false;
60: }
61:
62: stream_copy_to_stream($contents->fullMessageText(array(
63: 'stream' => true
64: )), $pipes[0]);
65:
66: fclose($pipes[0]);
67:
68: $stderr = '';
69: while (!feof($pipes[2])) {
70: $stderr .= fgets($pipes[2]);
71: }
72: fclose($pipes[2]);
73: if (!empty($stderr)) {
74: Horde::log(sprintf('Error reporting spam: %s', $stderr), 'ERR');
75: }
76:
77: proc_close($proc);
78:
79: return true;
80: }
81:
82: }
83: