1: <?php
2: /**
3: * A basic definition for a PHP based postfix filter.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Filter
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Filter
12: */
13:
14: /**
15: * A basic definition for a PHP based postfix filter.
16: *
17: * Copyright 2004-2010 Klarälvdalens Datakonsult AB
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Filter
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Filter
27: */
28: class Horde_Kolab_Filter_Base
29: {
30: /**
31: * The message ID.
32: *
33: * @var string
34: */
35: var $_id = '';
36:
37: /**
38: * Configuration.
39: *
40: * @param Horde_Kolab_Filter_Configuration
41: *
42: * @todo Make private
43: */
44: protected $_config;
45:
46: /**
47: * The log backend that needs to implement the debug(), info() and err()
48: * methods.
49: *
50: * @param Horde_Kolab_Filter_Logger
51: *
52: * @todo Make private/decorator
53: */
54: protected $_logger;
55:
56: /**
57: * Constructor.
58: *
59: * @param Horde_Kolab_Filter_Configuration $config The configuration.
60: * @param Horde_Kolab_Filter_Logger $logger The logging backend.
61: */
62: public function __construct(
63: Horde_Kolab_Filter_Configuration $config,
64: Horde_Log_Logger $logger
65: ) {
66: $this->_config = $config;
67: $this->_logger = $logger;
68: }
69:
70: /**
71: * Initialize the filter.
72: *
73: * @return NULL
74: */
75: public function init()
76: {
77: $this->_config->init();
78: }
79:
80: /**
81: * Handle the message.
82: *
83: * @param int $inh The file handle pointing to the message.
84: * @param string $transport The name of the transport driver.
85: *
86: * @return NULL
87: */
88: public function parse($inh = STDIN, $transport = null)
89: {
90: /* $this->_logger->debug( */
91: /* sprintf( */
92: /* "Arguments: %s", */
93: /* print_r($this->_config->getArguments(), true) */
94: /* ) */
95: /* ); */
96:
97: $this->_logger->debug(
98: sprintf(
99: "%s starting up (sender=%s, recipients=%s, client_address=%s)",
100: get_class($this),
101: $this->_config->getSender(),
102: join(', ',$this->_config->getRecipients()),
103: $this->_config->getClientAddress()
104: )
105: );
106:
107: $this->_parse($inh, $transport);
108:
109: $this->_logger->info(
110: sprintf(
111: "%s successfully completed (sender=%s, recipients=%s, client_address=%s, id=%s)",
112: get_class($this),
113: $this->_config->getSender(),
114: join(', ',$this->_config->getRecipients()),
115: $this->_config->getClientAddress(),
116: $this->_id
117: )
118: );
119: }
120: }
121:
122: