1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Horde_Imsp_Options
15: {
16: 17: 18: 19: 20:
21: protected $_imsp;
22:
23: 24: 25: 26: 27:
28: protected $_params;
29:
30: 31: 32: 33: 34: 35:
36: public function __construct(Horde_Imsp_Client_Base $client, array $params)
37: {
38: $this->_params = $params;
39: $this->_imsp = $client;
40: $this->_imsp->_logger->debug('Horde_Imsp_Options initialized.');
41: }
42:
43: 44: 45: 46: 47: 48: 49: 50: 51:
52: public function get($option)
53: {
54: $options = array();
55: $this->_imsp->send("GET $option", true, true);
56: $server_response = $this->_imsp->receive();
57: while (preg_match("/^\* OPTION/", $server_response)) {
58:
59: if (preg_match(Horde_Imsp_Client_Base::OCTET_COUNT, $server_response, $tempArray)) {
60: $temp = explode(' ', $server_response);
61: $options[$temp[2]] = $this->_imsp->receiveStringLiteral($tempArray[2]);
62: $this->_imsp->receive();
63: } else {
64: $temp = explode(' ', $server_response);
65: $options[$temp[2]] = trim($temp[3]);
66: $i = 3;
67: $lastChar = "";
68: $nextElement = trim($temp[3]);
69:
70:
71: if ((substr($nextElement, 0, 1) == '"') &&
72: (substr($nextElement, strlen($nextElement) - 1, 1) != '"')) {
73: do {
74: $nextElement = $temp[$i + 1];
75: $lastChar = substr($nextElement, strlen($nextElement) - 1, 1);
76: $options[$temp[2]] .= ' ' . $nextElement;
77: if ($lastChar == '"') {
78: $done = true;
79: } else {
80: $done = false;
81: $lastChar = substr($temp[$i + 2], strlen($temp[$i + 2]) - 1, 1);
82: $i++;
83: }
84:
85: } while ($lastChar != '"');
86:
87: if (!$done) {
88: $nextElement = $temp[$i + 1];
89: $options[$temp[2]] .= ' ' . $nextElement;
90: }
91: }
92: }
93: $server_response = $this->_imsp->receive();
94: }
95:
96: if ($server_response != 'OK') {
97: throw new Horde_Imsp_Exception('Did not receive the expected response from the server.');
98: }
99:
100: $this->_imsp->_logger->debug('GET command OK.');
101: return $options;
102: }
103:
104: 105: 106: 107: 108: 109: 110: 111:
112: public function set($option, $value)
113: {
114:
115: $this->_imsp->send("SET $option ", true, false);
116:
117:
118: if (preg_match(Horde_Imsp_Client_Base::MUST_USE_LITERAL, $value)) {
119: $biValue = sprintf("{%d}", strlen($value));
120: $result = $this->_imsp->send($biValue, false, true, true);
121: }
122:
123:
124: $result = $this->_imsp->send($value, false, true);
125: $server_response = $this->_imsp->receive();
126: if ($server_response != 'OK') {
127: throw new Horde_Imsp_Exception('The option could not be set on the IMSP server.');
128: }
129: $this->_imsp->_logger->debug('SET command OK.');
130: }
131:
132: public function logout()
133: {
134: $this->_imsp->logout();
135: }
136:
137: }
138: