1: <?php
2: /**
3: * Copyright 2010-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 2010-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * The abstract class that all sentmail implementations inherit from.
16: *
17: * @author Jan Schneider <jan@horde.org>
18: * @author Michael Slusarz <slusarz@horde.org>
19: * @category Horde
20: * @copyright 2010-2014 Horde LLC
21: * @license http://www.horde.org/licenses/gpl GPL
22: * @package IMP
23: *
24: * @property-read integer $limit_period If limiting recipients per time
25: * period, how many hours should this
26: * period last?
27: * @property-read integer $threshold How many days should old log entries be
28: * kept?
29: */
30: abstract class IMP_Sentmail
31: {
32: /* Action constants. */
33: const NEWMSG = 'new';
34: const REPLY = 'reply';
35: const FORWARD = 'forward';
36: const REDIRECT = 'redirect';
37: const MDN = 'mdn';
38:
39: /**
40: * Hash containing configuration parameters.
41: *
42: * @var array
43: */
44: protected $_params = array();
45:
46: /**
47: * Constructor.
48: *
49: * @param array $params Configuration parameters the driver needs.
50: *
51: * @throws IMP_Exception
52: */
53: public function __construct(array $params = array())
54: {
55: $this->_params = array_merge($this->_params, $params);
56: }
57:
58: /**
59: */
60: public function __get($name)
61: {
62: switch ($name) {
63: case 'limit_period':
64: case 'threshold':
65: return isset($this->_params[$name])
66: ? intval($this->_params[$name])
67: : 0;
68: }
69: }
70:
71: /**
72: * Logs an attempt to send a message.
73: *
74: * @param integer $action Why the message was sent (IMP_Sentmail
75: * constant).
76: * @param string $message_id The Message-ID.
77: * @param string|array $recipients The list of message recipients.
78: * @param boolean $success Whether the attempt was successful.
79: */
80: public function log($action, $message_id, $recipients, $success = true)
81: {
82: if (!is_array($recipients)) {
83: $recipients = array($recipients);
84: }
85:
86: foreach ($recipients as $addresses) {
87: foreach (IMP::parseAddressList($addresses) as $recipient) {
88: $this->_log($action, $message_id, $recipient->bare_address, $success);
89: }
90: }
91: }
92:
93: /**
94: * Garbage collect log entries.
95: */
96: public function gc()
97: {
98: $this->_deleteOldEntries(time() - ($this->threshold * 86400));
99: }
100:
101: /**
102: * Logs an attempt to send a message per recipient.
103: *
104: * @param integer $action Why the message was sent (IMP_Sentmail
105: * constant).
106: * @param string $message_id The Message-ID.
107: * @param string $recipient A message recipient.
108: * @param boolean $success Whether the attempt was successful.
109: */
110: abstract protected function _log($action, $message_id, $recipient,
111: $success);
112:
113: /**
114: * Returns the favourite recipients.
115: *
116: * @param integer $limit Return this number of recipients.
117: * @param mixed $filter A list of messages types that should be
118: * returned. Null returns all message types.
119: *
120: * @return array A list with the $limit most favourite recipients.
121: */
122: abstract public function favouriteRecipients($limit, $filter = null);
123:
124: /**
125: * Returns the number of recipients within a certain time period.
126: *
127: * @param integer $hours Time period in hours.
128: * @param boolean $user Return the number of recipients for the current
129: * user?
130: *
131: * @return integer The number of recipients in the given time period.
132: */
133: abstract public function numberOfRecipients($hours, $user = false);
134:
135: /**
136: * Deletes all log entries older than a certain date.
137: *
138: * @param integer $before Unix timestamp before that all log entries
139: * should be deleted.
140: */
141: abstract protected function _deleteOldEntries($before);
142:
143: }
144: