Overview

Packages

  • Horde
    • Icalendar
      • UnitTests
  • Ingo
    • UnitTests
  • None

Classes

  • Horde_Core_Ui_VarRenderer_Ingo
  • Ingo
  • Ingo_Api
  • Ingo_Exception
  • Ingo_Exception_Pear
  • Ingo_LoginTasks_SystemTask_Upgrade
  • Ingo_Script
  • Ingo_Script_Imap
  • Ingo_Script_Imap_Api
  • Ingo_Script_Imap_Live
  • Ingo_Script_Maildrop
  • Ingo_Script_Maildrop_Comment
  • Ingo_Script_Maildrop_Recipe
  • Ingo_Script_Maildrop_Variable
  • Ingo_Script_Procmail
  • Ingo_Script_Procmail_Comment
  • Ingo_Script_Procmail_Recipe
  • Ingo_Script_Procmail_Variable
  • Ingo_Script_Sieve
  • Ingo_Script_Sieve_Action
  • Ingo_Script_Sieve_Action_Addflag
  • Ingo_Script_Sieve_Action_Discard
  • Ingo_Script_Sieve_Action_Fileinto
  • Ingo_Script_Sieve_Action_Flag
  • Ingo_Script_Sieve_Action_Keep
  • Ingo_Script_Sieve_Action_Notify
  • Ingo_Script_Sieve_Action_Redirect
  • Ingo_Script_Sieve_Action_Reject
  • Ingo_Script_Sieve_Action_Removeflag
  • Ingo_Script_Sieve_Action_Stop
  • Ingo_Script_Sieve_Action_Vacation
  • Ingo_Script_Sieve_Comment
  • Ingo_Script_Sieve_Else
  • Ingo_Script_Sieve_Elsif
  • Ingo_Script_Sieve_If
  • Ingo_Script_Sieve_Test
  • Ingo_Script_Sieve_Test_Address
  • Ingo_Script_Sieve_Test_Allof
  • Ingo_Script_Sieve_Test_Anyof
  • Ingo_Script_Sieve_Test_Body
  • Ingo_Script_Sieve_Test_Exists
  • Ingo_Script_Sieve_Test_False
  • Ingo_Script_Sieve_Test_Header
  • Ingo_Script_Sieve_Test_Not
  • Ingo_Script_Sieve_Test_Relational
  • Ingo_Script_Sieve_Test_Size
  • Ingo_Script_Sieve_Test_True
  • Ingo_Storage
  • Ingo_Storage_Blacklist
  • Ingo_Storage_Filters
  • Ingo_Storage_Filters_Sql
  • Ingo_Storage_Forward
  • Ingo_Storage_Mock
  • Ingo_Storage_Prefs
  • Ingo_Storage_Rule
  • Ingo_Storage_Spam
  • Ingo_Storage_Sql
  • Ingo_Storage_Vacation
  • Ingo_Storage_VacationTest
  • Ingo_Storage_Whitelist
  • Ingo_Test
  • Ingo_Transport
  • Ingo_Transport_Ldap
  • Ingo_Transport_Null
  • Ingo_Transport_Sivtest
  • Ingo_Transport_Timsieved
  • Ingo_Transport_Vfs
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Ingo external API interface.
  4:  *
  5:  * This file defines Ingo's external API interface. Other applications
  6:  * can interact with Ingo through this API.
  7:  *
  8:  * See the enclosed file LICENSE for license information (ASL).  If you
  9:  * did not receive this file, see http://www.horde.org/licenses/apache.
 10:  *
 11:  * @package Ingo
 12:  */
 13: class Ingo_Api extends Horde_Registry_Api
 14: {
 15:     /**
 16:      * Links.
 17:      *
 18:      * @var array
 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:      * Add addresses to the blacklist.
 29:      *
 30:      * @param string $addresses  The addresses to add to the blacklist.
 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:      * Add addresses to the whitelist.
 51:      *
 52:      * @param string $addresses  The addresses to add to the whitelist.
 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:      * Can this driver perform on-demand filtering?
 71:      *
 72:      * @return boolean  True if perform() is available, false if not.
 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:      * Perform the filtering specified in the rules.
 85:      *
 86:      * @param array $params  The parameter array:
 87:      * <pre>
 88:      * filter_seen
 89:      * mailbox
 90:      * show_filter_msg
 91:      * </pre>
 92:      *
 93:      * @return boolean  True if filtering was performed, false if not.
 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:      * Set vacation
113:      *
114:      * @param array $info  Vacation details.
115:      *
116:      * @return boolean  True on success.
117:      */
118:     public function setVacation($info)
119:     {
120:         if (empty($info)) {
121:             return true;
122:         }
123: 
124:         /* Get vacation filter. */
125:         $filters = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_FILTERS);
126:         $vacation_rule_id = $filters->findRuleId(Ingo_Storage::ACTION_VACATION);
127: 
128:         /* Set vacation object and rules. */
129:         $vacation = $GLOBALS['ingo_storage']->retrieve(Ingo_Storage::ACTION_VACATION);
130: 
131:         /* Make sure we have at least one address. */
132:         if (empty($info['addresses'])) {
133:             $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
134:             /* Remove empty lines. */
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:             /* Update the timestamp for the rules. */
175:             $GLOBALS['session']->set('ingo', 'change', time());
176: 
177:             return true;
178:         } catch (Ingo_Exception $e) {}
179: 
180:         return false;
181:     }
182: 
183:     /**
184:      * Disable vacation
185:      *
186:      * @return boolean  True on success.
187:      */
188:     public function disableVacation()
189:     {
190:         /* Get vacation filter. */
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:             /* Update the timestamp for the rules. */
204:             $GLOBALS['session']->set('ingo', 'change', time());
205: 
206:             return true;
207:         } catch (Ingo_Exception $e) {}
208: 
209:         return false;
210:     }
211: 
212: }
213: 
API documentation generated by ApiGen