1: <?php
2: /**
3: * Copyright 2012-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 2012-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Utility methods to parse address lists used by dynamic code.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2012-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Dynamic_AddressList
24: {
25: /**
26: * Parse an address list created by the dynamic view JS code.
27: *
28: * @param string $json JSON input code.
29: *
30: * @return Horde_Mail_Rfc822_List A list of addresses.
31: */
32: public function parseAddressList($json)
33: {
34: $data = json_decode($json);
35: $out = new Horde_Mail_Rfc822_List();
36:
37: if (isset($data->g)) {
38: $addrs = $data->a;
39: $ob = new Horde_Mail_Rfc822_Group($data->g);
40: $ob_add = $ob->addresses;
41: $out->add($ob);
42: } else {
43: $addrs = array($data);
44: $ob_add = $out;
45: }
46:
47: foreach ($addrs as $jval) {
48: $addr_ob = new Horde_Mail_Rfc822_Address($jval->b);
49: if (isset($jval->p)) {
50: $addr_ob->personal = $jval->p;
51: }
52: $ob_add->add($addr_ob);
53: }
54:
55: return $out;
56: }
57:
58: }
59: