alecpl
2012-04-14 1495ac7913095ae8284c3501b7d4e6dd31a484ec
commit | author | age
0c2596 1 <?php
A 2
3 /**
4  +-----------------------------------------------------------------------+
5  | program/include/rcube_message_header.php                              |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2005-2012, The Roundcube Dev Team                       |
9  | Copyright (C) 2011-2012, Kolab Systems AG                             |
10  |                                                                       |
11  | Licensed under the GNU General Public License version 3 or            |
12  | any later version with exceptions for skins & plugins.                |
13  | See the README file for a full license statement.                     |
14  |                                                                       |
15  | PURPOSE:                                                              |
16  |   E-mail message headers representation                               |
17  |                                                                       |
18  +-----------------------------------------------------------------------+
19  | Author: Aleksander Machniak <alec@alec.pl>                            |
20  +-----------------------------------------------------------------------+
21
22  $Id$
23
24 */
25
26 /**
27  * Struct representing an e-mail message header
28  *
29  * @package Mail
30  * @author  Aleksander Machniak <alec@alec.pl>
31  */
32 class rcube_message_header
33 {
34     /**
35      * Message sequence number
36      *
37      * @var int
38      */
39     public $id;
40
41     /**
42      * Message unique identifier
43      *
44      * @var int
45      */
46     public $uid;
47
48     /**
49      * Message subject
50      *
51      * @var string
52      */
53     public $subject;
54
55     /**
56      * Message sender (From)
57      *
58      * @var string
59      */
60     public $from;
61
62     /**
63      * Message recipient (To)
64      *
65      * @var string
66      */
67     public $to;
68
69     /**
70      * Message additional recipients (Cc)
71      *
72      * @var string
73      */
74     public $cc;
75
76     /**
77      * Message Reply-To header
78      *
79      * @var string
80      */
81     public $replyto;
82
83     /**
84      * Message In-Reply-To header
85      *
86      * @var string
87      */
88     public $in_reply_to;
89
90     /**
91      * Message date (Date)
92      *
93      * @var string
94      */
95     public $date;
96
97     /**
98      * Message identifier (Message-ID)
99      *
100      * @var string
101      */
102     public $messageID;
103
104     /**
105      * Message size
106      *
107      * @var int
108      */
109     public $size;
110
111     /**
112      * Message encoding
113      *
114      * @var string
115      */
116     public $encoding;
117
118     /**
119      * Message charset
120      *
121      * @var string
122      */
123     public $charset;
124
125     /**
126      * Message Content-type
127      *
128      * @var string
129      */
130     public $ctype;
131
132     /**
133      * Message timestamp (based on message date)
134      *
135      * @var int
136      */
137     public $timestamp;
138
139     /**
140      * IMAP bodystructure string
141      *
142      * @var string
143      */
144     public $bodystructure;
145
146     /**
147      * IMAP internal date
148      *
149      * @var string
150      */
151     public $internaldate;
152
153     /**
154      * Message References header
155      *
156      * @var string
157      */
158     public $references;
159
160     /**
161      * Message priority (X-Priority)
162      *
163      * @var int
164      */
165     public $priority;
166
167     /**
168      * Message receipt recipient
169      *
170      * @var string
171      */
172     public $mdn_to;
173
174     /**
175      * Other message headers
176      *
177      * @var array
178      */
179     public $others = array();
180
181     /**
182      * Message flags
183      *
184      * @var array
185      */
186     public $flags = array();
187 }
188
189
190 /**
191  * Class for sorting an array of rcube_message_header objects in a predetermined order.
192  *
193  * @package Mail
194  * @author  Aleksander Machniak <alec@alec.pl>
195  */
196 class rcube_message_header_sorter
197 {
198     private $uids = array();
199
200
201     /**
202      * Set the predetermined sort order.
203      *
204      * @param array $index  Numerically indexed array of IMAP UIDs
205      */
206     function set_index($index)
207     {
208         $index = array_flip($index);
209
210         $this->uids = $index;
211     }
212
213     /**
214      * Sort the array of header objects
215      *
216      * @param array $headers Array of rcube_message_header objects indexed by UID
217      */
218     function sort_headers(&$headers)
219     {
220         uksort($headers, array($this, "compare_uids"));
221     }
222
223     /**
224      * Sort method called by uksort()
225      *
226      * @param int $a Array key (UID)
227      * @param int $b Array key (UID)
228      */
229     function compare_uids($a, $b)
230     {
231         // then find each sequence number in my ordered list
232         $posa = isset($this->uids[$a]) ? intval($this->uids[$a]) : -1;
233         $posb = isset($this->uids[$b]) ? intval($this->uids[$b]) : -1;
234
235         // return the relative position as the comparison value
236         return $posa - $posb;
237     }
238 }