Overview

Packages

  • Imap
    • Client

Classes

  • Horde_Imap_Client
  • Horde_Imap_Client_Auth_DigestMD5
  • Horde_Imap_Client_Base
  • Horde_Imap_Client_Cache
  • Horde_Imap_Client_Data_Acl
  • Horde_Imap_Client_Data_AclCommon
  • Horde_Imap_Client_Data_AclNegative
  • Horde_Imap_Client_Data_AclRights
  • Horde_Imap_Client_Data_Envelope
  • Horde_Imap_Client_Data_Fetch
  • Horde_Imap_Client_Data_Fetch_Pop3
  • Horde_Imap_Client_Data_Thread
  • Horde_Imap_Client_DateTime
  • Horde_Imap_Client_Exception
  • Horde_Imap_Client_Exception_NoSupportExtension
  • Horde_Imap_Client_Fetch_Query
  • Horde_Imap_Client_Ids
  • Horde_Imap_Client_Ids_Pop3
  • Horde_Imap_Client_Mailbox
  • Horde_Imap_Client_Search_Query
  • Horde_Imap_Client_Socket
  • Horde_Imap_Client_Socket_Pop3
  • Horde_Imap_Client_Sort
  • Horde_Imap_Client_Translation
  • Horde_Imap_Client_Utf7imap
  • Horde_Imap_Client_Utils
  • Horde_Imap_Client_Utils_Pop3
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Utility functions for the Horde IMAP client - POP3 specific methods.
 4:  *
 5:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file COPYING for license information (LGPL). If you
 8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 9:  *
10:  * @author   Michael Slusarz <slusarz@horde.org>
11:  * @category Horde
12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
13:  * @package  Imap_Client
14:  */
15: class Horde_Imap_Client_Utils_Pop3 extends Horde_Imap_Client_Utils
16: {
17:     /**
18:      * Create a POP3 message sequence string from a list of UIDs.
19:      *
20:      * Index Format: {P[length]}UID1{P[length]}UID2...
21:      *
22:      * @param mixed $in       An array of UIDs (or a single UID).
23:      * @param array $options  Additional options. 'nosort' is not used in
24:      *                        this class.
25:      *
26:      * @return string  The POP3 message sequence string.
27:      */
28:     public function toSequenceString($in, $options = array())
29:     {
30:         if (!is_array($in)) {
31:             if (!strlen($in)) {
32:                 return '';
33:             }
34:             $in = array($in);
35:         } elseif (!empty($options['mailbox'])) {
36:             $tmp = $in;
37:             $in = array();
38:             foreach ($tmp as $val) {
39:                 $in = array_merge($in, $val);
40:             }
41:         }
42: 
43:         $str = '';
44: 
45:         // Make sure IDs are unique
46:         foreach (array_keys(array_flip($in)) as $val) {
47:             $str .= '{P' . strlen($val) . '}' . $val;
48:         }
49: 
50:         return $str;
51:     }
52: 
53:     /**
54:      * Parse a POP3 message sequence string into a list of indices.
55:      *
56:      * @param string $str  The POP3 message sequence string.
57:      *
58:      * @return array  An array of UIDs.
59:      */
60:     public function fromSequenceString($str)
61:     {
62:         $ids = array();
63:         $str = trim($str);
64: 
65:         while (strlen($str)) {
66:             /* Check for valid beginning of UID. */
67:             if (substr($str, 0, 2) != '{P') {
68:                 /* Assume this is the entire UID, if there is no other
69:                  * data. Otherwise, ignore garbage data. */
70:                 if (empty($ids)) {
71:                     $ids[] = $str;
72:                 }
73:                 break;
74:             }
75: 
76:             $i = strpos($str, '}', 2);
77:             $size = intval(substr($str, 2, $i - 2));
78:             $ids[] = substr($str, $i + 1, $size);
79: 
80:             $str = substr($str, $i + 1 + $size);
81:         }
82: 
83:         return $ids;
84:     }
85: 
86: }
87: 
API documentation generated by ApiGen