Overview

Packages

  • IMP

Classes

  • IMP
  • IMP_Ajax_Addresses
  • IMP_Ajax_Application
  • IMP_Ajax_Application_Compose
  • IMP_Ajax_Application_Handler_Common
  • IMP_Ajax_Application_Handler_ComposeAttach
  • IMP_Ajax_Application_Handler_Draft
  • IMP_Ajax_Application_Handler_Dynamic
  • IMP_Ajax_Application_Handler_ImageUnblock
  • IMP_Ajax_Application_Handler_Mboxtoggle
  • IMP_Ajax_Application_Handler_Passphrase
  • IMP_Ajax_Application_Handler_Remote
  • IMP_Ajax_Application_Handler_RemotePrefs
  • IMP_Ajax_Application_Handler_Search
  • IMP_Ajax_Application_Handler_Smartmobile
  • IMP_Ajax_Application_ListMessages
  • IMP_Ajax_Application_ShowMessage
  • IMP_Ajax_Application_Viewport
  • IMP_Ajax_Application_Viewport_Error
  • IMP_Ajax_Imple_ImportEncryptKey
  • IMP_Ajax_Imple_ItipRequest
  • IMP_Ajax_Imple_PassphraseDialog
  • IMP_Ajax_Imple_VcardImport
  • IMP_Ajax_Queue
  • IMP_Api
  • IMP_Application
  • IMP_Auth
  • IMP_Basic_Base
  • IMP_Basic_Compose
  • IMP_Basic_Contacts
  • IMP_Basic_Error
  • IMP_Basic_Folders
  • IMP_Basic_Listinfo
  • IMP_Basic_Mailbox
  • IMP_Basic_Message
  • IMP_Basic_Pgp
  • IMP_Basic_Saveimage
  • IMP_Basic_Search
  • IMP_Basic_Searchbasic
  • IMP_Basic_Smime
  • IMP_Basic_Thread
  • IMP_Block_Newmail
  • IMP_Block_Summary
  • IMP_Compose
  • IMP_Compose_Attachment
  • IMP_Compose_Attachment_Linked_Metadata
  • IMP_Compose_Attachment_Metadata
  • IMP_Compose_Attachment_Storage
  • IMP_Compose_Attachment_Storage_AutoDetermine
  • IMP_Compose_Attachment_Storage_Temp
  • IMP_Compose_Attachment_Storage_VfsLinked
  • IMP_Compose_Exception
  • IMP_Compose_Exception_Address
  • IMP_Compose_HtmlSignature
  • IMP_Compose_Link
  • IMP_Compose_LinkedAttachment
  • IMP_Compose_Ui
  • IMP_Compose_View
  • IMP_Contacts
  • IMP_Contacts_Avatar_Addressbook
  • IMP_Contacts_Avatar_Gravatar
  • IMP_Contacts_Avatar_Unknown
  • IMP_Contacts_Flag_Host
  • IMP_Contacts_Image
  • IMP_Contents
  • IMP_Contents_InlineOutput
  • IMP_Contents_View
  • IMP_Crypt_Pgp
  • IMP_Crypt_Smime
  • IMP_Dynamic_AddressList
  • IMP_Dynamic_Base
  • IMP_Dynamic_Compose
  • IMP_Dynamic_Compose_Common
  • IMP_Dynamic_Helper_Base
  • IMP_Dynamic_Mailbox
  • IMP_Dynamic_Message
  • IMP_Exception
  • IMP_Factory_AuthImap
  • IMP_Factory_Compose
  • IMP_Factory_ComposeAtc
  • IMP_Factory_Contacts
  • IMP_Factory_Contents
  • IMP_Factory_Flags
  • IMP_Factory_Ftree
  • IMP_Factory_Identity
  • IMP_Factory_Imap
  • IMP_Factory_Mail
  • IMP_Factory_MailAutoconfig
  • IMP_Factory_Mailbox
  • IMP_Factory_MailboxCache
  • IMP_Factory_MailboxList
  • IMP_Factory_Maillog
  • IMP_Factory_MimeViewer
  • IMP_Factory_Pgp
  • IMP_Factory_PrefsSort
  • IMP_Factory_Quota
  • IMP_Factory_Search
  • IMP_Factory_Sentmail
  • IMP_Factory_Smime
  • IMP_Factory_Spam
  • IMP_Filter
  • IMP_Flag_Base
  • IMP_Flag_Imap
  • IMP_Flag_Imap_Answered
  • IMP_Flag_Imap_Deleted
  • IMP_Flag_Imap_Draft
  • IMP_Flag_Imap_Flagged
  • IMP_Flag_Imap_Forwarded
  • IMP_Flag_Imap_Junk
  • IMP_Flag_Imap_NotJunk
  • IMP_Flag_Imap_Seen
  • IMP_Flag_System_Attachment
  • IMP_Flag_System_Encrypted
  • IMP_Flag_System_HighPriority
  • IMP_Flag_System_List
  • IMP_Flag_System_LowPriority
  • IMP_Flag_System_Match_Address
  • IMP_Flag_System_Match_Flag
  • IMP_Flag_System_Match_Header
  • IMP_Flag_System_Personal
  • IMP_Flag_System_Signed
  • IMP_Flag_System_Unseen
  • IMP_Flag_User
  • IMP_Flags
  • IMP_Ftree
  • IMP_Ftree_Account
  • IMP_Ftree_Account_Imap
  • IMP_Ftree_Account_Inboxonly
  • IMP_Ftree_Account_Remote
  • IMP_Ftree_Account_Vfolder
  • IMP_Ftree_Element
  • IMP_Ftree_Eltdiff
  • IMP_Ftree_Iterator
  • IMP_Ftree_Iterator_Ancestors
  • IMP_Ftree_IteratorFilter
  • IMP_Ftree_IteratorFilter_Children
  • IMP_Ftree_IteratorFilter_Containers
  • IMP_Ftree_IteratorFilter_Expanded
  • IMP_Ftree_IteratorFilter_Invisible
  • IMP_Ftree_IteratorFilter_Mailboxes
  • IMP_Ftree_IteratorFilter_Nonimap
  • IMP_Ftree_IteratorFilter_Polled
  • IMP_Ftree_IteratorFilter_Remote
  • IMP_Ftree_IteratorFilter_Special
  • IMP_Ftree_IteratorFilter_Subscribed
  • IMP_Ftree_IteratorFilter_Vfolder
  • IMP_Ftree_Prefs
  • IMP_Ftree_Prefs_Expanded
  • IMP_Ftree_Prefs_Poll
  • IMP_Ftree_Select
  • IMP_Images
  • IMP_Imap
  • IMP_Imap_Acl
  • IMP_Imap_Cache_Wrapper
  • IMP_Imap_Config
  • IMP_Imap_Exception
  • IMP_Imap_Password
  • IMP_Imap_PermanentFlags
  • IMP_Imap_Remote
  • IMP_Indices
  • IMP_Indices_Mailbox
  • IMP_LoginTasks_SystemTask_GarbageCollection
  • IMP_LoginTasks_SystemTask_Upgrade
  • IMP_LoginTasks_SystemTask_UpgradeAuth
  • IMP_LoginTasks_Task_Autocreate
  • IMP_LoginTasks_Task_DeleteAttachmentsMonthly
  • IMP_LoginTasks_Task_DeleteSentmailMonthly
  • IMP_LoginTasks_Task_FilterOnLogin
  • IMP_LoginTasks_Task_PurgeSentmail
  • IMP_LoginTasks_Task_PurgeSpam
  • IMP_LoginTasks_Task_PurgeTrash
  • IMP_LoginTasks_Task_RecoverDraft
  • IMP_LoginTasks_Task_RenameSentmailMonthly
  • IMP_Mailbox
  • IMP_Mailbox_List
  • IMP_Mailbox_List_Pop3
  • IMP_Mailbox_List_Thread
  • IMP_Mailbox_List_Virtual
  • IMP_Mailbox_SessionCache
  • IMP_Mailbox_Ui
  • IMP_Maillog
  • IMP_Maillog_Log_Base
  • IMP_Maillog_Log_Forward
  • IMP_Maillog_Log_Mdn
  • IMP_Maillog_Log_Redirect
  • IMP_Maillog_Log_Reply
  • IMP_Maillog_Log_Replyall
  • IMP_Maillog_Log_Replylist
  • IMP_Maillog_Message
  • IMP_Maillog_Storage_Base
  • IMP_Maillog_Storage_Composite
  • IMP_Maillog_Storage_History
  • IMP_Maillog_Storage_Mdnsent
  • IMP_Maillog_Storage_Null
  • IMP_Mbox_Generate
  • IMP_Mbox_Import
  • IMP_Mbox_Size
  • IMP_Message
  • IMP_Message_Date
  • IMP_Message_Ui
  • IMP_Mime_Headers
  • IMP_Mime_Status
  • IMP_Mime_Status_RenderIssue
  • IMP_Mime_Status_RenderIssue_Display
  • IMP_Mime_Viewer_Alternative
  • IMP_Mime_Viewer_Appledouble
  • IMP_Mime_Viewer_Audio
  • IMP_Mime_Viewer_Enriched
  • IMP_Mime_Viewer_Externalbody
  • IMP_Mime_Viewer_Html
  • IMP_Mime_Viewer_Images
  • IMP_Mime_Viewer_Itip
  • IMP_Mime_Viewer_Mdn
  • IMP_Mime_Viewer_Partial
  • IMP_Mime_Viewer_Pdf
  • IMP_Mime_Viewer_Pgp
  • IMP_Mime_Viewer_Plain
  • IMP_Mime_Viewer_Related
  • IMP_Mime_Viewer_Rfc822
  • IMP_Mime_Viewer_Smil
  • IMP_Mime_Viewer_Smime
  • IMP_Mime_Viewer_Status
  • IMP_Mime_Viewer_Vcard
  • IMP_Mime_Viewer_Video
  • IMP_Mime_Viewer_Zip
  • IMP_Minimal_Base
  • IMP_Minimal_Compose
  • IMP_Minimal_Error
  • IMP_Minimal_Folders
  • IMP_Minimal_Mailbox
  • IMP_Minimal_Message
  • IMP_Minimal_Messagepart
  • IMP_Minimal_Search
  • IMP_Notification_Event_Status
  • IMP_Notification_Handler_Decorator_ImapAlerts
  • IMP_Notification_Handler_Decorator_NewmailNotify
  • IMP_Perms
  • IMP_Prefs_AttribText
  • IMP_Prefs_Identity
  • IMP_Prefs_Sort
  • IMP_Prefs_Sort_FixedDate
  • IMP_Prefs_Sort_None
  • IMP_Prefs_Sort_Sortpref
  • IMP_Prefs_Sort_Sortpref_Locked
  • IMP_Prefs_Special_Acl
  • IMP_Prefs_Special_ComposeTemplates
  • IMP_Prefs_Special_Drafts
  • IMP_Prefs_Special_Encrypt
  • IMP_Prefs_Special_Flag
  • IMP_Prefs_Special_HtmlSignature
  • IMP_Prefs_Special_ImageReplacement
  • IMP_Prefs_Special_InitialPage
  • IMP_Prefs_Special_Mailto
  • IMP_Prefs_Special_NewmailSound
  • IMP_Prefs_Special_PgpPrivateKey
  • IMP_Prefs_Special_PgpPublicKey
  • IMP_Prefs_Special_Remote
  • IMP_Prefs_Special_Searches
  • IMP_Prefs_Special_Sentmail
  • IMP_Prefs_Special_SmimePrivateKey
  • IMP_Prefs_Special_SmimePublicKey
  • IMP_Prefs_Special_Sourceselect
  • IMP_Prefs_Special_Spam
  • IMP_Prefs_Special_SpecialMboxes
  • IMP_Prefs_Special_Trash
  • IMP_Quota
  • IMP_Quota_Hook
  • IMP_Quota_Imap
  • IMP_Quota_Null
  • IMP_Quota_Ui
  • IMP_Remote
  • IMP_Remote_Account
  • IMP_Script_Package_Autocomplete
  • IMP_Script_Package_ComposeBase
  • IMP_Script_Package_DynamicBase
  • IMP_Script_Package_Editor
  • IMP_Script_Package_Imp
  • IMP_Search
  • IMP_Search_Element
  • IMP_Search_Element_Attachment
  • IMP_Search_Element_Autogenerated
  • IMP_Search_Element_Bulk
  • IMP_Search_Element_Contacts
  • IMP_Search_Element_Daterange
  • IMP_Search_Element_Flag
  • IMP_Search_Element_Header
  • IMP_Search_Element_Mailinglist
  • IMP_Search_Element_Or
  • IMP_Search_Element_Personal
  • IMP_Search_Element_Recipient
  • IMP_Search_Element_Size
  • IMP_Search_Element_Text
  • IMP_Search_Element_Within
  • IMP_Search_Filter
  • IMP_Search_Filter_Attachment
  • IMP_Search_Filter_Autogenerated
  • IMP_Search_Filter_Builtin
  • IMP_Search_Filter_Bulk
  • IMP_Search_Filter_Contacts
  • IMP_Search_Filter_Mailinglist
  • IMP_Search_Filter_Personal
  • IMP_Search_IteratorFilter
  • IMP_Search_Query
  • IMP_Search_Ui
  • IMP_Search_Vfolder
  • IMP_Search_Vfolder_Builtin
  • IMP_Search_Vfolder_Vinbox
  • IMP_Search_Vfolder_Vtrash
  • IMP_Sentmail
  • IMP_Sentmail_Mongo
  • IMP_Sentmail_Null
  • IMP_Sentmail_Sql
  • IMP_Smartmobile
  • IMP_Spam
  • IMP_Spam_Email
  • IMP_Spam_Null
  • IMP_Spam_Program
  • IMP_Test
  • IMP_Tree_Flist
  • IMP_Tree_Jquerymobile
  • IMP_Tree_Simplehtml
  • IMP_View_Subinfo

Interfaces

  • IMP_Compose_Attachment_Linked
  • IMP_Contacts_Avatar_Backend
  • IMP_Contacts_Flag_Backend
  • IMP_Spam_Base
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2001-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 2001-2014 Horde LLC
 10:  * @license   http://www.horde.org/licenses/gpl GPL
 11:  * @package   IMP
 12:  */
 13: 
 14: /**
 15:  * This class provides an IMP-specific interface to all identities a
 16:  * user might have. Its methods take care of any site-specific
 17:  * restrictions configured in prefs.php and conf.php.
 18:  *
 19:  * @author    Jan Schneider <jan@horde.org>
 20:  * @author    Chuck Hagenbuch <chuck@horde.org>
 21:  * @category  Horde
 22:  * @copyright 2001-2014 Horde LLC
 23:  * @license   http://www.horde.org/licenses/gpl GPL
 24:  * @package   IMP
 25:  */
 26: class IMP_Prefs_Identity extends Horde_Core_Prefs_Identity
 27: {
 28:     /**
 29:      * Cached data.
 30:      *
 31:      * @var array
 32:      */
 33:     protected $_cached = array(
 34:         'aliases' => array(),
 35:         'from' => array(),
 36:         'names' => array(),
 37:         'signatures' => array()
 38:     );
 39: 
 40:     /**
 41:      * Identity preferences added by IMP.
 42:      *
 43:      * @var array
 44:      */
 45:     protected $_impPrefs = array(
 46:         'replyto_addr', 'alias_addr', 'tieto_addr', 'bcc_addr', 'signature',
 47:         'signature_html', 'save_sent_mail', IMP_Mailbox::MBOX_SENT
 48:     );
 49: 
 50:     /**
 51:      * Reads all the user's identities from the prefs object or builds
 52:      * a new identity from the standard values given in prefs.php.
 53:      *
 54:      * @see __construct()
 55:      */
 56:     public function __construct($params)
 57:     {
 58:         $this->_prefnames['properties'] = array_merge(
 59:             $this->_prefnames['properties'],
 60:             $this->_impPrefs
 61:         );
 62: 
 63:         parent::__construct($params);
 64:     }
 65: 
 66:     /**
 67:      */
 68:     public function save()
 69:     {
 70:         global $injector;
 71: 
 72:         parent::save();
 73: 
 74:         /* Changing the ID may change the sent-mail names, so clear the
 75:          * display cache.
 76:          * @todo If identity ID is changed outside of Horde, this won't be
 77:          * caught. */
 78:         $sc = $injector->getInstance('IMP_Mailbox_SessionCache');
 79:         foreach ($this->getAllSentmail() as $val) {
 80:             $sc->expire(IMP_Mailbox_SessionCache::CACHE_DISPLAY, $val);
 81:         }
 82:     }
 83: 
 84:     /**
 85:      * Verifies and sanitizes all identity properties.
 86:      *
 87:      * @param integer $identity  The identity to verify.
 88:      *
 89:      * @throws Horde_Prefs_Exception
 90:      */
 91:     public function verify($identity = null)
 92:     {
 93:         if (!isset($identity)) {
 94:             $identity = $this->getDefault();
 95:         }
 96: 
 97:         /* Fill missing IMP preferences with default values. */
 98:         foreach ($this->_impPrefs as $pref) {
 99:             if (!isset($this->_identities[$identity][$pref])) {
100:                 $this->_identities[$identity][$pref] = $this->_prefs->getValue($pref);
101:             }
102:         }
103: 
104:         parent::verify($identity);
105:     }
106: 
107:     /**
108:      * Returns a complete From: header based on all relevant factors (fullname,
109:      * from address, input fields, locks etc.)
110:      *
111:      * @param integer $ident        The identity to retrieve the values from.
112:      * @param string $from_address  A default from address to use if no
113:      *                              identity is selected and the from_addr
114:      *                              preference is locked.
115:      *
116:      * @return Horde_Mail_Rfc822_Address  The address to use for From header.
117:      * @throws Horde_Exception
118:      */
119:     public function getFromLine($ident = null, $from_address = '')
120:     {
121:         $address = is_null($ident)
122:             ? $from_address
123:             : null;
124: 
125:         if (empty($address) ||
126:             $this->_prefs->isLocked($this->_prefnames['from_addr'])) {
127:             return $this->getFromAddress($ident);
128:         }
129: 
130:         $result = IMP::parseAddressList($address);
131:         return $result[0];
132:     }
133: 
134:     /**
135:      * Returns an array with the necessary values for the identity select
136:      * box in the IMP compose window.
137:      *
138:      * @return array  The array with the necessary strings
139:      */
140:     public function getSelectList()
141:     {
142:         $list = array();
143: 
144:         foreach ($this->getAll($this->_prefnames['id']) as $k => $v) {
145:             $list[$k] = strval($this->getFromAddress($k)) . ' (' . $v . ')';
146:         }
147: 
148:         return $list;
149:     }
150: 
151:     /**
152:      * Returns true if the given address belongs to one of the identities.
153:      * This function will search aliases for an identity automatically.
154:      *
155:      * @param mixed $address  The address(es) to search for in the identities.
156:      *
157:      * @return boolean  True if the address was found.
158:      */
159:     public function hasAddress($address)
160:     {
161:         $from_addr = $this->getAllFromAddresses();
162: 
163:         foreach (IMP::parseAddressList($address)->bare_addresses as $val) {
164:             if ($from_addr->contains($val)) {
165:                 return true;
166:             }
167:         }
168: 
169:         return false;
170:     }
171: 
172:     /**
173:      * Returns the from address based on the chosen identity. If no
174:      * address can be found it is built from the current user name and
175:      * the specified maildomain.
176:      *
177:      * @param integer $ident  The identity to retrieve the address from.
178:      *
179:      * @return Horde_Mail_Rfc822_Address  A valid from address.
180:      */
181:     public function getFromAddress($ident = null)
182:     {
183:         if (is_null($ident)) {
184:             $ident = $this->getDefault();
185:         }
186: 
187:         if (!isset($this->_cached['from'][$ident])) {
188:             $val = $this->getValue($this->_prefnames['from_addr'], $ident);
189:             if (!strlen($val)) {
190:                 $val = $GLOBALS['registry']->getAuth();
191:             }
192: 
193:             if (!strstr($val, '@')) {
194:                 $val .= '@' . $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->config->maildomain;
195:             }
196: 
197:             $ob = new Horde_Mail_Rfc822_Address($val);
198: 
199:             if (is_null($ob->personal)) {
200:                 $ob->personal = $this->getFullname($ident);
201:             }
202: 
203:             $this->_cached['from'][$ident] = $ob;
204:         }
205: 
206:         return $this->_cached['from'][$ident];
207:     }
208: 
209:     /**
210:      * Returns all aliases based on the chosen identity.
211:      *
212:      * @param integer $ident  The identity to retrieve the aliases from.
213:      *
214:      * @return Horde_Mail_Rfc822_List  Aliases for the identity.
215:      */
216:     public function getAliasAddress($ident = null)
217:     {
218:         if (is_null($ident)) {
219:             $ident = $this->getDefault();
220:         }
221: 
222:         if (!isset($this->_cached['aliases'][$ident])) {
223:             $list = IMP::parseAddressList($this->getValue('alias_addr', $ident));
224:             $list->add($this->getValue('replyto_addr', $ident));
225:             $this->_cached['aliases'][$ident] = $list;
226:         }
227: 
228:         return $this->_cached['aliases'][$ident];
229:     }
230: 
231:     /**
232:      * Returns all From addresses for one identity.
233:      *
234:      * @param integer $ident  The identity to retrieve the from addresses
235:      *                        from.
236:      *
237:      * @return Horde_Mail_Rfc822_List  Address list.
238:      */
239:     public function getFromAddresses($ident = null)
240:     {
241:         $list = new Horde_Mail_Rfc822_List($this->getFromAddress($ident));
242:         $list->add($this->getAliasAddress($ident));
243: 
244:         return $list;
245:     }
246: 
247:     /**
248:      * Returns all identities' From addresses.
249:      *
250:      * @return Horde_Mail_Rfc822_List  Address list.
251:      */
252:     public function getAllFromAddresses()
253:     {
254:         $list = new Horde_Mail_Rfc822_List();
255: 
256:         foreach (array_keys($this->_identities) as $key) {
257:             $list->add($this->getFromAddresses($key));
258:         }
259: 
260:         return $list;
261:     }
262: 
263:     /**
264:      * Get tie-to addresses.
265:      *
266:      * @param integer $ident  The identity to retrieve the tie-to addresses
267:      *                        from.
268:      *
269:      * @return Horde_Mail_Rfc822_List  A list of tie-to e-mail addresses.
270:      */
271:     public function getTieAddresses($ident = null)
272:     {
273:         return IMP::parseAddressList($this->getValue('tieto_addr', $ident));
274:     }
275: 
276:     /**
277:      * Get all 'tie to' address/identity pairs.
278:      *
279:      * @return Horde_Mail_Rfc822_List  A list of e-mail addresses.
280:      */
281:     public function getAllTieAddresses()
282:     {
283:         $list = new Horde_Mail_Rfc822_List();
284: 
285:         foreach (array_keys($this->_identities) as $key) {
286:             $list->add($this->getTieAddresses($key));
287:         }
288: 
289:         return $list;
290:     }
291: 
292:     /**
293:      * Returns a list of all e-mail addresses from all identities, including
294:      * both from addresses and tie addreses.
295:      *
296:      * @return Horde_Mail_Rfc822_List  A list of e-mail addresses.
297:      */
298:     public function getAllIdentityAddresses()
299:     {
300:         $list = $this->getAllFromAddresses();
301:         $list->add($this->getAllTieAddresses());
302: 
303:         return $list;
304:     }
305: 
306:     /**
307:      * Returns the list of identities with the default identity positioned
308:      * first.
309:      *
310:      * @return array  The identity keys with the default identity first.
311:      */
312:     protected function _identitiesWithDefaultFirst()
313:     {
314:         $ids = $this->_identities;
315:         $default = $this->getDefault();
316:         unset($ids[$default]);
317:         return array_merge(array($default), array_keys($ids));
318:     }
319: 
320:     /**
321:      * Returns the BCC addresses for a given identity.
322:      *
323:      * @param integer $ident  The identity to retrieve the Bcc addresses from.
324:      *
325:      * @return Horde_Mail_Rfc822_List  BCC addresses.
326:      */
327:     public function getBccAddresses($ident = null)
328:     {
329:         return IMP::parseAddressList($this->getValue('bcc_addr', $ident));
330:     }
331: 
332:     /**
333:      * Returns the identity's id that matches the passed addresses.
334:      *
335:      * @param mixed $addresses     Either an array or a single string or a
336:      *                             comma-separated list of email addresses.
337:      * @param boolean $search_own  Search for a matching identity in own
338:      *                             addresses also?
339:      *
340:      * @return integer  The id of the first identity that from or alias
341:      *                  addresses match (one of) the passed addresses or
342:      *                  null if none matches.
343:      */
344:     public function getMatchingIdentity($addresses, $search_own = true)
345:     {
346:         $addresses = IMP::parseAddressList($addresses);
347:         if (!count($addresses)) {
348:             return null;
349:         }
350: 
351:         foreach ($this->_identitiesWithDefaultFirst() as $key) {
352:             $tie_addr = $this->getTieAddresses($key);
353: 
354:             /* Search 'tieto' addresses first. Check for address first
355:              * and, if not found, check for the domain. */
356:             if (count($tie_addr)) {
357:                 foreach ($addresses as $val) {
358:                     foreach ($tie_addr as $val2) {
359:                         if (($val->bare_address == $val2->bare_address) &&
360:                             (strcasecmp($val->host, $val2->host) === 0)) {
361:                             return $key;
362:                         }
363:                     }
364:                 }
365:             }
366: 
367:             /* Next, search all from addresses. */
368:             if ($search_own) {
369:                 $from = $this->getFromAddresses($key);
370:                 foreach ($addresses as $val) {
371:                     if ($from->contains($val)) {
372:                         return $key;
373:                     }
374:                 }
375:             }
376:         }
377: 
378:         return null;
379:     }
380: 
381:     /**
382:      * Returns the user's full name.
383:      *
384:      * @param integer $ident  The identity to retrieve the name from.
385:      *
386:      * @return string  The user's full name.
387:      */
388:     public function getFullname($ident = null)
389:     {
390:         if (is_null($ident)) {
391:             $ident = $this->getDefault();
392:         }
393: 
394:         if (isset($this->_cached['names'][$ident])) {
395:             return $this->_cached['names'][$ident];
396:         }
397: 
398:         $this->_cached['names'][$ident] = $this->getValue($this->_prefnames['fullname'], $ident);
399: 
400:         return $this->_cached['names'][$ident];
401:     }
402: 
403:     /**
404:      * Returns the full signature based on the current settings for the
405:      * signature itself, the dashes and the position.
406:      *
407:      * @param string $type    Either 'text' or 'html'.
408:      * @param integer $ident  The identity to retrieve the signature from.
409:      *
410:      * @return string  The full signature.
411:      * @throws Horde_Exception
412:      */
413:     public function getSignature($type = 'text', $ident = null)
414:     {
415:         if (is_null($ident)) {
416:             $ident = $this->getDefault();
417:         }
418: 
419:         $convert = false;
420:         $key = $ident . '|' . $type;
421:         $val = null;
422: 
423:         if (isset($this->_cached['signatures'][$key])) {
424:             return $this->_cached['signatures'][$key];
425:         }
426: 
427:         if ($type == 'html') {
428:             $val = $this->getValue('signature_html', $ident);
429:             if (!strlen($val)) {
430:                 $convert = true;
431:                 $val = null;
432:             }
433:         }
434: 
435:         if (is_null($val)) {
436:             $val = $this->getValue('signature', $ident);
437: 
438:             if (strlen($val) && ($type == 'text')) {
439:                 $val = str_replace("\r\n", "\n", $val);
440:                 $val = ($this->getValue('sig_dashes', $ident))
441:                     ? "\n-- \n" . $val
442:                     : "\n\n" . $val;
443:             }
444:         }
445: 
446:         if ($val && ($type == 'html')) {
447:             if ($convert) {
448:                 $val = IMP_Compose::text2html(trim($val));
449:             }
450: 
451:             $val = '<div>' . $val . '</div>';
452:         }
453: 
454:         $this->_cached['signatures'][$key] = $val;
455: 
456:         return $val;
457:     }
458: 
459:     /**
460:      * Returns an array with the signatures from all identities
461:      *
462:      * @param string $type  Either 'text' or 'html'.
463:      *
464:      * @return array  The array with all the signatures.
465:      */
466:     public function getAllSignatures($type = 'text')
467:     {
468:         foreach (array_keys($this->_identities) as $key) {
469:             $list[$key] = $this->getSignature($type, $key);
470:         }
471: 
472:         return $list;
473:     }
474: 
475:     /**
476:      * Does the user have any signatures (either text or HTML)?
477:      *
478:      * @param boolean $compose_page  If true, checks for signatures as used on
479:      *                               the compose pages.
480:      *
481:      * @return boolean  True if the user has at least one signature.
482:      */
483:     public function hasSignature($compose_page = false)
484:     {
485:         global $prefs;
486: 
487:         if (!$compose_page || $prefs->getValue('signature_show_compose')) {
488:             foreach (array_keys($this->_identities) as $key) {
489:                 if (strlen(trim($this->getValue('signature_html', $key))) ||
490:                     strlen(trim($this->getValue('signature', $key)))) {
491:                     return true;
492:                 }
493:             }
494:         }
495: 
496:         return false;
497:     }
498: 
499:     /**
500:      * Returns a property from one of the identities.
501:      *
502:      * @see getValue()
503:      */
504:     public function getValue($key, $identity = null)
505:     {
506:         $val = parent::getValue($key, $identity);
507: 
508:         switch ($key) {
509:         case IMP_Mailbox::MBOX_SENT:
510:             return (is_string($val) && strlen($val))
511:                 ? IMP_Mailbox::get(IMP_Mailbox::prefFrom($val))
512:                 : null;
513: 
514:         default:
515:             return $val;
516:         }
517:     }
518: 
519:     /**
520:      * Sets a property with a specified value.
521:      *
522:      * @see setValue()
523:      */
524:     public function setValue($key, $val, $identity = null)
525:     {
526:         switch ($key) {
527:         case 'alias_addr':
528:         case 'bcc_addr':
529:         case 'replyto_addr':
530:         case 'tieto_addr':
531:             if (is_string($val) && (strpbrk($val, "\r\n") !== false)) {
532:                 $val = preg_split("/[\r\n]+/", $val);
533:             }
534: 
535:             /* Validate Reply-To, Alias, Tie-to, and BCC addresses. */
536:             $ob = IMP::parseAddressList($val, array(
537:                 'limit' => ($val == 'replyto_addr') ? 1 : 0
538:             ));
539: 
540:             foreach ($ob as $address) {
541:                 try {
542:                     IMP::parseAddressList($address, array(
543:                         'validate' => true
544:                     ));
545:                 } catch (Horde_Mail_Exception $e) {
546:                     throw new Horde_Prefs_Exception(sprintf(_("\"%s\" is not a valid email address.", strval($address))));
547:                 }
548:             }
549:             $val = $ob->addresses;
550:             break;
551: 
552:         case IMP_Mailbox::MBOX_SENT:
553:             $GLOBALS['injector']->getInstance('IMP_Mailbox_SessionCache')
554:                 ->expire(IMP_Mailbox_SessionCache::CACHE_SPECIALMBOXES);
555:             $val = IMP_Mailbox::prefTo($val);
556:             break;
557:         }
558: 
559:         return parent::setValue($key, $val, $identity);
560:     }
561: 
562:     /**
563:      * Returns an array with the sent-mail mailboxes from all identities.
564:      *
565:      * @param boolean $unique  If true, return the unique list of sent-mail
566:      *                         mailboxes. If false, returns list of
567:      *                         sent-mail mailboxes, with the key corresponding
568:      *                         to the identity.
569:      *
570:      * @return array  The array with the sent-mail IMP_Mailbox objects.
571:      */
572:     public function getAllSentmail($unique = true)
573:     {
574:         $list = array();
575: 
576:         foreach (array_keys($this->_identities) as $key) {
577:             if ($mbox = $this->getValue(IMP_Mailbox::MBOX_SENT, $key)) {
578:                 $list[$key] = $mbox;
579:             }
580:         }
581: 
582:         return $unique
583:             ? array_unique($list)
584:             : $list;
585:     }
586: 
587:     /**
588:      * Returns true if the mail should be saved and the user is allowed to.
589:      *
590:      * @param integer $ident  The identity to retrieve the setting from.
591:      *
592:      * @return boolean  True if the sent mail should be saved.
593:      */
594:     public function saveSentmail($ident = null)
595:     {
596:         return $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)
597:             ? $this->getValue('save_sent_mail', $ident)
598:             : false;
599:     }
600: 
601: }
602: 
API documentation generated by ApiGen