Test Failed
Push — master ( 647c72...cd42b5 )
by
unknown
10:25
created

ExpandDistlistModule::expandDist()   B

Complexity

Conditions 8
Paths 3

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 19
nc 3
nop 3
dl 0
loc 37
rs 8.4444
c 1
b 0
f 0
1
<?php
2
	/**
3
	 * ExpandDistlist Module
4
	 */
5
	class ExpandDistlistModule extends Module
6
	{
7
		/**
8
		 * Constructor
9
		 */
10
		function __construct($id, $data)
11
		{
12
			parent::__construct($id, $data);
13
14
			$this->properties = $GLOBALS["properties"]->getRecipientProperties();
0 ignored issues
show
Bug Best Practice introduced by
The property properties does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15
		}
16
17
		/**
18
		 * Executes all the actions in the $data variable.
19
		 */
20
		function execute()
21
		{
22
			foreach($this->data as $actionType => $action)
23
			{
24
				if(isset($actionType)) {
25
					try {
26
						switch($actionType)
27
						{
28
							case 'expand':
29
								$this->expand($action);
30
								break;
31
							default:
32
								$this->handleUnknownActionType($actionType);
33
						}
34
					} catch (MAPIException $e) {
35
						$this->processException($e, $actionType);
36
					}
37
				}
38
			}
39
		}
40
41
		/**
42
		 * Function which expands a distribution list, optionally expands a distribution list in a distribution list.
43
		 * Duplicate members will not be be filtered.
44
		 *
45
		 * @param string $entryid entryid of distribution list.
46
		 * @param array $data an array of members in the distribution list.
47
		 * @param boolean $isRecurse true if we want to expand a distribution list in distribution lists.
48
		 * @return array $data an array of members in the distribution list.
49
		 */
50
		function expandDist($entryid, $data = Array(), $isRecurse = false)
51
		{
52
			$heid = bin2hex($entryid);
53
			if($GLOBALS['entryid']->hasAddressBookGUID($heid) || $GLOBALS['entryid']->hasAddressBookRecipientGUID($heid)) {
54
				$abentry = mapi_ab_openentry($this->addrbook, $entryid);
55
				$table = mapi_folder_getcontentstable($abentry, MAPI_DEFERRED_ERRORS);
56
				$rows = mapi_table_queryrows($table, $this->properties, 0, (ABITEMDETAILS_MAX_NUM_DISTLIST_MEMBERS > 0) ? ABITEMDETAILS_MAX_NUM_DISTLIST_MEMBERS : 0x7fffffff);
57
				/*
58
				 * To prevent loading a huge list that the browser cannot handle, it is possible to
59
				 * limit the maximum number of shown items. Note that when the table doesn't
60
				 * contain the requested number of rows, it will not give any errors and simply
61
				 * return what is available.
62
				 * When the limit is 0 or below, then no limit is applied and we use 0x7fffffff
63
				 * to indicate we want to have all rows from the table.
64
				 */
65
				for ($i = 0, $len = count($rows); $i < $len; $i++) {
66
					$memberProps = Conversion::mapMAPI2XML($this->properties, $rows[$i]);
67
					$isDistlist = $memberProps['props']['object_type'] == MAPI_DISTLIST;
68
					if ($isDistlist && $isRecurse == True) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
69
						$data = array_merge($data, $this->expandDist(hex2bin($memberProps['entryid']), array(), $isRecurse));
70
					} else {
71
						$data[] = $memberProps;
72
					}
73
				}
74
			} else {
75
				/**
76
				 * If distribution list was belongs to local/shared folder then
77
				 * it will expand all members of distribution list.
78
				 */
79
				$distlistMembers = $GLOBALS['operations']->expandDistList($heid, $isRecurse);
80
				$recipients = array();
81
				foreach($distlistMembers as $distlistMember) {
82
					$recipients['props'] = $distlistMember;
83
					array_push($data, $recipients);
84
				}
85
			}
86
			return $data;
87
		}
88
89
		/**
90
		 * Function which expand the distribution list, sent by the client. This function is used
91
		 * when a user wants to replace the distribution list with its members
92
		 * in the to, cc and bcc field. This function retrieve members of that particular distribution list
93
		 * and send that list back to the client.
94
		 * @param array $action the action data, sent by the client
95
		 */
96
		function expand($action)
97
		{
98
			// Get the distribution list entryid from request
99
			$entryid = hex2bin($action["entryid"]);
100
			$this->addrbook = $GLOBALS["mapisession"]->getAddressbook();
0 ignored issues
show
Bug Best Practice introduced by
The property addrbook does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
101
102
			if($entryid) {
103
				$data["results"] = $this->expandDist($entryid, array(), $action['recurse']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
104
				$this->addActionData("expand", $data);
105
				$GLOBALS["bus"]->addData($this->getResponseData());
106
			}
107
		}
108
	}
109
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
110