1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ingo_Api extends Horde_Registry_Api
14: {
15: 16: 17: 18: 19:
20: public $links = array(
21: 'showBlacklist' => '%application%/blacklist.php',
22: 'showWhitelist' => '%application%/whitelist.php',
23: 'showFilters' => '%application%/filters.php',
24: 'showVacation' => '%application%/vacation.php'
25: );
26:
27: 28: 29: 30: 31:
32: public function blacklistFrom($addresses)
33: {
34: if (!empty($addresses)) {
35: try {
36: $blacklist = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_BLACKLIST);
37: $blacklist->setBlacklist(array_merge($blacklist->getBlacklist(), $addresses));
38: $GLOBALS['ingo_storage']->store($blacklist);
39: Ingo::updateScript();
40: foreach ($addresses as $from) {
41: $GLOBALS['notification']->push(sprintf(_("The address \"%s\" has been added to your blacklist."), $from));
42: }
43: } catch (Ingo_Exception $e) {
44: $GLOBALS['notification']->push($e);
45: }
46: }
47: }
48:
49: 50: 51: 52: 53:
54: public function whitelistFrom($addresses)
55: {
56: try {
57: $whitelist = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_WHITELIST);
58: $whitelist->setWhitelist(array_merge($whitelist->getWhitelist(), $addresses));
59: $GLOBALS['ingo_storage']->store($whitelist);
60: Ingo::updateScript();
61: foreach ($addresses as $from) {
62: $GLOBALS['notification']->push(sprintf(_("The address \"%s\" has been added to your whitelist."), $from));
63: }
64: } catch (Ingo_Exception $e) {
65: $GLOBALS['notification']->push($e);
66: }
67: }
68:
69: 70: 71: 72: 73:
74: public function canApplyFilters()
75: {
76: try {
77: return Ingo::loadIngoScript()->performAvailable();
78: } catch (Ingo_Exception $e) {
79: return false;
80: }
81: }
82:
83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94:
95: public function applyFilters($params = array())
96: {
97: try {
98: $ingo_script = Ingo::loadIngoScript();
99: } catch (Ingo_Exception $e) {
100: return false;
101: }
102:
103: $params = array_merge(array(
104: 'filter_seen' => $GLOBALS['prefs']->getValue('filter_seen'),
105: 'show_filter_msg' => $GLOBALS['prefs']->getValue('show_filter_msg')
106: ), $params);
107:
108: return $ingo_script->perform($params);
109: }
110:
111: 112: 113: 114: 115: 116: 117:
118: public function setVacation($info)
119: {
120: if (empty($info)) {
121: return true;
122: }
123:
124:
125: $filters = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_FILTERS);
126: $vacation_rule_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION);
127:
128:
129: $vacation = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_VACATION);
130:
131:
132: if (empty($info['addresses'])) {
133: $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
134:
135: $info['addresses'] = preg_replace('/\n{2,}/', "\n", implode("\n", $identity->getAll('from_addr')));
136: if (empty($addresses)) {
137: $info['addresses'] = $GLOBALS['registry']->getAuth();
138: }
139: }
140:
141: $vacation->setVacationAddresses($addresses);
142:
143: if (isset($info['days'])) {
144: $vacation->setVacationDays($info['days']);
145: }
146: if (isset($info['excludes'])) {
147: $vacation->setVacationExcludes($info['excludes']);
148: }
149: if (isset($info['ignorelist'])) {
150: $vacation->setVacationIgnorelist($info['ignorelist'] == 'on');
151: }
152: if (isset($info['reason'])) {
153: $vacation->setVacationReason($info['reason']);
154: }
155: if (isset($info['subject'])) {
156: $vacation->setVacationSubject($info['subject']);
157: }
158: if (isset($info['start'])) {
159: $vacation->setVacationStart($info['start']);
160: }
161: if (isset($info['end'])) {
162: $vacation->setVacationEnd($info['end']);
163: }
164:
165: $filters->ruleEnable($vacation_rule_id);
166:
167: try {
168: $GLOBALS['ingo_storage']->store($filters);
169:
170: if ($GLOBALS['prefs']->getValue('auto_update')) {
171: Ingo::updateScript();
172: }
173:
174:
175: $GLOBALS['session']->set('ingo', 'change', time());
176:
177: return true;
178: } catch (Ingo_Exception $e) {}
179:
180: return false;
181: }
182:
183: 184: 185: 186: 187:
188: public function disableVacation()
189: {
190:
191: $filters = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_FILTERS);
192: $vacation_rule_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION);
193:
194: $filters->ruleDisable($vacation_rule_id);
195:
196: try {
197: $GLOBALS['ingo_storage']->store($filters);
198:
199: if ($GLOBALS['prefs']->getValue('auto_update')) {
200: Ingo::updateScript();
201: }
202:
203:
204: $GLOBALS['session']->set('ingo', 'change', time());
205:
206: return true;
207: } catch (Ingo_Exception $e) {}
208:
209: return false;
210: }
211:
212: }
213: